Skip to content

Commit 07edbe5

Browse files
committed
fix: always generate the same tags
1 parent 070724f commit 07edbe5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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

Lines changed: 16 additions & 8 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,14 +238,15 @@ void pointValues() {
236238
@Test
237239
public void handleFlightRuntimeException() throws IOException {
238240
Instant now = Instant.now();
239-
String measurement = "/influxdb3-java/test/handleFlightRuntimeException";
241+
String measurement = "/influxdb3-java/test/ITQueryWrite/handleFlightRuntimeException";
240242

241243
client = getInstance();
242244

243245
int extraTagLength = 512;
244246
Map<String, String> extraTags = new HashMap<String, String>();
247+
Random seededRandom = new Random(1); // use seeded random to generate always the same tags
245248
for (int i = 0; i < 22; i++) {
246-
extraTags.put(makeLengthyTag(extraTagLength, 64, (byte) '/'), "extra-tag-" + i);
249+
extraTags.put(makeLengthyTag(extraTagLength, 64, (byte) '/', seededRandom), "extra-tag-" + i);
247250
}
248251

249252
Point p = Point.measurement(measurement)
@@ -273,17 +276,21 @@ public void handleFlightRuntimeException() throws IOException {
273276
});
274277
} catch (FlightRuntimeException fre) {
275278
Assertions.assertThat(fre.getMessage()).doesNotContain("http2 exception");
276-
Assertions.assertThat(fre.status().code()).isNotEqualTo(CallStatus.INTERNAL.code());
277-
Assertions.assertThat(fre.status().code()).
279+
FlightStatusCode statusCode = fre.status().code();
280+
Assertions.assertThat(statusCode).isNotEqualTo(CallStatus.INTERNAL.code());
281+
Assertions.assertThat(statusCode).
278282
as(String.format("Flight runtime exception was UNAVAILABLE. "
279283
+ "Target test case was not fully tested. "
280284
+ "Check limits of test account and target database %s.",
281285
System.getenv("TESTING_INFLUXDB_DATABASE")))
282286
.isNotEqualTo(CallStatus.UNAVAILABLE.code());
283-
Assertions.assertThat(fre.status().code()).
287+
Assertions.assertThat(statusCode).
284288
as("Flight runtime exception was UNAUTHENTICATED. "
285289
+ "Target test case was not fully tested. Check test account token.")
286290
.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());
287294
return;
288295
} catch (Exception e) {
289296
Assertions.fail(String.format("FlightRuntimeException should have been thrown. "
@@ -302,16 +309,17 @@ private static InfluxDBClient getInstance() {
302309
System.getenv("TESTING_INFLUXDB_DATABASE"));
303310
}
304311

305-
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) {
306314
final String legalVals = "0123456789abcdefghijklmnopqrstuvwxyz";
307315
byte[] bytes = new byte[length];
308316
int nextPartAddress = 0;
309317
for (int i = 0; i < length; i++) {
310318
if (i == nextPartAddress) {
311319
bytes[i] = separator;
312-
nextPartAddress = i + (int) (Math.random() * (maxPartLength - 3));
320+
nextPartAddress = i + (int) (random.nextDouble() * (maxPartLength - 3));
313321
} else {
314-
bytes[i] = legalVals.getBytes()[(int) (Math.random() * legalVals.length())];
322+
bytes[i] = legalVals.getBytes()[(int) (random.nextDouble() * legalVals.length())];
315323
}
316324
}
317325
return new String(bytes);

0 commit comments

Comments
 (0)