rpuch commented on code in PR #7232:
URL: https://github.com/apache/ignite-3/pull/7232#discussion_r2619488420


##########
modules/index/src/integrationTest/java/org/apache/ignite/internal/index/IndexBuildTestUtils.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.index;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static 
org.apache.ignite.internal.index.ItBuildIndexTest.getIndexDescriptor;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static org.apache.ignite.internal.table.TableTestUtils.getIndexStrict;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.Cluster;
+import org.apache.ignite.internal.TestWrappers;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.storage.StorageException;
+import org.apache.ignite.internal.storage.index.IndexRow;
+import org.apache.ignite.internal.storage.index.IndexStorage;
+import org.apache.ignite.internal.storage.index.SortedIndexStorage;
+import org.apache.ignite.internal.table.TableViewInternal;
+import org.apache.ignite.internal.util.Cursor;
+import org.apache.ignite.sql.IgniteSql;
+import org.apache.ignite.table.Table;
+import org.jetbrains.annotations.Nullable;
+
+class IndexBuildTestUtils {
+    private static final IgniteLogger LOG = 
Loggers.forClass(IndexBuildTestUtils.class);
+
+    private static final String ZONE_NAME = "ZONE_TABLE";
+
+    static final String TABLE_NAME = "TEST_TABLE";
+
+    static final String INDEX_NAME = "TEST_INDEX";
+
+    static void createTestTable(Cluster cluster, int replicas, int partitions) 
{
+        IgniteSql sql = cluster.node(0).sql();
+
+        sql.executeScript(format("CREATE ZONE IF NOT EXISTS {} (REPLICAS {}, 
PARTITIONS {}) STORAGE PROFILES ['{}']",
+                ZONE_NAME, replicas, partitions, DEFAULT_STORAGE_PROFILE
+        ));
+        sql.executeScript(format(
+                "CREATE TABLE {} (i0 INTEGER PRIMARY KEY, i1 INTEGER) ZONE {}",
+                TABLE_NAME, ZONE_NAME
+        ));
+    }
+
+    static void createIndex(Cluster cluster, String indexName) {
+        // We execute this operation asynchronously, because some tests block 
network messages, which makes the underlying code
+        // stuck with timeouts. We don't need to wait for the operation to 
complete, as we wait for the necessary invariants further
+        // below.
+        cluster.aliveNode().sql()
+                .executeAsync(null, format("CREATE INDEX {} ON {} (i1)", 
indexName, TABLE_NAME))
+                .whenComplete((res, ex) -> {
+                    if (ex != null) {
+                        LOG.error("Failed to create index", ex);
+                    }
+                });
+
+        waitForIndex(cluster, indexName);
+    }
+
+    /**
+     * Waits for all nodes in the cluster to have the given index in the 
Catalog.
+     *
+     * @param indexName Name of an index to wait for.
+     */
+    static void waitForIndex(Cluster cluster, String indexName) {
+        await().atMost(10, SECONDS).until(
+                () -> cluster.runningNodes()
+                        .map(TestWrappers::unwrapIgniteImpl)
+                        .map(node -> getIndexDescriptor(node, indexName))
+                        .allMatch(Objects::nonNull)
+        );
+    }
+
+    static void verifyNoNodesHaveAnythingInIndex(Cluster cluster, int 
initialNodes) {

Review Comment:
   Currently it's 'verify no nodes have anything in index' which seems to be 
exactly what it checks. We could invert first 'no', but we would need to 
replace it 'all', like 'verify all nodes have nothing in index'. TBH, I like 
the original name more.



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