amrishlal commented on a change in pull request #7174:
URL: https://github.com/apache/pinot/pull/7174#discussion_r687075618



##########
File path: 
pinot-core/src/test/java/org/apache/pinot/core/periodictask/PeriodicTaskSchedulerTest.java
##########
@@ -104,4 +105,79 @@ protected void cleanUpTask() {
     assertEquals(numTimesRunCalled.get(), numTasks * 2);
     assertEquals(numTimesStopCalled.get(), numTasks);
   }
+
+
+  /** Test that {@link PeriodicTaskScheduler} does not run the same task more 
than once at any time. */
+  @Test
+  public void testConcurrentExecutionOfSameTask() throws Exception {
+    // Count how many tasks were run.
+    final AtomicInteger counter = new AtomicInteger();
+
+    // Count how many attempts were made to run task
+    final AtomicInteger attempts = new AtomicInteger();
+
+
+    // Create periodic task.
+    PeriodicTask task = new BasePeriodicTask("TestTask", 1L, 0L) {
+      private volatile boolean isRunning = false;
+      @Override
+      protected void runTask() {
+        try {
+          if (isRunning) {
+            Assert.fail("More than one thread attempting to execute task at 
the same time.");
+          }
+          isRunning = true;
+          counter.incrementAndGet();
+          Thread.sleep(250);

Review comment:
       This delay to used to force a situation where multiple threads are 
attempting (or waiting) to run the same task.




-- 
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: commits-unsubscr...@pinot.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to