50
50
import java .util .Collection ;
51
51
import java .util .Collections ;
52
52
import java .util .HashMap ;
53
+ import java .util .concurrent .atomic .AtomicReference ;
53
54
import org .junit .jupiter .api .AfterEach ;
54
55
import org .junit .jupiter .api .BeforeEach ;
55
56
import org .junit .jupiter .api .Test ;
@@ -62,15 +63,16 @@ class LongPollServiceTest {
62
63
private Server server ;
63
64
private LongPollService longPollService ;
64
65
65
- private PollRequest request ;
66
+ private final AtomicReference < PollRequest > request = new AtomicReference <>( null ) ;
66
67
private PollResponse response ;
67
68
private Throwable responseError ;
68
69
private int port ;
70
+ private GrpcService grpcService ;
69
71
70
72
@ BeforeEach
71
73
void setUp () throws IOException {
72
74
final TestPollService testPollService = new TestPollService ((req , responseObserver ) -> {
73
- request = req ;
75
+ request . set ( req ) ;
74
76
if (responseError != null ) {
75
77
responseObserver .onError (responseError );
76
78
} else {
@@ -92,14 +94,18 @@ void setUp() throws IOException {
92
94
agentArgs .put (ISettings .KEY_SERVICE_URL , "localhost:" + port );
93
95
agentArgs .put (ISettings .KEY_SERVICE_SECURE , "false" );
94
96
final Settings settings = Settings .build (agentArgs );
97
+ settings .setActive (true );
95
98
settings .setResource (Resource .create (Collections .singletonMap ("test" , "resource" )));
96
- final GrpcService grpcService = new GrpcService (settings );
99
+ grpcService = new GrpcService (settings );
97
100
longPollService = new LongPollService (settings , grpcService );
98
101
}
99
102
100
103
@ AfterEach
101
- void tearDown () {
104
+ void tearDown () throws Exception {
102
105
server .shutdownNow ();
106
+ server .awaitTermination ();
107
+
108
+ grpcService .shutdown ();
103
109
}
104
110
105
111
@ Test
@@ -148,15 +154,15 @@ void propagateHashOnNextCall() {
148
154
149
155
longPollService .run (100 );
150
156
151
- assertEquals ("" , request .getCurrentHash ());
152
- assertEquals (100 , request .getTsNanos ());
157
+ assertEquals ("" , request .get (). getCurrentHash ());
158
+ assertEquals (100 , request .get (). getTsNanos ());
153
159
154
160
response = PollResponse .newBuilder ().setResponseType (ResponseType .UPDATE ).setCurrentHash ("321" ).build ();
155
161
156
162
longPollService .run (101 );
157
163
158
- assertEquals ("123" , request .getCurrentHash ());
159
- assertEquals (101 , request .getTsNanos ());
164
+ assertEquals ("123" , request .get (). getCurrentHash ());
165
+ assertEquals (101 , request .get (). getTsNanos ());
160
166
verify (instrumentationService , times (2 )).processBreakpoints (Mockito .anyCollection ());
161
167
}
162
168
@@ -204,8 +210,8 @@ void doesSendResourceOnRequest() {
204
210
205
211
longPollService .run (100 );
206
212
207
- assertNotNull (request .getResource ());
208
- assertEquals ("test" , request .getResource ().getAttributes (0 ).getKey ());
209
- assertEquals ("resource" , request .getResource ().getAttributes (0 ).getValue ().getStringValue ());
213
+ assertNotNull (request .get (). getResource ());
214
+ assertEquals ("test" , request .get (). getResource ().getAttributes (0 ).getKey ());
215
+ assertEquals ("resource" , request .get (). getResource ().getAttributes (0 ).getValue ().getStringValue ());
210
216
}
211
217
}
0 commit comments