use of io.pravega.shared.protocol.netty.WireCommands.CreateSegment in project pravega by pravega.
the class PravegaRequestProcessor method createSegment.
@Override
public void createSegment(CreateSegment createStreamsSegment) {
Timer timer = new Timer();
Collection<AttributeUpdate> attributes = Arrays.asList(new AttributeUpdate(SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ((Byte) createStreamsSegment.getScaleType()).longValue()), new AttributeUpdate(SCALE_POLICY_RATE, AttributeUpdateType.Replace, ((Integer) createStreamsSegment.getTargetRate()).longValue()));
if (!verifyToken(createStreamsSegment.getSegment(), createStreamsSegment.getRequestId(), createStreamsSegment.getDelegationToken(), READ_UPDATE, "Create Segment")) {
return;
}
segmentStore.createStreamSegment(createStreamsSegment.getSegment(), attributes, TIMEOUT).thenAccept(v -> {
createStreamSegment.reportSuccessEvent(timer.getElapsed());
connection.send(new SegmentCreated(createStreamsSegment.getRequestId(), createStreamsSegment.getSegment()));
}).whenComplete((res, e) -> {
if (e == null) {
if (statsRecorder != null) {
statsRecorder.createSegment(createStreamsSegment.getSegment(), createStreamsSegment.getScaleType(), createStreamsSegment.getTargetRate());
}
} else {
createStreamSegment.reportFailEvent(timer.getElapsed());
handleException(createStreamsSegment.getRequestId(), createStreamsSegment.getSegment(), "Create segment", e);
}
});
}
use of io.pravega.shared.protocol.netty.WireCommands.CreateSegment in project pravega by pravega.
the class MockController method createSegment.
private boolean createSegment(String name, PravegaNodeUri uri) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
result.completeExceptionally(new ConnectionClosedException());
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
result.completeExceptionally(new UnsupportedOperationException());
}
@Override
public void segmentAlreadyExists(WireCommands.SegmentAlreadyExists segmentAlreadyExists) {
result.complete(false);
}
@Override
public void segmentCreated(WireCommands.SegmentCreated segmentCreated) {
result.complete(true);
}
@Override
public void processingFailure(Exception error) {
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
}
};
CreateSegment command = new WireCommands.CreateSegment(idGenerator.get(), name, WireCommands.CreateSegment.NO_SCALE, 0, "");
sendRequestOverNewConnection(command, replyProcessor, result);
return getAndHandleExceptions(result, RuntimeException::new);
}
use of io.pravega.shared.protocol.netty.WireCommands.CreateSegment in project pravega by pravega.
the class AppendTest method testMultipleAppends.
@Test(timeout = 10000)
public void testMultipleAppends() throws Exception {
String segment = "123";
ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, ""));
assertEquals(segment, created.getSegment());
UUID uuid = UUID.randomUUID();
AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, ""));
assertEquals(segment, setup.getSegment());
assertEquals(uuid, setup.getWriterId());
data.retain();
DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, 1, data, null));
assertEquals(uuid, ack.getWriterId());
assertEquals(1, ack.getEventNumber());
assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, data, null));
assertEquals(uuid, ack2.getWriterId());
assertEquals(2, ack2.getEventNumber());
assertEquals(1, ack2.getPreviousEventNumber());
}
use of io.pravega.shared.protocol.netty.WireCommands.CreateSegment in project pravega by pravega.
the class AppendTest method sendReceivingAppend.
@Test
public void sendReceivingAppend() throws Exception {
String segment = "123";
ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, ""));
assertEquals(segment, created.getSegment());
UUID uuid = UUID.randomUUID();
AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, ""));
assertEquals(segment, setup.getSegment());
assertEquals(uuid, setup.getWriterId());
DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, data.readableBytes(), data, null));
assertEquals(uuid, ack.getWriterId());
assertEquals(data.readableBytes(), ack.getEventNumber());
assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
}
use of io.pravega.shared.protocol.netty.WireCommands.CreateSegment in project pravega by pravega.
the class BatchClientImplTest method testSegmentIterator.
@Test(timeout = 5000)
public void testSegmentIterator() throws ConnectionFailedException {
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
ClientConnection connection = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CreateSegment request = (CreateSegment) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new SegmentCreated(request.getRequestId(), request.getSegment()));
return null;
}
}).when(connection).send(Mockito.any(CreateSegment.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
GetStreamSegmentInfo request = (GetStreamSegmentInfo) invocation.getArgument(0);
connectionFactory.getProcessor(location).process(new StreamSegmentInfo(request.getRequestId(), request.getSegmentName(), true, false, false, 0, 0, 0));
return null;
}
}).when(connection).send(Mockito.any(GetStreamSegmentInfo.class));
connectionFactory.provideConnection(location, connection);
MockController mockController = new MockController(location.getEndpoint(), location.getPort(), connectionFactory);
BatchClientImpl client = new BatchClientImpl(mockController, connectionFactory);
Stream stream = new StreamImpl("scope", "stream");
mockController.createScope("scope");
mockController.createStream(StreamConfiguration.builder().scope("scope").streamName("stream").scalingPolicy(ScalingPolicy.fixed(3)).build()).join();
Iterator<SegmentRange> segments = client.getSegments(stream, null, null).getIterator();
assertTrue(segments.hasNext());
assertEquals(0, segments.next().asImpl().getSegment().getSegmentNumber());
assertTrue(segments.hasNext());
assertEquals(1, segments.next().asImpl().getSegment().getSegmentNumber());
assertTrue(segments.hasNext());
assertEquals(2, segments.next().asImpl().getSegment().getSegmentNumber());
assertFalse(segments.hasNext());
}
Aggregations