Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-42045: [Java] Update Unit Tests for Flight Module #42158

Merged
merged 15 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading