tkalkirill commented on code in PR #3446:
URL: https://github.com/apache/ignite-3/pull/3446#discussion_r1533368888


##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/TableUtilsTest.java:
##########
@@ -35,95 +37,163 @@
 import static org.apache.ignite.internal.util.IgniteUtils.closeAll;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 
 import java.util.List;
-import java.util.function.Consumer;
 import org.apache.ignite.internal.catalog.CatalogManager;
-import org.apache.ignite.internal.catalog.CatalogService;
 import org.apache.ignite.internal.catalog.CatalogTestUtils;
 import org.apache.ignite.internal.hlc.HybridClock;
 import org.apache.ignite.internal.hlc.HybridClockImpl;
 import org.apache.ignite.internal.hlc.HybridTimestamp;
 import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /** For {@link TableUtils} testing. */
 public class TableUtilsTest extends IgniteAbstractTest {
     private final HybridClock clock = new HybridClockImpl();
 
-    @Test
-    void testIndexIdsAtRwTxBeginTs() throws Exception {
-        withCatalogManager(catalogManager -> {
-            createSimpleTable(catalogManager, TABLE_NAME);
-
-            String indexName0 = INDEX_NAME + 0;
-            String indexName1 = INDEX_NAME + 1;
-            String indexName2 = INDEX_NAME + 2;
-            String indexName3 = INDEX_NAME + 3;
-            String indexName4 = INDEX_NAME + 4;
-
-            for (String indexName : List.of(indexName0, indexName1, 
indexName2, indexName3, indexName4)) {
-                createSimpleHashIndex(catalogManager, TABLE_NAME, indexName);
-            }
-
-            int indexId0 = indexId(catalogManager, indexName0);
-            int indexId1 = indexId(catalogManager, indexName1);
-            int indexId2 = indexId(catalogManager, indexName2);
-            int indexId3 = indexId(catalogManager, indexName3);
-            int indexId4 = indexId(catalogManager, indexName4);
-
-            for (String indexName : List.of(indexName1, indexName2, 
indexName3, indexName4)) {
-                startBuildingIndex(catalogManager, indexId(catalogManager, 
indexName));
-            }
-
-            for (String indexName : List.of(indexName2, indexName3, 
indexName4)) {
-                makeIndexAvailable(catalogManager, indexId(catalogManager, 
indexName));
-            }
-
-            for (String indexName : List.of(indexName3, indexName4)) {
-                dropIndex(catalogManager, DEFAULT_SCHEMA_NAME, indexName);
-            }
-
-            removeIndex(catalogManager, indexId4);
-
-            CatalogManager spy = spy(catalogManager);
-
-            HybridTimestamp beginTs = clock.now();
-
-            int tableId = getTableIdStrict(catalogManager, TABLE_NAME, 
clock.nowLong());
-
-            assertThat(
-                    indexIdsAtRwTxBeginTs(spy, transactionId(beginTs, 1), 
tableId),
-                    contains(
-                            indexId(catalogManager, pkIndexName(TABLE_NAME)),
-                            indexId0,
-                            indexId1,
-                            indexId2,
-                            indexId3
-                    )
-            );
-
-            verify(spy).activeCatalogVersion(eq(beginTs.longValue()));
-            
verify(spy).indexes(eq(catalogManager.activeCatalogVersion(beginTs.longValue())),
 eq(tableId));
-        });
+    private final CatalogManager catalogManager = 
CatalogTestUtils.createTestCatalogManager("test-node", clock);
+
+    @BeforeEach
+    void setUp() {
+        assertThat(catalogManager.start(), willCompleteSuccessfully());
+    }
+
+    @AfterEach
+    void tearDown() throws Exception {
+        closeAll(
+                catalogManager::beforeNodeStop,
+                catalogManager::stop
+        );
     }
 
-    private void withCatalogManager(Consumer<CatalogManager> consumer) throws 
Exception {
-        CatalogManager catalogManager = 
CatalogTestUtils.createTestCatalogManager("test-node", clock);
+    @Test
+    void testIndexIdsAtRwTxBeginTs() {
+        createSimpleTable(catalogManager, TABLE_NAME);
 
-        assertThat(catalogManager.start(), willCompleteSuccessfully());
+        String indexName0 = INDEX_NAME + 0;
+        String indexName1 = INDEX_NAME + 1;
+        String indexName2 = INDEX_NAME + 2;
+        String indexName3 = INDEX_NAME + 3;
+        String indexName4 = INDEX_NAME + 4;
 
-        try {
-            consumer.accept(catalogManager);
-        } finally {
-            closeAll(catalogManager::beforeNodeStop, catalogManager::stop);
+        for (String indexName : List.of(indexName0, indexName1, indexName2, 
indexName3, indexName4)) {
+            createSimpleHashIndex(catalogManager, TABLE_NAME, indexName);
         }
+
+        int indexId0 = indexId(indexName0);
+        int indexId1 = indexId(indexName1);
+        int indexId2 = indexId(indexName2);
+        int indexId3 = indexId(indexName3);
+        int indexId4 = indexId(indexName4);
+
+        for (String indexName : List.of(indexName1, indexName2, indexName3, 
indexName4)) {
+            startBuildingIndex(catalogManager, indexId(indexName));
+        }
+
+        for (String indexName : List.of(indexName2, indexName3, indexName4)) {
+            makeIndexAvailable(catalogManager, indexId(indexName));
+        }
+
+        for (String indexName : List.of(indexName3, indexName4)) {
+            dropIndex(catalogManager, DEFAULT_SCHEMA_NAME, indexName);
+        }
+
+        removeIndex(catalogManager, indexId4);
+
+        CatalogManager spy = spy(catalogManager);
+
+        HybridTimestamp beginTs = clock.now();
+
+        int tableId = getTableIdStrict(catalogManager, TABLE_NAME, 
clock.nowLong());
+
+        assertThat(
+                indexIdsAtRwTxBeginTs(spy, transactionId(beginTs, 1), tableId),
+                contains(
+                        indexId(pkIndexName(TABLE_NAME)),
+                        indexId0,
+                        indexId1,
+                        indexId2,
+                        indexId3
+                )
+        );
+
+        verify(spy).activeCatalogVersion(eq(beginTs.longValue()));
+        
verify(spy).indexes(eq(catalogManager.activeCatalogVersion(beginTs.longValue())),
 eq(tableId));
+    }
+
+    @Test
+    void testDroppedTables() {
+        String tableName0 = TABLE_NAME + 0;
+        String tableName1 = TABLE_NAME + 1;
+        String tableName2 = TABLE_NAME + 2;
+
+        createSimpleTable(catalogManager, tableName0);
+        createSimpleTable(catalogManager, tableName1);
+        createSimpleTable(catalogManager, tableName2);
+
+        int tableId0 = tableId(tableName0);
+        int tableId1 = tableId(tableName1);
+
+        int catalogVersionBeforeRemoveTable1 = 
catalogManager.latestCatalogVersion();
+        dropSimpleTable(catalogManager, tableName1);
+
+        int catalogVersionBeforeRemoveTable0 = 
catalogManager.latestCatalogVersion();
+        dropSimpleTable(catalogManager, tableName0);
+
+        assertThat(droppedTables(null), empty());
+        
assertThat(droppedTables(catalogTime(catalogVersionBeforeRemoveTable1)), 
empty());
+        
assertThat(droppedTables(catalogTime(catalogVersionBeforeRemoveTable1).addPhysicalTime(1)),
 empty());

Review Comment:
   It checks that not only the directory version is working correctly for the 
duration of activation, but also for a slightly longer period of time. I can 
remove the check if you wish.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to