use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentMetadataClientImpl method updatePropertyAsync.
private CompletableFuture<SegmentAttributeUpdated> updatePropertyAsync(UUID attributeId, long expected, long value) {
log.trace("Updating segment attribute: {}", attributeId);
RawClient connection = getConnection();
long requestId = connection.getFlow().getNextSequenceNumber();
return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new UpdateSegmentAttribute(requestId, segmentId.getScopedName(), attributeId, value, expected, token))).thenApply(r -> transformReply(r, SegmentAttributeUpdated.class));
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class ConditionalOutputStreamImpl method closeConnection.
private void closeConnection(String message) {
if (closed.get()) {
log.debug("Closing connection as a result of receiving: {} for segment: {} and conditional writerId: {}", message, segmentId, writerId);
} else {
log.warn("Closing connection as a result of receiving: {} for segment: {} and conditional writerId: {}", message, segmentId, writerId);
}
RawClient c;
synchronized (lock) {
c = client;
client = null;
}
if (c != null) {
try {
c.close();
} catch (Exception e) {
log.warn("Exception tearing down connection for writerId: {} ", writerId, e);
}
}
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class SegmentMetadataClientImpl method getStreamSegmentInfo.
@VisibleForTesting
CompletableFuture<StreamSegmentInfo> getStreamSegmentInfo() {
log.debug("Getting segment info for segment: {}", segmentId);
RawClient connection = getConnection();
long requestId = connection.getFlow().getNextSequenceNumber();
return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new GetStreamSegmentInfo(requestId, segmentId.getScopedName(), token))).thenApply(r -> transformReply(r, StreamSegmentInfo.class));
}
use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.
the class AppendTest method appendALotOfData.
@Test(timeout = 100000)
public void appendALotOfData() {
String endpoint = "localhost";
String scope = "Scope";
String streamName = "appendALotOfData";
int port = TestUtils.getAvailableListenPort();
long heapSize = Runtime.getRuntime().maxMemory();
long messageSize = Math.min(1024 * 1024, heapSize / 20000);
ByteBuffer payload = ByteBuffer.allocate((int) messageSize);
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
TableStore tableStore = SERVICE_BUILDER.createTableStoreService();
@Cleanup("shutdown") InlineExecutor tokenExpiryExecutor = new InlineExecutor();
@Cleanup PravegaConnectionListener server = new PravegaConnectionListener(false, port, store, tableStore, tokenExpiryExecutor);
server.startListening();
ClientConfig config = ClientConfig.builder().build();
SocketConnectionFactoryImpl clientCF = new SocketConnectionFactoryImpl(config);
@Cleanup ConnectionPoolImpl connectionPool = new ConnectionPoolImpl(config, clientCF);
Controller controller = new MockController(endpoint, port, connectionPool, true);
@Cleanup StreamManagerImpl streamManager = new StreamManagerImpl(controller, connectionPool);
streamManager.createScope(scope);
@Cleanup ClientFactoryImpl clientFactory = new ClientFactoryImpl(scope, controller, config);
streamManager.createStream("Scope", streamName, StreamConfiguration.builder().scalingPolicy(ScalingPolicy.fixed(1)).build());
@Cleanup EventStreamWriter<ByteBuffer> producer = clientFactory.createEventWriter(streamName, new ByteBufferSerializer(), EventWriterConfig.builder().build());
@Cleanup RawClient rawClient = new RawClient(new PravegaNodeUri(endpoint, port), connectionPool);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 100; j++) {
producer.writeEvent(payload.slice());
}
producer.flush();
long requestId = rawClient.getFlow().getNextSequenceNumber();
String scopedName = new Segment(scope, streamName, 0).getScopedName();
WireCommands.TruncateSegment request = new WireCommands.TruncateSegment(requestId, scopedName, i * 100L * (payload.remaining() + TYPE_PLUS_LENGTH_SIZE), "");
Reply reply = rawClient.sendRequest(requestId, request).join();
assertFalse(reply.toString(), reply.isFailure());
}
producer.close();
}
Aggregations