@@ -170,7 +170,7 @@ private void waitUntilAddedToQueue(SessionRequest request) {
170
170
@ MethodSource ("data" )
171
171
void shouldBeAbleToAddToQueueAndGetValidResponse (Supplier <TestData > supplier ) {
172
172
setup (supplier );
173
-
173
+
174
174
AtomicBoolean isPresent = new AtomicBoolean (false );
175
175
176
176
new Thread (
@@ -207,112 +207,125 @@ void shouldBeAbleToAddToQueueAndGetValidResponse(Supplier<TestData> supplier) {
207
207
assertThat (isPresent .get ()).isTrue ();
208
208
assertEquals (HTTP_OK , httpResponse .getStatus ());
209
209
}
210
-
211
210
212
211
@ ParameterizedTest
213
212
@ MethodSource ("data" )
214
- void shouldBeAbleToAddToQueueWithTimeoutAndGetValidResponse (Supplier <TestData > supplier ) {
213
+ void shouldBeAbleToAddToQueueWithTimeoutAndGetValidResponse (Supplier <TestData > supplier ) {
215
214
setup (supplier );
216
215
217
- SessionRequest sessionRequestWithTimeout = new SessionRequest (
218
- new RequestId (UUID .randomUUID ()),
219
- Instant .now (),
220
- Set .of (W3C ),
221
- Set .of (CAPS ),
222
- Map .of (),
223
- Map .of ());
216
+ SessionRequest sessionRequestWithTimeout =
217
+ new SessionRequest (
218
+ new RequestId (UUID .randomUUID ()),
219
+ Instant .now (),
220
+ Set .of (W3C ),
221
+ Set .of (CAPS ),
222
+ Map .of (),
223
+ Map .of ());
224
224
225
225
AtomicBoolean isPresent = new AtomicBoolean (false );
226
226
227
- new Thread (() -> {
228
- waitUntilAddedToQueue (sessionRequestWithTimeout );
229
- isPresent .set (true );
230
-
231
- Capabilities capabilities = new ImmutableCapabilities ("browserName" , "chrome" );
232
-
233
- try {
234
- Thread .sleep (4000 ); // simulate session waiting in queue
235
- } catch (InterruptedException e ) {}
236
-
237
- // remove request from queue
238
- Map <Capabilities , Long > stereotypes = new HashMap <>();
239
- stereotypes .put (new ImmutableCapabilities ("browserName" , "cheese" ), 1L );
240
- List <SessionRequest > requests = queue .getNextAvailable (stereotypes );
241
-
242
- SessionId sessionId = new SessionId ("123" );
243
- Session session =
244
- new Session (
245
- sessionId ,
246
- URI .create ("https://example.com" ),
247
- CAPS ,
248
- capabilities ,
249
- Instant .now ());
250
- CreateSessionResponse sessionResponse = new CreateSessionResponse (
251
- session ,
252
- JSON .toJson (
253
- ImmutableMap .of (
254
- "value" , ImmutableMap .of (
255
- "sessionId" , sessionId ,
256
- "capabilities" , capabilities )))
257
- .getBytes (UTF_8 ));
258
-
259
- try {
260
- Thread .sleep (2000 ); // simulate session creation delay
261
- } catch (InterruptedException e ) {}
262
- queue .complete (sessionRequestWithTimeout .getRequestId (), Either .right (sessionResponse ));
263
- }).start ();
227
+ new Thread (
228
+ () -> {
229
+ waitUntilAddedToQueue (sessionRequestWithTimeout );
230
+ isPresent .set (true );
231
+
232
+ Capabilities capabilities = new ImmutableCapabilities ("browserName" , "chrome" );
233
+
234
+ try {
235
+ Thread .sleep (4000 ); // simulate session waiting in queue
236
+ } catch (InterruptedException ignore ) {
237
+ }
238
+
239
+ // remove request from queue
240
+ Map <Capabilities , Long > stereotypes = new HashMap <>();
241
+ stereotypes .put (new ImmutableCapabilities ("browserName" , "cheese" ), 1L );
242
+ queue .getNextAvailable (stereotypes );
243
+
244
+ SessionId sessionId = new SessionId ("123" );
245
+ Session session =
246
+ new Session (
247
+ sessionId ,
248
+ URI .create ("https://example.com" ),
249
+ CAPS ,
250
+ capabilities ,
251
+ Instant .now ());
252
+ CreateSessionResponse sessionResponse =
253
+ new CreateSessionResponse (
254
+ session ,
255
+ JSON .toJson (
256
+ ImmutableMap .of (
257
+ "value" ,
258
+ ImmutableMap .of (
259
+ "sessionId" , sessionId ,
260
+ "capabilities" , capabilities )))
261
+ .getBytes (UTF_8 ));
262
+
263
+ try {
264
+ Thread .sleep (2000 ); // simulate session creation delay
265
+ } catch (InterruptedException ignore ) {
266
+ }
267
+ queue .complete (
268
+ sessionRequestWithTimeout .getRequestId (), Either .right (sessionResponse ));
269
+ })
270
+ .start ();
264
271
265
272
HttpResponse httpResponse = queue .addToQueue (sessionRequestWithTimeout );
266
273
267
274
assertThat (isPresent .get ()).isTrue ();
268
275
assertEquals (HTTP_OK , httpResponse .getStatus ());
269
276
}
270
277
271
-
272
278
@ ParameterizedTest
273
279
@ MethodSource ("data" )
274
- void shouldBeAbleToAddToQueueWithTimeoutAndTimeoutResponse (Supplier <TestData > supplier ) {
280
+ void shouldBeAbleToAddToQueueWithTimeoutAndTimeoutResponse (Supplier <TestData > supplier ) {
275
281
setup (supplier );
276
282
277
- SessionRequest sessionRequestWithTimeout = new SessionRequest (
278
- new RequestId (UUID .randomUUID ()),
279
- Instant .now (),
280
- Set .of (W3C ),
281
- Set .of (CAPS ),
282
- Map .of (),
283
- Map .of ());
283
+ SessionRequest sessionRequestWithTimeout =
284
+ new SessionRequest (
285
+ new RequestId (UUID .randomUUID ()),
286
+ Instant .now (),
287
+ Set .of (W3C ),
288
+ Set .of (CAPS ),
289
+ Map .of (),
290
+ Map .of ());
284
291
285
292
AtomicBoolean isPresent = new AtomicBoolean (false );
286
293
287
- new Thread (() -> {
288
- waitUntilAddedToQueue (sessionRequestWithTimeout );
289
- isPresent .set (true );
290
-
291
- Capabilities capabilities = new ImmutableCapabilities ("browserName" , "chrome" );
292
-
293
- try {
294
- Thread .sleep (5500 ); // simulate session waiting in queue
295
- } catch (InterruptedException e ) {}
296
-
297
- SessionId sessionId = new SessionId ("123" );
298
- Session session =
299
- new Session (
300
- sessionId ,
301
- URI .create ("https://example.com" ),
302
- CAPS ,
303
- capabilities ,
304
- Instant .now ());
305
- CreateSessionResponse sessionResponse = new CreateSessionResponse (
306
- session ,
307
- JSON .toJson (
308
- ImmutableMap .of (
309
- "value" , ImmutableMap .of (
310
- "sessionId" , sessionId ,
311
- "capabilities" , capabilities )))
312
- .getBytes (UTF_8 ));
313
-
314
- queue .complete (sessionRequestWithTimeout .getRequestId (), Either .right (sessionResponse ));
315
- }).start ();
294
+ new Thread (
295
+ () -> {
296
+ waitUntilAddedToQueue (sessionRequestWithTimeout );
297
+ isPresent .set (true );
298
+
299
+ Capabilities capabilities = new ImmutableCapabilities ("browserName" , "chrome" );
300
+
301
+ try {
302
+ Thread .sleep (5500 ); // simulate session waiting in queue
303
+ } catch (InterruptedException ignore ) {
304
+ }
305
+
306
+ SessionId sessionId = new SessionId ("123" );
307
+ Session session =
308
+ new Session (
309
+ sessionId ,
310
+ URI .create ("https://example.com" ),
311
+ CAPS ,
312
+ capabilities ,
313
+ Instant .now ());
314
+ CreateSessionResponse sessionResponse =
315
+ new CreateSessionResponse (
316
+ session ,
317
+ JSON .toJson (
318
+ ImmutableMap .of (
319
+ "value" ,
320
+ ImmutableMap .of (
321
+ "sessionId" , sessionId ,
322
+ "capabilities" , capabilities )))
323
+ .getBytes (UTF_8 ));
324
+
325
+ queue .complete (
326
+ sessionRequestWithTimeout .getRequestId (), Either .right (sessionResponse ));
327
+ })
328
+ .start ();
316
329
317
330
HttpResponse httpResponse = queue .addToQueue (sessionRequestWithTimeout );
318
331
0 commit comments