|
21 | 21 | */
|
22 | 22 | package com.influxdb.client;
|
23 | 23 |
|
24 |
| -import java.io.ByteArrayOutputStream; |
25 |
| -import java.io.IOException; |
26 |
| -import java.io.OutputStream; |
27 |
| -import java.net.InetSocketAddress; |
28 |
| -import java.net.Proxy; |
29 |
| -import java.util.List; |
30 |
| -import java.util.Objects; |
31 |
| -import java.util.logging.Level; |
32 |
| -import java.util.logging.LogRecord; |
33 |
| -import java.util.logging.Logger; |
34 |
| -import javax.annotation.Nonnull; |
35 |
| - |
36 |
| -import com.influxdb.client.domain.InfluxQLQuery; |
37 |
| -import com.influxdb.client.service.InfluxQLQueryService; |
38 |
| -import com.sun.net.httpserver.HttpExchange; |
39 |
| -import com.sun.net.httpserver.HttpServer; |
40 |
| -import com.sun.net.httpserver.HttpHandler; |
41 | 24 | import com.influxdb.LogLevel;
|
42 |
| -import com.influxdb.client.domain.Authorization; |
43 |
| -import com.influxdb.client.domain.Run; |
44 |
| -import com.influxdb.client.domain.WriteConsistency; |
45 |
| -import com.influxdb.client.domain.WritePrecision; |
| 25 | +import com.influxdb.client.domain.*; |
46 | 26 | import com.influxdb.client.internal.AbstractInfluxDBClientTest;
|
47 |
| - |
48 |
| -import okhttp3.HttpUrl; |
49 |
| -import okhttp3.Interceptor; |
50 |
| -import okhttp3.OkHttpClient; |
51 |
| -import okhttp3.Request; |
52 |
| -import okhttp3.Response; |
53 |
| -import okhttp3.ResponseBody; |
| 27 | +import com.influxdb.client.service.InfluxQLQueryService; |
| 28 | +import okhttp3.*; |
54 | 29 | import okhttp3.mockwebserver.Dispatcher;
|
55 | 30 | import okhttp3.mockwebserver.MockResponse;
|
56 | 31 | import okhttp3.mockwebserver.MockWebServer;
|
|
59 | 34 | import org.junit.jupiter.api.Test;
|
60 | 35 | import retrofit2.Call;
|
61 | 36 |
|
| 37 | +import javax.annotation.Nonnull; |
| 38 | +import java.io.IOException; |
| 39 | +import java.net.InetSocketAddress; |
| 40 | +import java.net.Proxy; |
| 41 | +import java.util.List; |
| 42 | +import java.util.Objects; |
| 43 | +import java.util.logging.Level; |
| 44 | +import java.util.logging.LogRecord; |
| 45 | +import java.util.logging.Logger; |
| 46 | + |
62 | 47 | /**
|
63 | 48 | * @author Jakub Bednar (bednar@github) (05/09/2018 14:00)
|
64 | 49 | */
|
@@ -500,6 +485,43 @@ public void redactedAuthorizationHeader() {
|
500 | 485 | Assertions.assertThat(authorizationLog.getMessage()).isEqualTo("Authorization: ██");
|
501 | 486 | }
|
502 | 487 |
|
| 488 | + @Test |
| 489 | + void testDefaultInterceptors() { |
| 490 | + String url = "http://localhost:8086"; |
| 491 | + InfluxDBClientOptions options = new InfluxDBClientOptions.Builder() |
| 492 | + .url(url) |
| 493 | + .build(); |
| 494 | + |
| 495 | + InfluxDBClient client = InfluxDBClientFactory.create(options); |
| 496 | + List<Interceptor> interceptors = options.getOkHttpClient().interceptors(); |
| 497 | + Assertions.assertThat(interceptors.size()).isEqualTo(4); |
| 498 | + client.close(); |
| 499 | + |
| 500 | + InfluxDBClient client1 = InfluxDBClientFactory.create(options); |
| 501 | + interceptors = options.getOkHttpClient().interceptors(); |
| 502 | + Assertions.assertThat(interceptors.size()).isEqualTo(4); |
| 503 | + client1.close(); |
| 504 | + |
| 505 | + // okHttpBuilder with additional Interceptors |
| 506 | + OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder(); |
| 507 | + okHttpBuilder.addInterceptor(chain -> chain.proceed(chain.request())); |
| 508 | + okHttpBuilder.addInterceptor(chain -> chain.proceed(chain.request())); |
| 509 | + |
| 510 | + InfluxDBClientOptions options1 = new InfluxDBClientOptions.Builder() |
| 511 | + .url(url) |
| 512 | + .okHttpClient(okHttpBuilder) |
| 513 | + .build(); |
| 514 | + client = InfluxDBClientFactory.create(options1); |
| 515 | + interceptors = options1.getOkHttpClient().interceptors(); |
| 516 | + Assertions.assertThat(interceptors.size()).isEqualTo(6); |
| 517 | + client.close(); |
| 518 | + |
| 519 | + client1 = InfluxDBClientFactory.create(options1); |
| 520 | + interceptors = options1.getOkHttpClient().interceptors(); |
| 521 | + Assertions.assertThat(interceptors.size()).isEqualTo(6); |
| 522 | + client1.close(); |
| 523 | + } |
| 524 | + |
503 | 525 | private void queryAndTest(final String expected) throws InterruptedException {
|
504 | 526 | RecordedRequest request = takeRequest();
|
505 | 527 | Assertions.assertThat(request).isNotNull();
|
|
0 commit comments