use of io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated in project pravega by pravega.
the class SegmentMetadataClientImpl method truncateSegmentAsync.
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));
}
use of io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated in project pravega by pravega.
the class SegmentMetadataClientTest method testTruncate.
@Test(timeout = 10000)
public void testTruncate() throws ConnectionFailedException {
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, true);
@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);
AtomicLong requestId = new AtomicLong();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.TruncateSegment truncateSegment = invocation.getArgument(0);
processor.process(new SegmentTruncated(truncateSegment.getRequestId(), segment.getScopedName()));
requestId.set(truncateSegment.getRequestId());
return null;
}
}).when(connection).send(any(WireCommands.TruncateSegment.class));
client.truncateSegment(123L).join();
Mockito.verify(connection).send(Mockito.eq(new WireCommands.TruncateSegment(requestId.get(), segment.getScopedName(), 123L, "")));
}
use of io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated in project pravega by pravega.
the class PravegaRequestProcessor method truncateSegment.
@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, offset, operation, e));
}
use of io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated in project pravega by pravega.
the class SegmentMetadataClientImpl method truncateSegmentAsync.
private CompletableFuture<SegmentTruncated> truncateSegmentAsync(Segment segment, long offset, DelegationTokenProvider tokenProvider) {
log.debug("Truncating segment: {} at offset {}", segment, offset);
RawClient connection = getConnection();
long requestId = connection.getFlow().getNextSequenceNumber();
return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new TruncateSegment(requestId, segment.getScopedName(), offset, token))).thenApply(r -> transformReply(r, SegmentTruncated.class));
}
Aggregations