Skip to content

Commit

Permalink
apacheGH-42045: [Java] Update Unit Tests for Flight Module (apache#42158
Browse files Browse the repository at this point in the history
)

### Rationale for this change

Update package from JUnit 4(`org.junit`) to JUnit 5(`org.junit.jupiter`).

### What changes are included in this PR?

- **common** for all module
  - Step 1. Replacing `org.junit` with `org.junit.jupiter.api`
  - Step 2. Updating `Assertions.assertXXX` to `assertXXX` using static imports
- `flight-core`
  - [x] Updating common
  - [x] Updating annotations
  - [x] Doing self review
- `flight-integration-tests` - nothing to change
- `flight-sql`
  - [x] Updating common 
  - [x] Doing self review
- `flight-sql-jdbc-core`
  - [x] Updating common
  - [x] Updating annotations
    - Adding annotations different from before:
      - `ErrorCollection`
      - `TestRule` for `FlightServerTestExtension` and `RootAllocatorExtension`
      - `ExpectedException`
  - [x] Doing self review
- `flight-sql-jdbc-driver`
  - [x] Updating common
  - [x] Updating annotations 
  - [x] Doing self review

### Are these changes tested?

Yes, existing tests have passed.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#42045

Authored-by: Hyunseok Seo <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
llama90 authored Jun 19, 2024
1 parent b75cc99 commit 9d93287
Show file tree
Hide file tree
Showing 81 changed files with 2,729 additions and 2,701 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
*/
package org.apache.arrow.flight;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import org.apache.arrow.vector.test.util.ArrowTestDataUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;

/** Utility methods and constants for testing flight servers. */
Expand Down Expand Up @@ -88,8 +90,8 @@ static boolean isNativeTransportAvailable() {
* @return The thrown status.
*/
public static CallStatus assertCode(FlightStatusCode code, Executable r) {
final FlightRuntimeException ex = Assertions.assertThrows(FlightRuntimeException.class, r);
Assertions.assertEquals(code, ex.status().code());
final FlightRuntimeException ex = assertThrows(FlightRuntimeException.class, r);
assertEquals(code, ex.status().code());
return ex.status();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
import static org.apache.arrow.flight.Location.forGrpcInsecure;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
Expand All @@ -34,7 +37,6 @@
import org.apache.arrow.vector.types.pojo.ArrowType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.Schema;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand All @@ -57,9 +59,9 @@ public void retrieveMetadata() {
byte i = 0;
while (stream.next()) {
final IntVector vector = (IntVector) stream.getRoot().getVector("a");
Assertions.assertEquals(1, vector.getValueCount());
Assertions.assertEquals(10, vector.get(0));
Assertions.assertEquals(i, stream.getLatestMetadata().getByte(0));
assertEquals(1, vector.getValueCount());
assertEquals(10, vector.get(0));
assertEquals(i, stream.getLatestMetadata().getByte(0));
i++;
}
} catch (Exception e) {
Expand All @@ -86,7 +88,7 @@ public void arrow6136() {
// Must attempt to retrieve the result to get any server-side errors.
final CallStatus status =
FlightTestUtil.assertCode(FlightStatusCode.INTERNAL, writer::getResult);
Assertions.assertEquals(MESSAGE_ARROW_6136, status.description());
assertEquals(MESSAGE_ARROW_6136, status.description());
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -110,8 +112,8 @@ public void uploadMetadataAsync() {

@Override
public void onNext(PutResult val) {
Assertions.assertNotNull(val);
Assertions.assertEquals(counter, val.getApplicationMetadata().getByte(0));
assertNotNull(val);
assertEquals(counter, val.getApplicationMetadata().getByte(0));
counter++;
}
};
Expand Down Expand Up @@ -161,8 +163,8 @@ public void uploadMetadataSync() {
root.setRowCount(1);
writer.putNext(metadata);
try (final PutResult message = listener.poll(5000, TimeUnit.SECONDS)) {
Assertions.assertNotNull(message);
Assertions.assertEquals(i, message.getApplicationMetadata().getByte(0));
assertNotNull(message);
assertEquals(i, message.getApplicationMetadata().getByte(0));
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -229,10 +231,10 @@ public void testMetadataEndianness() throws Exception {
final FlightClient.ClientStreamListener writer = client.startPut(descriptor, root, reader);
writer.completed();
try (final PutResult metadata = reader.read()) {
Assertions.assertEquals(16, metadata.getApplicationMetadata().readableBytes());
assertEquals(16, metadata.getApplicationMetadata().readableBytes());
byte[] bytes = new byte[16];
metadata.getApplicationMetadata().readBytes(bytes);
Assertions.assertArrayEquals(EndianFlightProducer.EXPECTED_BYTES, bytes);
assertArrayEquals(EndianFlightProducer.EXPECTED_BYTES, bytes);
}
writer.getResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@

import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
import static org.apache.arrow.flight.Location.forGrpcInsecure;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Iterator;
import java.util.Optional;
import org.apache.arrow.flight.auth.ClientAuthHandler;
import org.apache.arrow.flight.auth.ServerAuthHandler;
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class TestAuth {

/** An auth handler that does not send messages should not block the server forever. */
@Test
public void noMessages() throws Exception {
Assertions.assertThrows(
assertThrows(
RuntimeException.class,
() -> {
try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
Expand Down Expand Up @@ -62,7 +62,7 @@ public byte[] getCallToken() {
/** An auth handler that sends an error should not block the server forever. */
@Test
public void clientError() throws Exception {
Assertions.assertThrows(
assertThrows(
RuntimeException.class,
() -> {
try (final BufferAllocator allocator = new RootAllocator(Integer.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.apache.arrow.flight.FlightTestUtil.LOCALHOST;
import static org.apache.arrow.flight.Location.forGrpcInsecure;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.google.common.collect.ImmutableList;
import java.util.concurrent.ExecutorService;
Expand All @@ -33,7 +34,6 @@
import org.apache.arrow.vector.types.Types.MinorType;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.Schema;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -181,7 +181,7 @@ public void getStream(
root.clear();
}
long expected = wait - epsilon;
Assertions.assertTrue(
assertTrue(
bpStrategy.getSleepTime() > expected,
String.format(
"Expected a sleep of at least %dms but only slept for %d",
Expand Down
Loading

0 comments on commit 9d93287

Please sign in to comment.