Index: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NearFinishRequestDelayTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NearFinishRequestDelayTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NearFinishRequestDelayTest.java new file mode 100644 --- /dev/null (date 1695920698562) +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/NearFinishRequestDelayTest.java (date 1695920698562) @@ -0,0 +1,130 @@ +/* + * 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.processors.cache.transactions; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.TestRecordingCommunicationSpi; +import org.apache.ignite.internal.managers.communication.GridIoMessage; +import org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxFinishRequest; +import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.lang.IgniteRunnable; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.spi.IgniteSpiException; +import org.apache.ignite.spi.communication.CommunicationListener; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; +import org.apache.ignite.testframework.junits.WithSystemProperty; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; +import static org.apache.ignite.internal.TestRecordingCommunicationSpi.spi; +import static org.apache.ignite.testframework.GridTestUtils.assertThrows; +import static org.apache.ignite.testframework.GridTestUtils.getFieldValue; +import static org.apache.ignite.testframework.GridTestUtils.runAsync; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; + +/** + * + */ +@WithSystemProperty(key = IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, value = "" + NearFinishRequestDelayTest.DUMP_TIMEOUT) +public class NearFinishRequestDelayTest extends GridCommonAbstractTest { + /** Servers count.*/ + private static final int SERVERS_COUNT = 3; + + /** Transaction timeout. */ + private static final int TRANSACTION_TIMEOUT = 1000; + + /** Tx dump timeout. */ + public static final int DUMP_TIMEOUT = 5000; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setCommunicationSpi(new TestRecordingCommunicationSpi()) + .setCacheConfiguration(new CacheConfiguration<>() + .setName(DEFAULT_CACHE_NAME) + .setAtomicityMode(TRANSACTIONAL) + .setBackups(2) + .setWriteSynchronizationMode(FULL_SYNC)) + .setTransactionConfiguration(new TransactionConfiguration().setDefaultTxTimeout(TRANSACTION_TIMEOUT)); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * + */ + @Test + @SuppressWarnings("ThrowableNotThrown") + public void testSinglePut() throws Exception { + startGrids(SERVERS_COUNT); + + IgniteEx client = startClientGrid(SERVERS_COUNT); + + spi(client).blockMessages((n, msg) -> msg instanceof GridNearTxFinishRequest); + + IgniteCache cache = client.cache(DEFAULT_CACHE_NAME); + + IgniteInternalFuture actionFut = runAsync(() -> doInTransaction( + client, + () -> { + cache.put(0, "0"); + + return null; + })); + + assertThrows(log, () -> actionFut.get(TRANSACTION_TIMEOUT + DUMP_TIMEOUT * 3), IgniteFutureTimeoutCheckedException.class, null); + + // Uncomment in order to pass test +// spi(client).stopBlock(); + + actionFut.get(TRANSACTION_TIMEOUT); + } +}