WireCommands.GetStreamSegmentInfo getSegmentInfo1 = new WireCommands.GetStreamSegmentInfo(2, segment.getScopedName(), ""); Mockito.doAnswer(new Answer<Void>() { @Override WireCommands.GetStreamSegmentInfo getSegmentInfo2 = new WireCommands.GetStreamSegmentInfo(3, segment.getScopedName(), ""); Mockito.doAnswer(new Answer<Void>() { @Override
processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 2, store)); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); processor.mergeSegments(new WireCommands.MergeSegments(3, streamSegmentName, transactionName, "")); order.verify(connection).send(new WireCommands.SegmentsMerged(3, streamSegmentName, transactionName)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(4, transactionName, "")); order.verify(connection) .send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store)); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); order.verify(connection).send(Mockito.argThat(t -> { return t instanceof WireCommands.StreamSegmentInfo && ((WireCommands.StreamSegmentInfo) t).exists(); processor.deleteSegment(new WireCommands.DeleteSegment(3, transactionName, "")); order.verify(connection).send(new WireCommands.SegmentDeleted(3, transactionName)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(4, transactionName, "")); order.verify(connection) .send(new WireCommands.NoSuchSegment(4, StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), "")); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 2, store)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(4, transactionName, "")); order.verify(connection)
WireCommands.GetStreamSegmentInfo request = new WireCommands.GetStreamSegmentInfo(idGenerator.get(), qualifiedName, delegationToken); sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, ""); client.getConnection(); WireCommands.GetStreamSegmentInfo getSegmentInfo1 = new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), ""); Mockito.doAnswer(new Answer<Void>() { @Override WireCommands.GetStreamSegmentInfo getSegmentInfo2 = new WireCommands.GetStreamSegmentInfo(2, segment.getScopedName(), ""); Mockito.doAnswer(new Answer<Void>() { @Override
@Test(timeout = 10000) public void testCurrentStreamLength() throws Exception { Segment segment = new Segment("scope", "testRetry", 4); PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0); @Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl(); @Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf); @Cleanup ClientConnection connection = mock(ClientConnection.class); cf.provideConnection(endpoint, connection); @Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, ""); client.getConnection(); ReplyProcessor processor = cf.getProcessor(endpoint); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { processor.process(new StreamSegmentInfo(1, segment.getScopedName(), true, false, false, 0, 123, 121)); return null; } }).when(connection).sendAsync(Mockito.eq(new WireCommands.GetStreamSegmentInfo(1, segment.getScopedName(), "")), Mockito.any(ClientConnection.CompletedCallback.class)); long length = client.fetchCurrentSegmentLength(); assertEquals(123, length); }
@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()); }
@Override public void getStreamSegmentInfo(GetStreamSegmentInfo getStreamSegmentInfo) { String segmentName = getStreamSegmentInfo.getSegmentName(); final String operation = "getStreamSegmentInfo"; if (!verifyToken(segmentName, getStreamSegmentInfo.getRequestId(), getStreamSegmentInfo.getDelegationToken(), operation)) { return; } segmentStore.getStreamSegmentInfo(segmentName, TIMEOUT) .thenAccept(properties -> { if (properties != null) { StreamSegmentInfo result = new StreamSegmentInfo(getStreamSegmentInfo.getRequestId(), properties.getName(), true, properties.isSealed(), properties.isDeleted(), properties.getLastModified().getTime(), properties.getLength(), properties.getStartOffset()); log.trace("Read stream segment info: {}", result); connection.send(result); } else { log.trace("getStreamSegmentInfo could not find segment {}", segmentName); connection.send(new StreamSegmentInfo(getStreamSegmentInfo.getRequestId(), segmentName, false, true, true, 0, 0, 0)); } }) .exceptionally(e -> handleException(getStreamSegmentInfo.getRequestId(), segmentName, operation, e)); }
@Test public void getStreamSegmentInfo() { processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(100L, "segment", "token")); verify(connection).send(new WireCommands.AuthTokenCheckFailed(100L, "")); }
public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String delegationToken = in.readUTF(); return new GetStreamSegmentInfo(requestId, segment, delegationToken); } }
@Test public void testGetStreamSegmentInfo() throws IOException { testCommand(new WireCommands.GetStreamSegmentInfo(l, testString1, "")); }
private CompletableFuture<StreamSegmentInfo> getStreamSegmentInfo(String delegationToken) { long requestId = requestIdGenerator.get(); log.debug("Getting segment info for segment: {}", segmentId); RawClient connection = getConnection(); return connection.sendRequest(requestId, new GetStreamSegmentInfo(requestId, segmentId.getScopedName(), delegationToken)) .thenApply(r -> transformReply(r, StreamSegmentInfo.class)); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0)); return null; } }).when(connection).sendAsync(Mockito.any(GetStreamSegmentInfo.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { WireCommands.GetStreamSegmentInfo request = (WireCommands.GetStreamSegmentInfo) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new WireCommands.StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0)); return null; } }).when(connection).sendAsync(Mockito.any(WireCommands.GetStreamSegmentInfo.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0)); return null; } }).when(connection).sendAsync(Mockito.any(GetStreamSegmentInfo.class),