@Test public void testBatchViewAsSingletonToIsmRecord() throws Exception { DoFnTester< KV<Integer, Iterable<KV<GlobalWindow, WindowedValue<String>>>>, IsmRecord<WindowedValue<String>>> doFnTester = DoFnTester.of( new BatchViewOverrides.BatchViewAsSingleton.IsmRecordForSingularValuePerWindowDoFn< String, GlobalWindow>(GlobalWindow.Coder.INSTANCE)); assertThat( doFnTester.processBundle( ImmutableList.of( KV.of( 0, ImmutableList.of(KV.of(GlobalWindow.INSTANCE, valueInGlobalWindow("a")))))), contains(IsmRecord.of(ImmutableList.of(GlobalWindow.INSTANCE), valueInGlobalWindow("a")))); }
@Test public void testBatchViewAsSingletonToIsmRecordWithMultipleValuesThrowsException() throws Exception { DoFnTester< KV<Integer, Iterable<KV<GlobalWindow, WindowedValue<String>>>>, IsmRecord<WindowedValue<String>>> doFnTester = DoFnTester.of( new BatchViewOverrides.BatchViewAsSingleton.IsmRecordForSingularValuePerWindowDoFn< String, GlobalWindow>(GlobalWindow.Coder.INSTANCE)); thrown.expect(IllegalStateException.class); thrown.expectMessage("found for singleton within window"); doFnTester.processBundle( ImmutableList.of( KV.of( 0, ImmutableList.of( KV.of(GlobalWindow.INSTANCE, valueInGlobalWindow("a")), KV.of(GlobalWindow.INSTANCE, valueInGlobalWindow("b")))))); }
@Override public PCollection<?> expand(PCollection<T> input) { input = input.apply(Combine.globally(combineFn).withoutDefaults().withFanout(fanout)); @SuppressWarnings("unchecked") Coder<BoundedWindow> windowCoder = (Coder<BoundedWindow>) input.getWindowingStrategy().getWindowFn().windowCoder(); return BatchViewAsSingleton.applyForSingleton( runner, input, new IsmRecordForSingularValuePerWindowDoFn<>(windowCoder), input.getCoder(), view); }