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