Search in sources :

Example 1 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class ServiceStarter method start.

// endregion
// region Service Operation
public void start() throws Exception {
    Exceptions.checkNotClosed(this.closed, this);
    log.info("Initializing metrics provider ...");
    MetricsProvider.initialize(builderConfig.getConfig(MetricsConfig::builder));
    statsProvider = MetricsProvider.getMetricsProvider();
    statsProvider.start();
    log.info("Initializing ZooKeeper Client ...");
    this.zkClient = createZKClient();
    log.info("Initializing Service Builder ...");
    this.serviceBuilder.initialize();
    log.info("Creating StreamSegmentService ...");
    StreamSegmentStore service = this.serviceBuilder.createStreamSegmentService();
    log.info("Creating Segment Stats recorder ...");
    segmentStatsFactory = new SegmentStatsFactory();
    SegmentStatsRecorder statsRecorder = segmentStatsFactory.createSegmentStatsRecorder(service, builderConfig.getConfig(AutoScalerConfig::builder));
    TokenVerifierImpl tokenVerifier = new TokenVerifierImpl(builderConfig.getConfig(AutoScalerConfig::builder));
    this.listener = new PravegaConnectionListener(this.serviceConfig.isEnableTls(), this.serviceConfig.getListeningIPAddress(), this.serviceConfig.getListeningPort(), service, statsRecorder, tokenVerifier, this.serviceConfig.getCertFile(), this.serviceConfig.getKeyFile());
    this.listener.startListening();
    log.info("PravegaConnectionListener started successfully.");
    log.info("StreamSegmentService started.");
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SegmentStatsRecorder(io.pravega.segmentstore.server.host.stat.SegmentStatsRecorder) SegmentStatsFactory(io.pravega.segmentstore.server.host.stat.SegmentStatsFactory) TokenVerifierImpl(io.pravega.segmentstore.server.host.delegationtoken.TokenVerifierImpl) PravegaConnectionListener(io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)

Example 2 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class AppendProcessorTest method testAppend.

@Test
public void testAppend() {
    String streamSegmentName = "testAppendSegment";
    UUID clientId = UUID.randomUUID();
    byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    ServerConnection connection = mock(ServerConnection.class);
    AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
    setupGetStreamSegmentInfo(streamSegmentName, clientId, store);
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
    verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT);
    verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).send(new DataAppended(clientId, data.length, 0L));
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class AppendProcessorTest method testSwitchingStream.

@Test
public void testSwitchingStream() {
    String segment1 = "segment1";
    String segment2 = "segment2";
    UUID clientId1 = UUID.randomUUID();
    UUID clientId2 = UUID.randomUUID();
    byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    ServerConnection connection = mock(ServerConnection.class);
    AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
    setupGetStreamSegmentInfo(segment1, clientId1, store);
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    when(store.append(segment1, data, updateEventNumber(clientId1, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    setupGetStreamSegmentInfo(segment2, clientId2, store);
    result = CompletableFuture.completedFuture(null);
    when(store.append(segment2, data, updateEventNumber(clientId2, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.setupAppend(new SetupAppend(1, clientId1, segment1, ""));
    processor.append(new Append(segment1, clientId1, data.length, Unpooled.wrappedBuffer(data), null));
    processor.setupAppend(new SetupAppend(2, clientId2, segment2, ""));
    processor.append(new Append(segment2, clientId2, data.length, Unpooled.wrappedBuffer(data), null));
    verify(store).getStreamSegmentInfo(eq(segment1), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(segment1, data, updateEventNumber(clientId1, data.length), AppendProcessor.TIMEOUT);
    verify(store).getStreamSegmentInfo(eq(segment2), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(segment2, data, updateEventNumber(clientId2, data.length), AppendProcessor.TIMEOUT);
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).send(new AppendSetup(1, segment1, clientId1, 0));
    verify(connection).send(new DataAppended(clientId1, data.length, 0));
    verify(connection).send(new AppendSetup(2, segment2, clientId2, 0));
    verify(connection).send(new DataAppended(clientId2, data.length, 0));
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class PravegaRequestProcessorAuthFailedTest method setUp.

@Before
public void setUp() throws Exception {
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    connection = mock(ServerConnection.class);
    processor = new PravegaRequestProcessor(store, connection, null, (resource, token, expectedLevel) -> false);
}
Also used : After(org.junit.After) Test(org.junit.Test) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Before(org.junit.Before)

Example 5 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore 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)

Aggregations

StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)75 Test (org.junit.Test)52 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)45 Cleanup (lombok.Cleanup)40 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)25 UUID (java.util.UUID)23 TestingServerStarter (io.pravega.test.common.TestingServerStarter)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)19 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)18 Before (org.junit.Before)17 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)16 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)15 Append (io.pravega.shared.protocol.netty.Append)14 CompletableFuture (java.util.concurrent.CompletableFuture)12 FailingRequestProcessor (io.pravega.shared.protocol.netty.FailingRequestProcessor)11 WireCommands (io.pravega.shared.protocol.netty.WireCommands)11 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)10 Controller (io.pravega.client.stream.impl.Controller)10 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)10