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


##########
modules/partition-replicator/src/integrationTest/java/org/apache/ignite/internal/partition/replicator/WriteIntentSwitchRequestHandlerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.partition.replicator;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ComponentStoppingException;
+import 
org.apache.ignite.internal.partition.replicator.handlers.WriteIntentSwitchRequestHandler;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.ignite.internal.tx.impl.TxCleanupRequestHandler;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link WriteIntentSwitchRequestHandler}. */
+public class WriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        
builder.clusterConfiguration(aggressiveLowWatermarkIncreaseClusterConfig());
+    }
+
+    private static String aggressiveLowWatermarkIncreaseClusterConfig() {
+        return "{\n"
+                + "  ignite.gc.lowWatermark {\n"
+                + "    dataAvailabilityTimeMillis: 1000,\n"
+                + "    updateIntervalMillis: 100\n"
+                + "  },\n"
+                // Disable tx state storage cleanup.
+                + "  ignite.system.properties." + 
TxManagerImpl.RESOURCE_TTL_PROP + " = " + Long.MAX_VALUE + "\n"
+                + "}";
+    }
+
+    @Test
+    void testWriteIntentResolutionAfterTableAlreadyDestroyed() {
+        String tableName = "test";
+
+        executeSql("CREATE TABLE " + tableName + " (id INT PRIMARY KEY, val 
INT)");
+
+        // This node will send WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl senderNode = unwrapIgniteImpl(cluster.node(0));
+
+        int receiverNodeIndex = 1;
+        // This node will process WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl receiverNode = 
unwrapIgniteImpl(cluster.node(receiverNodeIndex));
+
+        CompletableFuture<Void> tableDroppedFut = new CompletableFuture<>();
+
+        failIntentSwitchUntilTableIsDestroyed(senderNode, tableDroppedFut);
+
+        receiverNode.transactions().runInTransaction((tx) -> {
+            for (int i = 0; i < 10; i++) {
+                executeSql(receiverNodeIndex, tx, "INSERT INTO " + tableName + 
" (id, val) VALUES (?, ?)", i, i);
+            }
+        });
+
+        
assertThat(receiverNode.distributedTableManager().cachedTable(tableName), 
notNullValue());

Review Comment:
   Why do we need this?



##########
modules/partition-replicator/src/integrationTest/java/org/apache/ignite/internal/partition/replicator/WriteIntentSwitchRequestHandlerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.partition.replicator;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ComponentStoppingException;
+import 
org.apache.ignite.internal.partition.replicator.handlers.WriteIntentSwitchRequestHandler;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.ignite.internal.tx.impl.TxCleanupRequestHandler;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link WriteIntentSwitchRequestHandler}. */
+public class WriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        
builder.clusterConfiguration(aggressiveLowWatermarkIncreaseClusterConfig());
+    }
+
+    private static String aggressiveLowWatermarkIncreaseClusterConfig() {
+        return "{\n"
+                + "  ignite.gc.lowWatermark {\n"
+                + "    dataAvailabilityTimeMillis: 1000,\n"
+                + "    updateIntervalMillis: 100\n"
+                + "  },\n"
+                // Disable tx state storage cleanup.
+                + "  ignite.system.properties." + 
TxManagerImpl.RESOURCE_TTL_PROP + " = " + Long.MAX_VALUE + "\n"
+                + "}";
+    }
+
+    @Test
+    void testWriteIntentResolutionAfterTableAlreadyDestroyed() {
+        String tableName = "test";
+
+        executeSql("CREATE TABLE " + tableName + " (id INT PRIMARY KEY, val 
INT)");
+
+        // This node will send WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl senderNode = unwrapIgniteImpl(cluster.node(0));
+
+        int receiverNodeIndex = 1;
+        // This node will process WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl receiverNode = 
unwrapIgniteImpl(cluster.node(receiverNodeIndex));
+
+        CompletableFuture<Void> tableDroppedFut = new CompletableFuture<>();
+
+        failIntentSwitchUntilTableIsDestroyed(senderNode, tableDroppedFut);
+
+        receiverNode.transactions().runInTransaction((tx) -> {
+            for (int i = 0; i < 10; i++) {
+                executeSql(receiverNodeIndex, tx, "INSERT INTO " + tableName + 
" (id, val) VALUES (?, ?)", i, i);
+            }
+        });
+
+        
assertThat(receiverNode.distributedTableManager().cachedTable(tableName), 
notNullValue());
+
+        executeSql("DROP TABLE " + tableName);
+
+        // Await real table destruction.
+        Awaitility.await().until(() -> 
receiverNode.distributedTableManager().cachedTable(tableName) == null);
+
+        LogInspector logInspector = new LogInspector(
+                TxCleanupRequestHandler.class.getName(),
+                event -> hasCause(event.getThrown(), 
ComponentStoppingException.class, "Table is already destroyed")
+        );
+
+        logInspector.start();
+
+        try {
+            tableDroppedFut.complete(null);
+
+            Awaitility.await().until(logInspector::isMatched);

Review Comment:
   Why do we need this wait? Let's explain in a comment/method name



##########
modules/partition-replicator/src/integrationTest/java/org/apache/ignite/internal/partition/replicator/WriteIntentSwitchRequestHandlerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.partition.replicator;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ComponentStoppingException;
+import 
org.apache.ignite.internal.partition.replicator.handlers.WriteIntentSwitchRequestHandler;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.ignite.internal.tx.impl.TxCleanupRequestHandler;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link WriteIntentSwitchRequestHandler}. */
+public class WriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        
builder.clusterConfiguration(aggressiveLowWatermarkIncreaseClusterConfig());
+    }
+
+    private static String aggressiveLowWatermarkIncreaseClusterConfig() {
+        return "{\n"
+                + "  ignite.gc.lowWatermark {\n"
+                + "    dataAvailabilityTimeMillis: 1000,\n"
+                + "    updateIntervalMillis: 100\n"
+                + "  },\n"
+                // Disable tx state storage cleanup.
+                + "  ignite.system.properties." + 
TxManagerImpl.RESOURCE_TTL_PROP + " = " + Long.MAX_VALUE + "\n"

Review Comment:
   Why is this needed in this particular test?



##########
modules/partition-replicator/src/integrationTest/java/org/apache/ignite/internal/partition/replicator/WriteIntentSwitchRequestHandlerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.partition.replicator;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ComponentStoppingException;
+import 
org.apache.ignite.internal.partition.replicator.handlers.WriteIntentSwitchRequestHandler;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.ignite.internal.tx.impl.TxCleanupRequestHandler;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link WriteIntentSwitchRequestHandler}. */
+public class WriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {

Review Comment:
   ```suggestion
   public class ItWriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {
   ```



##########
modules/partition-replicator/src/integrationTest/java/org/apache/ignite/internal/partition/replicator/WriteIntentSwitchRequestHandlerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.partition.replicator;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ComponentStoppingException;
+import 
org.apache.ignite.internal.partition.replicator.handlers.WriteIntentSwitchRequestHandler;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.ignite.internal.tx.impl.TxCleanupRequestHandler;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link WriteIntentSwitchRequestHandler}. */
+public class WriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        
builder.clusterConfiguration(aggressiveLowWatermarkIncreaseClusterConfig());
+    }
+
+    private static String aggressiveLowWatermarkIncreaseClusterConfig() {
+        return "{\n"
+                + "  ignite.gc.lowWatermark {\n"
+                + "    dataAvailabilityTimeMillis: 1000,\n"
+                + "    updateIntervalMillis: 100\n"
+                + "  },\n"
+                // Disable tx state storage cleanup.
+                + "  ignite.system.properties." + 
TxManagerImpl.RESOURCE_TTL_PROP + " = " + Long.MAX_VALUE + "\n"
+                + "}";
+    }
+
+    @Test
+    void testWriteIntentResolutionAfterTableAlreadyDestroyed() {
+        String tableName = "test";
+
+        executeSql("CREATE TABLE " + tableName + " (id INT PRIMARY KEY, val 
INT)");
+
+        // This node will send WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl senderNode = unwrapIgniteImpl(cluster.node(0));
+
+        int receiverNodeIndex = 1;
+        // This node will process WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl receiverNode = 
unwrapIgniteImpl(cluster.node(receiverNodeIndex));
+
+        CompletableFuture<Void> tableDroppedFut = new CompletableFuture<>();

Review Comment:
   ```suggestion
           CompletableFuture<Void> tableDestroyedFut = new 
CompletableFuture<>();
   ```



##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/ClusterPerTestIntegrationTest.java:
##########
@@ -219,9 +220,13 @@ protected final List<List<Object>> executeSql(String sql, 
Object... args) {
     }
 
     protected final List<List<Object>> executeSql(int nodeIndex, String sql, 
Object... args) {
+        return executeSql(nodeIndex, null, sql, args);
+    }
+
+    protected final List<List<Object>> executeSql(int nodeIndex, Transaction 
tx, String sql, Object... args) {

Review Comment:
   ```suggestion
       protected final List<List<Object>> executeSql(int nodeIndex, @Nullable 
Transaction tx, String sql, Object... args) {
   ```



##########
modules/partition-replicator/src/integrationTest/java/org/apache/ignite/internal/partition/replicator/WriteIntentSwitchRequestHandlerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.partition.replicator;
+
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ComponentStoppingException;
+import 
org.apache.ignite.internal.partition.replicator.handlers.WriteIntentSwitchRequestHandler;
+import org.apache.ignite.internal.testframework.log4j2.LogInspector;
+import org.apache.ignite.internal.tx.impl.TxCleanupRequestHandler;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link WriteIntentSwitchRequestHandler}. */
+public class WriteIntentSwitchRequestHandlerTest extends 
ClusterPerTestIntegrationTest {
+    @Override
+    protected int initialNodes() {
+        return 2;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        
builder.clusterConfiguration(aggressiveLowWatermarkIncreaseClusterConfig());
+    }
+
+    private static String aggressiveLowWatermarkIncreaseClusterConfig() {
+        return "{\n"
+                + "  ignite.gc.lowWatermark {\n"
+                + "    dataAvailabilityTimeMillis: 1000,\n"
+                + "    updateIntervalMillis: 100\n"
+                + "  },\n"
+                // Disable tx state storage cleanup.
+                + "  ignite.system.properties." + 
TxManagerImpl.RESOURCE_TTL_PROP + " = " + Long.MAX_VALUE + "\n"
+                + "}";
+    }
+
+    @Test
+    void testWriteIntentResolutionAfterTableAlreadyDestroyed() {
+        String tableName = "test";
+
+        executeSql("CREATE TABLE " + tableName + " (id INT PRIMARY KEY, val 
INT)");
+
+        // This node will send WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl senderNode = unwrapIgniteImpl(cluster.node(0));
+
+        int receiverNodeIndex = 1;
+        // This node will process WriteIntentSwitchReplicaRequest messages.
+        IgniteImpl receiverNode = 
unwrapIgniteImpl(cluster.node(receiverNodeIndex));
+
+        CompletableFuture<Void> tableDroppedFut = new CompletableFuture<>();
+
+        failIntentSwitchUntilTableIsDestroyed(senderNode, tableDroppedFut);
+
+        receiverNode.transactions().runInTransaction((tx) -> {
+            for (int i = 0; i < 10; i++) {
+                executeSql(receiverNodeIndex, tx, "INSERT INTO " + tableName + 
" (id, val) VALUES (?, ?)", i, i);
+            }
+        });
+
+        
assertThat(receiverNode.distributedTableManager().cachedTable(tableName), 
notNullValue());
+
+        executeSql("DROP TABLE " + tableName);
+
+        // Await real table destruction.
+        Awaitility.await().until(() -> 
receiverNode.distributedTableManager().cachedTable(tableName) == null);

Review Comment:
   Let's import `await()` statically



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