Skip to content

Commit

Permalink
Change testAuth2 to allocate only one server/client
Browse files Browse the repository at this point in the history
  • Loading branch information
jduo committed Nov 14, 2023
1 parent 0a93a6a commit 00aa719
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
import org.apache.arrow.vector.types.Types;
import org.apache.arrow.vector.types.pojo.Field;
import org.apache.arrow.vector.types.pojo.Schema;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;

Expand All @@ -57,18 +57,18 @@ public class TestBasicAuth2 {
private static final String NO_USERNAME = "";
private static final String PASSWORD_1 = "woohoo1";
private static final String PASSWORD_2 = "woohoo2";
private BufferAllocator allocator;
private FlightServer server;
private FlightClient client;
private FlightClient client2;
private static BufferAllocator allocator;
private static FlightServer server;
private static FlightClient client;
private static FlightClient client2;

@BeforeEach
public void setup() throws Exception {
@BeforeAll
public static void setup() throws Exception {
allocator = new RootAllocator(Long.MAX_VALUE);
startServerAndClient();
}

private FlightProducer getFlightProducer() {
private static FlightProducer getFlightProducer() {
return new NoOpFlightProducer() {
@Override
public void listFlights(CallContext context, Criteria criteria,
Expand Down Expand Up @@ -99,19 +99,19 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l
};
}

private void startServerAndClient() throws IOException {
private static void startServerAndClient() throws IOException {
final FlightProducer flightProducer = getFlightProducer();
this.server = FlightServer
server = FlightServer
.builder(allocator, forGrpcInsecure(LOCALHOST, 0), flightProducer)
.headerAuthenticator(new GeneratedBearerTokenAuthenticator(
new BasicCallHeaderAuthenticator(this::validate)))
.build().start();
this.client = FlightClient.builder(allocator, server.getLocation())
client = FlightClient.builder(allocator, server.getLocation())
.build();
}

@AfterEach
public void shutdown() throws Exception {
@AfterAll
public static void shutdown() throws Exception {
AutoCloseables.close(client, client2, server);
client = null;
client2 = null;
Expand Down

0 comments on commit 00aa719

Please sign in to comment.