41
41
import org .apache .arrow .vector .types .Types ;
42
42
import org .apache .arrow .vector .types .pojo .Field ;
43
43
import org .apache .arrow .vector .types .pojo .Schema ;
44
- import org .junit .jupiter .api .AfterEach ;
44
+ import org .junit .jupiter .api .AfterAll ;
45
45
import org .junit .jupiter .api .Assertions ;
46
- import org .junit .jupiter .api .BeforeEach ;
47
- import org .junit .jupiter .api .Disabled ;
46
+ import org .junit .jupiter .api .BeforeAll ;
48
47
import org .junit .jupiter .api .Test ;
49
48
50
49
import com .google .common .base .Strings ;
@@ -57,18 +56,18 @@ public class TestBasicAuth2 {
57
56
private static final String NO_USERNAME = "" ;
58
57
private static final String PASSWORD_1 = "woohoo1" ;
59
58
private static final String PASSWORD_2 = "woohoo2" ;
60
- private BufferAllocator allocator ;
61
- private FlightServer server ;
62
- private FlightClient client ;
63
- private FlightClient client2 ;
59
+ private static BufferAllocator allocator ;
60
+ private static FlightServer server ;
61
+ private static FlightClient client ;
62
+ private static FlightClient client2 ;
64
63
65
- @ BeforeEach
66
- public void setup () throws Exception {
64
+ @ BeforeAll
65
+ public static void setup () throws Exception {
67
66
allocator = new RootAllocator (Long .MAX_VALUE );
68
67
startServerAndClient ();
69
68
}
70
69
71
- private FlightProducer getFlightProducer () {
70
+ private static FlightProducer getFlightProducer () {
72
71
return new NoOpFlightProducer () {
73
72
@ Override
74
73
public void listFlights (CallContext context , Criteria criteria ,
@@ -99,23 +98,26 @@ public void getStream(CallContext context, Ticket ticket, ServerStreamListener l
99
98
};
100
99
}
101
100
102
- private void startServerAndClient () throws IOException {
101
+ private static void startServerAndClient () throws IOException {
103
102
final FlightProducer flightProducer = getFlightProducer ();
104
- this . server = FlightServer
103
+ server = FlightServer
105
104
.builder (allocator , forGrpcInsecure (LOCALHOST , 0 ), flightProducer )
106
105
.headerAuthenticator (new GeneratedBearerTokenAuthenticator (
107
- new BasicCallHeaderAuthenticator (this ::validate )))
106
+ new BasicCallHeaderAuthenticator (TestBasicAuth2 ::validate )))
108
107
.build ().start ();
109
- this . client = FlightClient .builder (allocator , server .getLocation ())
108
+ client = FlightClient .builder (allocator , server .getLocation ())
110
109
.build ();
111
110
}
112
111
113
- @ AfterEach
114
- public void shutdown () throws Exception {
115
- AutoCloseables .close (client , client2 , server , allocator );
112
+ @ AfterAll
113
+ public static void shutdown () throws Exception {
114
+ AutoCloseables .close (client , client2 , server );
116
115
client = null ;
117
116
client2 = null ;
118
117
server = null ;
118
+
119
+ allocator .getChildAllocators ().forEach (BufferAllocator ::close );
120
+ AutoCloseables .close (allocator );
119
121
allocator = null ;
120
122
}
121
123
@@ -124,7 +126,7 @@ private void startClient2() throws IOException {
124
126
.build ();
125
127
}
126
128
127
- private CallHeaderAuthenticator .AuthResult validate (String username , String password ) {
129
+ private static CallHeaderAuthenticator .AuthResult validate (String username , String password ) {
128
130
if (Strings .isNullOrEmpty (username )) {
129
131
throw CallStatus .UNAUTHENTICATED .withDescription ("Credentials not supplied." ).toRuntimeException ();
130
132
}
@@ -156,14 +158,12 @@ public void validAuthWithMultipleClientsWithDifferentCredentialsWithBearerAuthSe
156
158
testValidAuthWithMultipleClientsWithDifferentCredentials (client , client2 );
157
159
}
158
160
159
- // ARROW-7722: this test occasionally leaks memory
160
- @ Disabled
161
161
@ Test
162
162
public void asyncCall () throws Exception {
163
163
final CredentialCallOption bearerToken = client
164
164
.authenticateBasicToken (USERNAME_1 , PASSWORD_1 ).get ();
165
165
client .listFlights (Criteria .ALL , bearerToken );
166
- try (final FlightStream s = client .getStream (new Ticket (new byte [1 ]))) {
166
+ try (final FlightStream s = client .getStream (new Ticket (new byte [1 ]), bearerToken )) {
167
167
while (s .next ()) {
168
168
Assertions .assertEquals (4095 , s .getRoot ().getRowCount ());
169
169
}
0 commit comments