use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DefaultHttp2ConnectionDecoderTest method multipleHeadersContentLength.
private void multipleHeadersContentLength(boolean same) throws Exception {
final int padding = 10;
when(connection.isServer()).thenReturn(true);
final Http2Headers headers = new DefaultHttp2Headers();
if (same) {
headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 0);
headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 0);
} else {
headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 0);
headers.addLong(HttpHeaderNames.CONTENT_LENGTH, 1);
}
if (same) {
decode().onHeadersRead(ctx, STREAM_ID, headers, padding, true);
verify(listener, times(1)).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class), anyInt(), anyShort(), anyBoolean(), anyInt(), anyBoolean());
assertEquals(1, headers.getAll(HttpHeaderNames.CONTENT_LENGTH).size());
} else {
assertThrows(Http2Exception.StreamException.class, new Executable() {
@Override
public void execute() throws Throwable {
decode().onHeadersRead(ctx, STREAM_ID, headers, padding, true);
}
});
// Verify that the event was absorbed and not propagated to the observer.
verify(listener, never()).onHeadersRead(eq(ctx), anyInt(), any(Http2Headers.class), anyInt(), anyShort(), anyBoolean(), anyInt(), anyBoolean());
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DefaultHttp2ConnectionDecoderTest method errorDuringDeliveryShouldReturnCorrectNumberOfBytes.
@Test
public void errorDuringDeliveryShouldReturnCorrectNumberOfBytes() throws Exception {
final ByteBuf data = dummyData();
final int padding = 10;
final AtomicInteger unprocessed = new AtomicInteger(data.readableBytes() + padding);
doAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock in) throws Throwable {
return unprocessed.get();
}
}).when(localFlow).unconsumedBytes(eq(stream));
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock in) throws Throwable {
int delta = (Integer) in.getArguments()[1];
int newValue = unprocessed.addAndGet(-delta);
if (newValue < 0) {
throw new RuntimeException("Returned too many bytes");
}
return null;
}
}).when(localFlow).consumeBytes(eq(stream), anyInt());
// When the listener callback is called, process a few bytes and then throw.
doAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock in) throws Throwable {
localFlow.consumeBytes(stream, 4);
throw new RuntimeException("Fake Exception");
}
}).when(listener).onDataRead(eq(ctx), eq(STREAM_ID), any(ByteBuf.class), eq(10), eq(true));
try {
assertThrows(RuntimeException.class, new Executable() {
@Override
public void execute() throws Throwable {
decode().onDataRead(ctx, STREAM_ID, data, padding, true);
}
});
verify(localFlow).receiveFlowControlledFrame(eq(stream), eq(data), eq(padding), eq(true));
verify(listener).onDataRead(eq(ctx), eq(STREAM_ID), eq(data), eq(padding), eq(true));
assertEquals(0, localFlow.unconsumedBytes(stream));
} finally {
data.release();
}
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DefaultHttp2ConnectionTest method reserveWithPushDisallowedShouldThrow.
@Test
public void reserveWithPushDisallowedShouldThrow() throws Http2Exception {
final Http2Stream stream = server.remote().createStream(3, true);
server.remote().allowPushTo(false);
assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
server.local().reservePushStream(2, stream);
}
});
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DefaultHttp2ConnectionTest method serverCreatePushShouldFailOnRemoteEndpointWhenMaxAllowedStreamsExceeded.
@Test
public void serverCreatePushShouldFailOnRemoteEndpointWhenMaxAllowedStreamsExceeded() throws Http2Exception {
server = new DefaultHttp2Connection(true, 0);
server.remote().maxActiveStreams(1);
final Http2Stream requestStream = server.remote().createStream(3, false);
assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
server.remote().reservePushStream(2, requestStream);
}
});
}
use of org.junit.jupiter.api.function.Executable in project netty by netty.
the class DefaultHttp2HeadersEncoderTest method headersExceedMaxSetSizeShouldFail.
@Test
public void headersExceedMaxSetSizeShouldFail() throws Http2Exception {
final Http2Headers headers = headers();
encoder.maxHeaderListSize(2);
assertThrows(StreamException.class, new Executable() {
@Override
public void execute() throws Throwable {
encoder.encodeHeaders(3, /* randomly chosen */
headers, Unpooled.buffer());
}
});
}
Aggregations