Java Code Examples for reactor.netty.resources.ConnectionProvider#dispose()
The following examples show how to use
reactor.netty.resources.ConnectionProvider#dispose() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpClientWithTomcatTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void contentHeader() { ConnectionProvider fixed = ConnectionProvider.create("contentHeader", 1); HttpClient client = HttpClient.create(fixed) .wiretap(true) .headers(h -> h.add("content-length", "1")); HttpResponseStatus r = client.request(HttpMethod.GET) .uri(getURL()) .send(ByteBufFlux.fromString(Mono.just(" "))) .responseSingle((res, buf) -> Mono.just(res.status())) .block(Duration.ofSeconds(30)); client.request(HttpMethod.GET) .uri(getURL()) .send(ByteBufFlux.fromString(Mono.just(" "))) .responseSingle((res, buf) -> Mono.just(res.status())) .block(Duration.ofSeconds(30)); Assert.assertEquals(r, HttpResponseStatus.BAD_REQUEST); fixed.dispose(); }
Example 2
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void testExplicitSendMonoErrorOnGet() { disposableServer = HttpServer.create() .port(0) .handle((req, res) -> res.send(req.receive().retain())) .bindNow(); ConnectionProvider pool = ConnectionProvider.create("test", 1); StepVerifier.create( Flux.range(0, 1000) .flatMapDelayError(i -> createHttpClientForContextWithAddress(pool) .request(HttpMethod.GET) .uri("/") .send((req, out) -> out.send(Mono.error(new Exception("test")))) .responseContent(), Queues.SMALL_BUFFER_SIZE, Queues.XS_BUFFER_SIZE)) .expectError() .verify(Duration.ofSeconds(30)); pool.dispose(); }
Example 3
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 6 votes |
private ChannelId[] doTestConnectionIdleTime(ConnectionProvider provider) throws Exception { disposableServer = HttpServer.create() .port(0) .wiretap(true) .handle((req, res) -> res.sendString(Mono.just("hello"))) .bindNow(); Flux<ChannelId> id = createHttpClientForContextWithAddress(provider) .get() .uri("/") .responseConnection((res, conn) -> Mono.just(conn.channel().id()) .delayUntil(ch -> conn.inbound().receive())); ChannelId id1 = id.blockLast(Duration.ofSeconds(30)); Thread.sleep(30); ChannelId id2 = id.blockLast(Duration.ofSeconds(30)); assertThat(id1).isNotNull(); assertThat(id2).isNotNull(); provider.dispose(); return new ChannelId[] {id1, id2}; }
Example 4
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 6 votes |
private ChannelId[] doTestConnectionLifeTime(ConnectionProvider provider) throws Exception { disposableServer = HttpServer.create() .port(0) .handle((req, resp) -> resp.sendObject(ByteBufFlux.fromString(Mono.delay(Duration.ofMillis(30)) .map(Objects::toString)))) .wiretap(true) .bindNow(); Flux<ChannelId> id = createHttpClientForContextWithAddress(provider) .get() .uri("/") .responseConnection((res, conn) -> Mono.just(conn.channel().id()) .delayUntil(ch -> conn.inbound().receive())); ChannelId id1 = id.blockLast(Duration.ofSeconds(30)); Thread.sleep(10); ChannelId id2 = id.blockLast(Duration.ofSeconds(30)); assertThat(id1).isNotNull(); assertThat(id2).isNotNull(); provider.dispose(); return new ChannelId[] {id1, id2}; }
Example 5
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void userIssue() throws Exception { final ConnectionProvider pool = ConnectionProvider.create("userIssue", 1); CountDownLatch latch = new CountDownLatch(3); Set<String> localAddresses = ConcurrentHashMap.newKeySet(); disposableServer = HttpServer.create() .port(8080) .route(r -> r.post("/", (req, resp) -> req.receive() .asString() .flatMap(data -> { latch.countDown(); return resp.status(200) .send(); }))) .wiretap(true) .bindNow(); final HttpClient client = createHttpClientForContextWithAddress(pool); Flux.just("1", "2", "3") .concatMap(data -> client.doOnResponse((res, conn) -> localAddresses.add(conn.channel() .localAddress() .toString())) .post() .uri("/") .send(ByteBufFlux.fromString(Flux.just(data))) .responseContent()) .subscribe(); latch.await(); pool.dispose(); System.out.println("Local Addresses used: " + localAddresses); }
Example 6
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void testClientReuseIssue405(){ disposableServer = HttpServer.create() .port(0) .handle((in,out)->out.sendString(Flux.just("hello"))) .wiretap(true) .bindNow(); ConnectionProvider pool = ConnectionProvider.create("testClientReuseIssue405", 1); HttpClient httpClient = createHttpClientForContextWithPort(pool); Mono<String> mono1 = httpClient.get() .responseSingle((r, buf) -> buf.asString()) .log("mono1"); Mono<String> mono2 = httpClient.get() .responseSingle((r, buf) -> buf.asString()) .log("mono1"); StepVerifier.create(Flux.zip(mono1,mono2)) .expectNext(Tuples.of("hello","hello")) .expectComplete() .verify(Duration.ofSeconds(20)); pool.dispose(); }
Example 7
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void closePool() { ConnectionProvider pr = ConnectionProvider.create("closePool", 1); disposableServer = HttpServer.create() .port(0) .handle((in, out) -> out.sendString(Mono.just("test") .delayElement(Duration.ofMillis(100)) .repeat())) .wiretap(true) .bindNow(); Flux<String> ws = createHttpClientForContextWithPort(pr) .get() .uri("/") .responseContent() .asString(); List<String> expected = Flux.range(1, 20) .map(v -> "test") .collectList() .block(); Assert.assertNotNull(expected); StepVerifier.create( Flux.range(1, 10) .concatMap(i -> ws.take(2) .log())) .expectNextSequence(expected) .expectComplete() .verify(); pr.dispose(); }
Example 8
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void testExplicitEmptyBodyOnGetWorks() throws Exception { SelfSignedCertificate ssc = new SelfSignedCertificate(); SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .build(); SslContext sslClient = SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE) .build(); disposableServer = HttpServer.create() .secure(ssl -> ssl.sslContext(sslServer)) .port(0) .handle((req, res) -> res.send(req.receive().retain())) .bindNow(); ConnectionProvider pool = ConnectionProvider.create("testExplicitEmptyBodyOnGetWorks", 1); for (int i = 0; i < 4; i++) { StepVerifier.create(createHttpClientForContextWithAddress(pool) .secure(ssl -> ssl.sslContext(sslClient)) .request(HttpMethod.GET) .uri("/") .send((req, out) -> out.send(Flux.empty())) .responseContent()) .expectComplete() .verify(Duration.ofSeconds(30)); } pool.dispose(); }
Example 9
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 5 votes |
private void doTestIssue600(boolean withLoop) { disposableServer = HttpServer.create() .port(0) .handle((req, res) -> res.send(req.receive() .retain() .delaySubscription(Duration.ofSeconds(1)))) .wiretap(true) .bindNow(); ConnectionProvider pool = ConnectionProvider.create("doTestIssue600", 10); LoopResources loop = LoopResources.create("test", 4, true); HttpClient client; if (withLoop) { client = createHttpClientForContextWithAddress(pool) .runOn(loop); } else { client = createHttpClientForContextWithAddress(pool); } Set<String> threadNames = new ConcurrentSkipListSet<>(); StepVerifier.create( Flux.range(1,4) .flatMap(i -> client.request(HttpMethod.GET) .uri("/") .send((req, out) -> out.send(Flux.empty())) .responseContent() .doFinally(s -> threadNames.add(Thread.currentThread().getName())))) .expectComplete() .verify(Duration.ofSeconds(30)); pool.dispose(); loop.dispose(); assertThat(threadNames.size()).isGreaterThan(1); }
Example 10
Source File: HttpClientWithTomcatTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void disableChunkImplicitDefault() { ConnectionProvider p = ConnectionProvider.create("disableChunkImplicitDefault", 1); HttpClient client = HttpClient.create(p) .host("localhost") .port(getPort()) .wiretap(true); Tuple2<HttpResponseStatus, Channel> r = client.get() .uri("/status/404") .responseConnection((res, conn) -> Mono.just(res.status()) .delayUntil(s -> conn.inbound().receive()) .zipWith(Mono.just(conn.channel()))) .blockLast(Duration.ofSeconds(30)); assertThat(r).isNotNull(); Channel r2 = client.get() .uri("/status/404") .responseConnection((res, conn) -> Mono.just(conn.channel()) .delayUntil(s -> conn.inbound().receive())) .blockLast(Duration.ofSeconds(30)); assertThat(r2).isNotNull(); Assert.assertSame(r.getT2(), r2); Assert.assertEquals(r.getT1(), HttpResponseStatus.NOT_FOUND); p.dispose(); }
Example 11
Source File: WebsocketTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void closePool() { ConnectionProvider pr = ConnectionProvider.create("closePool", 1); httpServer = HttpServer.create() .port(0) .handle((in, out) -> out.sendWebsocket( (i, o) -> o.sendString( Mono.just("test") .delayElement(Duration.ofMillis(100)) .repeat()))) .wiretap(true) .bindNow(); Flux<String> ws = HttpClient.create(pr) .port(httpServer.port()) .websocket() .uri("/") .receive() .asString(); List<String> expected = Flux.range(1, 20) .map(v -> "test") .collectList() .block(); Assert.assertNotNull(expected); StepVerifier.create( Flux.range(1, 10) .concatMap(i -> ws.take(2) .log())) .expectNextSequence(expected) .expectComplete() .verify(); pr.dispose(); }
Example 12
Source File: HttpClientWithTomcatTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void simpleTest404_1() { ConnectionProvider pool = ConnectionProvider.create("simpleTest404_1", 1); HttpClient client = HttpClient.create(pool) .port(getPort()) .host("localhost") .wiretap(true); doSimpleTest404(client); doSimpleTest404(client); pool.dispose(); }
Example 13
Source File: HttpClientWithTomcatTest.java From reactor-netty with Apache License 2.0 | 5 votes |
@Test public void simpleClientPooling() { ConnectionProvider p = ConnectionProvider.create("simpleClientPooling", 1); AtomicReference<Channel> ch1 = new AtomicReference<>(); AtomicReference<Channel> ch2 = new AtomicReference<>(); HttpResponseStatus r = HttpClient.create(p) .doOnResponse((res, c) -> ch1.set(c.channel())) .wiretap(true) .get() .uri(getURL() + "/status/404") .responseSingle((res, buf) -> buf.thenReturn(res.status())) .block(Duration.ofSeconds(30)); HttpClient.create(p) .doOnResponse((res, c) -> ch2.set(c.channel())) .wiretap(true) .get() .uri(getURL() + "/status/404") .responseSingle((res, buf) -> buf.thenReturn(res.status())) .block(Duration.ofSeconds(30)); AtomicBoolean same = new AtomicBoolean(); same.set(ch1.get() == ch2.get()); Assert.assertTrue(same.get()); Assert.assertEquals(r, HttpResponseStatus.NOT_FOUND); p.dispose(); }
Example 14
Source File: HttpServerTests.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void keepAlive() throws URISyntaxException { Path resource = Paths.get(getClass().getResource("/public").toURI()); disposableServer = HttpServer.create() .port(0) .route(routes -> routes.directory("/test", resource)) .wiretap(true) .bindNow(); ConnectionProvider p = ConnectionProvider.create("keepAlive", 1); Channel response0 = HttpClient.create(p) .port(disposableServer.port()) .wiretap(true) .get() .uri("/test/index.html") .responseConnection((res, c) -> Mono.just(c.channel()) .delayUntil(ch -> c.inbound().receive())) .blockLast(Duration.ofSeconds(3099)); Channel response1 = HttpClient.create(p) .port(disposableServer.port()) .wiretap(true) .get() .uri("/test/test.css") .responseConnection((res, c) -> Mono.just(c.channel()) .delayUntil(ch -> c.inbound().receive())) .blockLast(Duration.ofSeconds(3099)); Channel response2 = HttpClient.create(p) .port(disposableServer.port()) .wiretap(true) .get() .uri("/test/test1.css") .responseConnection((res, c) -> Mono.just(c.channel()) .delayUntil(ch -> c.inbound().receive())) .blockLast(Duration.ofSeconds(30)); Channel response3 = HttpClient.create(p) .port(disposableServer.port()) .wiretap(true) .get() .uri("/test/test2.css") .responseConnection((res, c) -> Mono.just(c.channel()) .delayUntil(ch -> c.inbound().receive())) .blockLast(Duration.ofSeconds(30)); Channel response4 = HttpClient.create(p) .port(disposableServer.port()) .wiretap(true) .get() .uri("/test/test3.css") .responseConnection((res, c) -> Mono.just(c.channel()) .delayUntil(ch -> c.inbound().receive())) .blockLast(Duration.ofSeconds(30)); Channel response5 = HttpClient.create(p) .port(disposableServer.port()) .wiretap(true) .get() .uri("/test/test4.css") .responseConnection((res, c) -> Mono.just(c.channel()) .delayUntil(ch -> c.inbound().receive())) .blockLast(Duration.ofSeconds(30)); assertThat(response0).isEqualTo(response1); assertThat(response0).isEqualTo(response2); assertThat(response0).isEqualTo(response3); assertThat(response0).isEqualTo(response4); assertThat(response0).isEqualTo(response5); p.dispose(); }
Example 15
Source File: TcpClientTests.java From reactor-netty with Apache License 2.0 | 4 votes |
private void doTestIssue600(boolean withLoop) { DisposableServer server = TcpServer.create() .port(0) .handle((req, res) -> res.send(req.receive() .retain() .delaySubscription(Duration.ofSeconds(1)))) .wiretap(true) .bindNow(); ConnectionProvider pool = ConnectionProvider.create("doTestIssue600", 10); LoopResources loop = LoopResources.create("test", 4, true); TcpClient client; if (withLoop) { client = TcpClient.create(pool) .remoteAddress(server::address) .runOn(loop); } else { client = TcpClient.create(pool) .remoteAddress(server::address); } Set<String> threadNames = new ConcurrentSkipListSet<>(); StepVerifier.create( Flux.range(1,4) .flatMap(i -> client.handle((in, out) -> { threadNames.add(Thread.currentThread().getName()); return out.send(Flux.empty()); }) .connect())) .expectNextCount(4) .expectComplete() .verify(Duration.ofSeconds(30)); pool.dispose(); loop.dispose(); server.disposeNow(); Assertions.assertThat(threadNames.size()).isGreaterThan(1); }
Example 16
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void testIssue988() { disposableServer = HttpServer.create() .port(0) .handle((req, res) -> res.sendString(Mono.just("test"))) .wiretap(true) .bindNow(Duration.ofSeconds(30)); ConnectionProvider provider = ConnectionProvider.create("testIssue988", 1); HttpClient client = createHttpClientForContextWithAddress(provider) .wiretap("testIssue988", LogLevel.INFO) .metrics(true, s -> s); AtomicReference<Channel> ch1 = new AtomicReference<>(); StepVerifier.create(client.doOnConnected(c -> ch1.set(c.channel())) .get() .uri("/1") .responseContent() .aggregate() .asString()) .expectNextMatches("test"::equals) .expectComplete() .verify(Duration.ofSeconds(30)); AtomicReference<Channel> ch2 = new AtomicReference<>(); StepVerifier.create(client.doOnConnected(c -> ch2.set(c.channel())) .post() .uri("/2") .send(ByteBufFlux.fromString(Mono.just("test"))) .responseContent() .aggregate() .asString()) .expectNextMatches("test"::equals) .expectComplete() .verify(Duration.ofSeconds(30)); AtomicReference<Channel> ch3 = new AtomicReference<>(); StepVerifier.create( client.doOnConnected(c -> ch3.set(c.channel())) .wiretap("testIssue988", LogLevel.ERROR) .post() .uri("/3") .responseContent() .aggregate() .asString()) .expectNextMatches("test"::equals) .expectComplete() .verify(Duration.ofSeconds(30)); assertThat(ch1.get()).isSameAs(ch2.get()); assertThat(ch1.get()).isNotSameAs(ch3.get()); provider.dispose(); }
Example 17
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void testIssue361() { disposableServer = HttpServer.create() .port(0) .handle((req, res) -> req.receive() .aggregate() .asString() .flatMap(s -> res.sendString(Mono.just(s)) .then())) .bindNow(); assertThat(disposableServer).isNotNull(); ConnectionProvider connectionProvider = ConnectionProvider.create("testIssue361", 1); HttpClient client = createHttpClientForContextWithPort(connectionProvider); String response = client.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("test") .then(Mono.error(new Exception("error"))))) .responseContent() .aggregate() .asString() .onErrorResume(t -> Mono.just(t.getMessage())) .block(Duration.ofSeconds(30)); assertThat(response).isEqualTo("error"); response = client.post() .uri("/") .send(ByteBufFlux.fromString(Mono.just("test"))) .responseContent() .aggregate() .asString() .block(Duration.ofSeconds(30)); assertThat(response).isEqualTo("test"); connectionProvider.dispose(); }
Example 18
Source File: HttpClientTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Test public void abort() { disposableServer = TcpServer.create() .port(0) .handle((in, out) -> in.receive() .take(1) .thenMany(Flux.defer(() -> out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())) .sendObject(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED)) .then(Mono.delay(Duration.ofSeconds(2)).then())))) .wiretap(true) .bindNow(); ConnectionProvider pool = ConnectionProvider.create("abort", 1); HttpClient client = createHttpClientForContextWithPort(pool); client.get() .uri("/") .responseSingle((r, buf) -> Mono.just(r.status().code())) .log() .block(Duration.ofSeconds(30)); client.get() .uri("/") .responseContent() .log() .blockLast(Duration.ofSeconds(30)); client.get() .uri("/") .responseContent() .log() .blockLast(Duration.ofSeconds(30)); pool.dispose(); }