@Override public void process(ReplyProcessor cp) { cp.noSuchSegment(this); }
@Override public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) { getNextReplyProcessor().noSuchSegment(noSuchSegment); }
private void validateNoSuchSegment(MockConnectionFactory factory, Supplier<CompletableFuture<?>> futureSupplier) { CompletableFuture<?> future = futureSupplier.get(); factory.rp.noSuchSegment(new WireCommands.NoSuchSegment(0, "segment", "SomeException")); AssertExtensions.assertThrows("", future::join, ex -> ex instanceof WireCommandFailedException && (((WireCommandFailedException) ex).getReason() == WireCommandFailedException.Reason.SegmentDoesNotExist)); }
@Test(timeout = 10000) public void testConnectAndFailedSetupAppendDueToTruncation() throws Exception { AtomicBoolean callbackInvoked = new AtomicBoolean(); Consumer<Segment> resendToSuccessorsCallback = segment -> { callbackInvoked.set(true); }; UUID cid = UUID.randomUUID(); PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT); MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl(); ScheduledExecutorService executor = mock(ScheduledExecutorService.class); implementAsDirectExecutor(executor); // Ensure task submitted to executor is run inline. cf.setExecutor(executor); MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf); ClientConnection connection = mock(ClientConnection.class); cf.provideConnection(uri, connection); @Cleanup SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, resendToSuccessorsCallback, RETRY_SCHEDULE, ""); output.reconnect(); verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(1, SEGMENT, "SomeException")); CompletableFuture<ClientConnection> connectionFuture = output.getConnection(); assertThrows(NoSuchSegmentException.class, () -> Futures.getThrowingException(connectionFuture)); assertTrue(callbackInvoked.get()); }
cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(1, TXN_SEGMENT, "SomeException"));
@Test(timeout = 10000) public void testFlushDuringTransactionAbort() 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(TXN_SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, ""); output.reconnect(); order.verify(connection).send(new SetupAppend(1, cid, TXN_SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, TXN_SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); // Write an Event. CompletableFuture<Void> ack = new CompletableFuture<>(); output.write(PendingEvent.withoutHeader(null, data, ack)); order.verify(connection).send(new Append(TXN_SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null)); assertFalse(ack.isDone()); //writer is not complete until a response from Segment Store is received. // Validate that flush() is blocking until there is a response from Segment Store. AssertExtensions.assertBlocks(() -> { // A flush() should throw a SegmentSealedException. AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }, () -> { // Simulate a NoSuchSegment response from SegmentStore due to a Transaction abort. cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(1, TXN_SEGMENT, "SomeException")); }); AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }
@Test public void testDeleteTableSegment() { MockConnectionFactory factory = new MockConnectionFactory(); // On receiving NoSuchSegment true should be returned. CompletableFuture<Boolean> result = helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); factory.rp.noSuchSegment(new WireCommands.NoSuchSegment(0, getQualifiedStreamSegmentName("", "", 0L), "")); assertTrue(result.join()); // On receiving SegmentDeleted true should be returned. result = helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); factory.rp.segmentDeleted(new WireCommands.SegmentDeleted(0, getQualifiedStreamSegmentName("", "", 0L))); assertTrue(result.join()); // On receiving TableSegmentNotEmpty WireCommandFailedException is thrown. result = helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); factory.rp.tableSegmentNotEmpty(new WireCommands.TableSegmentNotEmpty(0, getQualifiedStreamSegmentName("", "", 0L), "")); AssertExtensions.assertThrows("", result::join, ex -> ex instanceof WireCommandFailedException && (((WireCommandFailedException) ex).getReason() == WireCommandFailedException.Reason.TableSegmentNotEmpty)); Supplier<CompletableFuture<?>> futureSupplier = () -> helper.deleteTableSegment("", "", true, new MockHostControllerStore(), factory, "", System.nanoTime()); validateAuthTokenCheckFailed(factory, futureSupplier); validateWrongHost(factory, futureSupplier); validateConnectionDropped(factory, futureSupplier); validateProcessingFailure(factory, futureSupplier); }
@Test(timeout = 10000) public void testNoSuchSegment() 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"); //Write an Event. 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()); //writer is not complete until a response from Segment Store is received. //Simulate a No Such Segment while waiting on flush. AssertExtensions.assertBlocks(() -> { AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }, () -> { cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(1, SEGMENT, "SomeException")); output.getUnackedEventsOnSeal(); }); AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }