protected DataBuffer stringBuffer(String value) { return byteBuffer(value.getBytes(StandardCharsets.UTF_8)); }
/** * Wait until allocations are at 0, or the given duration elapses. */ protected void waitForDataBufferRelease(Duration duration) throws InterruptedException { Instant start = Instant.now(); while (Instant.now().isBefore(start.plus(duration))) { try { verifyAllocations(); break; } catch (AssertionError ex) { // ignore; } Thread.sleep(50); } }
protected Mono<DataBuffer> deferStringBuffer(String value) { return Mono.defer(() -> Mono.just(stringBuffer(value))); }
private void verifyAllocations() { if (this.bufferFactory instanceof NettyDataBufferFactory) { ByteBufAllocator allocator = ((NettyDataBufferFactory) this.bufferFactory).getByteBufAllocator(); if (allocator instanceof PooledByteBufAllocator) { PooledByteBufAllocatorMetric metric = ((PooledByteBufAllocator) allocator).metric(); long total = getAllocations(metric.directArenas()) + getAllocations(metric.heapArenas()); assertEquals("ByteBuf Leak: " + total + " unreleased allocations", 0, total); } } }