use of io.pravega.client.tables.impl.TableSegmentKey in project pravega by pravega.
the class SegmentHelper method readTableKeys.
public CompletableFuture<HashTableIteratorItem<TableSegmentKey>> readTableKeys(final String tableName, final PravegaNodeUri uri, final int suggestedKeyCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE_KEYS;
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
final HashTableIteratorItem.State token = (state == null) ? HashTableIteratorItem.State.EMPTY : state;
WireCommands.TableIteratorArgs args = new WireCommands.TableIteratorArgs(token.getToken(), Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
WireCommands.ReadTableKeys request = new WireCommands.ReadTableKeys(requestId, tableName, delegationToken, suggestedKeyCount, args);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableKeys.class, type);
WireCommands.TableKeysRead tableKeysRead = (WireCommands.TableKeysRead) rpl;
final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableKeysRead.getContinuationToken());
final List<TableSegmentKey> keys = tableKeysRead.getKeys().stream().map(k -> TableSegmentKey.versioned(k.getData(), k.getKeyVersion())).collect(Collectors.toList());
return new HashTableIteratorItem<>(newState, keys);
});
}
use of io.pravega.client.tables.impl.TableSegmentKey in project pravega by pravega.
the class SegmentHelper method readTable.
public CompletableFuture<List<TableSegmentEntry>> readTable(final String tableName, final PravegaNodeUri uri, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.READ_TABLE;
// the version is always NO_VERSION as read returns the latest version of value.
List<WireCommands.TableKey> keyList = keys.stream().map(k -> new WireCommands.TableKey(k.getKey(), k.getVersion().getSegmentVersion())).collect(Collectors.toList());
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.ReadTable request = new WireCommands.ReadTable(requestId, tableName, delegationToken, keyList);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTable.class, type);
return ((WireCommands.TableRead) rpl).getEntries().getEntries().stream().map(this::convertFromWireCommand).collect(Collectors.toList());
});
}
use of io.pravega.client.tables.impl.TableSegmentKey in project pravega by pravega.
the class PravegaTablesScopeTest method testRemoveTagsUnderScope.
@Test(timeout = 5000)
@SuppressWarnings("unchecked")
public void testRemoveTagsUnderScope() {
// Setup Mocks.
GrpcAuthHelper authHelper = mock(GrpcAuthHelper.class);
when(authHelper.retrieveMasterToken()).thenReturn("");
SegmentHelper segmentHelper = mock(SegmentHelper.class);
PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
PravegaTablesScope tablesScope = spy(new PravegaTablesScope(scope, storeHelper));
doReturn(CompletableFuture.completedFuture(indexTable)).when(tablesScope).getAllStreamTagsInScopeTableNames(stream, context);
// Simulate an empty value being returned.
TableSegmentEntry entry = TableSegmentEntry.versioned(tagBytes, new byte[0], 1L);
when(segmentHelper.readTable(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(entry)));
when(segmentHelper.updateTableEntries(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(TableSegmentKeyVersion.from(2L))));
when(segmentHelper.removeTableKeys(eq(indexTable), any(), anyString(), anyLong())).thenAnswer(invocation -> {
// Capture the key value sent during removeTableKeys.
keySnapshot = (List<TableSegmentKey>) invocation.getArguments()[1];
return CompletableFuture.completedFuture(null);
});
// Invoke the removeTags method.
tablesScope.removeTagsUnderScope(stream, Set.of(tag), context).join();
// Verify if correctly detect that the data is empty and the entry is cleaned up.
verify(segmentHelper, times(1)).removeTableKeys(eq(indexTable), eq(keySnapshot), anyString(), anyLong());
// Verify if the version number is as expected.
assertEquals(2L, keySnapshot.get(0).getVersion().getSegmentVersion());
}
Aggregations