use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project cassandra by apache.
the class ConnectionTest method testCRCCorruption.
@Test
public void testCRCCorruption() throws Throwable {
test((inbound, outbound, endpoint) -> {
int version = outbound.settings().acceptVersions.max;
if (version < VERSION_40)
return;
unsafeSetSerializer(Verb._TEST_1, () -> new IVersionedSerializer<Object>() {
public void serialize(Object o, DataOutputPlus out, int version) throws IOException {
out.writeInt((Integer) o);
}
public Object deserialize(DataInputPlus in, int version) throws IOException {
return in.readInt();
}
public long serializedSize(Object o, int version) {
return Integer.BYTES;
}
});
connect(outbound);
outbound.unsafeGetChannel().pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ByteBuf bb = (ByteBuf) msg;
bb.setByte(0, 0xAB);
ctx.write(msg, promise);
}
});
outbound.enqueue(Message.out(Verb._TEST_1, 0xffffffff));
CompletableFuture.runAsync(() -> {
while (outbound.isConnected() && !Thread.interrupted()) {
}
}).get(10, SECONDS);
Assert.assertFalse(outbound.isConnected());
// TODO: count corruptions
connect(outbound);
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project cassandra by apache.
the class EntireSSTableStreamingCorrectFilesCountTest method createMockNettyChannel.
private EmbeddedChannel createMockNettyChannel(ByteBuf serializedFile) {
WritableByteChannel wbc = new WritableByteChannel() {
private boolean isOpen = true;
public int write(ByteBuffer src) {
int size = src.limit();
serializedFile.writeBytes(src);
return size;
}
public boolean isOpen() {
return isOpen;
}
public void close() {
isOpen = false;
}
};
return new EmbeddedChannel(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
((SharedDefaultFileRegion) msg).transferTo(wbc, 0);
super.write(ctx, msg, promise);
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project cassandra by apache.
the class StreamingMultiplexedChannelTest method onControlMessageComplete_Exception.
@Test
public void onControlMessageComplete_Exception() throws InterruptedException, ExecutionException, TimeoutException {
Assert.assertTrue(channel.isOpen());
Assert.assertTrue(sender.connected());
ChannelPromise promise = channel.newPromise();
promise.setFailure(new RuntimeException("this is just a testing exception"));
Future f = sender.onMessageComplete(promise, new CompleteMessage());
f.get(5, TimeUnit.SECONDS);
Assert.assertFalse(channel.isOpen());
Assert.assertFalse(sender.connected());
Assert.assertEquals(StreamSession.State.FAILED, session.state());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project flink by apache.
the class NettyMessage method writeToChannel.
// ------------------------------------------------------------------------
void writeToChannel(ChannelOutboundInvoker out, ChannelPromise promise, ByteBufAllocator allocator, Consumer<ByteBuf> consumer, byte id, int length) throws IOException {
ByteBuf byteBuf = null;
try {
byteBuf = allocateBuffer(allocator, id, length);
consumer.accept(byteBuf);
out.write(byteBuf, promise);
} catch (Throwable t) {
handleException(byteBuf, null, t);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPromise in project flink by apache.
the class ClientTransportErrorHandlingTest method testExceptionOnWrite.
/**
* Verifies that failed client requests via {@link PartitionRequestClient} are correctly
* attributed to the respective {@link RemoteInputChannel}.
*/
@Test
public void testExceptionOnWrite() throws Exception {
NettyProtocol protocol = new NettyProtocol(mock(ResultPartitionProvider.class), mock(TaskEventDispatcher.class)) {
@Override
public ChannelHandler[] getServerChannelHandlers() {
return new ChannelHandler[0];
}
};
// We need a real server and client in this test, because Netty's EmbeddedChannel is
// not failing the ChannelPromise of failed writes.
NettyServerAndClient serverAndClient = initServerAndClient(protocol, createConfig());
Channel ch = connect(serverAndClient);
NetworkClientHandler handler = getClientHandler(ch);
// Last outbound handler throws Exception after 1st write
ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() {
int writeNum = 0;
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (writeNum >= 1) {
throw new RuntimeException("Expected test exception.");
}
writeNum++;
ctx.write(msg, promise);
}
});
PartitionRequestClient requestClient = new NettyPartitionRequestClient(ch, handler, mock(ConnectionID.class), mock(PartitionRequestClientFactory.class));
// Create input channels
RemoteInputChannel[] rich = new RemoteInputChannel[] { createRemoteInputChannel(), createRemoteInputChannel() };
final CountDownLatch sync = new CountDownLatch(1);
// Do this with explicit synchronization. Otherwise this is not robust against slow timings
// of the callback (e.g. we cannot just verify that it was called once, because there is
// a chance that we do this too early).
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
sync.countDown();
return null;
}
}).when(rich[1]).onError(isA(LocalTransportException.class));
// First request is successful
requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[0], 0);
// Second request is *not* successful
requestClient.requestSubpartition(new ResultPartitionID(), 0, rich[1], 0);
// Wait for the notification and it could confirm all the request operations are done
if (!sync.await(TestingUtils.TESTING_DURATION.toMillis(), TimeUnit.MILLISECONDS)) {
fail("Timed out after waiting for " + TestingUtils.TESTING_DURATION.toMillis() + " ms to be notified about the channel error.");
}
// Only the second channel should be notified about the error
verify(rich[0], times(0)).onError(any(LocalTransportException.class));
shutdown(serverAndClient);
}
Aggregations