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());
}
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());
}
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);
}
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());
}
Aggregations