|
39 | 39 | import java.sql.Statement; |
40 | 40 | import java.util.ArrayList; |
41 | 41 | import java.util.Arrays; |
| 42 | +import java.util.Collections; |
42 | 43 | import java.util.HashSet; |
43 | 44 | import java.util.List; |
44 | 45 | import java.util.Random; |
|
49 | 50 | import org.apache.arrow.driver.jdbc.utils.PartitionedFlightSqlProducer; |
50 | 51 | import org.apache.arrow.flight.FlightEndpoint; |
51 | 52 | import org.apache.arrow.flight.FlightProducer; |
| 53 | +import org.apache.arrow.flight.FlightRuntimeException; |
52 | 54 | import org.apache.arrow.flight.FlightServer; |
| 55 | +import org.apache.arrow.flight.FlightStatusCode; |
| 56 | +import org.apache.arrow.flight.Location; |
53 | 57 | import org.apache.arrow.flight.Ticket; |
54 | 58 | import org.apache.arrow.memory.BufferAllocator; |
55 | 59 | import org.apache.arrow.memory.RootAllocator; |
|
63 | 67 | import org.junit.ClassRule; |
64 | 68 | import org.junit.Rule; |
65 | 69 | import org.junit.Test; |
| 70 | +import org.junit.jupiter.api.Assertions; |
66 | 71 | import org.junit.rules.ErrorCollector; |
67 | 72 |
|
68 | 73 | import com.google.common.collect.ImmutableSet; |
@@ -351,7 +356,7 @@ public void testShouldInterruptFlightStreamsIfQueryIsCancelledMidProcessingForTi |
351 | 356 | .toString(), |
352 | 357 | anyOf(is(format("Error while executing SQL \"%s\": Query canceled", query)), |
353 | 358 | allOf(containsString(format("Error while executing SQL \"%s\"", query)), |
354 | | - containsString("CANCELLED")))); |
| 359 | + anyOf(containsString("CANCELLED"), containsString("Cancelling"))))); |
355 | 360 | } |
356 | 361 | } |
357 | 362 |
|
@@ -455,6 +460,90 @@ allocator, forGrpcInsecure("localhost", 0), rootProducer) |
455 | 460 | } |
456 | 461 | } |
457 | 462 |
|
| 463 | + @Test |
| 464 | + public void testPartitionedFlightServerIgnoreFailure() throws Exception { |
| 465 | + final Schema schema = new Schema( |
| 466 | + Collections.singletonList(Field.nullablePrimitive("int_column", new ArrowType.Int(32, true)))); |
| 467 | + try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE)) { |
| 468 | + final FlightEndpoint firstEndpoint = |
| 469 | + new FlightEndpoint(new Ticket("first".getBytes(StandardCharsets.UTF_8)), |
| 470 | + Location.forGrpcInsecure("127.0.0.2", 1234), |
| 471 | + Location.forGrpcInsecure("127.0.0.3", 1234)); |
| 472 | + |
| 473 | + try (final PartitionedFlightSqlProducer rootProducer = new PartitionedFlightSqlProducer( |
| 474 | + schema, firstEndpoint); |
| 475 | + FlightServer rootServer = FlightServer.builder( |
| 476 | + allocator, forGrpcInsecure("localhost", 0), rootProducer) |
| 477 | + .build() |
| 478 | + .start(); |
| 479 | + Connection newConnection = DriverManager.getConnection(String.format( |
| 480 | + "jdbc:arrow-flight-sql://%s:%d/?useEncryption=false", |
| 481 | + rootServer.getLocation().getUri().getHost(), rootServer.getPort())); |
| 482 | + Statement newStatement = newConnection.createStatement()) { |
| 483 | + final SQLException e = Assertions.assertThrows(SQLException.class, () -> { |
| 484 | + ResultSet result = newStatement.executeQuery("Select partitioned_data"); |
| 485 | + while (result.next()) { |
| 486 | + } |
| 487 | + }); |
| 488 | + final Throwable cause = e.getCause(); |
| 489 | + Assertions.assertTrue(cause instanceof FlightRuntimeException); |
| 490 | + final FlightRuntimeException fre = (FlightRuntimeException) cause; |
| 491 | + Assertions.assertEquals(FlightStatusCode.UNAVAILABLE, fre.status().code()); |
| 492 | + } |
| 493 | + } |
| 494 | + } |
| 495 | + |
| 496 | + @Test |
| 497 | + public void testPartitionedFlightServerAllFailure() throws Exception { |
| 498 | + // Arrange |
| 499 | + final Schema schema = new Schema( |
| 500 | + Collections.singletonList(Field.nullablePrimitive("int_column", new ArrowType.Int(32, true)))); |
| 501 | + try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE); |
| 502 | + VectorSchemaRoot firstPartition = VectorSchemaRoot.create(schema, allocator)) { |
| 503 | + firstPartition.setRowCount(1); |
| 504 | + ((IntVector) firstPartition.getVector(0)).set(0, 1); |
| 505 | + |
| 506 | + // Construct the data-only nodes first. |
| 507 | + FlightProducer firstProducer = new PartitionedFlightSqlProducer.DataOnlyFlightSqlProducer( |
| 508 | + new Ticket("first".getBytes(StandardCharsets.UTF_8)), firstPartition); |
| 509 | + |
| 510 | + final FlightServer.Builder firstBuilder = FlightServer.builder( |
| 511 | + allocator, forGrpcInsecure("localhost", 0), firstProducer); |
| 512 | + |
| 513 | + // Run the data-only nodes so that we can get the Locations they are running at. |
| 514 | + try (FlightServer firstServer = firstBuilder.build()) { |
| 515 | + firstServer.start(); |
| 516 | + final Location badLocation = Location.forGrpcInsecure("127.0.0.2", 1234); |
| 517 | + final FlightEndpoint firstEndpoint = |
| 518 | + new FlightEndpoint(new Ticket("first".getBytes(StandardCharsets.UTF_8)), |
| 519 | + badLocation, firstServer.getLocation()); |
| 520 | + |
| 521 | + // Finally start the root node. |
| 522 | + try (final PartitionedFlightSqlProducer rootProducer = new PartitionedFlightSqlProducer( |
| 523 | + schema, firstEndpoint); |
| 524 | + FlightServer rootServer = FlightServer.builder( |
| 525 | + allocator, forGrpcInsecure("localhost", 0), rootProducer) |
| 526 | + .build() |
| 527 | + .start(); |
| 528 | + Connection newConnection = DriverManager.getConnection(String.format( |
| 529 | + "jdbc:arrow-flight-sql://%s:%d/?useEncryption=false", |
| 530 | + rootServer.getLocation().getUri().getHost(), rootServer.getPort())); |
| 531 | + Statement newStatement = newConnection.createStatement(); |
| 532 | + // Act |
| 533 | + ResultSet result = newStatement.executeQuery("Select partitioned_data")) { |
| 534 | + List<Integer> resultData = new ArrayList<>(); |
| 535 | + while (result.next()) { |
| 536 | + resultData.add(result.getInt(1)); |
| 537 | + } |
| 538 | + |
| 539 | + // Assert |
| 540 | + assertEquals(firstPartition.getRowCount(), resultData.size()); |
| 541 | + assertTrue(resultData.contains(((IntVector) firstPartition.getVector(0)).get(0))); |
| 542 | + } |
| 543 | + } |
| 544 | + } |
| 545 | + } |
| 546 | + |
458 | 547 | @Test |
459 | 548 | public void testShouldRunSelectQueryWithEmptyVectorsEmbedded() throws Exception { |
460 | 549 | try (Statement statement = connection.createStatement(); |
|
0 commit comments