use of org.apache.beam.sdk.state.BagState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testGetWithAbsentInUnderlying.
@Test
public void testGetWithAbsentInUnderlying() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<String>> bagTag = StateTags.bag("foo", StringUtf8Coder.of());
BagState<String> stringBag = internals.state(namespace, bagTag);
assertThat(stringBag.read(), emptyIterable());
stringBag.add("bar");
stringBag.add("baz");
assertThat(stringBag.read(), containsInAnyOrder("baz", "bar"));
BagState<String> reReadVoidBag = internals.state(namespace, bagTag);
assertThat(reReadVoidBag.read(), containsInAnyOrder("baz", "bar"));
BagState<String> underlyingState = underlying.state(namespace, bagTag);
assertThat(underlyingState.read(), emptyIterable());
}
use of org.apache.beam.sdk.state.BagState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testCommitWithEmptyNewAndFullUnderlyingIsNotEmpty.
@Test
public void testCommitWithEmptyNewAndFullUnderlyingIsNotEmpty() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<String>> bagTag = StateTags.bag("foo", StringUtf8Coder.of());
BagState<String> stringBag = underlying.state(namespace, bagTag);
assertThat(stringBag.read(), emptyIterable());
stringBag.add("bar");
stringBag.add("baz");
internals.commit();
assertThat(internals.isEmpty(), is(false));
}
use of org.apache.beam.sdk.state.BagState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testCommitWithUnderlying.
@Test
public void testCommitWithUnderlying() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<String>> bagTag = StateTags.bag("foo", StringUtf8Coder.of());
BagState<String> stringBag = underlying.state(namespace, bagTag);
assertThat(stringBag.read(), emptyIterable());
stringBag.add("bar");
stringBag.add("baz");
internals.commit();
BagState<String> reReadStringBag = internals.state(namespace, bagTag);
assertThat(reReadStringBag.read(), containsInAnyOrder("baz", "bar"));
reReadStringBag.add("spam");
BagState<String> underlyingState = underlying.state(namespace, bagTag);
assertThat(underlyingState.read(), containsInAnyOrder("spam", "bar", "baz"));
assertThat(underlyingState, is(theInstance(stringBag)));
assertThat(internals.isEmpty(), is(false));
}
use of org.apache.beam.sdk.state.BagState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testBagStateWithUnderlying.
@Test
public void testBagStateWithUnderlying() {
CopyOnAccessInMemoryStateInternals<String> underlying = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<Integer>> valueTag = StateTags.bag("foo", VarIntCoder.of());
BagState<Integer> underlyingValue = underlying.state(namespace, valueTag);
assertThat(underlyingValue.read(), emptyIterable());
underlyingValue.add(1);
assertThat(underlyingValue.read(), containsInAnyOrder(1));
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, underlying);
BagState<Integer> copyOnAccessState = internals.state(namespace, valueTag);
assertThat(copyOnAccessState.read(), containsInAnyOrder(1));
copyOnAccessState.add(4);
assertThat(copyOnAccessState.read(), containsInAnyOrder(4, 1));
assertThat(underlyingValue.read(), containsInAnyOrder(1));
BagState<Integer> reReadUnderlyingValue = underlying.state(namespace, valueTag);
assertThat(underlyingValue.read(), equalTo(reReadUnderlyingValue.read()));
}
use of org.apache.beam.sdk.state.BagState in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testGetWithEmpty.
@Test
public void testGetWithEmpty() {
CopyOnAccessInMemoryStateInternals<String> internals = CopyOnAccessInMemoryStateInternals.withUnderlying(key, null);
StateNamespace namespace = new StateNamespaceForTest("foo");
StateTag<BagState<String>> bagTag = StateTags.bag("foo", StringUtf8Coder.of());
BagState<String> stringBag = internals.state(namespace, bagTag);
assertThat(stringBag.read(), emptyIterable());
stringBag.add("bar");
stringBag.add("baz");
assertThat(stringBag.read(), containsInAnyOrder("baz", "bar"));
BagState<String> reReadStringBag = internals.state(namespace, bagTag);
assertThat(reReadStringBag.read(), containsInAnyOrder("baz", "bar"));
}
Aggregations