Search in sources :

Example 31 with TableEntry

use of io.pravega.segmentstore.contracts.tables.TableEntry in project pravega by pravega.

the class PravegaRequestProcessorTest method testRemoveKeys.

@Test(timeout = 30000)
public void testRemoveKeys() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against
    val rnd = new Random(0);
    String tableSegmentName = "testRemoveEntries";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    ServerConnection connection = mock(ServerConnection.class);
    ConnectionTracker tracker = mock(ConnectionTracker.class);
    InOrder order = inOrder(connection);
    val recorderMock = mock(TableSegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, new TrackedConnection(connection, tracker), SegmentStatsRecorder.noOp(), recorderMock, new PassingTokenVerifier(), false);
    // Generate keys.
    ArrayList<ArrayView> keys = generateKeys(3, rnd);
    // Create a table segment and add data.
    processor.createTableSegment(new WireCommands.CreateTableSegment(1, tableSegmentName, false, 0, "", 0));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, tableSegmentName));
    TableEntry e1 = TableEntry.unversioned(keys.get(0), generateValue(rnd));
    processor.updateTableEntries(new WireCommands.UpdateTableEntries(2, tableSegmentName, "", getTableEntries(singletonList(e1)), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    order.verify(connection).send(new WireCommands.TableEntriesUpdated(2, singletonList(0L)));
    verify(recorderMock).createTableSegment(eq(tableSegmentName), any());
    verify(recorderMock).updateEntries(eq(tableSegmentName), eq(1), eq(false), any());
    verifyConnectionTracker(e1, connection, tracker);
    // Remove a Table Key
    WireCommands.TableKey key = new WireCommands.TableKey(toByteBuf(e1.getKey().getKey()), 0L);
    processor.removeTableKeys(new WireCommands.RemoveTableKeys(3, tableSegmentName, "", singletonList(key), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    order.verify(connection).send(new WireCommands.TableKeysRemoved(3, tableSegmentName));
    verify(recorderMock).removeKeys(eq(tableSegmentName), eq(1), eq(true), any());
    verifyConnectionTracker(key, connection, tracker);
    // Test with non-existent key.
    key = new WireCommands.TableKey(toByteBuf(e1.getKey().getKey()), 0L);
    processor.removeTableKeys(new WireCommands.RemoveTableKeys(4, tableSegmentName, "", singletonList(key), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    order.verify(connection).send(new WireCommands.TableKeyBadVersion(4, tableSegmentName, ""));
    verifyConnectionTracker(key, connection, tracker);
    long segmentLength = store.getStreamSegmentInfo(tableSegmentName, Duration.ofMinutes(1)).get().getLength();
    // Test when providing a matching tableSegmentOffset.
    TableEntry e2 = TableEntry.unversioned(keys.get(1), generateValue(rnd));
    key = new WireCommands.TableKey(toByteBuf(e2.getKey().getKey()), e2.getKey().getVersion());
    processor.removeTableKeys(new WireCommands.RemoveTableKeys(5, tableSegmentName, "", singletonList(key), segmentLength));
    order.verify(connection).send(new WireCommands.TableKeysRemoved(5, tableSegmentName));
    verify(recorderMock).removeKeys(eq(tableSegmentName), eq(1), eq(true), any());
    verifyConnectionTracker(key, connection, tracker);
    // // Test when providing a mismatching tableSegmentOffset.
    long badOffset = segmentLength - 1;
    TableEntry e3 = TableEntry.unversioned(keys.get(2), generateValue(rnd));
    key = new WireCommands.TableKey(toByteBuf(e3.getKey().getKey()), e3.getKey().getVersion());
    processor.removeTableKeys(new WireCommands.RemoveTableKeys(6, tableSegmentName, "", singletonList(key), badOffset));
    segmentLength = store.getStreamSegmentInfo(tableSegmentName, Duration.ofMinutes(1)).get().getLength();
    // BadOffsetException should be thrown, prompting a SegmentIsTruncated response.
    order.verify(connection).send(new WireCommands.SegmentIsTruncated(6, tableSegmentName, segmentLength, "", badOffset));
    verify(recorderMock).removeKeys(eq(tableSegmentName), eq(1), eq(true), any());
    verifyConnectionTracker(key, connection, tracker);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Random(java.util.Random) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) WireCommands(io.pravega.shared.protocol.netty.WireCommands) lombok.val(lombok.val) InOrder(org.mockito.InOrder) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) ArrayView(io.pravega.common.util.ArrayView) Test(org.junit.Test)

Example 32 with TableEntry

use of io.pravega.segmentstore.contracts.tables.TableEntry in project pravega by pravega.

the class PravegaRequestProcessorTest method testReadTableEntriesDelta.

@Test
public void testReadTableEntriesDelta() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against
    val rnd = new Random(0);
    String tableSegmentName = "testReadTableEntriesDelta";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    val recorderMock = mock(TableSegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, new TrackedConnection(connection), SegmentStatsRecorder.noOp(), recorderMock, new PassingTokenVerifier(), false);
    // Generate keys.
    ArrayList<ArrayView> keys = generateKeys(3, rnd);
    ArrayView testValue = generateValue(rnd);
    TableEntry e1 = TableEntry.unversioned(keys.get(0), testValue);
    TableEntry e2 = TableEntry.unversioned(keys.get(1), testValue);
    TableEntry e3 = TableEntry.unversioned(keys.get(2), testValue);
    // Create a table segment and add data.
    processor.createTableSegment(new WireCommands.CreateTableSegment(1, tableSegmentName, false, 0, "", 0));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, tableSegmentName));
    verify(recorderMock).createTableSegment(eq(tableSegmentName), any());
    processor.updateTableEntries(new WireCommands.UpdateTableEntries(2, tableSegmentName, "", getTableEntries(asList(e1, e2, e3)), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    verify(recorderMock).updateEntries(eq(tableSegmentName), eq(3), eq(false), any());
    // 1. Now read the table entries where suggestedEntryCount is equal to number of entries in the Table Store.
    processor.readTableEntriesDelta(new WireCommands.ReadTableEntriesDelta(3, tableSegmentName, "", 0, 3));
    // Capture the WireCommands sent.
    ArgumentCaptor<WireCommand> wireCommandsCaptor = ArgumentCaptor.forClass(WireCommand.class);
    order.verify(connection, times(2)).send(wireCommandsCaptor.capture());
    verify(recorderMock).iterateEntries(eq(tableSegmentName), eq(3), any());
    // Verify the WireCommands.
    List<Long> keyVersions = ((WireCommands.TableEntriesUpdated) wireCommandsCaptor.getAllValues().get(0)).getUpdatedVersions();
    WireCommands.TableEntriesDeltaRead getTableEntriesIteratorsResp = (WireCommands.TableEntriesDeltaRead) wireCommandsCaptor.getAllValues().get(1);
    assertTrue(getTableEntriesIteratorsResp.getEntries().getEntries().stream().map(e -> e.getKey().getKeyVersion()).collect(Collectors.toList()).containsAll(keyVersions));
    // Verify if the value is correct.
    assertTrue(getTableEntriesIteratorsResp.getEntries().getEntries().stream().allMatch(e -> {
        ByteBuf buf = e.getValue().getData();
        byte[] bytes = new byte[buf.readableBytes()];
        buf.getBytes(buf.readerIndex(), bytes);
        return testValue.equals(new ByteArraySegment(bytes));
    }));
    // 2. Now read the table entries where suggestedEntryCount is less than the number of entries in the Table Store.
    processor.readTableEntriesDelta(new WireCommands.ReadTableEntriesDelta(3, tableSegmentName, "", 0L, 1));
    // Capture the WireCommands sent.
    ArgumentCaptor<WireCommands.TableEntriesDeltaRead> tableEntriesCaptor = ArgumentCaptor.forClass(WireCommands.TableEntriesDeltaRead.class);
    order.verify(connection, times(1)).send(tableEntriesCaptor.capture());
    // Verify the WireCommands.
    getTableEntriesIteratorsResp = tableEntriesCaptor.getAllValues().get(0);
    assertEquals(1, getTableEntriesIteratorsResp.getEntries().getEntries().size());
    assertTrue(keyVersions.contains(getTableEntriesIteratorsResp.getEntries().getEntries().get(0).getKey().getKeyVersion()));
    assertFalse(getTableEntriesIteratorsResp.isShouldClear());
    assertFalse(getTableEntriesIteratorsResp.isReachedEnd());
    // Get the last position.
    long lastPosition = getTableEntriesIteratorsResp.getLastPosition();
    // 3. Now read the remaining table entries by providing a higher suggestedKeyCount and the state to the iterator.
    processor.readTableEntriesDelta(new WireCommands.ReadTableEntriesDelta(3, tableSegmentName, "", lastPosition, 3));
    // Capture the WireCommands sent.
    order.verify(connection, times(1)).send(tableEntriesCaptor.capture());
    verify(recorderMock).iterateEntries(eq(tableSegmentName), eq(1), any());
    // Verify the WireCommands.
    getTableEntriesIteratorsResp = tableEntriesCaptor.getAllValues().get(1);
    // We read through all the entries, so this should report as having reached the end.
    assertTrue(getTableEntriesIteratorsResp.isReachedEnd());
    assertEquals(2, getTableEntriesIteratorsResp.getEntries().getEntries().size());
    assertTrue(keyVersions.containsAll(getTableEntriesIteratorsResp.getEntries().getEntries().stream().map(e -> e.getKey().getKeyVersion()).collect(Collectors.toList())));
    // 4. Update some TableEntry.
    TableEntry e4 = TableEntry.versioned(keys.get(0), generateValue(rnd), keyVersions.get(0));
    processor.updateTableEntries(new WireCommands.UpdateTableEntries(4, tableSegmentName, "", getTableEntries(asList(e4)), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    verify(recorderMock).updateEntries(eq(tableSegmentName), eq(1), eq(true), any());
    // 5. Remove some TableEntry.
    TableEntry e5 = TableEntry.versioned(keys.get(1), generateValue(rnd), keyVersions.get(1));
    WireCommands.TableKey key = new WireCommands.TableKey(toByteBuf(e5.getKey().getKey()), e5.getKey().getVersion());
    processor.removeTableKeys(new WireCommands.RemoveTableKeys(5, tableSegmentName, "", singletonList(key), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    order.verify(connection).send(new WireCommands.TableKeysRemoved(5, tableSegmentName));
    verify(recorderMock).removeKeys(eq(tableSegmentName), eq(1), eq(true), any());
    // // Now very the delta iteration returns a list with an updated key (4.) and a removed key (5.).
    processor.readTableEntriesDelta(new WireCommands.ReadTableEntriesDelta(6, tableSegmentName, "", 0L, 4));
    // verify(recorderMock).iterateEntries(eq(tableSegmentName), eq(3), any());
    // Capture the WireCommands sent.
    order.verify(connection).send(tableEntriesCaptor.capture());
    // Verify the WireCommands.
    getTableEntriesIteratorsResp = tableEntriesCaptor.getAllValues().get(2);
    val results = getTableEntriesIteratorsResp.getEntries().getEntries().stream().map(e -> TableEntry.versioned(new ByteBufWrapper(e.getKey().getData()), new ByteBufWrapper(e.getValue().getData()), e.getKey().getKeyVersion())).collect(Collectors.toList());
    assertEquals("Expecting 2 entries left in the TableSegment", 2, results.size());
    // Does not container entry removed.
    assertFalse(results.contains(e5));
}
Also used : ReadResultEntryBase(io.pravega.segmentstore.server.reading.ReadResultEntryBase) StreamSegmentInformation(io.pravega.segmentstore.contracts.StreamSegmentInformation) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) AssertExtensions(io.pravega.test.common.AssertExtensions) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Cleanup(lombok.Cleanup) Random(java.util.Random) ServiceBuilderConfig(io.pravega.segmentstore.server.store.ServiceBuilderConfig) Unpooled(io.netty.buffer.Unpooled) Collections.singletonList(java.util.Collections.singletonList) ArrayView(io.pravega.common.util.ArrayView) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Arrays.asList(java.util.Arrays.asList) BufferView(io.pravega.common.util.BufferView) Duration(java.time.Duration) Map(java.util.Map) SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) Unpooled.wrappedBuffer(io.netty.buffer.Unpooled.wrappedBuffer) Mockito.doReturn(org.mockito.Mockito.doReturn) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) StreamSegmentReadResult(io.pravega.segmentstore.server.reading.StreamSegmentReadResult) Attributes(io.pravega.segmentstore.contracts.Attributes) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) Mockito.clearInvocations(org.mockito.Mockito.clearInvocations) CancellationException(java.util.concurrent.CancellationException) ReadResultEntryType(io.pravega.segmentstore.contracts.ReadResultEntryType) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MetricsProvider(io.pravega.shared.metrics.MetricsProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ByteArraySegment(io.pravega.common.util.ByteArraySegment) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) Assert.assertFalse(org.junit.Assert.assertFalse) Mockito.inOrder(org.mockito.Mockito.inOrder) TestUtils(io.pravega.test.common.TestUtils) Futures(io.pravega.common.concurrent.Futures) ReadResult(io.pravega.segmentstore.contracts.ReadResult) StreamSegmentService(io.pravega.segmentstore.server.store.StreamSegmentService) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Setter(lombok.Setter) Getter(lombok.Getter) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) ServiceConfig(io.pravega.segmentstore.server.store.ServiceConfig) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) SegmentType(io.pravega.segmentstore.contracts.SegmentType) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ByteBuf(io.netty.buffer.ByteBuf) ReadResultEntry(io.pravega.segmentstore.contracts.ReadResultEntry) ByteBufWrapper(io.pravega.shared.protocol.netty.ByteBufWrapper) StreamSegmentTruncatedException(io.pravega.segmentstore.contracts.StreamSegmentTruncatedException) NameUtils(io.pravega.shared.NameUtils) Properties(java.util.Properties) InOrder(org.mockito.InOrder) SerializedClassRunner(io.pravega.test.common.SerializedClassRunner) AttributeId(io.pravega.segmentstore.contracts.AttributeId) lombok.val(lombok.val) Assert.assertTrue(org.junit.Assert.assertTrue) TableExtensionConfig(io.pravega.segmentstore.server.tables.TableExtensionConfig) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) MergeStreamSegmentResult(io.pravega.segmentstore.contracts.MergeStreamSegmentResult) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) Mockito.when(org.mockito.Mockito.when) WireCommands(io.pravega.shared.protocol.netty.WireCommands) TableSegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.TableSegmentStatsRecorder) Mockito.verify(org.mockito.Mockito.verify) WireCommand(io.pravega.shared.protocol.netty.WireCommand) Mockito(org.mockito.Mockito) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) AbstractMap(java.util.AbstractMap) Collectors.toList(java.util.stream.Collectors.toList) InlineExecutor(io.pravega.test.common.InlineExecutor) MetricsConfig(io.pravega.shared.metrics.MetricsConfig) Preconditions(com.google.common.base.Preconditions) Assert(org.junit.Assert) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteArraySegment(io.pravega.common.util.ByteArraySegment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteBuf(io.netty.buffer.ByteBuf) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Random(java.util.Random) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) WireCommands(io.pravega.shared.protocol.netty.WireCommands) lombok.val(lombok.val) WireCommand(io.pravega.shared.protocol.netty.WireCommand) InOrder(org.mockito.InOrder) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) ArrayView(io.pravega.common.util.ArrayView) ByteBufWrapper(io.pravega.shared.protocol.netty.ByteBufWrapper) Test(org.junit.Test)

Example 33 with TableEntry

use of io.pravega.segmentstore.contracts.tables.TableEntry in project pravega by pravega.

the class PravegaRequestProcessorTest method testReadTable.

@Test(timeout = 30000)
public void testReadTable() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against
    val rnd = new Random(0);
    String tableSegmentName = "testReadTable";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    val recorderMock = mock(TableSegmentStatsRecorder.class);
    val recorderMockOrder = inOrder(recorderMock);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, new TrackedConnection(connection), SegmentStatsRecorder.noOp(), recorderMock, new PassingTokenVerifier(), false);
    // Generate keys.
    ArrayList<ArrayView> keys = generateKeys(2, rnd);
    // Create a table segment and add data.
    processor.createTableSegment(new WireCommands.CreateTableSegment(1, tableSegmentName, false, 0, "", 0));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, tableSegmentName));
    recorderMockOrder.verify(recorderMock).createTableSegment(eq(tableSegmentName), any());
    TableEntry entry = TableEntry.unversioned(keys.get(0), generateValue(rnd));
    // Read value of a non-existent key.
    WireCommands.TableKey key = new WireCommands.TableKey(toByteBuf(entry.getKey().getKey()), TableKey.NO_VERSION);
    processor.readTable(new WireCommands.ReadTable(2, tableSegmentName, "", singletonList(key)));
    // expected result is Key (with key with version as NOT_EXISTS) and an empty TableValue.)
    WireCommands.TableKey keyResponse = new WireCommands.TableKey(toByteBuf(entry.getKey().getKey()), WireCommands.TableKey.NOT_EXISTS);
    order.verify(connection).send(new WireCommands.TableRead(2, tableSegmentName, new WireCommands.TableEntries(singletonList(new AbstractMap.SimpleImmutableEntry<>(keyResponse, WireCommands.TableValue.EMPTY)))));
    recorderMockOrder.verify(recorderMock).getKeys(eq(tableSegmentName), eq(1), any());
    // Update a value to a key.
    processor.updateTableEntries(new WireCommands.UpdateTableEntries(3, tableSegmentName, "", getTableEntries(singletonList(entry)), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    order.verify(connection).send(new WireCommands.TableEntriesUpdated(3, singletonList(0L)));
    recorderMockOrder.verify(recorderMock).updateEntries(eq(tableSegmentName), eq(1), eq(false), any());
    // Read the value of the key.
    key = new WireCommands.TableKey(toByteBuf(entry.getKey().getKey()), 0L);
    TableEntry expectedEntry = TableEntry.versioned(entry.getKey().getKey(), entry.getValue(), 0L);
    processor.readTable(new WireCommands.ReadTable(4, tableSegmentName, "", singletonList(key)));
    order.verify(connection).send(new WireCommands.TableRead(4, tableSegmentName, getTableEntries(singletonList(expectedEntry))));
    recorderMockOrder.verify(recorderMock).getKeys(eq(tableSegmentName), eq(1), any());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) Random(java.util.Random) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) WireCommands(io.pravega.shared.protocol.netty.WireCommands) lombok.val(lombok.val) InOrder(org.mockito.InOrder) TableKey(io.pravega.segmentstore.contracts.tables.TableKey) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) ArrayView(io.pravega.common.util.ArrayView) Test(org.junit.Test)

Example 34 with TableEntry

use of io.pravega.segmentstore.contracts.tables.TableEntry in project pravega by pravega.

the class PravegaRequestProcessorTest method testDeleteNonEmptyTable.

@Test(timeout = 30000)
public void testDeleteNonEmptyTable() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against
    val rnd = new Random(0);
    String tableSegmentName = "testTable";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    val recorderMock = mock(TableSegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, new TrackedConnection(connection), SegmentStatsRecorder.noOp(), recorderMock, new PassingTokenVerifier(), false);
    // Generate keys.
    ArrayList<ArrayView> keys = generateKeys(2, rnd);
    // Create a table segment and add data.
    processor.createTableSegment(new WireCommands.CreateTableSegment(3, tableSegmentName, false, 0, "", 0));
    order.verify(connection).send(new WireCommands.SegmentCreated(3, tableSegmentName));
    verify(recorderMock).createTableSegment(eq(tableSegmentName), any());
    TableEntry e1 = TableEntry.unversioned(keys.get(0), generateValue(rnd));
    processor.updateTableEntries(new WireCommands.UpdateTableEntries(4, tableSegmentName, "", getTableEntries(singletonList(e1)), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    order.verify(connection).send(new WireCommands.TableEntriesUpdated(4, singletonList(0L)));
    verify(recorderMock).updateEntries(eq(tableSegmentName), eq(1), eq(false), any());
    // Delete a table segment which has data.
    processor.deleteTableSegment(new WireCommands.DeleteTableSegment(5, tableSegmentName, true, ""));
    order.verify(connection).send(new WireCommands.TableSegmentNotEmpty(5, tableSegmentName, ""));
    verifyNoMoreInteractions(recorderMock);
}
Also used : lombok.val(lombok.val) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) Random(java.util.Random) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) ArrayView(io.pravega.common.util.ArrayView) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 35 with TableEntry

use of io.pravega.segmentstore.contracts.tables.TableEntry in project pravega by pravega.

the class PravegaRequestProcessorTest method testReadTableEntriesDeltaOutOfBounds.

@Test
public void testReadTableEntriesDeltaOutOfBounds() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against
    val rnd = new Random(0);
    String tableSegmentName = "testReadTableEntriesDelta";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    TableStore tableStore = serviceBuilder.createTableStoreService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    val recorderMock = mock(TableSegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, new TrackedConnection(connection), SegmentStatsRecorder.noOp(), recorderMock, new PassingTokenVerifier(), false);
    processor.createTableSegment(new WireCommands.CreateTableSegment(1, tableSegmentName, false, 0, "", 0));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, tableSegmentName));
    verify(recorderMock).createTableSegment(eq(tableSegmentName), any());
    // Generate keys.
    ArrayList<ArrayView> keys = generateKeys(3, rnd);
    ArrayView testValue = generateValue(rnd);
    TableEntry e1 = TableEntry.unversioned(keys.get(0), testValue);
    TableEntry e2 = TableEntry.unversioned(keys.get(1), testValue);
    TableEntry e3 = TableEntry.unversioned(keys.get(2), testValue);
    processor.updateTableEntries(new WireCommands.UpdateTableEntries(2, tableSegmentName, "", getTableEntries(asList(e1, e2, e3)), WireCommands.NULL_TABLE_SEGMENT_OFFSET));
    verify(recorderMock).updateEntries(eq(tableSegmentName), eq(3), eq(false), any());
    long length = store.getStreamSegmentInfo(tableSegmentName, Duration.ofMinutes(1)).get().getLength();
    processor.readTableEntriesDelta(new WireCommands.ReadTableEntriesDelta(1, tableSegmentName, "", length + 1, 3));
    order.verify(connection).send(new WireCommands.ErrorMessage(1, tableSegmentName, "fromPosition (652) can not exceed the length (651) of the TableSegment.", WireCommands.ErrorMessage.ErrorCode.valueOf(IllegalArgumentException.class)));
    verify(recorderMock, times(0)).iterateEntries(eq(tableSegmentName), eq(3), any());
}
Also used : lombok.val(lombok.val) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) TableEntry(io.pravega.segmentstore.contracts.tables.TableEntry) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) Random(java.util.Random) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) ArrayView(io.pravega.common.util.ArrayView) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Aggregations

TableEntry (io.pravega.segmentstore.contracts.tables.TableEntry)36 lombok.val (lombok.val)33 ArrayList (java.util.ArrayList)21 BufferView (io.pravega.common.util.BufferView)20 HashMap (java.util.HashMap)18 Test (org.junit.Test)17 TableKey (io.pravega.segmentstore.contracts.tables.TableKey)16 Duration (java.time.Duration)16 Collectors (java.util.stream.Collectors)16 List (java.util.List)15 CompletableFuture (java.util.concurrent.CompletableFuture)15 Cleanup (lombok.Cleanup)15 Map (java.util.Map)14 ByteArraySegment (io.pravega.common.util.ByteArraySegment)13 SegmentType (io.pravega.segmentstore.contracts.SegmentType)13 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)13 Futures (io.pravega.common.concurrent.Futures)12 Collections (java.util.Collections)12 AttributeId (io.pravega.segmentstore.contracts.AttributeId)11 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)11