tejasiyer-dev commented on code in PR #40543:
URL: https://github.com/apache/beam/pull/40543#discussion_r4698202523


##########
sdks/java/core/src/test/java/org/apache/beam/sdk/io/WriteFilesTest.java:
##########
@@ -422,6 +434,505 @@ public void testWithRunnerDeterminedShardingTestStream() 
throws IOException {
         getBaseOutputFilename(), elements, Optional.absent(), 
!write.getWindowedWrites(), null);
   }
 
+  @Test
+  @Category({NeedsRunner.class, UsesUnboundedPCollections.class, 
UsesTestStream.class})
+  public void testDirectWriteAllBundlesLarge() throws IOException {
+    runDirectWriteTestStream(1L);
+  }
+
+  @Test
+  @Category({NeedsRunner.class, UsesUnboundedPCollections.class, 
UsesTestStream.class})
+  public void testDirectWriteAllBundlesSmall() throws IOException {
+    runDirectWriteTestStream(Long.MAX_VALUE);
+  }
+
+  @Test
+  @Category({NeedsRunner.class, UsesUnboundedPCollections.class, 
UsesTestStream.class})
+  public void testDirectWriteUnshardedMixedBundles() throws IOException {
+    List<String> elements = Lists.newArrayList();
+    for (int i = 0; i < 30; ++i) {
+      elements.add("number: " + i);
+    }
+    Instant startInstant = new Instant(0L);
+    // Two 10-element bundles (~100 bytes each), one 8-element bundle (~88 
bytes), and one
+    // 2-element bundle (~22 bytes, < 50) so both direct and auto-sharded 
paths run.
+    TestStream<String> testStream =
+        TestStream.create(StringUtf8Coder.of())
+            .advanceWatermarkTo(startInstant)
+            .addElements(elements.get(0), 
Iterables.toArray(elements.subList(1, 10), String.class))
+            .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+            .addElements(
+                elements.get(10), Iterables.toArray(elements.subList(11, 20), 
String.class))
+            
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+            .addElements(
+                elements.get(20), Iterables.toArray(elements.subList(21, 28), 
String.class))
+            .addElements(elements.get(28), elements.get(29))
+            .advanceWatermarkToInfinity();
+
+    WriteFiles<String, Void, String> write =
+        WriteFiles.to(makeSimpleSink())
+            .withWindowedWrites()
+            .withRunnerDeterminedSharding()
+            .withDirectWriteByteThreshold(50L);
+    p.apply(testStream)
+        .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+        .apply(write)
+        .getPerDestinationOutputFilenames()
+        .apply(new VerifyFilesExist<>());
+    PipelineResult result = p.run();
+
+    checkFileContents(getBaseOutputFilename(), elements, Optional.absent(), 
false, null);
+    assertThat(counterValue(result, "directWriteBundles"), 
Matchers.greaterThan(0L));
+  }
+
+  @Test
+  @Category(NeedsRunner.class)
+  public void testDirectWriteDisabledForBoundedWithFixedSharding() throws 
IOException {

Review Comment:
   Done. Converted all four disabled tests to inspect the expanded pipeline 
graph via pipeline.traverseTopologically without p.run(), and added 
testDirectWriteEnabledExpansion as a positive check.



##########
sdks/java/core/src/test/java/org/apache/beam/sdk/io/WriteFilesTest.java:
##########
@@ -422,6 +434,505 @@ public void testWithRunnerDeterminedShardingTestStream() 
throws IOException {
         getBaseOutputFilename(), elements, Optional.absent(), 
!write.getWindowedWrites(), null);
   }
 
+  @Test
+  @Category({NeedsRunner.class, UsesUnboundedPCollections.class, 
UsesTestStream.class})
+  public void testDirectWriteAllBundlesLarge() throws IOException {
+    runDirectWriteTestStream(1L);
+  }
+
+  @Test
+  @Category({NeedsRunner.class, UsesUnboundedPCollections.class, 
UsesTestStream.class})
+  public void testDirectWriteAllBundlesSmall() throws IOException {
+    runDirectWriteTestStream(Long.MAX_VALUE);
+  }
+
+  @Test
+  @Category({NeedsRunner.class, UsesUnboundedPCollections.class, 
UsesTestStream.class})
+  public void testDirectWriteUnshardedMixedBundles() throws IOException {
+    List<String> elements = Lists.newArrayList();
+    for (int i = 0; i < 30; ++i) {
+      elements.add("number: " + i);
+    }
+    Instant startInstant = new Instant(0L);
+    // Two 10-element bundles (~100 bytes each), one 8-element bundle (~88 
bytes), and one
+    // 2-element bundle (~22 bytes, < 50) so both direct and auto-sharded 
paths run.
+    TestStream<String> testStream =
+        TestStream.create(StringUtf8Coder.of())
+            .advanceWatermarkTo(startInstant)
+            .addElements(elements.get(0), 
Iterables.toArray(elements.subList(1, 10), String.class))
+            .advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(5)))
+            .addElements(
+                elements.get(10), Iterables.toArray(elements.subList(11, 20), 
String.class))
+            
.advanceWatermarkTo(startInstant.plus(Duration.standardSeconds(10)))
+            .addElements(
+                elements.get(20), Iterables.toArray(elements.subList(21, 28), 
String.class))
+            .addElements(elements.get(28), elements.get(29))
+            .advanceWatermarkToInfinity();
+
+    WriteFiles<String, Void, String> write =
+        WriteFiles.to(makeSimpleSink())
+            .withWindowedWrites()
+            .withRunnerDeterminedSharding()
+            .withDirectWriteByteThreshold(50L);
+    p.apply(testStream)
+        .apply(Window.into(FixedWindows.of(Duration.standardSeconds(10))))
+        .apply(write)
+        .getPerDestinationOutputFilenames()
+        .apply(new VerifyFilesExist<>());
+    PipelineResult result = p.run();
+
+    checkFileContents(getBaseOutputFilename(), elements, Optional.absent(), 
false, null);
+    assertThat(counterValue(result, "directWriteBundles"), 
Matchers.greaterThan(0L));
+  }
+
+  @Test
+  @Category(NeedsRunner.class)
+  public void testDirectWriteDisabledForBoundedWithFixedSharding() throws 
IOException {
+    List<String> elements = Lists.newArrayList();
+    for (int i = 0; i < 30; ++i) {
+      elements.add("number: " + i);
+    }
+    WriteFiles<String, Void, String> write =
+        
WriteFiles.to(makeSimpleSink()).withNumShards(3).withDirectWriteByteThreshold(1L);
+    p.apply(Create.of(elements)).apply(write);
+    PipelineResult result = p.run();
+
+    checkFileContents(getBaseOutputFilename(), elements, Optional.of(3), true, 
null);
+    assertEquals(0L, counterValue(result, "directWriteBundles"));
+  }
+
+  @Test
+  @Category(NeedsRunner.class)
+  public void testDirectWriteDisabledForBoundedWithoutFixedSharding() throws 
IOException {

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