Skip to content

Commit 27267a9

Browse files
authored
test: use the same measurement in test (#240)
* test: use the same measurement in test * fix: always generate the same tags
1 parent fcfdb06 commit 27267a9

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/test/java/com/influxdb/v3/client/ITQueryWrite.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import java.util.HashMap;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.Random;
3132
import java.util.stream.Collectors;
3233
import java.util.stream.Stream;
3334

3435
import org.apache.arrow.flight.CallStatus;
3536
import org.apache.arrow.flight.FlightRuntimeException;
37+
import org.apache.arrow.flight.FlightStatusCode;
3638
import org.apache.arrow.vector.VectorSchemaRoot;
3739
import org.assertj.core.api.Assertions;
3840
import org.jetbrains.annotations.NotNull;
@@ -236,16 +238,15 @@ void pointValues() {
236238
@Test
237239
public void handleFlightRuntimeException() throws IOException {
238240
Instant now = Instant.now();
239-
String measurement = String.format(
240-
"/%d/test/com/influxdb/v3/client/ITQueryWrite/handleFlightRuntimeException", now.toEpochMilli()
241-
);
241+
String measurement = "/influxdb3-java/test/ITQueryWrite/handleFlightRuntimeException";
242242

243243
client = getInstance();
244244

245245
int extraTagLength = 512;
246246
Map<String, String> extraTags = new HashMap<String, String>();
247+
Random seededRandom = new Random(1); // use seeded random to generate always the same tags
247248
for (int i = 0; i < 22; i++) {
248-
extraTags.put(makeLengthyTag(extraTagLength, 64, (byte) '/'), "extra-tag-" + i);
249+
extraTags.put(makeLengthyTag(extraTagLength, 64, (byte) '/', seededRandom), "extra-tag-" + i);
249250
}
250251

251252
Point p = Point.measurement(measurement)
@@ -275,17 +276,21 @@ public void handleFlightRuntimeException() throws IOException {
275276
});
276277
} catch (FlightRuntimeException fre) {
277278
Assertions.assertThat(fre.getMessage()).doesNotContain("http2 exception");
278-
Assertions.assertThat(fre.status().code()).isNotEqualTo(CallStatus.INTERNAL.code());
279-
Assertions.assertThat(fre.status().code()).
279+
FlightStatusCode statusCode = fre.status().code();
280+
Assertions.assertThat(statusCode).isNotEqualTo(CallStatus.INTERNAL.code());
281+
Assertions.assertThat(statusCode).
280282
as(String.format("Flight runtime exception was UNAVAILABLE. "
281283
+ "Target test case was not fully tested. "
282284
+ "Check limits of test account and target database %s.",
283285
System.getenv("TESTING_INFLUXDB_DATABASE")))
284286
.isNotEqualTo(CallStatus.UNAVAILABLE.code());
285-
Assertions.assertThat(fre.status().code()).
287+
Assertions.assertThat(statusCode).
286288
as("Flight runtime exception was UNAUTHENTICATED. "
287289
+ "Target test case was not fully tested. Check test account token.")
288290
.isNotEqualTo(CallStatus.UNAUTHENTICATED.code());
291+
Assertions.assertThat(statusCode).
292+
as("Flight runtime exception was not INVALID_ARGUMENT but: " + statusCode.toString())
293+
.isEqualTo(CallStatus.INVALID_ARGUMENT.code());
289294
return;
290295
} catch (Exception e) {
291296
Assertions.fail(String.format("FlightRuntimeException should have been thrown. "
@@ -304,16 +309,17 @@ private static InfluxDBClient getInstance() {
304309
System.getenv("TESTING_INFLUXDB_DATABASE"));
305310
}
306311

307-
private String makeLengthyTag(final int length, final int maxPartLength, final byte separator) {
312+
private String makeLengthyTag(final int length, final int maxPartLength, final byte separator,
313+
final Random random) {
308314
final String legalVals = "0123456789abcdefghijklmnopqrstuvwxyz";
309315
byte[] bytes = new byte[length];
310316
int nextPartAddress = 0;
311317
for (int i = 0; i < length; i++) {
312318
if (i == nextPartAddress) {
313319
bytes[i] = separator;
314-
nextPartAddress = i + (int) (Math.random() * (maxPartLength - 3));
320+
nextPartAddress = i + (int) (random.nextDouble() * (maxPartLength - 3));
315321
} else {
316-
bytes[i] = legalVals.getBytes()[(int) (Math.random() * legalVals.length())];
322+
bytes[i] = legalVals.getBytes()[(int) (random.nextDouble() * legalVals.length())];
317323
}
318324
}
319325
return new String(bytes);

0 commit comments

Comments
 (0)