public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String delegationToken = in.readUTF(); return new SealSegment(requestId, segment, delegationToken); } }
WireCommands.SealSegment request = new WireCommands.SealSegment(requestId, qualifiedName, delegationToken); sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri)); return result;
assertTrue(append(streamSegmentName, 2, store)); processor.sealSegment(new WireCommands.SealSegment(2, streamSegmentName, "")); assertFalse(append(streamSegmentName, 2, store));
@Test(timeout = 10000) public void testSeal() throws Exception { Segment segment = new Segment("scope", "testSeal", 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 WireCommands.SegmentSealed(1, segment.getScopedName())); return null; } }).when(connection).sendAsync(Mockito.eq(new WireCommands.SealSegment(1, segment.getScopedName(), "")), Mockito.any(ClientConnection.CompletedCallback.class)); client.sealSegment(); Mockito.verify(connection).sendAsync(Mockito.eq(new WireCommands.SealSegment(1, segment.getScopedName(), "")), Mockito.any(ClientConnection.CompletedCallback.class)); }
@Override public void sealSegment(SealSegment sealSegment) { String segment = sealSegment.getSegment(); final String operation = "sealSegment"; if (!verifyToken(segment, sealSegment.getRequestId(), sealSegment.getDelegationToken(), operation)) { return; } log.info(sealSegment.getRequestId(), "Sealing segment {} ", sealSegment); segmentStore.sealStreamSegment(segment, TIMEOUT) .thenAccept(size -> connection.send(new SegmentSealed(sealSegment.getRequestId(), segment))) .whenComplete((r, e) -> { if (e != null) { handleException(sealSegment.getRequestId(), segment, operation, e); } else { dynamicLogger.freezeCounter(nameFromSegment(SEGMENT_WRITE_BYTES, segment)); dynamicLogger.freezeCounter(nameFromSegment(SEGMENT_WRITE_EVENTS, segment)); if (statsRecorder != null) { statsRecorder.sealSegment(sealSegment.getSegment()); } } }); }
@Test public void testSealSegment() throws IOException { testCommand(new WireCommands.SealSegment(l, testString1, "")); }
private CompletableFuture<SegmentSealed> sealSegmentAsync(Segment segment, String delegationToken) { long requestId = requestIdGenerator.get(); log.trace("Sealing segment: {}", segment); RawClient connection = getConnection(); return connection.sendRequest(requestId, new SealSegment(requestId, segment.getScopedName(), delegationToken)) .thenApply(r -> transformReply(r, SegmentSealed.class)); }
@Test public void sealSegment() { processor.sealSegment(new WireCommands.SealSegment(100L, "segment", "token")); verify(connection).send(new WireCommands.AuthTokenCheckFailed(100L, "")); }