scwhittle commented on code in PR #33686:
URL: https://github.com/apache/beam/pull/33686#discussion_r1926614451
##########
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/util/BoundedQueueExecutorTest.java:
##########
@@ -284,6 +287,59 @@ public void
testRecordTotalTimeMaxActiveThreadsUsedWhenMaximumPoolSizeUpdated()
executor.shutdown();
}
+ @Test
+ public void
testRecordTotalTimeMaxActiveThreadsUsedWhenMaximumPoolSizeIsReduced()
+ throws Exception {
+ CountDownLatch processStart1 = new CountDownLatch(1);
+ CountDownLatch processStop1 = new CountDownLatch(1);
+ CountDownLatch processStart2 = new CountDownLatch(1);
+ CountDownLatch processStop2 = new CountDownLatch(1);
+ CountDownLatch processStart3 = new CountDownLatch(1);
+ CountDownLatch processStop3 = new CountDownLatch(1);
+ Runnable m1 = createSleepProcessWorkFn(processStart1, processStop1);
+ Runnable m2 = createSleepProcessWorkFn(processStart2, processStop2);
+ Runnable m3 = createSleepProcessWorkFn(processStart3, processStop3);
+
+ // Initial state.
+ assertEquals(0, executor.activeCount());
+ assertEquals(2, executor.getMaximumPoolSize());
+
+ // m1 is accepted.
+ executor.execute(m1, 1);
+ processStart1.await();
+ assertEquals(1, executor.activeCount());
+ assertEquals(2, executor.getMaximumPoolSize());
+ assertEquals(0L, executor.allThreadsActiveTime());
+
+ processStop1.countDown();
+ while (executor.activeCount() != 0) {
+ // Waiting for all threads to be ended.
+ Thread.sleep(200);
+ }
+
+ // Reduce max pool size to 1
+ executor.setMaximumPoolSize(1, 105);
+
+ assertEquals(0, executor.activeCount());
+ executor.execute(m2, 1);
+ processStart2.await();
+ long expectedMillisAtMaxThreads = 100;
+ Thread.sleep(expectedMillisAtMaxThreads);
+ assertEquals(1, executor.activeCount());
+ assertEquals(1, executor.getMaximumPoolSize());
+ processStop2.countDown();
+
+ while (executor.activeCount() != 0) {
+ // Waiting for all threads to be ended.
+ Thread.sleep(200);
+ }
+
+ // allThreadsActiveTime() should be recorded
+ // since when the second task was running it reached the new max pool size.
+ assertThat(executor.allThreadsActiveTime(),
greaterThanOrEqualTo(expectedMillisAtMaxThreads));
Review Comment:
should we just make sure it is greater than zero similar to the other test
to avoid flakiness?
--
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]