Skip to content

Commit e084b2e

Browse files
authored
feat: url to connect to the InfluxDB is always evaluate as a connection string (#335)
1 parent 7b26209 commit e084b2e

File tree

12 files changed

+205
-32
lines changed

12 files changed

+205
-32
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ This release also uses new version of InfluxDB OSS API definitions - [oss.yml](h
6767
1. [#315](https://github.com/influxdata/influxdb-client-java/pull/315): Add support for timezones [FluxDSL]
6868
1. [#317](https://github.com/influxdata/influxdb-client-java/pull/317): Gets HTTP headers from the unsuccessful HTTP request
6969
1. [#334](https://github.com/influxdata/influxdb-client-java/pull/334): Supports not operator [FluxDSL]
70+
1. [#335](https://github.com/influxdata/influxdb-client-java/pull/335): URL to connect to the InfluxDB is always evaluate as a connection string
7071
1. [#329](https://github.com/influxdata/influxdb-client-java/pull/329): Add support for write `consistency` parameter [InfluxDB Enterprise]
7172

7273
Configure `consistency` via `Write API`:

client-kotlin/src/main/kotlin/com/influxdb/client/kotlin/InfluxDBClientKotlinFactory.kt

+29-6
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ class InfluxDBClientKotlinFactory {
5050
}
5151

5252
/**
53-
* Create an instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
53+
* Create an instance of the InfluxDB 2.x client.
5454
*
55-
* e.g.: "http://localhost:8086?readTimeout=5000&connectTimeout=5000&logLevel=BASIC
55+
* <p>
56+
* The url could be a connection string with various configurations. For more info
57+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
58+
* </p>
5659
*
5760
* @param connectionString connection string with various configurations.
5861
* @return client
@@ -76,7 +79,12 @@ class InfluxDBClientKotlinFactory {
7679
* and client produces {@link com.influxdb.exceptions.UnauthorizedException}.
7780
* </p>
7881
*
79-
* @param url the url to connect to the InfluxDB
82+
* <p>
83+
* The url could be a connection string with various configurations. For more info
84+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
85+
* </p>
86+
*
87+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
8088
* @param username the username to use in the basic auth
8189
* @param password the password to use in the basic auth
8290
* @return client
@@ -97,7 +105,12 @@ class InfluxDBClientKotlinFactory {
97105
/**
98106
* Create an instance of the InfluxDB 2.x reactive client.
99107
*
100-
* @param url the url to connect to the InfluxDB
108+
* <p>
109+
* The url could be a connection string with various configurations. For more info
110+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
111+
* </p>
112+
*
113+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
101114
* @param token the token to use for the authorization
102115
* @return client
103116
* @see InfluxDBClientOptions.Builder.url
@@ -110,7 +123,12 @@ class InfluxDBClientKotlinFactory {
110123
/**
111124
* Create an instance of the InfluxDB 2.x reactive client.
112125
*
113-
* @param url the url to connect to the InfluxDB
126+
* <p>
127+
* The url could be a connection string with various configurations. For more info
128+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
129+
* </p>
130+
*
131+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
114132
* @param token the token to use for the authorization
115133
* @param org the name of an organization
116134
* @return client
@@ -124,7 +142,12 @@ class InfluxDBClientKotlinFactory {
124142
/**
125143
* Create an instance of the InfluxDB 2.x reactive client.
126144
*
127-
* @param url the url to connect to the InfluxDB
145+
* <p>
146+
* The url could be a connection string with various configurations. For more info
147+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
148+
* </p>
149+
*
150+
* @param url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
128151
* @param token the token to use for the authorization
129152
* @param org the name of an organization
130153
* @param bucket the name of a bucket

client-kotlin/src/test/kotlin/com/influxdb/client/kotlin/InfluxDBClientKotlinFactoryTest.kt

+9
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,13 @@ class InfluxDBClientKotlinFactoryTest : AbstractTest() {
7676
Assertions.assertThat(it).isNotNull
7777
}
7878
}
79+
80+
@Test
81+
@Throws(NoSuchFieldException::class, IllegalAccessException::class)
82+
fun connectionStringConfiguration() {
83+
val client = InfluxDBClientKotlinFactory.create("http://localhost:8086?connectTimeout=45000", "xyz".toCharArray())
84+
val retrofit = getDeclaredField<Retrofit>(client, "retrofit", AbstractInfluxDBClient::class.java)
85+
val okHttpClient = retrofit.callFactory() as OkHttpClient
86+
Assertions.assertThat(okHttpClient.connectTimeoutMillis).isEqualTo(45000)
87+
}
7988
}

client-reactive/src/main/java/com/influxdb/client/reactive/InfluxDBClientReactiveFactory.java

+29-6
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ public static InfluxDBClientReactive create() {
5555
}
5656

5757
/**
58-
* Create an instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
58+
* Create an instance of the InfluxDB 2.x client.
59+
*
5960
* <p>
60-
* e.g.: "http://localhost:8086?readTimeout=5000&amp;connectTimeout=5000&amp;logLevel=BASIC
61+
* The url could be a connection string with various configurations. For more info
62+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
63+
* </p>
6164
*
6265
* @param connectionString connection string with various configurations.
6366
* @return client
@@ -82,7 +85,12 @@ public static InfluxDBClientReactive create(@Nonnull final String connectionStri
8285
* and client produces {@link com.influxdb.exceptions.UnauthorizedException}.
8386
* </p>
8487
*
85-
* @param url the url to connect to the InfluxDB
88+
* <p>
89+
* The url could be a connection string with various configurations. For more info
90+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
91+
* </p>
92+
*
93+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
8694
* @param username the username to use in the basic auth
8795
* @param password the password to use in the basic auth
8896
* @return client
@@ -104,7 +112,12 @@ public static InfluxDBClientReactive create(@Nonnull final String url,
104112
/**
105113
* Create an instance of the InfluxDB 2.x reactive client.
106114
*
107-
* @param url the url to connect to the InfluxDB
115+
* <p>
116+
* The url could be a connection string with various configurations. For more info
117+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
118+
* </p>
119+
*
120+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
108121
* @param token the token to use for the authorization
109122
* @return client
110123
* @see InfluxDBClientOptions.Builder#url(String)
@@ -118,7 +131,12 @@ public static InfluxDBClientReactive create(@Nonnull final String url, @Nonnull
118131
/**
119132
* Create an instance of the InfluxDB 2.x reactive client.
120133
*
121-
* @param url the url to connect to the InfluxDB
134+
* <p>
135+
* The url could be a connection string with various configurations. For more info
136+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
137+
* </p>
138+
*
139+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
122140
* @param token the token to use for the authorization
123141
* @param org the name of an organization
124142
* @return client
@@ -135,7 +153,12 @@ public static InfluxDBClientReactive create(@Nonnull final String url,
135153
/**
136154
* Create an instance of the InfluxDB 2.x reactive client.
137155
*
138-
* @param url the url to connect to the InfluxDB
156+
* <p>
157+
* The url could be a connection string with various configurations. For more info
158+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
159+
* </p>
160+
*
161+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
139162
* @param token the token to use for the authorization
140163
* @param org the name of an organization
141164
* @param bucket the name of a bucket

client-reactive/src/test/java/com/influxdb/client/reactive/InfluxDBClientReactiveFactoryTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,16 @@ public void autoClosable() {
9191
Assertions.assertThat(client).isNotNull();
9292
}
9393
}
94+
95+
@Test
96+
void connectionStringConfiguration() throws NoSuchFieldException, IllegalAccessException {
97+
InfluxDBClientReactive client = InfluxDBClientReactiveFactory.create("http://localhost:8086?readTimeout=15000", "xyz".toCharArray());
98+
99+
Assertions.assertThat(client).isNotNull();
100+
101+
Retrofit retrofit = getDeclaredField(client, "retrofit", AbstractInfluxDBClient.class);
102+
OkHttpClient okHttpClient = (OkHttpClient) retrofit.callFactory();
103+
104+
Assertions.assertThat(okHttpClient.readTimeoutMillis()).isEqualTo(15_000);
105+
}
94106
}

client-reactive/src/test/java/com/influxdb/client/reactive/QueryReactiveApiTest.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
package com.influxdb.client.reactive;
2323

2424
import java.io.InterruptedIOException;
25+
import java.util.ArrayList;
26+
import java.util.List;
2527
import java.util.concurrent.Executors;
2628
import java.util.concurrent.Future;
2729
import java.util.concurrent.TimeUnit;
2830

31+
import com.influxdb.exceptions.InfluxException;
2932
import com.influxdb.test.AbstractMockServerTest;
3033

3134
import io.reactivex.rxjava3.core.Flowable;
@@ -64,7 +67,7 @@ public void doNotPropagateErrorOnCanceledConsumer() throws InterruptedException
6467

6568
QueryReactiveApi queryApi = influxDBClient.getQueryReactiveApi();
6669

67-
final Throwable[] throwable = new Throwable[1];
70+
final List<Throwable> throwable = new ArrayList<>();
6871
Future<?> future = Executors
6972
.newSingleThreadScheduledExecutor()
7073
.scheduleWithFixedDelay(() -> Flowable
@@ -73,14 +76,14 @@ public void doNotPropagateErrorOnCanceledConsumer() throws InterruptedException
7376
s -> {
7477

7578
},
76-
t -> throwable[0] = t),
79+
throwable::add),
7780
0, 1, TimeUnit.SECONDS);
7881

7982
Thread.sleep(2_000);
8083
future.cancel(true);
8184
Thread.sleep(2_000);
8285

83-
Assertions.assertThat(throwable[0]).isNotNull();
84-
Assertions.assertThat(throwable[0]).isInstanceOf(InterruptedIOException.class);
86+
Assertions.assertThat(throwable).isNotEmpty();
87+
Assertions.assertThat(throwable).hasOnlyElementsOfTypes(InterruptedIOException.class, InfluxException.class);
8588
}
8689
}

client-scala/src/main/scala/com/influxdb/client/scala/InfluxDBClientScalaFactory.scala

+19-6
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ object InfluxDBClientScalaFactory {
5151
}
5252

5353
/**
54-
* Create an instance of the InfluxDB 2.x client. The url could be a connection string with various configurations.
54+
* Create an instance of the InfluxDB 2.x client.
5555
*
56-
* e.g.: "http://localhost:8086?readTimeout=5000&amp;connectTimeout=5000&amp;logLevel=BASIC
56+
* The url could be a connection string with various configurations. For more info
57+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
5758
*
5859
* @param connectionString connection string with various configurations.
5960
* @return client
@@ -75,7 +76,10 @@ object InfluxDBClientScalaFactory {
7576
* [[http://bit.ly/session-length time-to-live (TTL)]] (default 60 minutes) is reached
7677
* and client produces [[com.influxdb.exceptions.UnauthorizedException]].
7778
*
78-
* @param url the url to connect to the InfluxDB
79+
* The url could be a connection string with various configurations. For more info
80+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
81+
*
82+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
7983
* @param username the username to use in the basic auth
8084
* @param password the password to use in the basic auth
8185
* @return client
@@ -94,7 +98,10 @@ object InfluxDBClientScalaFactory {
9498
/**
9599
* Create an instance of the InfluxDB 2.x reactive client.
96100
*
97-
* @param url the url to connect to the InfluxDB
101+
* The url could be a connection string with various configurations. For more info
102+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
103+
*
104+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
98105
* @param token the token to use for the authorization
99106
* @return client
100107
* @see [[InfluxDBClientOptions.Builder]]
@@ -107,7 +114,10 @@ object InfluxDBClientScalaFactory {
107114
/**
108115
* Create an instance of the InfluxDB 2.x reactive client.
109116
*
110-
* @param url the url to connect to the InfluxDB
117+
* The url could be a connection string with various configurations. For more info
118+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
119+
*
120+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
111121
* @param token the token to use for the authorization
112122
* @param org the name of an organization
113123
* @return client
@@ -121,7 +131,10 @@ object InfluxDBClientScalaFactory {
121131
/**
122132
* Create an instance of the InfluxDB 2.x reactive client.
123133
*
124-
* @param url the url to connect to the InfluxDB
134+
* The url could be a connection string with various configurations. For more info
135+
* see: [[InfluxDBClientOptions.Builder#connectionString(connectionString:java.lang.String)]].
136+
*
137+
* @param url the url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
125138
* @param token the token to use for the authorization
126139
* @param org the name of an organization
127140
* @param bucket the name of a bucket

client-scala/src/test/scala/com/influxdb/client/scala/InfluxDBClientScalaFactoryTest.scala

+12
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,16 @@ class InfluxDBClientScalaFactoryTest extends AnyFunSuite with Matchers {
6262
okHttpClient.writeTimeoutMillis should be(10000)
6363
okHttpClient.connectTimeoutMillis should be(18000)
6464
}
65+
66+
test("connectionStringConfiguration") {
67+
68+
val utils = new InfluxDBUtils {}
69+
70+
val client = InfluxDBClientScalaFactory.create("http://localhost:8086?readTimeout=55000", "xyz".toCharArray)
71+
72+
val retrofit = utils.getDeclaredField(client, "retrofit", classOf[AbstractInfluxDBClient]).asInstanceOf[Retrofit]
73+
val okHttpClient = retrofit.callFactory.asInstanceOf[OkHttpClient]
74+
75+
okHttpClient.readTimeoutMillis should be(55000)
76+
}
6577
}

client/src/main/java/com/influxdb/client/InfluxDBClientFactory.java

+36-6
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ public static InfluxDBClient create(@Nonnull final String connectionString) {
8484
* and client produces {@link com.influxdb.exceptions.UnauthorizedException}.
8585
* </p>
8686
*
87-
* @param url the url to connect to the InfluxDB
87+
* <p>
88+
* The url could be a connection string with various configurations. For more info
89+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
90+
* </p>
91+
*
92+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
8893
* @param username the username to use in the basic auth
8994
* @param password the password to use in the basic auth
9095
* @return client
@@ -106,7 +111,12 @@ public static InfluxDBClient create(@Nonnull final String url,
106111
/**
107112
* Create an instance of the InfluxDB 2.x client.
108113
*
109-
* @param url the url to connect to the InfluxDB
114+
* <p>
115+
* The url could be a connection string with various configurations. For more info
116+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
117+
* </p>
118+
*
119+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
110120
* @param token the token to use for the authorization
111121
* @return client
112122
* @see InfluxDBClientOptions.Builder#url(String)
@@ -120,7 +130,12 @@ public static InfluxDBClient create(@Nonnull final String url, @Nonnull final ch
120130
/**
121131
* Create an instance of the InfluxDB 2.x client.
122132
*
123-
* @param url the url to connect to the InfluxDB
133+
* <p>
134+
* The url could be a connection string with various configurations. For more info
135+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
136+
* </p>
137+
*
138+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
124139
* @param token the token to use for the authorization
125140
* @param org the name of an organization
126141
* @return client
@@ -137,7 +152,12 @@ public static InfluxDBClient create(@Nonnull final String url,
137152
/**
138153
* Create an instance of the InfluxDB 2.x client.
139154
*
140-
* @param url the url to connect to the InfluxDB
155+
* <p>
156+
* The url could be a connection string with various configurations. For more info
157+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
158+
* </p>
159+
*
160+
* @param url url the url to connect to InfluxDB (required). Example: http://localhost:8086?readTimeout=5000
141161
* @param token the token to use for the authorization
142162
* @param org the name of an organization
143163
* @param bucket the name of a bucket
@@ -163,7 +183,12 @@ public static InfluxDBClient create(@Nonnull final String url,
163183
/**
164184
* Create an instance of the InfluxDB 2.x client to connect into InfluxDB 1.8.
165185
*
166-
* @param url the url to connect to the InfluxDB 1.8
186+
* <p>
187+
* The url could be a connection string with various configurations. For more info
188+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
189+
* </p>
190+
*
191+
* @param url the url to connect to InfluxDB 1.8 (required). http://localhost:8086?readTimeout=5000
167192
* @param username authorization username
168193
* @param password authorization password
169194
* @param database database name
@@ -182,7 +207,12 @@ public static InfluxDBClient createV1(@Nonnull final String url,
182207
/**
183208
* Create an instance of the InfluxDB 2.x client to connect into InfluxDB 1.8.
184209
*
185-
* @param url the url to connect to the InfluxDB 1.8
210+
* <p>
211+
* The url could be a connection string with various configurations. For more info
212+
* see: {@link InfluxDBClientOptions.Builder#connectionString(String)}.
213+
* </p>
214+
*
215+
* @param url the url to connect to InfluxDB 1.8 (required). http://localhost:8086?readTimeout=5000
186216
* @param username authorization username
187217
* @param password authorization password
188218
* @param database database name

0 commit comments

Comments
 (0)