/** * Disconnected. * @see io.netty.channel.ChannelInboundHandler#channelUnregistered(io.netty.channel.ChannelHandlerContext) */ @Override public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { registeredFutureLatch.reset(); ScheduledFuture<?> future = keepAliveFuture.get(); if (future != null) { future.cancel(false); } channel.set(null); processor.connectionDropped(); super.channelUnregistered(ctx); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { ReplyProcessor processor = cf.getProcessor(endpoint); processor.connectionDropped(); return null; } }).when(connection).sendAsync(Mockito.eq(getSegmentInfo1), Mockito.any(ClientConnection.CompletedCallback.class));
private void validateConnectionDropped(MockConnectionFactory factory, Supplier<CompletableFuture<?>> futureSupplier) { CompletableFuture<?> future = futureSupplier.get(); factory.rp.connectionDropped(); AssertExtensions.assertThrows("", future::join, ex -> ex instanceof WireCommandFailedException && (((WireCommandFailedException) ex).getReason() == WireCommandFailedException.Reason.ConnectionDropped)); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { cf.getProcessor(uri).connectionDropped(); throw new ConnectionFailedException(); } }).doNothing().when(connection).send(new WireCommands.KeepAlive());
@Override public Void answer(InvocationOnMock invocation) throws Throwable { cf.getProcessor(uri).connectionDropped(); throw new ConnectionFailedException(); } }).when(connection).send(append);
@Override public Void answer(InvocationOnMock invocation) throws Throwable { ConditionalAppend argument = (ConditionalAppend) invocation.getArgument(0); ReplyProcessor processor = connectionFactory.getProcessor(location); if (count.getAndIncrement() < 2) { processor.connectionDropped(); } else { processor.process(new WireCommands.DataAppended(argument.getWriterId(), argument.getEventNumber(), 0)); } return null; } }).when(mock).sendAsync(any(ConditionalAppend.class), any(ClientConnection.CompletedCallback.class));
@Test(timeout = 10000) public void testConnectAndConnectionDrop() throws Exception { 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, segmentSealedCallback, RETRY_SCHEDULE, ""); output.reconnect(); verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); cf.getProcessor(uri).connectionDropped(); // simulate a connection dropped //Ensure setup Append is invoked on the executor. verify(connection).send(new SetupAppend(2, cid, SEGMENT, "")); }
cf.getProcessor(uri).connectionDropped(); AssertExtensions.assertBlocks(() -> output.write(PendingEvent.withoutHeader(null, getBuffer("test3"), new CompletableFuture<>())), () -> {
output.flush(); }, () -> { cf.getProcessor(uri).connectionDropped(); }); order.verify(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
output.write(PendingEvent.withoutHeader(null, getBuffer("test2"), new CompletableFuture<>())); answerSuccess(connection); cf.getProcessor(uri).connectionDropped(); AssertExtensions.assertBlocks(() -> output.write(PendingEvent.withoutHeader(null, getBuffer("test3"), new CompletableFuture<>())), () -> cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)));
@Test(timeout = 10000) public void testConnectWithMultipleFailures() throws Exception { 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, segmentSealedCallback, RETRY_SCHEDULE, ""); output.reconnect(); verify(connection).send(new SetupAppend(1, cid, SEGMENT, "")); //simulate a processing Failure and ensure SetupAppend is executed. cf.getProcessor(uri).processingFailure(new IOException()); verify(connection).send(new SetupAppend(2, cid, SEGMENT, "")); cf.getProcessor(uri).connectionDropped(); verify(connection).send(new SetupAppend(3, cid, SEGMENT, "")); cf.getProcessor(uri).wrongHost(new WireCommands.WrongHost(3, SEGMENT, "newHost", "SomeException")); verify(connection).send(new SetupAppend(4, cid, SEGMENT, "")); }