rohdesamuel commented on code in PR #27121:
URL: https://github.com/apache/beam/pull/27121#discussion_r1231306375


##########
sdks/java/harness/src/test/java/org/apache/beam/fn/harness/debug/OutputSamplerTest.java:
##########
@@ -139,6 +139,69 @@ public void testActsLikeCircularBuffer() throws Exception {
     assertThat(samples, containsInAnyOrder(expected.toArray()));
   }
 
+  /**
+   * Test that elements with exceptions can be sampled. TODO: test that the 
exception metadata is
+   * set.
+   *
+   * @throws Exception when encoding fails (shouldn't happen).
+   */
+  @Test
+  public void testCanSampleExceptions() throws Exception {

Review Comment:
   Done



##########
sdks/java/harness/src/test/java/org/apache/beam/fn/harness/debug/OutputSamplerTest.java:
##########
@@ -139,6 +139,69 @@ public void testActsLikeCircularBuffer() throws Exception {
     assertThat(samples, containsInAnyOrder(expected.toArray()));
   }
 
+  /**
+   * Test that elements with exceptions can be sampled. TODO: test that the 
exception metadata is
+   * set.
+   *
+   * @throws Exception when encoding fails (shouldn't happen).
+   */
+  @Test
+  public void testCanSampleExceptions() throws Exception {
+    VarIntCoder coder = VarIntCoder.of();
+    OutputSampler<Integer> outputSampler = new OutputSampler<>(coder, 5, 20);
+
+    WindowedValue<Integer> windowedValue = 
WindowedValue.valueInGlobalWindow(1);
+    ElementSample<Integer> elementSample = outputSampler.sample(windowedValue);
+
+    Exception exception = new RuntimeException("Test exception");
+    outputSampler.exception(elementSample, exception);
+
+    // The first 10 are always sampled, but with maxSamples = 5, the first ten 
are downsampled to
+    // 4..9 inclusive. Then,
+    // the 20th element is sampled (19) and every 20 after.
+    List<BeamFnApi.SampledElement> expected = new ArrayList<>();
+    expected.add(encodeInt(1));
+
+    List<BeamFnApi.SampledElement> samples = outputSampler.samples();
+    assertThat(samples, containsInAnyOrder(expected.toArray()));
+  }
+
+  /**
+   * Tests that multiple samples don't push out exception samples. TODO: test 
that the exception
+   * metadata is set.
+   *
+   * @throws Exception when encoding fails (shouldn't happen).
+   */
+  @Test
+  public void testExceptionSamplesAreNotRemoved() throws Exception {

Review Comment:
   Done



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