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


##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java:
##########
@@ -185,6 +185,42 @@ protected static void insertPersons(String tableName, 
Person... people) {
         );
     }
 
+    /**
+     * Updates data in the table created by {@link #createZoneAndTable(String, 
String, int, int)}.
+     *
+     * @param tableName Table name.
+     * @param people People to update in the table.
+     */
+    protected static void updatePersons(String tableName, Person... people) {

Review Comment:
   Nitpicking: plural form of 'person' seems to be 'people'



##########
modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItBuildIndexOneNodeTest.java:
##########
@@ -0,0 +1,334 @@
+/*
+ * 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.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.sql.engine.util.QueryChecker.containsIndexScan;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.will;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.events.CatalogEvent;
+import 
org.apache.ignite.internal.catalog.events.MakeIndexAvailableEventParameters;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
+import org.apache.ignite.internal.sql.engine.util.QueryChecker;
+import 
org.apache.ignite.internal.table.distributed.replication.request.BuildIndexReplicaRequest;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Integration test for testing the building of an index in a single node 
cluster. */
+public class ItBuildIndexOneNodeTest extends BaseSqlIntegrationTest {
+    private static final String TABLE_NAME = "TEST_TABLE";
+
+    private static final String ZONE_NAME = zoneName(TABLE_NAME);
+
+    private static final String INDEX_NAME = "TEST_INDEX";
+
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @BeforeEach
+    void setup() {
+        setAwaitIndexAvailability(false);
+    }
+
+    @AfterEach
+    void tearDown() {
+        sql("DROP TABLE IF EXISTS " + TABLE_NAME);
+        sql("DROP ZONE IF EXISTS " + ZONE_NAME);
+
+        CLUSTER.runningNodes().forEach(IgniteImpl::stopDroppingMessages);
+    }
+
+    @Test
+    void testRecoveryBuildingIndex() throws Exception {
+        createZoneAndTable(ZONE_NAME, TABLE_NAME, 1, 1);
+
+        insertPersons(TABLE_NAME, new Person(0, "0", 10.0));
+
+        CompletableFuture<Void> awaitBuildIndexReplicaRequest = new 
CompletableFuture<>();
+
+        node().dropMessages((s, networkMessage) -> {
+            if (networkMessage instanceof BuildIndexReplicaRequest) {
+                awaitBuildIndexReplicaRequest.complete(null);
+
+                return true;
+            }
+
+            return false;
+        });
+
+        createIndex(TABLE_NAME, INDEX_NAME, "ID");
+
+        assertThat(awaitBuildIndexReplicaRequest, willCompleteSuccessfully());
+
+        assertFalse(isIndexAvailable(node(), INDEX_NAME));
+
+        // Let's restart the node.
+        CLUSTER.stopNode(0);
+        CLUSTER.startNode(0);
+
+        awaitIndexBecomeAvailable(node(), INDEX_NAME);
+    }
+
+    @Test
+    void testBuildingIndex() throws Exception {
+        createZoneAndTable(ZONE_NAME, TABLE_NAME, 1, 1);
+
+        insertPersons(TABLE_NAME, new Person(0, "0", 10.0));
+
+        createIndex(TABLE_NAME, INDEX_NAME, "ID");
+
+        awaitIndexBecomeAvailable(node(), INDEX_NAME);

Review Comment:
   Shouldn't we also verify that a select would use the index and that it will 
find the person we just inserted?



##########
modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItBuildIndexOneNodeTest.java:
##########
@@ -0,0 +1,334 @@
+/*
+ * 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.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.sql.engine.util.QueryChecker.containsIndexScan;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.will;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.events.CatalogEvent;
+import 
org.apache.ignite.internal.catalog.events.MakeIndexAvailableEventParameters;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
+import org.apache.ignite.internal.sql.engine.util.QueryChecker;
+import 
org.apache.ignite.internal.table.distributed.replication.request.BuildIndexReplicaRequest;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Integration test for testing the building of an index in a single node 
cluster. */
+public class ItBuildIndexOneNodeTest extends BaseSqlIntegrationTest {
+    private static final String TABLE_NAME = "TEST_TABLE";
+
+    private static final String ZONE_NAME = zoneName(TABLE_NAME);
+
+    private static final String INDEX_NAME = "TEST_INDEX";
+
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @BeforeEach
+    void setup() {
+        setAwaitIndexAvailability(false);
+    }
+
+    @AfterEach
+    void tearDown() {
+        sql("DROP TABLE IF EXISTS " + TABLE_NAME);
+        sql("DROP ZONE IF EXISTS " + ZONE_NAME);
+
+        CLUSTER.runningNodes().forEach(IgniteImpl::stopDroppingMessages);
+    }
+
+    @Test
+    void testRecoveryBuildingIndex() throws Exception {

Review Comment:
   ```suggestion
       void testRecoverBuildingIndex() throws Exception {
   ```



##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerClassIntegrationTest.java:
##########
@@ -185,6 +185,42 @@ protected static void insertPersons(String tableName, 
Person... people) {
         );
     }
 
+    /**
+     * Updates data in the table created by {@link #createZoneAndTable(String, 
String, int, int)}.
+     *
+     * @param tableName Table name.
+     * @param people People to update in the table.
+     */
+    protected static void updatePersons(String tableName, Person... people) {
+        Transaction tx = CLUSTER.node(0).transactions().begin();
+
+        String sql = String.format("UPDATE %s SET NAME=?, SALARY=? WHERE 
ID=?", tableName);
+
+        for (Person person : people) {
+            sql(tx, sql, person.name, person.salary, person.id);
+        }
+
+        tx.commit();
+    }
+
+    /**
+     * Deletes data in the table created by {@link #createZoneAndTable(String, 
String, int, int)}.
+     *
+     * @param tableName Table name.
+     * @param personIds Person IDs to delete.
+     */
+    protected static void deletePersons(String tableName, int... personIds) {

Review Comment:
   It's a bit strange that these methods concerning some Person class are 
defined in a generic integration test class, they don't seem to belong here. I 
suggest moving them to another class (maybe as static methods, or this new 
helper might be instantiated in each test class that actually needs it).



##########
modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItBuildIndexOneNodeTest.java:
##########
@@ -0,0 +1,334 @@
+/*
+ * 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.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
+import static 
org.apache.ignite.internal.sql.engine.util.QueryChecker.containsIndexScan;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.will;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor;
+import org.apache.ignite.internal.catalog.events.CatalogEvent;
+import 
org.apache.ignite.internal.catalog.events.MakeIndexAvailableEventParameters;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
+import org.apache.ignite.internal.sql.engine.util.QueryChecker;
+import 
org.apache.ignite.internal.table.distributed.replication.request.BuildIndexReplicaRequest;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/** Integration test for testing the building of an index in a single node 
cluster. */
+public class ItBuildIndexOneNodeTest extends BaseSqlIntegrationTest {
+    private static final String TABLE_NAME = "TEST_TABLE";
+
+    private static final String ZONE_NAME = zoneName(TABLE_NAME);
+
+    private static final String INDEX_NAME = "TEST_INDEX";
+
+    @Override
+    protected int initialNodes() {
+        return 1;
+    }
+
+    @BeforeEach
+    void setup() {
+        setAwaitIndexAvailability(false);
+    }
+
+    @AfterEach
+    void tearDown() {
+        sql("DROP TABLE IF EXISTS " + TABLE_NAME);
+        sql("DROP ZONE IF EXISTS " + ZONE_NAME);
+
+        CLUSTER.runningNodes().forEach(IgniteImpl::stopDroppingMessages);
+    }
+
+    @Test
+    void testRecoveryBuildingIndex() throws Exception {
+        createZoneAndTable(ZONE_NAME, TABLE_NAME, 1, 1);
+
+        insertPersons(TABLE_NAME, new Person(0, "0", 10.0));
+
+        CompletableFuture<Void> awaitBuildIndexReplicaRequest = new 
CompletableFuture<>();
+
+        node().dropMessages((s, networkMessage) -> {
+            if (networkMessage instanceof BuildIndexReplicaRequest) {
+                awaitBuildIndexReplicaRequest.complete(null);
+
+                return true;
+            }
+
+            return false;
+        });
+
+        createIndex(TABLE_NAME, INDEX_NAME, "ID");
+
+        assertThat(awaitBuildIndexReplicaRequest, willCompleteSuccessfully());
+
+        assertFalse(isIndexAvailable(node(), INDEX_NAME));
+
+        // Let's restart the node.
+        CLUSTER.stopNode(0);
+        CLUSTER.startNode(0);
+
+        awaitIndexBecomeAvailable(node(), INDEX_NAME);
+    }
+
+    @Test
+    void testBuildingIndex() throws Exception {
+        createZoneAndTable(ZONE_NAME, TABLE_NAME, 1, 1);
+
+        insertPersons(TABLE_NAME, new Person(0, "0", 10.0));
+
+        createIndex(TABLE_NAME, INDEX_NAME, "ID");
+
+        awaitIndexBecomeAvailable(node(), INDEX_NAME);
+    }
+
+    @Test
+    void testBuildingIndexAndInsertIntoTableInParallel() throws Exception {
+        AtomicInteger nextPersonId = new AtomicInteger();
+
+        createTableAndInsertManyPeople(nextPersonId);
+
+        CompletableFuture<Void> awaitIndexBecomeAvailableEventAsync = 
awaitIndexBecomeAvailableEventAsync(node(), INDEX_NAME);
+
+        CompletableFuture<Integer> insertIntoTableFuture = 
runAsyncWithWaitStartExecution(() -> {
+            int insertionsCount = 0;
+            int batchSize = 10;
+
+            while (!awaitIndexBecomeAvailableEventAsync.isDone()) {
+                insertPersons(TABLE_NAME, createPeopleBatch(nextPersonId, 
batchSize));
+
+                insertionsCount += batchSize;
+            }
+
+            return insertionsCount;
+        });
+
+        createIndexForSalaryFieldAndWaitBecomeAvailable();
+
+        assertThat(awaitIndexBecomeAvailableEventAsync, 
willCompleteSuccessfully());
+        assertThat(insertIntoTableFuture, will(greaterThan(0)));

Review Comment:
   ```suggestion
           assertThat(insertIntoTableFuture, willBe(greaterThan(0)));
   ```



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