timoninmaxim commented on code in PR #12569:
URL: https://github.com/apache/ignite/pull/12569#discussion_r2651705276


##########
modules/core/src/test/java/org/apache/ignite/internal/client/thin/TimeoutTest.java:
##########
@@ -217,4 +218,108 @@ public void testClientTimeoutOnOperation() throws 
Exception {
             }
         }
     }
+
+    /**
+     * Test that connection timeout is independent of request timeout during 
connection establishment.
+     */
+    @Test
+    @SuppressWarnings("ThrowableNotThrown")
+    public void testConnectionTimeoutIndependentOfRequest() throws Exception {
+        ServerSocket sock = new ServerSocket();
+        sock.bind(new InetSocketAddress("127.0.0.1", DFLT_PORT));
+
+        CountDownLatch connectionAccepted = new CountDownLatch(1);
+
+        IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
+            try {
+                Socket accepted = sock.accept();
+                connectionAccepted.countDown();
+
+                Thread.sleep(2000);
+
+                U.closeQuiet(accepted);
+            }
+            catch (Exception e) {
+                throw new IgniteException("Accept thread failed: " + 
e.getMessage(), e);
+            }
+        });
+
+        try {
+            ClientConfiguration cfg = new ClientConfiguration()
+                .setAddresses("127.0.0.1:" + DFLT_PORT)
+                .setConnectionTimeout(500)
+                .setRequestTimeout(Integer.MAX_VALUE);
+
+            GridTestUtils.assertThrowsWithCause(
+                () -> Ignition.startClient(cfg),
+                IgniteFutureTimeoutCheckedException.class
+            );
+        }
+        finally {
+            U.closeQuiet(sock);
+        }
+
+        assertTrue("Connection should have been accepted", 
connectionAccepted.await(1, TimeUnit.SECONDS));
+
+        fut.get();
+    }
+
+    /**
+     * Test that request timeout is independent of connection timeout during 
operations.
+     */
+    @Test
+    @SuppressWarnings("ThrowableNotThrown")
+    public void testRequestTimeoutIndependentOfConnection() throws Exception {
+        IgniteConfiguration igniteCfg = 
getConfiguration(getTestIgniteInstanceName());
+        igniteCfg.setClientConnectorConfiguration(new 
ClientConnectorConfiguration().setHandshakeTimeout(Integer.MAX_VALUE));
+
+        try (Ignite ignite = startGrid(igniteCfg)) {
+            ClientConfiguration cfg = getClientConfiguration(ignite)
+                .setConnectionTimeout(Integer.MAX_VALUE)
+                .setRequestTimeout(500);
+
+            try (IgniteClient client = Ignition.startClient(cfg)) {
+                ClientCache<Object, Object> cache = 
client.getOrCreateCache("testTimeoutCache");
+
+                ClientCacheConfiguration txCacheCfg = new 
ClientCacheConfiguration()
+                    .setName("txCache")
+                    .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+
+                ClientCache<Object, Object> txCache = 
client.getOrCreateCache(txCacheCfg);
+
+                CyclicBarrier barrier = new CyclicBarrier(2);
+
+                IgniteInternalFuture<?> blockingThread = 
GridTestUtils.runAsync(() -> {
+                    try (ClientTransaction ignored1 = 
client.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                        txCache.put(1, "blocked");
+
+                        barrier.await(2, TimeUnit.SECONDS);
+
+                        Thread.sleep(2000);
+
+                        barrier.await(2, TimeUnit.SECONDS);

Review Comment:
   For which reason you awaits main thread after sleeping?



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