use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class InMemoryStateInternalsTest method testWatermarkEarliestState.
@Test
public void testWatermarkEarliestState() throws Exception {
WatermarkHoldState value = underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR);
// State instances are cached, but depend on the namespace.
assertEquals(value, underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR));
assertFalse(value.equals(underTest.state(NAMESPACE_2, WATERMARK_EARLIEST_ADDR)));
assertThat(value.read(), Matchers.nullValue());
value.add(new Instant(2000));
assertThat(value.read(), equalTo(new Instant(2000)));
value.add(new Instant(3000));
assertThat(value.read(), equalTo(new Instant(2000)));
value.add(new Instant(1000));
assertThat(value.read(), equalTo(new Instant(1000)));
value.clear();
assertThat(value.read(), equalTo(null));
assertThat(underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR), Matchers.sameInstance(value));
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class ApexStateInternalsTest method testMergeEarliestWatermarkIntoSource.
@Test
public void testMergeEarliestWatermarkIntoSource() throws Exception {
WatermarkHoldState value1 = underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR);
WatermarkHoldState value2 = underTest.state(NAMESPACE_2, WATERMARK_EARLIEST_ADDR);
value1.add(new Instant(3000));
value2.add(new Instant(5000));
value1.add(new Instant(4000));
value2.add(new Instant(2000));
// Merging clears the old values and updates the merged value.
StateMerging.mergeWatermarks(Arrays.asList(value1, value2), value1, WINDOW_1);
assertThat(value1.read(), Matchers.equalTo(new Instant(2000)));
assertThat(value2.read(), Matchers.equalTo(null));
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class FlinkStateInternalsTest method testMergeLatestWatermarkIntoSource.
@Test
public void testMergeLatestWatermarkIntoSource() throws Exception {
WatermarkHoldState value1 = underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR);
WatermarkHoldState value2 = underTest.state(NAMESPACE_2, WATERMARK_LATEST_ADDR);
WatermarkHoldState value3 = underTest.state(NAMESPACE_3, WATERMARK_LATEST_ADDR);
value1.add(new Instant(3000));
value2.add(new Instant(5000));
value1.add(new Instant(4000));
value2.add(new Instant(2000));
// Merging clears the old values and updates the result value.
StateMerging.mergeWatermarks(Arrays.asList(value1, value2), value3, WINDOW_1);
// Merging clears the old values and updates the result value.
assertThat(value3.read(), Matchers.equalTo(new Instant(5000)));
assertThat(value1.read(), Matchers.equalTo(null));
assertThat(value2.read(), Matchers.equalTo(null));
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testWatermarkHoldStateWithUnderlying.
@Test
public void testWatermarkHoldStateWithUnderlying() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
TimestampCombiner timestampCombiner = TimestampCombiner.EARLIEST;
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<WatermarkHoldState> stateTag = StateTags.watermarkStateInternal("wmstate", timestampCombiner);
WatermarkHoldState underlyingValue = underlying.state(namespace, stateTag);
assertThat(underlyingValue.read(), nullValue());
underlyingValue.add(new Instant(250L));
assertThat(underlyingValue.read(), equalTo(new Instant(250L)));
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
WatermarkHoldState copyOnAccessState = internals.state(namespace, stateTag);
assertThat(copyOnAccessState.read(), equalTo(new Instant(250L)));
copyOnAccessState.add(new Instant(100L));
assertThat(copyOnAccessState.read(), equalTo(new Instant(100L)));
assertThat(underlyingValue.read(), equalTo(new Instant(250L)));
copyOnAccessState.add(new Instant(500L));
assertThat(copyOnAccessState.read(), equalTo(new Instant(100L)));
WatermarkHoldState reReadUnderlyingValue = underlying.state(namespace, stateTag);
assertThat(underlyingValue.read(), equalTo(reReadUnderlyingValue.read()));
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class ApexStateInternalsTest method testWatermarkStateIsEmpty.
@Test
public void testWatermarkStateIsEmpty() throws Exception {
WatermarkHoldState value = underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR);
assertThat(value.isEmpty().read(), Matchers.is(true));
ReadableState<Boolean> readFuture = value.isEmpty();
value.add(new Instant(1000));
assertThat(readFuture.read(), Matchers.is(false));
value.clear();
assertThat(readFuture.read(), Matchers.is(true));
}
Aggregations