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