use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class ByteStreamClientImpl method createByteStreamReaders.
private ByteStreamReader createByteStreamReaders(Segment segment) {
String delegationToken = Futures.getAndHandleExceptions(controller.getOrRefreshDelegationTokenFor(segment.getScope(), segment.getStream().getStreamName(), AccessOperation.READ), RuntimeException::new);
DelegationTokenProvider tokenProvider = DelegationTokenProviderFactory.create(delegationToken, controller, segment, AccessOperation.READ);
SegmentMetadataClient metaClient = metaStreamFactory.createSegmentMetadataClient(segment, tokenProvider);
long startOffset = Futures.getThrowingException(metaClient.getSegmentInfo()).getStartingOffset();
return new ByteStreamReaderImpl(inputStreamFactory.createInputStreamForSegment(segment, tokenProvider, startOffset), metaClient);
}
use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class BatchClientFactoryImpl method segmentToInfo.
private CompletableFuture<SegmentInfo> segmentToInfo(Segment s, DelegationTokenProvider tokenProvider) {
SegmentMetadataClient client = segmentMetadataClientFactory.createSegmentMetadataClient(s, tokenProvider);
CompletableFuture<SegmentInfo> result = client.getSegmentInfo();
result.whenComplete((r, e) -> client.close());
return result;
}
use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class AppendReconnectTest method reconnectOnSegmentClient.
@Test(timeout = 30000)
public void reconnectOnSegmentClient() throws Exception {
String endpoint = "localhost";
int port = TestUtils.getAvailableListenPort();
byte[] payload = "Hello world\n".getBytes();
String scope = "scope";
String stream = "stream";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
server.startListening();
@Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
Controller controller = new MockController(endpoint, port, connectionPool, true);
controller.createScope(scope);
controller.createStream(scope, stream, StreamConfiguration.builder().build());
SegmentOutputStreamFactoryImpl segmentClient = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup SegmentOutputStream out = segmentClient.createOutputStreamForSegment(segment, segmentSealedCallback, EventWriterConfig.builder().build(), DelegationTokenProviderFactory.createWithEmptyToken());
CompletableFuture<Void> ack = new CompletableFuture<>();
out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack));
for (AutoCloseable c : connectionPool.getActiveChannels()) {
c.close();
}
CompletableFuture<Void> ack2 = new CompletableFuture<>();
out.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(payload), ack2));
ack.get(5, TimeUnit.SECONDS);
ack2.get(5, TimeUnit.SECONDS);
@Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
assertEquals(payload.length * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
use of io.pravega.client.segment.impl.SegmentMetadataClient in project pravega by pravega.
the class AppendReconnectTest method reconnectThroughConditionalClient.
@Test(timeout = 30000)
public void reconnectThroughConditionalClient() throws Exception {
String endpoint = "localhost";
int port = TestUtils.getAvailableListenPort();
byte[] payload = "Hello world\n".getBytes();
String scope = "scope";
String stream = "stream";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, mock(TableStore.class), serviceBuilder.getLowPriorityExecutor());
server.startListening();
@Cleanup SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(ClientConfig.builder().build(), clientCF);
Controller controller = new MockController(endpoint, port, connectionPool, true);
controller.createScope(scope);
controller.createStream(scope, stream, StreamConfiguration.builder().build());
ConditionalOutputStreamFactoryImpl segmentClient = new ConditionalOutputStreamFactoryImpl(controller, connectionPool);
Segment segment = Futures.getAndHandleExceptions(controller.getCurrentSegments(scope, stream), RuntimeException::new).getSegments().iterator().next();
@Cleanup ConditionalOutputStream out = segmentClient.createConditionalOutputStream(segment, DelegationTokenProviderFactory.createWithEmptyToken(), EventWriterConfig.builder().build());
assertTrue(out.write(ByteBuffer.wrap(payload), 0));
for (AutoCloseable c : connectionPool.getActiveChannels()) {
c.close();
}
assertTrue(out.write(ByteBuffer.wrap(payload), payload.length + WireCommands.TYPE_PLUS_LENGTH_SIZE));
@Cleanup SegmentMetadataClient metadataClient = new SegmentMetadataClientFactoryImpl(controller, connectionPool).createSegmentMetadataClient(segment, DelegationTokenProviderFactory.createWithEmptyToken());
assertEquals((payload.length + WireCommands.TYPE_PLUS_LENGTH_SIZE) * 2, metadataClient.fetchCurrentSegmentLength().join().longValue());
}
Aggregations