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.");
}
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);
}
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);
}
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);
}
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));
}
Aggregations