@Override public void process(ReplyProcessor cp) { cp.segmentIsSealed(this); }
@Override public void segmentIsSealed(WireCommands.SegmentIsSealed segmentIsSealed) { getNextReplyProcessor().segmentIsSealed(segmentIsSealed); }
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }, () -> { cf.getProcessor(uri).segmentIsSealed(new WireCommands.SegmentIsSealed(1, SEGMENT, "SomeException")); output.getUnackedEventsOnSeal(); });
@Test(timeout = 10000) public void testSealedBeforeFlush() throws Exception { UUID cid = UUID.randomUUID(); PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT); MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl(); cf.setExecutor(executorService()); MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf); ClientConnection connection = mock(ClientConnection.class); cf.provideConnection(uri, connection); InOrder order = Mockito.inOrder(connection); SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, ""); output.reconnect(); order.verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); CompletableFuture<Void> ack = new CompletableFuture<>(); output.write(PendingEvent.withoutHeader(null, data, ack)); order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null)); assertEquals(false, ack.isDone()); cf.getProcessor(uri).segmentIsSealed(new WireCommands.SegmentIsSealed(1, SEGMENT, "SomeException")); output.getUnackedEventsOnSeal(); // this is invoked by the segmentSealedCallback. AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }
@Test(timeout = 10000) public void testSealedAfterFlush() throws Exception { UUID cid = UUID.randomUUID(); PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT); MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl(); cf.setExecutor(executorService()); MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf); ClientConnection connection = mock(ClientConnection.class); cf.provideConnection(uri, connection); InOrder order = Mockito.inOrder(connection); SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, ""); output.reconnect(); order.verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); CompletableFuture<Void> ack = new CompletableFuture<>(); output.write(PendingEvent.withoutHeader(null, data, ack)); order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null)); assertEquals(false, ack.isDone()); AssertExtensions.assertBlocks(() -> { AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }, () -> { cf.getProcessor(uri).segmentIsSealed(new WireCommands.SegmentIsSealed(1, SEGMENT, "SomeException")); output.getUnackedEventsOnSeal(); }); AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }
ScheduledExecutorService executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "netty-callback"); executor.submit(() -> cf.getProcessor(uri).segmentIsSealed(new WireCommands.SegmentIsSealed(1, SEGMENT, "SomeException")));