use of io.pravega.segmentstore.contracts.StreamSegmentStore 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.contracts.StreamSegmentStore 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.contracts.StreamSegmentStore 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.contracts.StreamSegmentStore 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());
}
use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.
the class ReadTest method testReadDirectlyFromStore.
@Test
public void testReadDirectlyFromStore() throws InterruptedException, ExecutionException, IOException {
String segmentName = "testReadFromStore";
final int entries = 10;
final byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
UUID clientId = UUID.randomUUID();
StreamSegmentStore segmentStore = serviceBuilder.createStreamSegmentService();
fillStoreForSegment(segmentName, clientId, data, entries, segmentStore);
ReadResult result = segmentStore.read(segmentName, 0, entries * data.length, Duration.ZERO).get();
int index = 0;
while (result.hasNext()) {
ReadResultEntry entry = result.next();
ReadResultEntryType type = entry.getType();
assertEquals(ReadResultEntryType.Cache, type);
// Each ReadResultEntryContents may be of an arbitrary length - we should make no assumptions.
ReadResultEntryContents contents = entry.getContent().get();
byte next;
while ((next = (byte) contents.getData().read()) != -1) {
byte expected = data[index % data.length];
assertEquals(expected, next);
index++;
}
}
assertEquals(entries * data.length, index);
}
Aggregations