@Override public void process(ReplyProcessor cp) { cp.authTokenCheckFailed(this); }
/** * 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 process(ReplyProcessor cp) { cp.noSuchSegment(this); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { Reply cmd = (Reply) msg; log.debug(connectionName + " processing reply: {}", cmd); if (cmd instanceof WireCommands.DataAppended) { batchSizeTracker.recordAck(((WireCommands.DataAppended) cmd).getEventNumber()); } try { processor.process(cmd); } catch (Exception e) { processor.processingFailure(e); } }
@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, "")); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { processor.process(new WireCommands.SegmentAttribute(1, 123)); return null; } }).when(connection).sendAsync(Mockito.eq(new WireCommands.GetSegmentAttribute(1, segment.getScopedName(), attributeId, "")),
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"); order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null)); assertEquals(false, acked1.isDone()); AssertExtensions.assertBlocks(() -> output.flush(), () -> cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(cid, 1, 0))); assertEquals(false, acked1.isCompletedExceptionally()); assertEquals(true, acked1.isDone()); order.verify(connection).send(new Append(SEGMENT, cid, 2, 1, Unpooled.wrappedBuffer(data), null)); assertEquals(false, acked2.isDone()); cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(cid, 3, 2L));
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"); cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(1, TXN_SEGMENT, "SomeException"));
cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); output.write(PendingEvent.withoutHeader(null, getBuffer("test1"), new CompletableFuture<>())); 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))); output.write(PendingEvent.withoutHeader(null, getBuffer("test4"), new CompletableFuture<>()));
@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 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); }
@Override public void process(ReplyProcessor cp) { cp.appendSetup(this); }
@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));
@Override public void process(ReplyProcessor cp) { cp.wrongHost(this); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { processor.processingFailure(new ConnectionFailedException(cause)); }
@Test public void testCreateTableSegment() { MockConnectionFactory factory = new MockConnectionFactory(); // On receiving SegmentAlreadyExists true should be returned. CompletableFuture<Boolean> result = helper.createTableSegment("", "", new MockHostControllerStore(), factory, "", Long.MIN_VALUE); factory.rp.segmentAlreadyExists(new WireCommands.SegmentAlreadyExists(0, getQualifiedStreamSegmentName("", "", 0L), "")); assertTrue(result.join()); // On Receiving SegmentCreated true should be returned. result = helper.createTableSegment("", "", new MockHostControllerStore(), factory, "", Long.MIN_VALUE); factory.rp.segmentCreated(new WireCommands.SegmentCreated(0, getQualifiedStreamSegmentName("", "", 0L))); assertTrue(result.join()); // Validate failure conditions. Supplier<CompletableFuture<?>> futureSupplier = () -> helper.createTableSegment("", "", new MockHostControllerStore(), factory, "", Long.MIN_VALUE); validateAuthTokenCheckFailed(factory, futureSupplier); validateWrongHost(factory, futureSupplier); validateConnectionDropped(factory, futureSupplier); validateProcessingFailure(factory, futureSupplier); }
@Override public void process(ReplyProcessor cp) { cp.segmentCreated(this); }
@Override public void process(ReplyProcessor cp) { cp.dataAppended(this); }
@Override public void process(ReplyProcessor cp) { cp.segmentAlreadyExists(this); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { processor.process(new SegmentAttributeUpdated(1, true)); return null; } }).when(connection).sendAsync(Mockito.eq(new WireCommands.UpdateSegmentAttribute(1, segment.getScopedName(), attributeId, 1234,