use of io.netty.buffer.ByteBufAllocator in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method beforeMethod.
@Before
public void beforeMethod() {
socketChannelMock = mock(SocketChannel.class);
channelPipelineMock = mock(ChannelPipeline.class);
ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class);
doReturn(channelPipelineMock).when(socketChannelMock).pipeline();
doReturn(byteBufAllocatorMock).when(socketChannelMock).alloc();
}
use of io.netty.buffer.ByteBufAllocator in project curiostack by curioswitch.
the class ServiceAccountAccessTokenProvider method refreshRequestContent.
@Override
ByteBuf refreshRequestContent(Type type) {
long currentTimeMillis = clock().millis();
String assertion = createAssertion(type, currentTimeMillis);
QueryStringEncoder formEncoder = new QueryStringEncoder("");
formEncoder.addParam("grant_type", GRANT_TYPE);
formEncoder.addParam("assertion", assertion);
String contentWithQuestionMark = formEncoder.toString();
ByteBufAllocator alloc = RequestContext.mapCurrent(RequestContext::alloc, () -> PooledByteBufAllocator.DEFAULT);
assert alloc != null;
ByteBuf content = alloc.buffer(contentWithQuestionMark.length() - 1);
ByteBufUtil.writeAscii(content, contentWithQuestionMark.substring(1));
return content;
}
use of io.netty.buffer.ByteBufAllocator in project reactor-netty by reactor.
the class HttpSendFileTests method doTestSendFileAsync.
private void doTestSendFileAsync(BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> fn, int chunk, @Nullable byte[] expectedContent) throws IOException, URISyntaxException {
Path largeFile = Paths.get(getClass().getResource("/largeFile.txt").toURI());
Path largeFileParent = largeFile.getParent();
assertThat(largeFileParent).isNotNull();
Path tempFile = Files.createTempFile(largeFileParent, "temp", ".txt");
tempFile.toFile().deleteOnExit();
byte[] fileBytes = Files.readAllBytes(largeFile);
for (int i = 0; i < 1000; i++) {
Files.write(tempFile, fileBytes, StandardOpenOption.APPEND);
}
ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
Flux<ByteBuf> content = Flux.using(() -> AsynchronousFileChannel.open(tempFile, StandardOpenOption.READ), ch -> Flux.<ByteBuf>create(fluxSink -> {
TestCompletionHandler handler = new TestCompletionHandler(ch, fluxSink, allocator, chunk);
fluxSink.onDispose(handler::dispose);
ByteBuffer buf = ByteBuffer.allocate(chunk);
ch.read(buf, 0, buf, handler);
}), ch -> {
/*the channel will be closed in the handler*/
}).doOnDiscard(ByteBuf.class, ByteBuf::release).log("send", Level.INFO, SignalType.REQUEST, SignalType.ON_COMPLETE);
disposableServer = customizeServerOptions(HttpServer.create().host("localhost")).handle(fn).bindNow();
byte[] response = customizeClientOptions(HttpClient.create().remoteAddress(disposableServer::address)).request(HttpMethod.POST).uri("/").send(content).responseContent().aggregate().asByteArray().onErrorReturn(IOException.class, expectedContent == null ? new byte[0] : expectedContent).block();
assertThat(response).isEqualTo(expectedContent == null ? Files.readAllBytes(tempFile) : expectedContent);
}
use of io.netty.buffer.ByteBufAllocator in project netty by netty.
the class AbstractComboTestsuiteTest method run.
protected void run() throws Throwable {
List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> combos = newFactories();
for (ByteBufAllocator allocator : newAllocators()) {
int i = 0;
for (TestsuitePermutation.BootstrapComboFactory<SB, CB> e : combos) {
sb = e.newServerInstance();
cb = e.newClientInstance();
configure(sb, cb, allocator);
logger.info(String.format("Running: %s %d of %d (%s + %s) with %s", testName.getMethodName(), ++i, combos.size(), sb, cb, StringUtil.simpleClassName(allocator)));
try {
Method m = getClass().getMethod(TestUtils.testMethodName(testName), sbClazz, cbClazz);
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
}
}
}
use of io.netty.buffer.ByteBufAllocator in project ratpack by ratpack.
the class MetricsWebsocketBroadcastHandler method handle.
@Override
public void handle(final Context context) throws Exception {
final MetricsBroadcaster broadcaster = context.get(MetricsBroadcaster.class);
final ByteBufAllocator byteBufAllocator = context.get(ByteBufAllocator.class);
final DropwizardMetricsConfig config = context.get(DropwizardMetricsConfig.class);
MetricFilter filter = MetricFilter.ALL;
if (config.getWebSocket().isPresent()) {
filter = new RegexMetricFilter(config.getWebSocket().get().getIncludeFilter(), config.getWebSocket().get().getExcludeFilter());
}
websocketByteBufBroadcast(context, broadcaster.map(new MetricRegistryJsonMapper(byteBufAllocator, filter)));
}
Aggregations