Skip to content

Commit

Permalink
fix: evaluation of connection string (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Apr 28, 2022
1 parent f50edf0 commit 124c691
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### Features
1. [#337](https://github.com/influxdata/influxdb-client-java/pull/337): Supports `columns` function [FluxDSL]

### Bug Fixes
1. [#339](https://github.com/influxdata/influxdb-client-java/pull/339): Evaluation of connection string

## 6.0.0 [2022-04-19]

### Migration Notice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,12 @@ private InfluxDBClientOptions.Builder configure(@Nonnull final String url,
@Nullable final String consistency) {

this.url = new ParsedUrl(url).urlWithoutParams;
org(org);
bucket(bucket);
if (org != null) {
org(org);
}
if (bucket != null) {
bucket(bucket);
}

if (token != null) {
authenticateToken(token.toCharArray());
Expand All @@ -588,8 +592,10 @@ private InfluxDBClientOptions.Builder configure(@Nonnull final String url,
consistency(Enum.valueOf(WriteConsistency.class, consistency));
}

okHttpClient = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1));
if (okHttpClient == null) {
okHttpClient = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1));
}
if (readTimeout != null) {
okHttpClient.readTimeout(toDuration(readTimeout));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.influxdb.client;

import java.util.Collections;
import java.util.List;

import com.influxdb.client.domain.WritePrecision;
Expand Down Expand Up @@ -118,4 +119,27 @@ void parseURLAsConnectionString() {
Assertions.assertThat(options.getBucket()).isEqualTo("my-bucket");
Assertions.assertThat(options.getOrg()).isEqualTo("my-org");
}

@Test
void keepBucketOrgSettingsIfAreBeforeURL() {
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.bucket("my-bucket")
.org("my-org")
.url("http://localhost:8086")
.authenticateToken("my-token".toCharArray())
.build();

Assertions.assertThat(options.getOrg()).isEqualTo("my-org");
Assertions.assertThat(options.getBucket()).isEqualTo("my-bucket");
}

@Test
void okHttpBeforeURL() {
InfluxDBClientOptions options = InfluxDBClientOptions.builder()
.okHttpClient(new OkHttpClient.Builder().protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE)))
.url("http://localhost:8086")
.build();

Assertions.assertThat(options.getOkHttpClient().build().protocols()).containsExactly(Protocol.H2_PRIOR_KNOWLEDGE);
}
}

0 comments on commit 124c691

Please sign in to comment.