Search in sources :

Example 1 with OrderedListState

use of org.apache.beam.sdk.state.OrderedListState in project beam by apache.

the class WindmillStateInternalsTest method testOrderedListAddPersist.

@Test
public void testOrderedListAddPersist() throws Exception {
    StateTag<OrderedListState<String>> addr = StateTags.orderedList("orderedList", StringUtf8Coder.of());
    OrderedListState<String> orderedList = underTest.state(NAMESPACE, addr);
    SettableFuture<Map<Range<Instant>, RangeSet<Long>>> orderedListFuture = SettableFuture.create();
    orderedListFuture.set(null);
    SettableFuture<Map<Range<Instant>, RangeSet<Instant>>> deletionsFuture = SettableFuture.create();
    deletionsFuture.set(null);
    when(mockReader.valueFuture(systemKey(NAMESPACE, "orderedList" + IdTracker.IDS_AVAILABLE_STR), STATE_FAMILY, IdTracker.IDS_AVAILABLE_CODER)).thenReturn(orderedListFuture);
    when(mockReader.valueFuture(systemKey(NAMESPACE, "orderedList" + IdTracker.DELETIONS_STR), STATE_FAMILY, IdTracker.SUBRANGE_DELETIONS_CODER)).thenReturn(deletionsFuture);
    orderedList.add(TimestampedValue.of("hello", Instant.ofEpochMilli(1)));
    Windmill.WorkItemCommitRequest.Builder commitBuilder = Windmill.WorkItemCommitRequest.newBuilder();
    underTest.persist(commitBuilder);
    assertEquals(1, commitBuilder.getSortedListUpdatesCount());
    TagSortedListUpdateRequest updates = commitBuilder.getSortedListUpdates(0);
    assertEquals(key(NAMESPACE, "orderedList"), updates.getTag());
    assertEquals(1, updates.getInsertsCount());
    assertEquals(1, updates.getInserts(0).getEntriesCount());
    assertEquals("hello", updates.getInserts(0).getEntries(0).getValue().toStringUtf8());
    assertEquals(1000, updates.getInserts(0).getEntries(0).getSortKey());
    assertEquals(IdTracker.MIN_ID, updates.getInserts(0).getEntries(0).getId());
}
Also used : OrderedListState(org.apache.beam.sdk.state.OrderedListState) Instant(org.joda.time.Instant) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) TagSortedListUpdateRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.TagSortedListUpdateRequest) Map(java.util.Map) AbstractMap(java.util.AbstractMap) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 2 with OrderedListState

use of org.apache.beam.sdk.state.OrderedListState in project beam by apache.

the class WindmillStateInternalsTest method testOrderedListPersistEmpty.

@Test
public void testOrderedListPersistEmpty() throws Exception {
    StateTag<OrderedListState<String>> addr = StateTags.orderedList("orderedList", StringUtf8Coder.of());
    OrderedListState<String> orderedListState = underTest.state(NAMESPACE, addr);
    orderedListState.clear();
    Windmill.WorkItemCommitRequest.Builder commitBuilder = Windmill.WorkItemCommitRequest.newBuilder();
    underTest.persist(commitBuilder);
    // 1 bag update = the clear
    assertEquals(1, commitBuilder.getSortedListUpdatesCount());
    TagSortedListUpdateRequest updates = commitBuilder.getSortedListUpdates(0);
    assertEquals(1, updates.getDeletesCount());
    assertEquals(WindmillOrderedList.MIN_TS_MICROS, updates.getDeletes(0).getRange().getStart());
    assertEquals(WindmillOrderedList.MAX_TS_MICROS, updates.getDeletes(0).getRange().getLimit());
}
Also used : OrderedListState(org.apache.beam.sdk.state.OrderedListState) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) TagSortedListUpdateRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.TagSortedListUpdateRequest) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 3 with OrderedListState

use of org.apache.beam.sdk.state.OrderedListState in project beam by apache.

the class WindmillStateInternalsTest method testOrderedListClearPersist.

@Test
public void testOrderedListClearPersist() throws Exception {
    StateTag<OrderedListState<String>> addr = StateTags.orderedList("orderedList", StringUtf8Coder.of());
    OrderedListState<String> orderedListState = underTest.state(NAMESPACE, addr);
    orderedListState.add(TimestampedValue.of("hello", Instant.ofEpochMilli(1)));
    orderedListState.clear();
    orderedListState.add(TimestampedValue.of("world", Instant.ofEpochMilli(2)));
    orderedListState.add(TimestampedValue.of("world", Instant.ofEpochMilli(2)));
    Windmill.WorkItemCommitRequest.Builder commitBuilder = Windmill.WorkItemCommitRequest.newBuilder();
    underTest.persist(commitBuilder);
    assertEquals(1, commitBuilder.getSortedListUpdatesCount());
    TagSortedListUpdateRequest updates = commitBuilder.getSortedListUpdates(0);
    assertEquals(STATE_FAMILY, updates.getStateFamily());
    assertEquals(key(NAMESPACE, "orderedList"), updates.getTag());
    assertEquals(1, updates.getInsertsCount());
    assertEquals(2, updates.getInserts(0).getEntriesCount());
    assertEquals("world", updates.getInserts(0).getEntries(0).getValue().toStringUtf8());
    assertEquals("world", updates.getInserts(0).getEntries(1).getValue().toStringUtf8());
    assertEquals(2000, updates.getInserts(0).getEntries(0).getSortKey());
    assertEquals(2000, updates.getInserts(0).getEntries(1).getSortKey());
    assertEquals(IdTracker.MIN_ID, updates.getInserts(0).getEntries(0).getId());
    assertEquals(IdTracker.MIN_ID + 1, updates.getInserts(0).getEntries(1).getId());
    Mockito.verifyNoMoreInteractions(mockReader);
}
Also used : OrderedListState(org.apache.beam.sdk.state.OrderedListState) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) TagSortedListUpdateRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.TagSortedListUpdateRequest) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 4 with OrderedListState

use of org.apache.beam.sdk.state.OrderedListState in project beam by apache.

the class WindmillStateInternalsTest method testOrderedListDeleteRangePersist.

@Test
public void testOrderedListDeleteRangePersist() {
    SettableFuture<Map<Range<Instant>, RangeSet<Long>>> orderedListFuture = SettableFuture.create();
    orderedListFuture.set(null);
    SettableFuture<Map<Range<Instant>, RangeSet<Instant>>> deletionsFuture = SettableFuture.create();
    deletionsFuture.set(null);
    when(mockReader.valueFuture(systemKey(NAMESPACE, "orderedList" + IdTracker.IDS_AVAILABLE_STR), STATE_FAMILY, IdTracker.IDS_AVAILABLE_CODER)).thenReturn(orderedListFuture);
    when(mockReader.valueFuture(systemKey(NAMESPACE, "orderedList" + IdTracker.DELETIONS_STR), STATE_FAMILY, IdTracker.SUBRANGE_DELETIONS_CODER)).thenReturn(deletionsFuture);
    StateTag<OrderedListState<String>> addr = StateTags.orderedList("orderedList", StringUtf8Coder.of());
    OrderedListState<String> orderedListState = underTest.state(NAMESPACE, addr);
    orderedListState.add(TimestampedValue.of("hello", Instant.ofEpochMilli(1)));
    orderedListState.add(TimestampedValue.of("hello", Instant.ofEpochMilli(2)));
    orderedListState.add(TimestampedValue.of("hello", Instant.ofEpochMilli(2)));
    orderedListState.add(TimestampedValue.of("world", Instant.ofEpochMilli(3)));
    orderedListState.add(TimestampedValue.of("world", Instant.ofEpochMilli(4)));
    orderedListState.clearRange(Instant.ofEpochMilli(2), Instant.ofEpochMilli(4));
    Windmill.WorkItemCommitRequest.Builder commitBuilder = Windmill.WorkItemCommitRequest.newBuilder();
    underTest.persist(commitBuilder);
    assertEquals(1, commitBuilder.getSortedListUpdatesCount());
    TagSortedListUpdateRequest updates = commitBuilder.getSortedListUpdates(0);
    assertEquals(STATE_FAMILY, updates.getStateFamily());
    assertEquals(key(NAMESPACE, "orderedList"), updates.getTag());
    assertEquals(1, updates.getInsertsCount());
    assertEquals(2, updates.getInserts(0).getEntriesCount());
    assertEquals("hello", updates.getInserts(0).getEntries(0).getValue().toStringUtf8());
    assertEquals("world", updates.getInserts(0).getEntries(1).getValue().toStringUtf8());
    assertEquals(1000, updates.getInserts(0).getEntries(0).getSortKey());
    assertEquals(4000, updates.getInserts(0).getEntries(1).getSortKey());
    assertEquals(IdTracker.MIN_ID, updates.getInserts(0).getEntries(0).getId());
    assertEquals(IdTracker.MIN_ID + 1, updates.getInserts(0).getEntries(1).getId());
}
Also used : OrderedListState(org.apache.beam.sdk.state.OrderedListState) Instant(org.joda.time.Instant) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) TagSortedListUpdateRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.TagSortedListUpdateRequest) Map(java.util.Map) AbstractMap(java.util.AbstractMap) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Aggregations

StateNamespaceForTest (org.apache.beam.runners.core.StateNamespaceForTest)4 TagSortedListUpdateRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.TagSortedListUpdateRequest)4 OrderedListState (org.apache.beam.sdk.state.OrderedListState)4 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)4 Test (org.junit.Test)4 AbstractMap (java.util.AbstractMap)2 Map (java.util.Map)2 Instant (org.joda.time.Instant)2