use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project ambry by linkedin.
the class ChannelWriteCallback method closeTest.
/**
* Tests that the underlying network channel is closed when {@link NettyResponseChannel#close()} is called.
*/
@Test
public void closeTest() {
// request is keep-alive by default.
HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.Close.toString());
EmbeddedChannel channel = createEmbeddedChannel();
channel.writeInbound(request);
HttpResponse response = (HttpResponse) channel.readOutbound();
assertEquals("Unexpected response status", HttpResponseStatus.INTERNAL_SERVER_ERROR, response.status());
assertFalse("Inconsistent value for Connection header", HttpUtil.isKeepAlive(response));
// drain the channel of content.
while (channel.readOutbound() != null) {
}
assertFalse("Channel should be closed", channel.isOpen());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project ambry by linkedin.
the class ChannelWriteCallback method doBadStateTransitionTest.
// badStateTransitionsTest() helpers
/**
* Creates a channel and sends the request to the {@link EmbeddedChannel}. Checks for an exception and verifies the
* exception class matches. If {@code exceptionClass} is {@link RestServiceException}, then checks the provided
* {@link RestServiceErrorCode}.
* @param uri the uri to hit.
* @param exceptionClass the class of the exception expected.
* @throws Exception
*/
private void doBadStateTransitionTest(TestingUri uri, Class exceptionClass) throws Exception {
EmbeddedChannel channel = createEmbeddedChannel();
MockNettyMessageProcessor processor = channel.pipeline().get(MockNettyMessageProcessor.class);
try {
channel.writeInbound(RestTestUtils.createRequest(HttpMethod.GET, uri.toString(), null));
verifyCallbacks(processor);
fail("This test was expecting the handler in the channel to throw an exception");
} catch (Exception e) {
if (!exceptionClass.isInstance(e)) {
throw e;
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.
the class GetBlobResponseEncoderTest method shouldEncodeOneChunkResponse.
@Test
public void shouldEncodeOneChunkResponse() throws Exception {
byte[] blobData = new byte[] { 1, 2, 3 };
String blobId = "blobId";
byte mask = createMask(1, 1);
EmbeddedChannel channel = new EmbeddedChannel(new ChunkedWriteHandler(), new GetBlobResponseEncoder(3));
channel.writeOutbound(new GetBlobResponse("clientId", blobId, new ByteArrayInputStream(blobData), blobData.length));
ByteBuf buffer = (ByteBuf) channel.readOutbound();
ByteBuf expected = createBlobChunkBuffer(Messages.HEADER_BLOB, 3L, blobId, blobData, mask);
assertEquals(expected, buffer);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.
the class ResponseDecoderTest method shouldDecodeValidOneChunkGetBlobResponses.
@Test
public void shouldDecodeValidOneChunkGetBlobResponses() throws Exception {
byte[] blobData = new byte[] { 1, 2, 3 };
String blobId = "blobId";
byte mask = createMask(1, 1);
ByteBuf buf = createBlobChunkBuffer(Messages.HEADER_BLOB, 3L, blobId, blobData, mask);
EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder(folder.newFolder()));
channel.writeInbound(buf);
GetBlobResponse response = (GetBlobResponse) channel.readInbound();
assertEquals("blobId", response.getBlobId());
assertEquals(blobData.length, response.getLength());
try (InputStream is = response.getInputStream()) {
byte[] receivedData = IOUtils.toByteArray(is);
assertArrayEquals(blobData, receivedData);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.
the class ResponseDecoderTest method shouldDropInvalidGetBlobResponses.
@Test
public void shouldDropInvalidGetBlobResponses() throws Exception {
byte[] blobData = new byte[] { 1, 2, 3 };
String blobId = "blobId";
byte[] blobIdBytes = blobId.getBytes(Charsets.UTF_8);
byte mask = createMask(1, 1);
ByteBuf buf = Unpooled.buffer();
buf.writeInt(1 + 1 + 8 + 4 + blobIdBytes.length + 8 + blobData.length);
buf.writeByte(Messages.HEADER_BLOB);
buf.writeByte(mask);
buf.writeLong(3L);
buf.writeInt(blobIdBytes.length);
buf.writeBytes(blobIdBytes);
buf.writeLong(hash(mask, 3L, blobData) + 1);
buf.writeBytes(blobData);
EmbeddedChannel channel = new EmbeddedChannel(new ResponseDecoder(folder.newFolder()));
channel.writeInbound(buf);
assertNull(channel.readInbound());
}
Aggregations