You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2022/04/13 08:36:58 UTC

[GitHub] [cassandra] smiklosovic commented on a diff in pull request #1563: CASSANDRA-17492 the second take

smiklosovic commented on code in PR #1563:
URL: https://github.com/apache/cassandra/pull/1563#discussion_r849227272


##########
test/unit/org/apache/cassandra/service/StorageServiceTest.java:
##########
@@ -156,4 +169,30 @@ public void testGetChangedReplicasForLeaving() throws Exception
         expectedResult.put(new Replica(aAddress, dRange, false), new Replica(bAddress, dRange, false));
         assertMultimapEqualsIgnoreOrder(result, expectedResult.build());
     }
+
+    @Test
+    public void testScheduledExecutorsShutdownOnDrain() throws Throwable
+    {
+        final AtomicReference<Integer> numberOfRuns = new AtomicReference<>(0);
+
+        ScheduledExecutors.scheduledTasks.scheduleAtFixedRate(() -> numberOfRuns.updateAndGet(i -> i + 1),
+                                                              0, 20, SECONDS);
+
+        // we expect three runs, at time 0s, 20s and 40s
+        logger.info("Sleeping for 45 seconds to verify scheduled executor was shut down.");
+        Thread.sleep(45_000);
+
+        StorageService.instance.drain();
+
+        // wait another 20s, by that time, if the draining does not work
+        // we would see 4th counter run which would fail the test
+        Thread.sleep(20_000);
+
+        assertEquals(3, numberOfRuns.get().intValue());
+
+        assertTrue(ScheduledExecutors.scheduledTasks.isTerminated());
+        assertTrue(ScheduledExecutors.nonPeriodicTasks.isTerminated());
+        assertTrue(ScheduledExecutors.scheduledFastTasks.isTerminated());
+        assertTrue(ScheduledExecutors.optionalTasks.isTerminated());
+    }

Review Comment:
   ah yes this is better way how to look at it, I couldnt remember that AtomicInteger as I was in the rush :D No problem with Awaitility either.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org