|
23 | 23 |
|
24 | 24 | import java.io.IOException; |
25 | 25 | import java.math.BigInteger; |
| 26 | +import java.time.Duration; |
26 | 27 | import java.time.Instant; |
27 | 28 | import java.time.temporal.ChronoUnit; |
28 | 29 | import java.util.HashMap; |
29 | 30 | import java.util.List; |
30 | 31 | import java.util.Map; |
31 | 32 | import java.util.Random; |
| 33 | +import java.util.concurrent.TimeUnit; |
32 | 34 | import java.util.stream.Collectors; |
33 | 35 | import java.util.stream.Stream; |
34 | 36 |
|
| 37 | +import com.influxdb.v3.client.internal.GrpcCallOptions; |
| 38 | +import io.grpc.Deadline; |
35 | 39 | import org.apache.arrow.flight.CallStatus; |
36 | 40 | import org.apache.arrow.flight.FlightRuntimeException; |
37 | 41 | import org.apache.arrow.flight.FlightStatusCode; |
38 | 42 | import org.apache.arrow.vector.VectorSchemaRoot; |
39 | 43 | import org.assertj.core.api.Assertions; |
40 | 44 | import org.jetbrains.annotations.NotNull; |
41 | 45 | import org.junit.jupiter.api.AfterEach; |
| 46 | +import org.junit.jupiter.api.Disabled; |
42 | 47 | import org.junit.jupiter.api.Test; |
43 | 48 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; |
44 | 49 |
|
|
47 | 52 | import com.influxdb.v3.client.write.WriteOptions; |
48 | 53 | import com.influxdb.v3.client.write.WritePrecision; |
49 | 54 |
|
| 55 | +import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable; |
| 56 | + |
50 | 57 | class ITQueryWrite { |
51 | 58 |
|
52 | 59 | private InfluxDBClient client; |
@@ -301,6 +308,202 @@ public void handleFlightRuntimeException() throws IOException { |
301 | 308 |
|
302 | 309 | } |
303 | 310 |
|
| 311 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
| 312 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
| 313 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
| 314 | + @Test |
| 315 | + public void queryTimeoutExceededTest() { |
| 316 | + client = InfluxDBClient.getInstance(new ClientConfig.Builder() |
| 317 | + .host(System.getenv("TESTING_INFLUXDB_URL")) |
| 318 | + .token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray()) |
| 319 | + .database(System.getenv("TESTING_INFLUXDB_DATABASE")) |
| 320 | + .queryTimeout(Duration.ofMillis(100)) |
| 321 | + .build()); |
| 322 | + |
| 323 | + String measurement = "timeout_test_" + Math.round(Math.random() * 100_000); |
| 324 | + long testId = System.currentTimeMillis(); |
| 325 | + client.writeRecord(measurement + ",type=used value=123.0,testId=" + testId); |
| 326 | + |
| 327 | + String sql = String.format("SELECT value FROM %s WHERE \"testId\"=%d", measurement, testId); |
| 328 | + |
| 329 | + Throwable thrown = catchThrowable(() -> { |
| 330 | + Stream<Object[]> stream = client.query(sql); |
| 331 | + stream.forEach(row -> { |
| 332 | + Assertions.assertThat(row).hasSize(1); |
| 333 | + Assertions.assertThat(row[0]).isEqualTo(123.0); |
| 334 | + }); |
| 335 | + }); |
| 336 | + |
| 337 | + Assertions.assertThat(thrown).isInstanceOf(FlightRuntimeException.class); |
| 338 | + Assertions.assertThat(thrown.getMessage()).matches(".*deadline.*exceeded.*"); |
| 339 | + } |
| 340 | + |
| 341 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
| 342 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
| 343 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
| 344 | + @Test |
| 345 | + public void queryTimeoutOKTest() { |
| 346 | + client = InfluxDBClient.getInstance(new ClientConfig.Builder() |
| 347 | + .host(System.getenv("TESTING_INFLUXDB_URL")) |
| 348 | + .token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray()) |
| 349 | + .database(System.getenv("TESTING_INFLUXDB_DATABASE")) |
| 350 | + .queryTimeout(Duration.ofSeconds(3)) |
| 351 | + .build()); |
| 352 | + |
| 353 | + String measurement = "timeout_test_" + Math.round(Math.random() * 100_000); |
| 354 | + long testId = System.currentTimeMillis(); |
| 355 | + client.writeRecord(measurement + ",type=used value=123.0,testId=" + testId); |
| 356 | + |
| 357 | + String sql = String.format("SELECT value FROM %s WHERE \"testId\"=%d", measurement, testId); |
| 358 | + |
| 359 | + try(Stream<Object[]> stream = client.query(sql)) { |
| 360 | + stream.forEach(row -> { |
| 361 | + Assertions.assertThat(row).hasSize(1); |
| 362 | + Assertions.assertThat(row[0]).isEqualTo(123.0); |
| 363 | + }); |
| 364 | + } catch (Exception e) { |
| 365 | + throw new RuntimeException(e); |
| 366 | + } |
| 367 | + } |
| 368 | + |
| 369 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
| 370 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
| 371 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
| 372 | + @Test |
| 373 | + public void queryTimeoutOtherGrpcOptUnaffectedTest() { |
| 374 | + client = InfluxDBClient.getInstance(new ClientConfig.Builder() |
| 375 | + .host(System.getenv("TESTING_INFLUXDB_URL")) |
| 376 | + .token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray()) |
| 377 | + .database(System.getenv("TESTING_INFLUXDB_DATABASE")) |
| 378 | + .queryTimeout(Duration.ofSeconds(3)) |
| 379 | + .build()); |
| 380 | + |
| 381 | + String measurement = "timeout_test_" + Math.round(Math.random() * 100_000); |
| 382 | + long testId = System.currentTimeMillis(); |
| 383 | + client.writeRecord(measurement + ",type=used value=123.0,testId=" + testId); |
| 384 | + |
| 385 | + String sql = String.format("SELECT value FROM %s WHERE \"testId\"=%d", measurement, testId); |
| 386 | + |
| 387 | + QueryOptions queryOptions = QueryOptions.defaultQueryOptions(); |
| 388 | + queryOptions.setGrpcCallOptions(new GrpcCallOptions.Builder() |
| 389 | + .withMaxInboundMessageSize(10) |
| 390 | + .build() |
| 391 | + ); |
| 392 | + |
| 393 | + Throwable thrown = catchThrowable(() -> { |
| 394 | + Stream<Object[]> stream = client.query(sql, queryOptions); |
| 395 | + stream.forEach(row -> { |
| 396 | + Assertions.assertThat(row).hasSize(1); |
| 397 | + Assertions.assertThat(row[0]).isEqualTo(123.0); |
| 398 | + }); |
| 399 | + }); |
| 400 | + |
| 401 | + Assertions.assertThat(thrown).isInstanceOf(FlightRuntimeException.class); |
| 402 | + Assertions.assertThat(thrown.getMessage()).contains("gRPC message exceeds maximum size"); |
| 403 | + } |
| 404 | + |
| 405 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
| 406 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
| 407 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
| 408 | + @Test |
| 409 | + public void queryTimeoutSuperceededByGrpcOptTest() { |
| 410 | + |
| 411 | + client = InfluxDBClient.getInstance(new ClientConfig.Builder() |
| 412 | + .host(System.getenv("TESTING_INFLUXDB_URL")) |
| 413 | + .token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray()) |
| 414 | + .database(System.getenv("TESTING_INFLUXDB_DATABASE")) |
| 415 | + .queryTimeout(Duration.ofSeconds(3)) |
| 416 | + .build()); |
| 417 | + |
| 418 | + String measurement = "timeout_test_" + Math.round(Math.random() * 100_000); |
| 419 | + long testId = System.currentTimeMillis(); |
| 420 | + client.writeRecord(measurement + ",type=used value=123.0,testId=" + testId); |
| 421 | + |
| 422 | + String sql = String.format("SELECT value FROM %s WHERE \"testId\"=%d", measurement, testId); |
| 423 | + |
| 424 | + QueryOptions queryOptions = QueryOptions.defaultQueryOptions(); |
| 425 | + queryOptions.setGrpcCallOptions(new GrpcCallOptions.Builder() |
| 426 | + .withDeadline(Deadline.after(100, TimeUnit.MILLISECONDS)) |
| 427 | + .build() |
| 428 | + ); |
| 429 | + |
| 430 | + Throwable thrown = catchThrowable(() -> { |
| 431 | + Stream<Object[]> stream = client.query(sql, queryOptions); |
| 432 | + stream.forEach(row -> { |
| 433 | + Assertions.assertThat(row).hasSize(1); |
| 434 | + Assertions.assertThat(row[0]).isEqualTo(123.0); |
| 435 | + }); |
| 436 | + }); |
| 437 | + |
| 438 | + Assertions.assertThat(thrown).isInstanceOf(FlightRuntimeException.class); |
| 439 | + Assertions.assertThat(thrown.getMessage()).matches(".*deadline.*exceeded.*"); |
| 440 | + } |
| 441 | + |
| 442 | + @Test |
| 443 | + public void repeatQueryWithTimeoutTest(){ |
| 444 | + long timeout = 1000; |
| 445 | + client = InfluxDBClient.getInstance(new ClientConfig.Builder() |
| 446 | + .host(System.getenv("TESTING_INFLUXDB_URL")) |
| 447 | + .token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray()) |
| 448 | + .database(System.getenv("TESTING_INFLUXDB_DATABASE")) |
| 449 | + .queryTimeout(Duration.ofMillis(timeout)) |
| 450 | + .build()); |
| 451 | + |
| 452 | + String measurement = "timeout_test_" + Math.round(Math.random() * 100_000); |
| 453 | + long testId = System.currentTimeMillis(); |
| 454 | + client.writeRecord(measurement + ",type=used value=123.0,testId=" + testId); |
| 455 | + |
| 456 | + String sql = String.format("SELECT value FROM %s WHERE \"testId\"=%d", measurement, testId); |
| 457 | + |
| 458 | + for (int i = 0; i < 3; i++){ |
| 459 | + try(Stream<Object[]> stream = client.query(sql)) { |
| 460 | + stream.forEach(row -> { |
| 461 | + Assertions.assertThat(row).hasSize(1); |
| 462 | + Assertions.assertThat(row[0]).isEqualTo(123.0); |
| 463 | + }); |
| 464 | + TimeUnit.MILLISECONDS.sleep(timeout + 100); |
| 465 | + } catch (Exception e) { |
| 466 | + throw new RuntimeException(e); |
| 467 | + } |
| 468 | + } |
| 469 | + } |
| 470 | + |
| 471 | + @Test |
| 472 | + @Disabled("Runs across issue 12109 in Grpc-Java library ") |
| 473 | + public void queryGrpcMaxOutSizeTest() { |
| 474 | + // See Grpc-java issue 12109 https://github.com/grpc/grpc-java/issues/12109 |
| 475 | + // TODO - re-enable after 12109 has a fix and dependencies are updated |
| 476 | + client = InfluxDBClient.getInstance(new ClientConfig.Builder() |
| 477 | + .host(System.getenv("TESTING_INFLUXDB_URL")) |
| 478 | + .token(System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray()) |
| 479 | + .database(System.getenv("TESTING_INFLUXDB_DATABASE")) |
| 480 | + // .queryTimeout(Duration.ofSeconds(3)) |
| 481 | + .build()); |
| 482 | + |
| 483 | + String measurement = "timeout_test_" + Math.round(Math.random() * 100_000); |
| 484 | + long testId = System.currentTimeMillis(); |
| 485 | + client.writeRecord(measurement + ",type=used value=123.0,testId=" + testId); |
| 486 | + |
| 487 | + String sql = String.format("SELECT value FROM %s WHERE \"testId\"=%d", measurement, testId); |
| 488 | + |
| 489 | + QueryOptions queryOptions = QueryOptions.defaultQueryOptions(); |
| 490 | + queryOptions.setGrpcCallOptions(new GrpcCallOptions.Builder() |
| 491 | + .withMaxOutboundMessageSize(10) |
| 492 | + .build() |
| 493 | + ); |
| 494 | + |
| 495 | + try(Stream<Object[]> stream = client.query(sql, queryOptions)) { |
| 496 | + stream.forEach(row -> { |
| 497 | + Assertions.assertThat(row).hasSize(1); |
| 498 | + Assertions.assertThat(row[0]).isEqualTo(123.0); |
| 499 | + }); |
| 500 | + |
| 501 | + } catch (Exception e) { |
| 502 | + throw new RuntimeException(e); |
| 503 | + } |
| 504 | + |
| 505 | + } |
| 506 | + |
304 | 507 | @NotNull |
305 | 508 | private static InfluxDBClient getInstance() { |
306 | 509 | return InfluxDBClient.getInstance( |
|
0 commit comments