Search in sources :

Example 16 with WatermarkHoldState

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);
}
Also used : Instant(org.joda.time.Instant) WatermarkHoldState(org.apache.beam.sdk.state.WatermarkHoldState) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 17 with WatermarkHoldState

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));
}
Also used : Instant(org.joda.time.Instant) WatermarkHoldState(org.apache.beam.sdk.state.WatermarkHoldState) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 18 with WatermarkHoldState

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)));
}
Also used : Instant(org.joda.time.Instant) BoundedWindow(org.apache.beam.sdk.transforms.windowing.BoundedWindow) WatermarkHoldState(org.apache.beam.sdk.state.WatermarkHoldState) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 19 with WatermarkHoldState

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)));
}
Also used : Instant(org.joda.time.Instant) BoundedWindow(org.apache.beam.sdk.transforms.windowing.BoundedWindow) WatermarkHoldState(org.apache.beam.sdk.state.WatermarkHoldState) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 20 with WatermarkHoldState

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)));
}
Also used : Instant(org.joda.time.Instant) BoundedWindow(org.apache.beam.sdk.transforms.windowing.BoundedWindow) WatermarkHoldState(org.apache.beam.sdk.state.WatermarkHoldState) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Aggregations

WatermarkHoldState (org.apache.beam.sdk.state.WatermarkHoldState)25 Instant (org.joda.time.Instant)24 Test (org.junit.Test)22 StateNamespaceForTest (org.apache.beam.runners.core.StateNamespaceForTest)16 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)3 ReadableState (org.apache.beam.sdk.state.ReadableState)2 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 StateNamespace (org.apache.beam.runners.core.StateNamespace)1 TimestampCombiner (org.apache.beam.sdk.transforms.windowing.TimestampCombiner)1