use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel 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.embedded.EmbeddedChannel in project cassandra by apache.
the class EntireSSTableStreamingCorrectFilesCountTest method constructDataOutputStream.
private AsyncStreamingOutputPlus constructDataOutputStream() {
// This is needed as Netty releases the ByteBuffers as soon as the channel is flushed
ByteBuf serializedFile = Unpooled.buffer(8192);
EmbeddedChannel channel = createMockNettyChannel(serializedFile);
return new AsyncStreamingOutputPlus(channel) {
public void flush() throws IOException {
// NO-OP
}
};
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project neo4j by neo4j.
the class FragmentedMessageDeliveryTest method testPermutation.
private void testPermutation(byte[] unfragmented, ByteBuf[] fragments) throws Exception {
// Given
channel = new EmbeddedChannel();
BoltChannel boltChannel = newTestBoltChannel(channel);
BoltStateMachine machine = mock(BoltStateMachine.class);
SynchronousBoltConnection boltConnection = new SynchronousBoltConnection(machine);
NullLogService logging = NullLogService.getInstance();
var bookmarksParser = mock(BookmarksParser.class);
var memoryTracker = mock(MemoryTracker.class);
BoltProtocol boltProtocol = new BoltProtocolV4(boltChannel, (ch, s, messageWriter) -> boltConnection, (v, ch, hints, mem) -> machine, Config.defaults(), bookmarksParser, logging, mock(TransportThrottleGroup.class), mock(ChannelProtector.class), memoryTracker);
boltProtocol.install();
// When data arrives split up according to the current permutation
for (ByteBuf fragment : fragments) {
channel.writeInbound(fragment.readerIndex(0).retain());
}
// Then the session should've received the specified messages, and the protocol should be in a nice clean state
try {
RequestMessage run = new RunMessage("Mjölnir", EMPTY_MAP);
verify(machine).process(eq(run), any(BoltResponseHandler.class));
} catch (AssertionError e) {
throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.toString(messages) + "\n" + "Chunk size: " + chunkSize + "\n" + "Serialized data delivered in fragments: " + describeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project neo4j by neo4j.
the class BoltChannelTest method shouldExposeClientConnectionInfo.
@Test
void shouldExposeClientConnectionInfo() {
EmbeddedChannel channel = new EmbeddedChannel();
BoltChannel boltChannel = new BoltChannel("bolt-42", "my-bolt", channel, ChannelProtector.NULL);
ClientConnectionInfo info1 = boltChannel.info();
assertEquals("bolt-42", info1.connectionId());
assertEquals("bolt", info1.protocol());
assertEquals(SocketAddress.format(channel.remoteAddress()), info1.clientAddress());
boltChannel.updateUser("Tom", "my-driver");
ClientConnectionInfo info2 = boltChannel.info();
assertEquals("bolt-42", info2.connectionId());
assertEquals("bolt", info2.protocol());
assertEquals(SocketAddress.format(channel.remoteAddress()), info2.clientAddress());
assertThat(info2.asConnectionDetails()).contains("my-driver");
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project neo4j by neo4j.
the class DefaultBoltProtocolFactoryTest method shouldCreateBoltProtocol.
@ParameterizedTest(name = "V{0}.{1}")
@CsvSource({ "3, 0", "4, 0", "4, 1", "4, 2", "4, 3" })
void shouldCreateBoltProtocol(int majorVersion, int minorVersion) throws Throwable {
EmbeddedChannel channel = new EmbeddedChannel();
BoltChannel boltChannel = newTestBoltChannel(channel);
BoltProtocolVersion boltProtocolVersion = new BoltProtocolVersion(majorVersion, minorVersion);
BoltStateMachineFactory stateMachineFactory = mock(BoltStateMachineFactory.class);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
var channelProtector = mock(ChannelProtector.class);
var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
when(stateMachineFactory.newStateMachine(boltProtocolVersion, boltChannel, MapValue.EMPTY, memoryTracker)).thenReturn(stateMachine);
BoltConnectionFactory connectionFactory = mock(BoltConnectionFactory.class);
BoltConnection connection = mock(BoltConnection.class);
when(connectionFactory.newConnection(eq(boltChannel), eq(stateMachine), any())).thenReturn(connection);
BoltProtocolFactory factory = new DefaultBoltProtocolFactory(connectionFactory, stateMachineFactory, Config.defaults(), NullLogService.getInstance(), new TestDatabaseIdRepository(), CustomBookmarkFormatParser.DEFAULT, mock(TransportThrottleGroup.class), Clocks.fakeClock(), Duration.ZERO);
BoltProtocol protocol = factory.create(boltProtocolVersion, boltChannel, channelProtector, memoryTracker);
protocol.install();
// handler with correct version is created
assertEquals(boltProtocolVersion, protocol.version());
// it uses the expected worker
verify(connectionFactory).newConnection(eq(boltChannel), any(BoltStateMachine.class), any(BoltResponseMessageWriter.class));
verify(memoryTracker, times(5)).allocateHeap(anyLong());
// and halts this same worker when closed
verify(connection, never()).stop();
channel.close();
verify(connection).stop();
channel.finishAndReleaseAll();
}
Aggregations