Search in sources :

Example 1 with ServiceBuilder

use of io.pravega.segmentstore.server.store.ServiceBuilder in project pravega by pravega.

the class PravegaRequestProcessorTest method testSegmentAttribute.

@Test(timeout = 20000)
public void testSegmentAttribute() throws Exception {
    String streamSegmentName = "testSegmentAttribute";
    UUID attribute = UUID.randomUUID();
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, connection);
    // Execute and Verify createSegment/getStreamSegmentInfo calling stack is executed as design.
    processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, ""));
    order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(2, streamSegmentName, attribute, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(2, WireCommands.NULL_ATTRIBUTE_VALUE));
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(2, streamSegmentName, attribute, 1, WireCommands.NULL_ATTRIBUTE_VALUE, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(2, true));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(3, streamSegmentName, attribute, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(3, 1));
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(4, streamSegmentName, attribute, 5, WireCommands.NULL_ATTRIBUTE_VALUE, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(4, false));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(5, streamSegmentName, attribute, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(5, 1));
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(6, streamSegmentName, attribute, 10, 1, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(6, true));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(7, streamSegmentName, attribute, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(7, 10));
    processor.updateSegmentAttribute(new WireCommands.UpdateSegmentAttribute(8, streamSegmentName, attribute, WireCommands.NULL_ATTRIBUTE_VALUE, 10, ""));
    order.verify(connection).send(new WireCommands.SegmentAttributeUpdated(8, true));
    processor.getSegmentAttribute(new WireCommands.GetSegmentAttribute(9, streamSegmentName, attribute, ""));
    order.verify(connection).send(new WireCommands.SegmentAttribute(9, WireCommands.NULL_ATTRIBUTE_VALUE));
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 2 with ServiceBuilder

use of io.pravega.segmentstore.server.store.ServiceBuilder in project pravega by pravega.

the class PravegaRequestProcessorTest method testMergedTransaction.

@Test(timeout = 20000)
public void testMergedTransaction() throws Exception {
    String streamSegmentName = "testMergedTxn";
    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);
    doReturn(Futures.failedFuture(new StreamSegmentMergedException(streamSegmentName))).when(store).sealStreamSegment(anyString(), any());
    doReturn(Futures.failedFuture(new StreamSegmentMergedException(streamSegmentName))).when(store).mergeTransaction(anyString(), any());
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, connection);
    processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, ""));
    order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName));
    processor.createTransaction(new WireCommands.CreateTransaction(1, streamSegmentName, txnid, ""));
    order.verify(connection).send(new WireCommands.TransactionCreated(1, streamSegmentName, txnid));
    processor.commitTransaction(new WireCommands.CommitTransaction(2, streamSegmentName, txnid, ""));
    order.verify(connection).send(new WireCommands.TransactionCommitted(2, streamSegmentName, txnid));
    txnid = UUID.randomUUID();
    doReturn(Futures.failedFuture(new StreamSegmentNotExistsException(streamSegmentName))).when(store).sealStreamSegment(anyString(), any());
    doReturn(Futures.failedFuture(new StreamSegmentNotExistsException(streamSegmentName))).when(store).mergeTransaction(anyString(), any());
    processor.createTransaction(new WireCommands.CreateTransaction(3, streamSegmentName, txnid, ""));
    order.verify(connection).send(new WireCommands.TransactionCreated(3, streamSegmentName, txnid));
    processor.commitTransaction(new WireCommands.CommitTransaction(4, streamSegmentName, txnid, ""));
    order.verify(connection).send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid)));
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) StreamSegmentMergedException(io.pravega.segmentstore.contracts.StreamSegmentMergedException) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 3 with ServiceBuilder

use of io.pravega.segmentstore.server.store.ServiceBuilder in project pravega by pravega.

the class PravegaRequestProcessorTest method testUnsupportedOperation.

@Test(timeout = 20000)
public void testUnsupportedOperation() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against
    String streamSegmentName = "testCreateSegment";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getReadOnlyBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, connection);
    // Execute and Verify createSegment/getStreamSegmentInfo calling stack is executed as design.
    processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, ""));
    order.verify(connection).send(new WireCommands.OperationUnsupported(1, "Create segment"));
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Test(org.junit.Test)

Example 4 with ServiceBuilder

use of io.pravega.segmentstore.server.store.ServiceBuilder in project pravega by pravega.

the class PravegaRequestProcessorTest method testCreateSealTruncateDelete.

@Test(timeout = 20000)
public void testCreateSealTruncateDelete() throws Exception {
    // Set up PravegaRequestProcessor instance to execute requests against.
    String streamSegmentName = "testCreateSealDelete";
    @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    ServerConnection connection = mock(ServerConnection.class);
    InOrder order = inOrder(connection);
    PravegaRequestProcessor processor = new PravegaRequestProcessor(store, connection);
    // Create a segment and append 2 bytes.
    processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, ""));
    assertTrue(append(streamSegmentName, 1, store));
    assertTrue(append(streamSegmentName, 2, store));
    processor.sealSegment(new WireCommands.SealSegment(2, streamSegmentName, ""));
    assertFalse(append(streamSegmentName, 2, store));
    // Truncate half.
    final long truncateOffset = store.getStreamSegmentInfo(streamSegmentName, false, PravegaRequestProcessor.TIMEOUT).join().getLength() / 2;
    AssertExtensions.assertGreaterThan("Nothing to truncate.", 0, truncateOffset);
    processor.truncateSegment(new WireCommands.TruncateSegment(3, streamSegmentName, truncateOffset, ""));
    assertEquals(truncateOffset, store.getStreamSegmentInfo(streamSegmentName, false, PravegaRequestProcessor.TIMEOUT).join().getStartOffset());
    // Truncate at the same offset - verify idempotence.
    processor.truncateSegment(new WireCommands.TruncateSegment(4, streamSegmentName, truncateOffset, ""));
    assertEquals(truncateOffset, store.getStreamSegmentInfo(streamSegmentName, false, PravegaRequestProcessor.TIMEOUT).join().getStartOffset());
    // Truncate at a lower offset - verify failure.
    processor.truncateSegment(new WireCommands.TruncateSegment(5, streamSegmentName, truncateOffset - 1, ""));
    assertEquals(truncateOffset, store.getStreamSegmentInfo(streamSegmentName, false, PravegaRequestProcessor.TIMEOUT).join().getStartOffset());
    // Delete.
    processor.deleteSegment(new WireCommands.DeleteSegment(6, streamSegmentName, ""));
    assertFalse(append(streamSegmentName, 4, store));
    // Verify connection response with same order.
    order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName));
    order.verify(connection).send(new WireCommands.SegmentSealed(2, streamSegmentName));
    order.verify(connection).send(new WireCommands.SegmentTruncated(3, streamSegmentName));
    order.verify(connection).send(new WireCommands.SegmentTruncated(4, streamSegmentName));
    order.verify(connection).send(new WireCommands.SegmentIsTruncated(5, streamSegmentName, truncateOffset));
    order.verify(connection).send(new WireCommands.SegmentDeleted(6, streamSegmentName));
    order.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SynchronousStreamSegmentStore(io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 5 with ServiceBuilder

use of io.pravega.segmentstore.server.store.ServiceBuilder in project pravega by pravega.

the class ReadFromDeletedStreamTest method testDeletedAndRecreatedStream.

@Test(timeout = 30000)
public void testDeletedAndRecreatedStream() throws Exception {
    @Cleanup MockStreamManager streamManager = new MockStreamManager("test", "localhost", Config.SERVICE_PORT);
    ServiceBuilder serviceBuilder = ServiceBuilder.newInMemoryBuilder(ServiceBuilderConfig.getDefaultConfig());
    serviceBuilder.initialize();
    StreamSegmentStore store = serviceBuilder.createStreamSegmentService();
    @Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, "localhost", 12345, store, null, null, null, null);
    server.startListening();
    streamManager.createScope("test");
    streamManager.createStream("test", "test", CONFIG);
    @Cleanup MockClientFactory clientFactory = streamManager.getClientFactory();
    // Mocking pravega service by putting scale up and scale down requests for the stream
    @Cleanup EventStreamWriter<String> test = clientFactory.createEventWriter("test", new JavaSerializer<>(), EventWriterConfig.builder().build());
    test.writeEvent("0", "foo").get();
    streamManager.deleteStream("test", "test");
    AssertExtensions.assertThrows(NoSuchSegmentException.class, () -> test.writeEvent("0", "foo").get());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) MockStreamManager(io.pravega.client.stream.mock.MockStreamManager) Cleanup(lombok.Cleanup) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener) MockClientFactory(io.pravega.client.stream.mock.MockClientFactory) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) Test(org.junit.Test)

Aggregations

ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)26 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)25 Cleanup (lombok.Cleanup)20 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)19 Test (org.junit.Test)15 TestingServerStarter (io.pravega.test.common.TestingServerStarter)11 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)9 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 Controller (io.pravega.client.stream.impl.Controller)8 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)7 TestingServer (org.apache.curator.test.TestingServer)7 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)6 SynchronousStreamSegmentStore (io.pravega.segmentstore.server.mocks.SynchronousStreamSegmentStore)6 WireCommands (io.pravega.shared.protocol.netty.WireCommands)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 InOrder (org.mockito.InOrder)6 ConnectionFactoryImpl (io.pravega.client.netty.impl.ConnectionFactoryImpl)5 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)5 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)5