Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,13 @@ private <T> void writeData(@Nonnull final List<T> data, @Nonnull final WriteOpti
+ "or use default configuration at 'ClientConfig.database'.");
}

WritePrecision precision = options.precisionSafe(config);
WritePrecision precision;
if (!data.isEmpty() && data.get(0) instanceof Point) {
// When writing points, timestamp always be converted to nanoseconds.
precision = WritePrecision.NS;
} else {
precision = options.precisionSafe(config);
}
options.validate(config);

String path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void writePointWithDefaultWriteOptionsCustomConfig() throws Exception {
mockServer.enqueue(createResponse(200));

ClientConfig cfg = new ClientConfig.Builder().host(baseURL).token("TOKEN".toCharArray()).database("DB")
.writePrecision(WritePrecision.S)
.writePrecision(WritePrecision.US)
.writeNoSync(true)
.gzipThreshold(1)
.build();
Expand All @@ -412,7 +412,10 @@ void writePointWithDefaultWriteOptionsCustomConfig() throws Exception {
client.writePoint(point);
}

checkWriteCalled("/api/v3/write_lp", "DB", "second", true, "true", null, true);
// When writing Point, precision send to the servers is always nanosecond
var expectedPrecision = "nanosecond";

checkWriteCalled("/api/v3/write_lp", "DB", expectedPrecision, true, "true", null, true);
}

@Test
Expand Down Expand Up @@ -447,7 +450,10 @@ void writePointsWithDefaultWriteOptionsCustomConfig() throws Exception {
client.writePoints(List.of(point));
}

checkWriteCalled("/api/v3/write_lp", "DB", "second", true, "true", null, true);
// When writing Point, precision send to the servers is always nanosecond
var expectedPrecision = "nanosecond";

checkWriteCalled("/api/v3/write_lp", "DB", expectedPrecision, true, "true", null, true);
}

private void checkWriteCalled(final String expectedPath, final String expectedDB,
Expand Down
37 changes: 35 additions & 2 deletions src/test/java/com/influxdb/v3/client/integration/E2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,43 @@ public void testMultipleQueries() throws Exception {
}
}
}


}

@EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*")
@EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*")
@EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*")
@Test
public void testWriteWithDifferentTimeUnit() throws Exception {
// These tests make sure that timestamp always converted to nanoseconds when writing Points.
try (InfluxDBClient client = InfluxDBClient.getInstance(
System.getenv("TESTING_INFLUXDB_URL"),
System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray(),
System.getenv("TESTING_INFLUXDB_DATABASE"),
null)) {
var writeOptions = new WriteOptions.Builder().precision(WritePrecision.MS).build();
String measurement = "test_" + Instant.now().toEpochMilli() % 1000;
List<Point> points = List.of(
Point.measurement(measurement)
.setTag("type", "test")
.setFloatField("rads", 3.14)
.setIntegerField("life", 42)
.setTimestamp(Instant.now().toEpochMilli(), WritePrecision.MS),
Point.measurement(measurement)
.setTag("type", "test")
.setFloatField("rads", 3.14)
.setIntegerField("life", 12)
.setTimestamp(Instant.now().plusSeconds(1).toEpochMilli() / 1000, WritePrecision.S),
Point.measurement(measurement)
.setTag("type", "test")
.setFloatField("rads", 3.14)
.setIntegerField("life", 432)
.setTimestamp(Instant.now().plusSeconds(2).toEpochMilli() * 1000, WritePrecision.US)
);
client.writePoints(points, writeOptions);
var results = client.queryPoints("select * from " + measurement).collect(Collectors.toList());
Assertions.assertThat(results).hasSize(3);
}
}

private void assertGetDataSuccess(@Nonnull final InfluxDBClient influxDBClient) {
influxDBClient.writePoint(
Expand Down
Loading