order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName)); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); processor.mergeSegments(new WireCommands.MergeSegments(2, streamSegmentName, transactionName, "")); order.verify(connection).send(new WireCommands.SegmentsMerged(2, streamSegmentName, transactionName)); order.verify(connection).send(new WireCommands.SegmentCreated(3, transactionName)); processor.mergeSegments(new WireCommands.MergeSegments(4, streamSegmentName, transactionName, ""));
order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 2, store)); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); order.verify(connection).send(Mockito.argThat(t -> { return t instanceof WireCommands.StreamSegmentInfo && ((WireCommands.StreamSegmentInfo) t).exists(); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); order.verify(connection).send(Mockito.argThat(t -> {
order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); TableEntry entry = TableEntry.unversioned(keys.get(0), generateValue(rnd));
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.SegmentCreated(1, streamSegmentName));
order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); TableEntry e1 = TableEntry.unversioned(keys.get(0), generateValue(rnd)); processor.updateTableEntries(new WireCommands.UpdateTableEntries(2, streamSegmentName, "", getTableEntries(singletonList(e1))));
order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName));
@Override public void createSegment(CreateSegment createStreamSegment) { Timer timer = new Timer(); final String operation = "createSegment"; Collection<AttributeUpdate> attributes = Arrays.asList( new AttributeUpdate(SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ((Byte) createStreamSegment.getScaleType()).longValue()), new AttributeUpdate(SCALE_POLICY_RATE, AttributeUpdateType.Replace, ((Integer) createStreamSegment.getTargetRate()).longValue()), new AttributeUpdate(CREATION_TIME, AttributeUpdateType.None, System.currentTimeMillis()) ); if (!verifyToken(createStreamSegment.getSegment(), createStreamSegment.getRequestId(), createStreamSegment.getDelegationToken(), operation)) { return; } log.info(createStreamSegment.getRequestId(), "Creating stream segment {}.", createStreamSegment); segmentStore.createStreamSegment(createStreamSegment.getSegment(), attributes, TIMEOUT) .thenAccept(v -> { this.createStreamSegment.reportSuccessEvent(timer.getElapsed()); connection.send(new SegmentCreated(createStreamSegment.getRequestId(), createStreamSegment.getSegment())); }) .whenComplete((res, e) -> { if (e == null) { if (statsRecorder != null) { statsRecorder.createSegment(createStreamSegment.getSegment(), createStreamSegment.getScaleType(), createStreamSegment.getTargetRate()); } } else { this.createStreamSegment.reportFailEvent(timer.getElapsed()); handleException(createStreamSegment.getRequestId(), createStreamSegment.getSegment(), operation, e); } }); }
@Test(timeout = 30000) public void testDeleteTableWithData() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against val rnd = new Random(0); String streamSegmentName = "testTable"; @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig()); serviceBuilder.initialize(); StreamSegmentStore store = serviceBuilder.createStreamSegmentService(); TableStore tableStore = serviceBuilder.createTableStoreService(); ServerConnection connection = mock(ServerConnection.class); InOrder order = inOrder(connection); PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, connection); // Generate keys. ArrayList<HashedArray> keys = generateKeys(2, rnd); // Create a table segment and add data. processor.createTableSegment(new WireCommands.CreateTableSegment(3, streamSegmentName, "")); order.verify(connection).send(new WireCommands.SegmentCreated(3, streamSegmentName)); TableEntry e1 = TableEntry.unversioned(keys.get(0), generateValue(rnd)); processor.updateTableEntries(new WireCommands.UpdateTableEntries(4, streamSegmentName, "", getTableEntries(singletonList(e1)))); order.verify(connection).send(new WireCommands.TableEntriesUpdated(4, singletonList(0L))); // Delete a table segment which has data. processor.deleteTableSegment(new WireCommands.DeleteTableSegment(5, streamSegmentName, true, "")); order.verify(connection).send(new WireCommands.TableSegmentNotEmpty(5, streamSegmentName, "")); }
@Test(timeout = 20000) public void testCreateSegment() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against String streamSegmentName = "testCreateSegment"; @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, mock(TableStore.class), connection); // Execute and Verify createSegment/getStreamSegmentInfo calling stack is executed as design. processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(streamSegmentName, 1, store)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(1, streamSegmentName, "")); assertTrue(append(streamSegmentName, 2, store)); order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); order.verify(connection).send(Mockito.any(WireCommands.StreamSegmentInfo.class)); // TestCreateSealDelete may executed before this test case, // so createSegmentStats may record 1 or 2 createSegment operation here. OpStatsData createSegmentStats = processor.getCreateStreamSegment().toOpStatsData(); assertNotEquals(0, createSegmentStats.getNumSuccessfulEvents()); assertEquals(0, createSegmentStats.getNumFailedEvents()); }
@Test(timeout = 10000) public void testMultipleAppends() throws Exception { String segment = "123"; ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes()); StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService(); @Cleanup EmbeddedChannel channel = createChannel(store); SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, "")); assertEquals(segment, created.getSegment()); UUID uuid = UUID.randomUUID(); AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, "")); assertEquals(segment, setup.getSegment()); assertEquals(uuid, setup.getWriterId()); data.retain(); DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, 1, new Event(data))); assertEquals(uuid, ack.getWriterId()); assertEquals(1, ack.getEventNumber()); assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber()); DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, new Event(data))); assertEquals(uuid, ack2.getWriterId()); assertEquals(2, ack2.getEventNumber()); assertEquals(1, ack2.getPreviousEventNumber()); }
@Test(timeout = 30000) public void testDeleteTableWithoutData() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against val rnd = new Random(0); String streamSegmentName = "testTable1"; @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig()); serviceBuilder.initialize(); StreamSegmentStore store = serviceBuilder.createStreamSegmentService(); TableStore tableStore = serviceBuilder.createTableStoreService(); ServerConnection connection = mock(ServerConnection.class); InOrder order = inOrder(connection); PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, connection); // Generate keys. ArrayList<HashedArray> keys = generateKeys(2, rnd); // Create a table segment. processor.createTableSegment(new WireCommands.CreateTableSegment(1, streamSegmentName, "")); order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); processor.deleteTableSegment(new WireCommands.DeleteTableSegment(2, streamSegmentName, true, "")); order.verify(connection).send(new WireCommands.SegmentDeleted(2, streamSegmentName)); }
@Test(timeout = 20000) public void testCreateTableSegment() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against String streamSegmentName = "testCreateTableSegment"; @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig()); serviceBuilder.initialize(); StreamSegmentStore store = serviceBuilder.createStreamSegmentService(); TableStore tableStore = serviceBuilder.createTableStoreService(); ServerConnection connection = mock(ServerConnection.class); InOrder order = inOrder(connection); PravegaRequestProcessor processor = new PravegaRequestProcessor(store, tableStore, connection); // Execute and Verify createTableSegment calling stack is executed as design. processor.createTableSegment(new WireCommands.CreateTableSegment(1, streamSegmentName, "")); order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); processor.createTableSegment(new WireCommands.CreateTableSegment(2, streamSegmentName, "")); order.verify(connection).send(new WireCommands.SegmentAlreadyExists(2, streamSegmentName, "")); }
@Test public void sendReceivingAppend() throws Exception { String segment = "123"; ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes()); StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService(); @Cleanup EmbeddedChannel channel = createChannel(store); SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, "")); assertEquals(segment, created.getSegment()); UUID uuid = UUID.randomUUID(); AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, "")); assertEquals(segment, setup.getSegment()); assertEquals(uuid, setup.getWriterId()); DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, data.readableBytes(), new Event(data))); assertEquals(uuid, ack.getWriterId()); assertEquals(data.readableBytes(), ack.getEventNumber()); assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber()); }
@Test public void testCreateTableSegment() { MockConnectionFactory factory = new MockConnectionFactory(); // On receiving SegmentAlreadyExists true should be returned. CompletableFuture<Boolean> result = helper.createTableSegment("", "", new MockHostControllerStore(), factory, "", Long.MIN_VALUE); factory.rp.segmentAlreadyExists(new WireCommands.SegmentAlreadyExists(0, getQualifiedStreamSegmentName("", "", 0L), "")); assertTrue(result.join()); // On Receiving SegmentCreated true should be returned. result = helper.createTableSegment("", "", new MockHostControllerStore(), factory, "", Long.MIN_VALUE); factory.rp.segmentCreated(new WireCommands.SegmentCreated(0, getQualifiedStreamSegmentName("", "", 0L))); assertTrue(result.join()); // Validate failure conditions. Supplier<CompletableFuture<?>> futureSupplier = () -> helper.createTableSegment("", "", new MockHostControllerStore(), factory, "", Long.MIN_VALUE); validateAuthTokenCheckFailed(factory, futureSupplier); validateWrongHost(factory, futureSupplier); validateConnectionDropped(factory, futureSupplier); validateProcessingFailure(factory, futureSupplier); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(endpoint) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(endpoint) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(WireCommands.CreateSegment.class),
public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); return new SegmentCreated(requestId, segment); } }