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));
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class ApexStateInternalsTest 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 ApexStateInternalsTest method testWatermarkLatestState.
@Test
public void testWatermarkLatestState() throws Exception {
WatermarkHoldState value = underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR);
// State instances are cached, but depend on the namespace.
assertEquals(value, underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR));
assertFalse(value.equals(underTest.state(NAMESPACE_2, WATERMARK_LATEST_ADDR)));
assertThat(value.read(), Matchers.nullValue());
value.add(new Instant(2000));
assertThat(value.read(), Matchers.equalTo(new Instant(2000)));
value.add(new Instant(3000));
assertThat(value.read(), Matchers.equalTo(new Instant(3000)));
value.add(new Instant(1000));
assertThat(value.read(), Matchers.equalTo(new Instant(3000)));
value.clear();
assertThat(value.read(), Matchers.equalTo(null));
assertEquals(underTest.state(NAMESPACE_1, WATERMARK_LATEST_ADDR), value);
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class ApexStateInternalsTest method testWatermarkEndOfWindowState.
@Test
public void testWatermarkEndOfWindowState() throws Exception {
WatermarkHoldState value = underTest.state(NAMESPACE_1, WATERMARK_EOW_ADDR);
// State instances are cached, but depend on the namespace.
assertEquals(value, underTest.state(NAMESPACE_1, WATERMARK_EOW_ADDR));
assertFalse(value.equals(underTest.state(NAMESPACE_2, WATERMARK_EOW_ADDR)));
assertThat(value.read(), Matchers.nullValue());
value.add(new Instant(2000));
assertThat(value.read(), Matchers.equalTo(new Instant(2000)));
value.clear();
assertThat(value.read(), Matchers.equalTo(null));
assertEquals(underTest.state(NAMESPACE_1, WATERMARK_EOW_ADDR), value);
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class ApexStateInternalsTest 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(), Matchers.equalTo(new Instant(2000)));
value.add(new Instant(3000));
assertThat(value.read(), Matchers.equalTo(new Instant(2000)));
value.add(new Instant(1000));
assertThat(value.read(), Matchers.equalTo(new Instant(1000)));
value.clear();
assertThat(value.read(), Matchers.equalTo(null));
assertEquals(underTest.state(NAMESPACE_1, WATERMARK_EARLIEST_ADDR), value);
}
Aggregations