Skip to content

Commit 3447f11

Browse files
committed
Fix batching test issue
1 parent d6cb2f3 commit 3447f11

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

sdks/java/ml/inference/remote/src/test/java/org/apache/beam/sdk/ml/inference/remote/RemoteInferenceTest.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,27 @@ public void testPredictionResultMapping() {
518518
pipeline.run().waitUntilFinish();
519519
}
520520

521+
private static class GenerateInputsFn
522+
extends org.apache.beam.sdk.transforms.DoFn<Integer, TestInput> {
523+
@ProcessElement
524+
public void processElement(ProcessContext c) {
525+
c.output(new TestInput("input1"));
526+
c.output(new TestInput("input2"));
527+
}
528+
}
529+
521530
@Test
522531
public void testBatchingProducesCombinedBatches() {
523-
List<TestInput> inputs = Arrays.asList(new TestInput("input1"), new TestInput("input2"));
524-
525532
TestParameters params = TestParameters.builder().setConfig("test-config").build();
526533

534+
// Use a single element to trigger generation of inputs within the same bundle,
535+
// ensuring DirectRunner doesn't split them before BatchElements processes them.
527536
PCollection<TestInput> inputCollection =
528-
pipeline.apply(
529-
"CreateInputs", Create.of(inputs).withCoder(SerializableCoder.of(TestInput.class)));
537+
pipeline
538+
.apply("CreateTrigger", Create.of(1))
539+
.apply(
540+
"GenerateInputs", org.apache.beam.sdk.transforms.ParDo.of(new GenerateInputsFn()))
541+
.setCoder(SerializableCoder.of(TestInput.class));
530542

531543
// Configure BatchElements to force a batch of exactly 2
532544
org.apache.beam.sdk.transforms.BatchElements.BatchConfig batchConfig =

0 commit comments

Comments
 (0)