use of org.apache.beam.runners.core.StateNamespaceForTest in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testCommitWithoutUnderlying.
@Test
public void testCommitWithoutUnderlying() {
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"));
internals.commit();
BagState<String> reReadStringBag = internals.state(namespace, bagTag);
assertThat(reReadStringBag.read(), containsInAnyOrder("baz", "bar"));
assertThat(internals.isEmpty(), is(false));
}
use of org.apache.beam.runners.core.StateNamespaceForTest in project beam by apache.
the class CopyOnAccessInMemoryStateInternalsTest method testCommitWithOverwrittenUnderlying.
@Test
public void testCommitWithOverwrittenUnderlying() {
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");
BagState<String> internalsState = internals.state(namespace, bagTag);
internalsState.add("eggs");
internalsState.add("ham");
internalsState.add("0x00ff00");
internalsState.add("&");
internals.commit();
BagState<String> reReadInternalState = internals.state(namespace, bagTag);
assertThat(reReadInternalState.read(), containsInAnyOrder("bar", "baz", "0x00ff00", "eggs", "&", "ham"));
BagState<String> reReadUnderlyingState = underlying.state(namespace, bagTag);
assertThat(reReadUnderlyingState.read(), containsInAnyOrder("bar", "baz"));
}
use of org.apache.beam.runners.core.StateNamespaceForTest 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.runners.core.StateNamespaceForTest 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.runners.core.StateNamespaceForTest 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));
}
Aggregations