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);
}
use of org.apache.beam.sdk.state.WatermarkHoldState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testGetEarliestWatermarkHoldWithEarliestInUnderlyingTable.
@Test
public void testGetEarliestWatermarkHoldWithEarliestInUnderlyingTable() {
BoundedWindow first = new BoundedWindow() {
@Override
public Instant maxTimestamp() {
return new Instant(2048L);
}
};
BoundedWindow second = new BoundedWindow() {
@Override
public Instant maxTimestamp() {
return new Instant(689743L);
}
};
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying("foo", null);
StateTag<WatermarkHoldState> firstHoldAddress = StateTags.watermarkStateInternal("foo", TimestampCombiner.EARLIEST);
WatermarkHoldState firstHold = underlying.state(StateNamespaces.window(null, first), firstHoldAddress);
firstHold.add(new Instant(22L));
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying("foo", underlying.commit());
StateTag<WatermarkHoldState> secondHoldAddress = StateTags.watermarkStateInternal("foo", TimestampCombiner.EARLIEST);
WatermarkHoldState secondHold = internals.state(StateNamespaces.window(null, second), secondHoldAddress);
secondHold.add(new Instant(244L));
internals.commit();
assertThat(internals.getEarliestWatermarkHold(), equalTo(new Instant(22L)));
}
Aggregations