lowka commented on code in PR #2712:
URL: https://github.com/apache/ignite-3/pull/2712#discussion_r1399237554


##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java:
##########
@@ -227,4 +266,64 @@ public Person(int id, String name, double salary) {
             this.salary = salary;
         }
     }
+
+    /**
+     * Waits for some amount of time so that read-only transactions can 
observe the most recent version of the catalog.
+     */
+    protected static void waitForReadTimestampThatObservesMostRecentCatalog()  
{
+        // See TxManagerImpl::currentReadTimestamp.
+        long delay = HybridTimestamp.CLOCK_SKEW + 
TestIgnitionManager.DEFAULT_PARTITION_IDLE_SYNC_TIME_INTERVAL_MS;
+        try {
+            TimeUnit.MILLISECONDS.sleep(delay);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static List<List<Object>> executeAwaitingIndexes(IgniteImpl node, 
Function<IgniteImpl, List<List<Object>>> statement) {
+        CatalogManager catalogManager = node.catalogManager();
+
+        // Get existing indexes
+        Set<Integer> existing = 
catalogManager.indexes(catalogManager.latestCatalogVersion())
+                .stream().map(CatalogObjectDescriptor::id)
+                .collect(Collectors.toSet());
+
+        List<List<Object>> result = statement.apply(node);
+
+        // Get indexes after a statement and compute the difference
+        Set<Integer> difference = 
catalogManager.indexes(catalogManager.latestCatalogVersion()).stream()
+                .map(CatalogObjectDescriptor::id)
+                .collect(Collectors.toSet());
+
+        difference.removeAll(existing);
+
+        if (difference.isEmpty()) {
+            return result;
+        }
+
+        // If there are new indexes, wait for them to become available.
+
+        try {
+            waitForCondition(() -> {
+                int latestVersion = catalogManager.latestCatalogVersion();
+                int notAvailable = 0;
+
+                for (CatalogIndexDescriptor index : 
catalogManager.indexes(latestVersion)) {
+                    if (!index.available() && difference.contains(index.id())) 
{
+                        notAvailable++;
+                    }
+                }
+
+                return notAvailable == 0;
+            }, 10_000);
+
+            waitForReadTimestampThatObservesMostRecentCatalog();

Review Comment:
   We have to use some form of computation -  if we only use the constant, we 
get flaky test, since TxManagerImpl::currentReadTimestamp has an additional 
delay. We can multiple this constant by some number.



##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java:
##########
@@ -227,4 +266,64 @@ public Person(int id, String name, double salary) {
             this.salary = salary;
         }
     }
+
+    /**
+     * Waits for some amount of time so that read-only transactions can 
observe the most recent version of the catalog.
+     */
+    protected static void waitForReadTimestampThatObservesMostRecentCatalog()  
{
+        // See TxManagerImpl::currentReadTimestamp.
+        long delay = HybridTimestamp.CLOCK_SKEW + 
TestIgnitionManager.DEFAULT_PARTITION_IDLE_SYNC_TIME_INTERVAL_MS;
+        try {
+            TimeUnit.MILLISECONDS.sleep(delay);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static List<List<Object>> executeAwaitingIndexes(IgniteImpl node, 
Function<IgniteImpl, List<List<Object>>> statement) {
+        CatalogManager catalogManager = node.catalogManager();
+
+        // Get existing indexes
+        Set<Integer> existing = 
catalogManager.indexes(catalogManager.latestCatalogVersion())
+                .stream().map(CatalogObjectDescriptor::id)
+                .collect(Collectors.toSet());
+
+        List<List<Object>> result = statement.apply(node);
+
+        // Get indexes after a statement and compute the difference
+        Set<Integer> difference = 
catalogManager.indexes(catalogManager.latestCatalogVersion()).stream()
+                .map(CatalogObjectDescriptor::id)
+                .collect(Collectors.toSet());
+
+        difference.removeAll(existing);
+
+        if (difference.isEmpty()) {
+            return result;
+        }
+
+        // If there are new indexes, wait for them to become available.
+
+        try {
+            waitForCondition(() -> {
+                int latestVersion = catalogManager.latestCatalogVersion();
+                int notAvailable = 0;
+
+                for (CatalogIndexDescriptor index : 
catalogManager.indexes(latestVersion)) {
+                    if (!index.available() && difference.contains(index.id())) 
{
+                        notAvailable++;
+                    }
+                }
+
+                return notAvailable == 0;
+            }, 10_000);
+
+            waitForReadTimestampThatObservesMostRecentCatalog();

Review Comment:
   We have to use some form of computation -  if we only use the constant, we 
get flaky test, since TxManagerImpl::currentReadTimestamp has an additional 
delay. We can multiply this constant by some number.



-- 
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