use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AssignWindowsRunnerTest method multipleInputWindowsThrows.
@Test
public void multipleInputWindowsThrows() throws Exception {
WindowFn<Object, BoundedWindow> windowFn = new WindowFn<Object, BoundedWindow>() {
@Override
public Collection<BoundedWindow> assignWindows(AssignContext c) throws Exception {
return Collections.singleton(c.window());
}
@Override
public void mergeWindows(MergeContext c) throws Exception {
throw new UnsupportedOperationException();
}
@Override
public WindowMappingFn<BoundedWindow> getDefaultWindowMappingFn() {
throw new UnsupportedOperationException();
}
@Override
public boolean isCompatible(WindowFn<?, ?> other) {
throw new UnsupportedOperationException();
}
@Override
public Coder<BoundedWindow> windowCoder() {
throw new UnsupportedOperationException();
}
};
AssignWindowsRunner<Integer, BoundedWindow> runner = AssignWindowsRunner.create(windowFn);
thrown.expect(IllegalArgumentException.class);
runner.assignWindows(WindowedValue.of(2, new Instant(-10L), ImmutableList.of(new IntervalWindow(new Instant(-22L), Duration.standardMinutes(5L)), new IntervalWindow(new Instant(-120000L), Duration.standardMinutes(3L))), PaneInfo.ON_TIME_AND_ONLY_FIRING));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class AssignWindowsRunnerTest method factoryCreatesFromKnownWindowFn.
@Test
public void factoryCreatesFromKnownWindowFn() throws Exception {
SdkComponents components = SdkComponents.create();
components.registerEnvironment(Environments.createDockerEnvironment("java"));
PTransform windowPTransform = PTransform.newBuilder().putInputs("in", "input").putOutputs("out", "output").setSpec(FunctionSpec.newBuilder().setUrn(PTransformTranslation.ASSIGN_WINDOWS_TRANSFORM_URN).setPayload(WindowIntoPayload.newBuilder().setWindowFn(WindowingStrategyTranslation.toProto(Sessions.withGapDuration(Duration.standardMinutes(12L)), components)).build().toByteString()).build()).build();
ThrowingFunction<WindowedValue<?>, WindowedValue<?>> fn = (ThrowingFunction) factory.forPTransform("transform", windowPTransform);
WindowedValue<?> output = fn.apply(WindowedValue.of(22L, new Instant(5), new IntervalWindow(new Instant(0L), new Instant(20027L)), PaneInfo.ON_TIME_AND_ONLY_FIRING));
assertThat(output, equalTo(WindowedValue.of(22L, new Instant(5), new IntervalWindow(new Instant(5L), Duration.standardMinutes(12L)), PaneInfo.ON_TIME_AND_ONLY_FIRING)));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class MapFnRunnersTest method testFullWindowedValueMappingWithCompressedWindow.
@Test
public void testFullWindowedValueMappingWithCompressedWindow() throws Exception {
PTransformRunnerFactoryTestContext context = PTransformRunnerFactoryTestContext.builder(EXPECTED_ID, EXPECTED_PTRANSFORM).processBundleInstructionId("57").pCollections(Collections.singletonMap("inputPC", INPUT_PCOLLECTION)).coders(Collections.singletonMap("coder-id", valueCoder)).build();
List<WindowedValue<?>> outputConsumer = new ArrayList<>();
context.addPCollectionConsumer("outputPC", outputConsumer::add, StringUtf8Coder.of());
MapFnRunners.forWindowedValueMapFnFactory(this::createMapFunctionForPTransform).createRunnerForPTransform(context);
assertThat(context.getStartBundleFunctions(), empty());
assertThat(context.getFinishBundleFunctions(), empty());
assertThat(context.getTearDownFunctions(), empty());
assertThat(context.getPCollectionConsumers().keySet(), containsInAnyOrder("inputPC", "outputPC"));
IntervalWindow firstWindow = new IntervalWindow(new Instant(0L), Duration.standardMinutes(10L));
IntervalWindow secondWindow = new IntervalWindow(new Instant(-10L), Duration.standardSeconds(22L));
context.getPCollectionConsumer("inputPC").accept(WindowedValue.of("abc", new Instant(12), ImmutableSet.of(firstWindow, GlobalWindow.INSTANCE, secondWindow), PaneInfo.NO_FIRING));
assertThat(outputConsumer, containsInAnyOrder(WindowedValue.timestampedValueInGlobalWindow("ABC", new Instant(12)), WindowedValue.of("ABC", new Instant(12), secondWindow, PaneInfo.NO_FIRING), WindowedValue.of("ABC", new Instant(12), firstWindow, PaneInfo.NO_FIRING)));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class StateContextsTest method windowOnlyContextWindowReturnsWindow.
@Test
public void windowOnlyContextWindowReturnsWindow() {
BoundedWindow window = new IntervalWindow(new Instant(-137), Duration.millis(21L));
StateContext<BoundedWindow> context = StateContexts.windowOnlyContext(window);
assertThat(context.window(), equalTo(window));
}
use of org.apache.beam.sdk.transforms.windowing.IntervalWindow in project beam by apache.
the class StateContextsTest method windowOnlyContextThrowsOnOptions.
@Test
public void windowOnlyContextThrowsOnOptions() {
BoundedWindow window = new IntervalWindow(new Instant(-137), Duration.millis(21L));
StateContext<BoundedWindow> context = StateContexts.windowOnlyContext(window);
thrown.expect(IllegalArgumentException.class);
context.getPipelineOptions();
}
Aggregations