bvolpato commented on code in PR #28513:
URL: https://github.com/apache/beam/pull/28513#discussion_r1340174306


##########
runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/StreamingDataflowWorkerTest.java:
##########
@@ -2923,6 +2943,109 @@ public void run() {
     executor.shutdown();
   }
 
+  @Test
+  public void testActiveThreadMetric() throws Exception {
+    int maxThreads = 5;
+    int threadExpirationSec = 60;
+    // setting up actual implementation of executor instead of mocking to keep 
track of
+    // active thread count.
+    BoundedQueueExecutor executor =
+        new BoundedQueueExecutor(
+            maxThreads,
+            threadExpirationSec,
+            TimeUnit.SECONDS,
+            maxThreads,
+            10000000,
+            new ThreadFactoryBuilder()
+                .setNameFormat("DataflowWorkUnits-%d")
+                .setDaemon(true)
+                .build());
+
+    StreamingDataflowWorker.ComputationState computationState =
+        new StreamingDataflowWorker.ComputationState(
+            "computation",
+            
defaultMapTask(Arrays.asList(makeSourceInstruction(StringUtf8Coder.of()))),
+            executor,
+            ImmutableMap.of(),
+            null);
+
+    ShardedKey key1Shard1 = ShardedKey.create(ByteString.copyFromUtf8("key1"), 
1);
+
+    // real work
+    MockActiveWork m1 =
+        new MockActiveWork(1) {
+          @Override
+          public void run() {
+            synchronized (this) {
+              this.notify();
+            }
+            int count = 0;
+            while (!exit) {
+              count += 1;
+            }
+            Thread.currentThread().interrupt();
+          }
+        };
+
+    // idle work
+    MockWork m2 =
+        new MockWork(2) {
+          @Override
+          public void run() {
+            synchronized (this) {
+              this.notify();
+            }
+            try {
+              Thread.sleep(2000);
+            } catch (InterruptedException e) {
+              Thread.currentThread().interrupt();
+            }
+          }
+        };
+
+    // idle work
+    MockWork m3 =
+        new MockWork(3) {
+          @Override
+          public void run() {
+            synchronized (this) {
+              this.notify();
+            }
+            try {
+              Thread.sleep(2000);
+            } catch (InterruptedException e) {
+              Thread.currentThread().interrupt();
+            }
+          }
+        };
+    assertEquals(0, executor.activeCount());
+
+    assertTrue(computationState.activateWork(key1Shard1, m1));
+    synchronized (m1) {
+      executor.execute(m1, m1.getWorkItem().getSerializedSize());
+      LOG.info("[chengedward] waiting on thread start m1]");
+      m1.wait();
+    }
+    LOG.info("[chengedward] thread started m1]");

Review Comment:
   consider removing logs if they were mostly to debug, or let's at least 
remove personal information before sending this in
   



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