Skip to content

Commit

Permalink
chore: minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Mar 7, 2024
1 parent fb61c1c commit 0eb5ebc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public String getDatabase() {

/**
* Gets the default precision to use for the timestamp of points.
* If no precision is specified than 'ns' is used.
* If no precision is specified then 'ns' is used.
*
* @return the default precision to use for the timestamp of points, may be null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public void checkServerTrusted(
void request(@Nonnull final String path,
@Nonnull final HttpMethod method,
@Nullable final byte[] data,
@Nullable final Map<String, String> queryParams, @Nullable final Map<String, String> headers) {
@Nullable final Map<String, String> queryParams,
@Nullable final Map<String, String> headers) {

QueryStringEncoder uriEncoder = new QueryStringEncoder(String.format("%s%s", baseUrl, path));
if (queryParams != null) {
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/influxdb/v3/client/write/WriteOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Map<String, String> defaultTagsSafe(@Nonnull final ClientConfig config) {
public Integer gzipThresholdSafe(@Nonnull final ClientConfig config) {
Arguments.checkNotNull(config, "config");
return gzipThreshold != null ? gzipThreshold
: (config.getWritePrecision() != null ? config.getGzipThreshold() : DEFAULT_GZIP_THRESHOLD);
: (config.getGzipThreshold() != null ? config.getGzipThreshold() : DEFAULT_GZIP_THRESHOLD);
}

/**
Expand Down Expand Up @@ -232,6 +232,7 @@ public static final class Builder {
private WritePrecision precision;
private Integer gzipThreshold;
private Map<String, String> defaultTags = new HashMap<>();
private Map<String, String> headers = new HashMap<>();

/**
* Sets the database.
Expand Down Expand Up @@ -284,6 +285,18 @@ public Builder defaultTags(@Nonnull final Map<String, String> defaultTags) {
return this;
}

/**
* Sets the headers.
*
* @param headers headers
* @return this
*/
@Nonnull
public Builder headers(@Nonnull final Map<String, String> headers) {
this.headers = headers;
return this;
}

/**
* Build an instance of {@code ClientConfig}.
*
Expand All @@ -297,6 +310,6 @@ public WriteOptions build() {
}

private WriteOptions(@Nonnull final Builder builder) {
this(builder.database, builder.precision, builder.gzipThreshold, builder.defaultTags);
this(builder.database, builder.precision, builder.gzipThreshold, builder.defaultTags, builder.headers);
}
}
18 changes: 14 additions & 4 deletions src/test/java/com/influxdb/v3/client/write/WriteOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ void optionsWithDefaultTags() {
.build();

Assertions.assertThat(options).isEqualTo(optionsViaBuilder);
}

@Test
void optionsWithHeaders() {
Map<String, String> headers = Map.of("X-Trace-Id", "189");

WriteOptions options = new WriteOptions("mydb", WritePrecision.MS, 2048, null, headers);
WriteOptions optionsViaBuilder = new WriteOptions.Builder()
.database("mydb")
.precision(WritePrecision.MS)
.gzipThreshold(2048)
.headers(headers)
.build();

Assertions.assertThat(options).isEqualTo(optionsViaBuilder);
}

@Test
Expand Down Expand Up @@ -178,7 +192,6 @@ void optionsOverridesDefaultTags() {
Assertions.assertThat(options.precisionSafe(config)).isEqualTo(WritePrecision.S);
Assertions.assertThat(options.gzipThresholdSafe(config)).isEqualTo(512);
Assertions.assertThat(options.defaultTagsSafe(config)).isEqualTo(defaultTagsNew);

}

@Test
Expand All @@ -205,8 +218,6 @@ void optionsOverridesEmptyDefaultTags() {
Assertions.assertThat(options.precisionSafe(config)).isEqualTo(WritePrecision.S);
Assertions.assertThat(options.gzipThresholdSafe(config)).isEqualTo(512);
Assertions.assertThat(options.defaultTagsSafe(config)).isEqualTo(defaultTags);


}

@Test
Expand All @@ -221,6 +232,5 @@ void optionsHashCode() {
.isNotEqualTo(builder.database("my-database").build().hashCode());
Assertions.assertThat(baseOptions.hashCode())
.isNotEqualTo(builder.defaultTags(defaultTags).build().hashCode());

}
}

0 comments on commit 0eb5ebc

Please sign in to comment.