WireCommands.CreateSegment request = new WireCommands.CreateSegment(idGenerator.get(), transactionName, WireCommands.CreateSegment.NO_SCALE, 0, delegationToken); sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), connection); processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName)); processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, "")); transactionName = StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid); processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store)); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); transactionName = StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid); processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnid), 1, store)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(2, transactionName, ""));
WireCommands.CreateSegment request = new WireCommands.CreateSegment(requestId, qualifiedStreamSegmentName, extracted.getLeft(), extracted.getRight(), controllerToken); sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); order.verify(connection).send(new WireCommands.SegmentCreated(0, streamSegmentName)); processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); order.verify(connection).send(new WireCommands.SegmentCreated(1, transactionName)); processor.mergeSegments(new WireCommands.MergeSegments(2, streamSegmentName, transactionName, "")); anyString(), anyString(), any()); processor.createSegment(new WireCommands.CreateSegment(3, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); order.verify(connection).send(new WireCommands.SegmentCreated(3, transactionName)); processor.mergeSegments(new WireCommands.MergeSegments(4, streamSegmentName, transactionName, ""));
processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(streamSegmentName, 1, store)); assertTrue(append(streamSegmentName, 2, store));
processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName));
PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), connection, mockedDynamicLogger); processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); String transactionName = StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnId); processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); processor.mergeSegments(new WireCommands.MergeSegments(2, streamSegmentName, transactionName, "")); verify(mockedDynamicLogger).incCounterValue(nameFromSegment(SEGMENT_WRITE_BYTES, streamSegmentName), 100); processor = new PravegaRequestProcessor(store, mock(TableStore.class), connection, mockedDynamicLogger); processor.createSegment(new WireCommands.CreateSegment(0, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); transactionName = StreamSegmentNameUtils.getTransactionNameFromId(streamSegmentName, txnId); processor.createSegment(new WireCommands.CreateSegment(1, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "")); processor.mergeSegments(new WireCommands.MergeSegments(2, streamSegmentName, transactionName, "")); verify(mockedDynamicLogger, never()).incCounterValue(nameFromSegment(SEGMENT_WRITE_BYTES, streamSegmentName), 100);
private CompletableFuture<Void> createSegmentTx(UUID txId, Segment segment) { CompletableFuture<Void> result = new CompletableFuture<>(); FailingReplyProcessor replyProcessor = new FailingReplyProcessor() { @Override public void connectionDropped() { result.completeExceptionally(new ConnectionClosedException()); } @Override public void wrongHost(WrongHost wrongHost) { result.completeExceptionally(new UnsupportedOperationException()); } @Override public void segmentCreated(WireCommands.SegmentCreated transactionCreated) { result.complete(null); } @Override public void processingFailure(Exception error) { result.completeExceptionally(error); } @Override public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) { result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString())); } }; String transactionName = StreamSegmentNameUtils.getTransactionNameFromId(segment.getScopedName(), txId); sendRequestOverNewConnection(new CreateSegment(idGenerator.get(), transactionName, WireCommands.CreateSegment.NO_SCALE, 0, ""), replyProcessor, result); return result; }
CreateSegment command = new WireCommands.CreateSegment(idGenerator.get(), name, WireCommands.CreateSegment.NO_SCALE, 0, ""); sendRequestOverNewConnection(command, replyProcessor, result); return getAndHandleExceptions(result, RuntimeException::new);
@Override public void createSegment(CreateSegment createStreamSegment) { Timer timer = new Timer(); final String operation = "createSegment"; Collection<AttributeUpdate> attributes = Arrays.asList( new AttributeUpdate(SCALE_POLICY_TYPE, AttributeUpdateType.Replace, ((Byte) createStreamSegment.getScaleType()).longValue()), new AttributeUpdate(SCALE_POLICY_RATE, AttributeUpdateType.Replace, ((Integer) createStreamSegment.getTargetRate()).longValue()), new AttributeUpdate(CREATION_TIME, AttributeUpdateType.None, System.currentTimeMillis()) ); if (!verifyToken(createStreamSegment.getSegment(), createStreamSegment.getRequestId(), createStreamSegment.getDelegationToken(), operation)) { return; } log.info(createStreamSegment.getRequestId(), "Creating stream segment {}.", createStreamSegment); segmentStore.createStreamSegment(createStreamSegment.getSegment(), attributes, TIMEOUT) .thenAccept(v -> { this.createStreamSegment.reportSuccessEvent(timer.getElapsed()); connection.send(new SegmentCreated(createStreamSegment.getRequestId(), createStreamSegment.getSegment())); }) .whenComplete((res, e) -> { if (e == null) { if (statsRecorder != null) { statsRecorder.createSegment(createStreamSegment.getSegment(), createStreamSegment.getScaleType(), createStreamSegment.getTargetRate()); } } else { this.createStreamSegment.reportFailEvent(timer.getElapsed()); handleException(createStreamSegment.getRequestId(), createStreamSegment.getSegment(), operation, e); } }); }
@Test(timeout = 20000) public void testCreateSegment() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against String streamSegmentName = "testCreateSegment"; @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getBuilderConfig()); serviceBuilder.initialize(); StreamSegmentStore store = serviceBuilder.createStreamSegmentService(); ServerConnection connection = mock(ServerConnection.class); InOrder order = inOrder(connection); PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), connection); // Execute and Verify createSegment/getStreamSegmentInfo calling stack is executed as design. processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); assertTrue(append(streamSegmentName, 1, store)); processor.getStreamSegmentInfo(new WireCommands.GetStreamSegmentInfo(1, streamSegmentName, "")); assertTrue(append(streamSegmentName, 2, store)); order.verify(connection).send(new WireCommands.SegmentCreated(1, streamSegmentName)); order.verify(connection).send(Mockito.any(WireCommands.StreamSegmentInfo.class)); // TestCreateSealDelete may executed before this test case, // so createSegmentStats may record 1 or 2 createSegment operation here. OpStatsData createSegmentStats = processor.getCreateStreamSegment().toOpStatsData(); assertNotEquals(0, createSegmentStats.getNumSuccessfulEvents()); assertEquals(0, createSegmentStats.getNumFailedEvents()); }
@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, new Event(data))); assertEquals(uuid, ack.getWriterId()); assertEquals(1, ack.getEventNumber()); assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber()); DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, new Event(data))); assertEquals(uuid, ack2.getWriterId()); assertEquals(2, ack2.getEventNumber()); assertEquals(1, ack2.getPreviousEventNumber()); }
@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(), new Event(data))); assertEquals(uuid, ack.getWriterId()); assertEquals(data.readableBytes(), ack.getEventNumber()); assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber()); }
@Test(timeout = 20000) public void testUnsupportedOperation() throws Exception { // Set up PravegaRequestProcessor instance to execute requests against String streamSegmentName = "testCreateSegment"; @Cleanup ServiceBuilder serviceBuilder = newInlineExecutionInMemoryBuilder(getReadOnlyBuilderConfig()); serviceBuilder.initialize(); StreamSegmentStore store = serviceBuilder.createStreamSegmentService(); ServerConnection connection = mock(ServerConnection.class); InOrder order = inOrder(connection); PravegaRequestProcessor processor = new PravegaRequestProcessor(store, mock(TableStore.class), connection); // Execute and Verify createSegment/getStreamSegmentInfo calling stack is executed as design. processor.createSegment(new WireCommands.CreateSegment(1, streamSegmentName, WireCommands.CreateSegment.NO_SCALE, 0, "")); order.verify(connection).send(new WireCommands.OperationUnsupported(1, "createSegment", "")); }
@Test public void testCreateSegment() throws IOException { testCommand(new WireCommands.CreateSegment(l, testString1, b, i, "")); }
public static WireCommand readFrom(DataInput in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); int desiredRate = in.readInt(); byte scaleType = in.readByte(); String delegationToken = in.readUTF(); return new CreateSegment(requestId, segment, scaleType, desiredRate, delegationToken); } }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { CreateSegment request = (CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(endpoint) .process(new SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(CreateSegment.class),
@Override public Void answer(InvocationOnMock invocation) throws Throwable { WireCommands.CreateSegment request = (WireCommands.CreateSegment) invocation.getArgument(0); connectionFactory.getProcessor(location) .process(new WireCommands.SegmentCreated(request.getRequestId(), request.getSegment())); return null; } }).when(connection).sendAsync(Mockito.any(WireCommands.CreateSegment.class),
@Test public void createSegment() { processor.createSegment(new WireCommands.CreateSegment(100L, "segment", (byte) 0, 0, "token")); verify(connection).send(new WireCommands.AuthTokenCheckFailed(100L, "")); }
@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).sendAsync(Mockito.any(CreateSegment.class),