public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); long truncationOffset = in.readLong(); String delegationToken = in.readUTF(); return new TruncateSegment(requestId, segment, truncationOffset, delegationToken); } }
WireCommands.TruncateSegment request = new WireCommands.TruncateSegment(requestId, qualifiedName, offset, delegationToken); sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri)); return result;
.join().getLength() / 2; AssertExtensions.assertGreaterThan("Nothing to truncate.", 0, truncateOffset); processor.truncateSegment(new WireCommands.TruncateSegment(3, streamSegmentName, truncateOffset, "")); assertEquals(truncateOffset, store.getStreamSegmentInfo(streamSegmentName, PravegaRequestProcessor.TIMEOUT) .join().getStartOffset()); processor.truncateSegment(new WireCommands.TruncateSegment(4, streamSegmentName, truncateOffset, "")); assertEquals(truncateOffset, store.getStreamSegmentInfo(streamSegmentName, PravegaRequestProcessor.TIMEOUT) .join().getStartOffset()); processor.truncateSegment(new WireCommands.TruncateSegment(5, streamSegmentName, truncateOffset - 1, "")); assertEquals(truncateOffset, store.getStreamSegmentInfo(streamSegmentName, PravegaRequestProcessor.TIMEOUT) .join().getStartOffset());
@Test(timeout = 10000) public void testTruncate() throws Exception { Segment segment = new Segment("scope", "testTruncate", 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 SegmentTruncated(1, segment.getScopedName())); return null; } }).when(connection).sendAsync(Mockito.eq(new WireCommands.TruncateSegment(1, segment.getScopedName(), 123L, "")), Mockito.any(ClientConnection.CompletedCallback.class)); client.truncateSegment(123L); Mockito.verify(connection).sendAsync(Mockito.eq(new WireCommands.TruncateSegment(1, segment.getScopedName(), 123L, "")), Mockito.any(ClientConnection.CompletedCallback.class)); }
@Test public void testTruncateSegment() throws IOException { testCommand(new WireCommands.TruncateSegment(l, testString1, l + 1, "")); }
@Override public void truncateSegment(TruncateSegment truncateSegment) { String segment = truncateSegment.getSegment(); final String operation = "truncateSegment"; if (!verifyToken(segment, truncateSegment.getRequestId(), truncateSegment.getDelegationToken(), operation)) { return; } long offset = truncateSegment.getTruncationOffset(); log.info(truncateSegment.getRequestId(), "Truncating segment {} at offset {}.", segment, offset); segmentStore.truncateStreamSegment(segment, offset, TIMEOUT) .thenAccept(v -> connection.send(new SegmentTruncated(truncateSegment.getRequestId(), segment))) .exceptionally(e -> handleException(truncateSegment.getRequestId(), segment, operation, e)); }
private CompletableFuture<SegmentTruncated> truncateSegmentAsync(Segment segment, long offset, String delegationToken) { long requestId = requestIdGenerator.get(); log.trace("Truncating segment: {}", segment); RawClient connection = getConnection(); return connection.sendRequest(requestId, new TruncateSegment(requestId, segment.getScopedName(), offset, delegationToken)) .thenApply(r -> transformReply(r, SegmentTruncated.class)); }
@Test public void truncateSegment() { processor.truncateSegment(new WireCommands.TruncateSegment(100L, "segment", 0, "token")); verify(connection).send(new WireCommands.AuthTokenCheckFailed(100L, "")); }