Search in sources :

Example 1 with SegmentStatsRecorder

use of io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder in project pravega by pravega.

the class PravegaRequestProcessorTest method testConditionalSegmentMergeReplaceIfEquals.

@Test(timeout = 20000)
public void testConditionalSegmentMergeReplaceIfEquals() throws Exception {
    String streamSegmentName = "scope/stream/txnSegment";
    UUID txnId = UUID.randomUUID();
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = spy(serviceBuilder.createStreamSegmentService());
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    SegmentStatsRecorder recorderMock = mock(SegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), new TrackedConnection(connection), recorderMock, TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), false);
    processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0L));
    order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName));
    String transactionName = NameUtils.getTransactionNameFromId(streamSegmentName, txnId);
    processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0L));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName));
    // Try to merge the transaction conditionally, when the attributes on the parent segment do not match.
    UUID randomAttribute1 = UUID.randomUUID();
    UUID randomAttribute2 = UUID.randomUUID();
    List<WireCommands.ConditionalAttributeUpdate> attributeUpdates = asList(new WireCommands.ConditionalAttributeUpdate(randomAttribute1, WireCommands.ConditionalAttributeUpdate.REPLACE_IF_EQUALS, 1, streamSegmentName.hashCode()), new WireCommands.ConditionalAttributeUpdate(randomAttribute2, WireCommands.ConditionalAttributeUpdate.REPLACE_IF_EQUALS, 2, streamSegmentName.hashCode()));
    // The first attempt should fail as the attribute update is not going to work.
    assertTrue(append(transactionName, 1, store));
    processor.mergeSegments(new WireCommands.MergeSegments(2, streamSegmentName, transactionName, "", attributeUpdates));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(2, false));
    // Now, set the right attributes in the parent segment.
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(3, streamSegmentName, randomAttribute1, streamSegmentName.hashCode(), WireCommands.NULL_ATTRIBUTE_VALUE, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(3, true));
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(4, streamSegmentName, randomAttribute2, streamSegmentName.hashCode(), WireCommands.NULL_ATTRIBUTE_VALUE, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(4, true));
    // Merge segments conditionally, now it should work.
    processor.mergeSegments(new WireCommands.MergeSegments(5, streamSegmentName, transactionName, "", attributeUpdates));
    order.verify(connection).send(new WireCommands.SegmentsMerged(5, streamSegmentName, transactionName, 1));
    // Check the value of attributes post merge.
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(6, streamSegmentName, randomAttribute1, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(6, 1));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(7, streamSegmentName, randomAttribute2, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(7, 2));
}
Also used : SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) TableSegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.TableSegmentStatsRecorder) 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) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 2 with SegmentStatsRecorder

use of io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder in project pravega by pravega.

the class PravegaRequestProcessorTest method testMetricsOnSegmentMerge.

@Test(timeout = 20000)
public void testMetricsOnSegmentMerge() throws Exception {
    String streamSegmentName = "scope/stream/txnSegment";
    UUID txnId = UUID.randomUUID();
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = spy(serviceBuilder.createStreamSegmentService());
    ServerConnection connection = mock(ServerConnection.class);
    doReturn(Futures.failedFuture(new StreamSegmentMergedException(streamSegmentName))).when(store).sealStreamSegment(anyString(), any());
    // test txn segment merge
    CompletableFuture<MergeStreamSegmentResult> txnFuture = CompletableFuture.completedFuture(createMergeStreamSegmentResult(streamSegmentName, txnId));
    doReturn(txnFuture).when(store).mergeStreamSegment(anyString(), anyString(), any(), any());
    SegmentStatsRecorder recorderMock = mock(SegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), new TrackedConnection(connection), recorderMock, TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), false);
    processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0));
    String transactionName = NameUtils.getTransactionNameFromId(streamSegmentName, txnId);
    processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0));
    processor.mergeSegments(new WireCommands.MergeSegments(2, streamSegmentName, transactionName, ""));
    verify(recorderMock).merge(streamSegmentName, 100L, 10, streamSegmentName.hashCode());
}
Also used : SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) TableSegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.TableSegmentStatsRecorder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) MergeStreamSegmentResult(io.pravega.segmentstore.contracts.MergeStreamSegmentResult) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 3 with SegmentStatsRecorder

use of io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder in project pravega by pravega.

the class PravegaRequestProcessorTest method testConditionalSegmentMergeReplace.

@Test(timeout = 20000)
public void testConditionalSegmentMergeReplace() throws Exception {
    String streamSegmentName = "scope/stream/txnSegment";
    UUID txnId = UUID.randomUUID();
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = spy(serviceBuilder.createStreamSegmentService());
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    SegmentStatsRecorder recorderMock = mock(SegmentStatsRecorder.class);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), new TrackedConnection(connection), recorderMock, TableSegmentStatsRecorder.noOp(), new PassingTokenVerifier(), false);
    processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0L));
    order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName));
    String transactionName = NameUtils.getTransactionNameFromId(streamSegmentName, txnId);
    processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0L));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName));
    assertTrue(append(transactionName, 1, store));
    // Update to perform.
    UUID randomAttribute1 = UUID.randomUUID();
    UUID randomAttribute2 = UUID.randomUUID();
    List<WireCommands.ConditionalAttributeUpdate> attributeUpdates = asList(new WireCommands.ConditionalAttributeUpdate(randomAttribute1, WireCommands.ConditionalAttributeUpdate.REPLACE, 1, 0), new WireCommands.ConditionalAttributeUpdate(randomAttribute2, WireCommands.ConditionalAttributeUpdate.REPLACE, 2, 0));
    // Set a attributes in the parent segment with a certain value.
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(2, streamSegmentName, randomAttribute1, streamSegmentName.hashCode(), WireCommands.NULL_ATTRIBUTE_VALUE, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(2, true));
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(3, streamSegmentName, randomAttribute2, streamSegmentName.hashCode(), WireCommands.NULL_ATTRIBUTE_VALUE, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(3, true));
    // Check the value of attributes post merge.
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(4, streamSegmentName, randomAttribute1, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(4, streamSegmentName.hashCode()));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(5, streamSegmentName, randomAttribute2, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(5, streamSegmentName.hashCode()));
    // Merge segments replacing attributes, now it should work.
    processor.mergeSegments(new WireCommands.MergeSegments(6, streamSegmentName, transactionName, "", attributeUpdates));
    order.verify(connection).send(new WireCommands.SegmentsMerged(6, streamSegmentName, transactionName, 1));
    // Check the value of attributes post merge.
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(7, streamSegmentName, randomAttribute1, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(7, 1));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(8, streamSegmentName, randomAttribute2, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(8, 2));
}
Also used : SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) TableSegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.TableSegmentStatsRecorder) 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) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Aggregations

StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)3 TableStore (io.pravega.segmentstore.contracts.tables.TableStore)3 PassingTokenVerifier (io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier)3 SegmentStatsRecorder (io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder)3 TableSegmentStatsRecorder (io.pravega.segmentstore.server.host.stat.TableSegmentStatsRecorder)3 SynchronousStreamSegmentStore (io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore)3 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)3 WireCommands (io.pravega.shared.protocol.netty.WireCommands)3 UUID (java.util.UUID)3 Cleanup (lombok.Cleanup)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 InOrder (org.mockito.InOrder)2 MergeStreamSegmentResult (io.pravega.segmentstore.contracts.MergeStreamSegmentResult)1 StreamSegmentMergedException (io.pravega.segmentstore.contracts.StreamSegmentMergedException)1