-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathSQSConnectionTest.java
More file actions
793 lines (679 loc) · 24.7 KB
/
SQSConnectionTest.java
File metadata and controls
793 lines (679 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
/*
* Copyright 2010-2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazon.sqs.javamessaging;
import jakarta.jms.ExceptionListener;
import jakarta.jms.IllegalStateException;
import jakarta.jms.InvalidClientIDException;
import jakarta.jms.JMSException;
import jakarta.jms.Queue;
import jakarta.jms.Session;
import jakarta.jms.Topic;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
/**
* Test the SQSConnectionTest class
*/
public class SQSConnectionTest {
public static final String QUEUE_URL = "QueueUrl";
public static final String QUEUE_NAME = "QueueName";
private SQSConnection sqsConnection;
private SQSQueueDestination destination;
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
private SQSSession session1;
private SQSSession session2;
@BeforeEach
public void setup() throws JMSException {
destination = new SQSQueueDestination(QUEUE_NAME, QUEUE_URL);
int numberOfMessagesToPrefetch = 10;
AmazonSQSMessagingClientWrapper amazonSQSClientJMSWrapper = mock(AmazonSQSMessagingClientWrapper.class);
sqsConnection = spy(new SQSConnection(amazonSQSClientJMSWrapper, numberOfMessagesToPrefetch, false));
session1 = mock(SQSSession.class);
session2 = mock(SQSSession.class);
sqsConnection.getSessions().add(session1);
sqsConnection.getSessions().add(session2);
}
/**
* Test unsupported features
*/
@Test
public void testUnsupportedFeatures() {
assertThatThrownBy(() -> sqsConnection.createConnectionConsumer(destination, "messageSelector", null, 10))
.isInstanceOf(JMSException.class);
Topic topic = mock(Topic.class);
assertThatThrownBy(() -> sqsConnection.createDurableConnectionConsumer(topic, "subscriptionName", "messageSelector", null, 10))
.isInstanceOf(JMSException.class);
Queue queue = mock(Queue.class);
assertThatThrownBy(() -> sqsConnection.createConnectionConsumer(queue, "messageSelector", null, 10))
.isInstanceOf(JMSException.class);
}
/**
* Test set client id when connection is closing
*/
@Test
public void testSetClientIdWhenClosing() {
sqsConnection.setClosing(true);
assertThatThrownBy(() -> sqsConnection.setClientID("clientId"))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed or closing");
}
/**
* Test set client id on an invalid client id
*/
@Test
public void testSetClientIdInvalidClientId() {
assertThatThrownBy(() -> sqsConnection.setClientID(null))
.isInstanceOf(InvalidClientIDException.class)
.hasMessage("ClientID is empty");
assertThatThrownBy(() -> sqsConnection.setClientID(""))
.isInstanceOf(InvalidClientIDException.class)
.hasMessage("ClientID is empty");
}
/**
* Test set client id when action on connection is already made
*/
@Test
public void testSetClientIdActionTaken() {
sqsConnection.setActionOnConnectionTaken(true);
assertThatThrownBy(() -> sqsConnection.setClientID("id"))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Client ID cannot be set after any action on the connection is taken");
}
/**
* Test set client id
*/
@Test
public void testSetClientId() throws JMSException {
sqsConnection.setClientID("id");
assertThatThrownBy(() -> sqsConnection.setClientID("id2"))
.isInstanceOf(IllegalStateException.class)
.hasMessage("ClientID is already set");
assertEquals("id", sqsConnection.getClientID());
}
/**
* Test closing
*/
@Test
public void testClosing() throws JMSException {
sqsConnection.checkClosing();
sqsConnection.setClosing(true);
assertThatThrownBy(() -> sqsConnection.checkClosing())
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed or closing");
}
/**
* Test check closed
*/
@Test
public void testCheckClosed() throws JMSException {
sqsConnection.checkClosed();
sqsConnection.setClosed(true);
assertThatThrownBy(() -> sqsConnection.checkClosed())
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed");
}
/**
* Test exception listener
*/
@Test
public void testExceptionListener() throws JMSException {
ExceptionListener listener = mock(ExceptionListener.class);
sqsConnection.setExceptionListener(listener);
assertTrue(sqsConnection.isActionOnConnectionTaken());
assertEquals(listener, sqsConnection.getExceptionListener());
}
/**
* Test close when connection is already closed
*/
@Test
public void testCloseWhenAlreadyClosed() throws JMSException {
/*
* Set up connection
*/
sqsConnection.setClosed(true);
/*
* Do close
*/
sqsConnection.close();
/*
* Verify results
*/
verify(session1, never()).close();
verify(session2, never()).close();
}
/**
* Test close when connection is closing
*/
@Test
public void testCloseWhenClosing() throws JMSException, InterruptedException {
/*
* Set up connection and mocks
*/
sqsConnection.setClosing(true);
final CountDownLatch beforeCloseCall = new CountDownLatch(1);
final CountDownLatch passedCloseCall = new CountDownLatch(1);
/*
* call close in different thread
*/
executorService.execute(() -> {
try {
beforeCloseCall.countDown();
sqsConnection.close();
passedCloseCall.countDown();
} catch (JMSException e) {
e.printStackTrace();
}
});
// Yield execution to allow the connection to wait
assertTrue(beforeCloseCall.await(10, TimeUnit.SECONDS));
Thread.sleep(10);
// Release the lock and ensure that we are still waiting since the did not run
synchronized (sqsConnection.getStateLock()) {
sqsConnection.getStateLock().notifyAll();
}
assertFalse(passedCloseCall.await(2, TimeUnit.SECONDS));
// Simulate connection closed
sqsConnection.setClosed(true);
synchronized (sqsConnection.getStateLock()) {
sqsConnection.getStateLock().notifyAll();
}
passedCloseCall.await();
verify(session1, never()).close();
verify(session2, never()).close();
}
/**
* Test close
*/
@Test
public void testClose() throws JMSException {
/*
* Close
*/
sqsConnection.close();
/*
* Verify results
*/
verify(session1).close();
verify(session1).close();
assertTrue(sqsConnection.getSessions().isEmpty());
}
/**
* Test close from the callback thread
*/
@Test
public void testCloseThreadGroup() throws InterruptedException {
final AtomicBoolean flag = new AtomicBoolean(false);
final CountDownLatch passedCloseCall = new CountDownLatch(1);
Thread t = SQSSession.SESSION_THREAD_FACTORY.newThread(() -> {
try {
sqsConnection.close();
} catch (IllegalStateException e) {
flag.set(true);
} catch (JMSException e) {
e.printStackTrace();
}
passedCloseCall.countDown();
});
t.start();
/*
* Verify results
*/
passedCloseCall.await();
assertTrue(flag.get());
}
/**
* Test stop is a no op if already closed
*/
@Test
public void testStopNoOpIfAlreadyClosed() throws JMSException {
/*
* Set up connection
*/
sqsConnection.close();
/*
* stop consumer
*/
assertThatThrownBy(() -> sqsConnection.stop())
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed");
/*
* Verify results
*/
verify(session1, never()).stop();
verify(session2, never()).stop();
}
/**
* Test stop is a no op if already closed
*/
@Test
public void testStopNoOpIfNotRunning() throws JMSException {
/*
* Set up connection
*/
sqsConnection.setRunning(false);
/*
* stop connection
*/
sqsConnection.stop();
/*
* Verify results
*/
verify(session1, never()).stop();
verify(session2, never()).stop();
}
/**
* Test close from the callback thread
*/
@Test
public void testStopThreadGroup() throws JMSException, InterruptedException {
/*
* Set up connection
*/
final AtomicBoolean flag = new AtomicBoolean(false);
final CountDownLatch passedStopCall = new CountDownLatch(1);
sqsConnection.setRunning(true);
Thread t = SQSSession.SESSION_THREAD_FACTORY.newThread(() -> {
try {
sqsConnection.close();
} catch (IllegalStateException e) {
flag.set(true);
} catch (JMSException e) {
e.printStackTrace();
}
passedStopCall.countDown();
});
t.start();
/*
* Verify results
*/
passedStopCall.await();
assertTrue(flag.get());
verify(session1, never()).stop();
verify(session2, never()).stop();
}
/**
* Test stop when connection is closing
*/
@Test
public void testStopWhenClosing() throws JMSException {
/*
* Set up connection
*/
sqsConnection.setClosing(true);
sqsConnection.setRunning(true);
assertThatThrownBy(() -> sqsConnection.stop())
.isInstanceOf(IllegalStateException.class);
/*
* Verify results
*/
verify(session1, never()).stop();
verify(session2, never()).stop();
}
/**
* Test stop blocks on state lock
*/
@Test
public void testStopBlocksOnStateLock() throws InterruptedException, IllegalStateException {
/*
* Set up the latches and mocks
*/
final CountDownLatch mainRelease = new CountDownLatch(1);
final CountDownLatch holdStateLock = new CountDownLatch(1);
final CountDownLatch beforeConnectionStopCall = new CountDownLatch(1);
final CountDownLatch passedConnectionStopCall = new CountDownLatch(1);
sqsConnection.setRunning(true);
// Run a thread to hold the stateLock
executorService.execute(() -> {
try {
synchronized (sqsConnection.getStateLock()) {
holdStateLock.countDown();
mainRelease.await();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
// Waiting for the thread to hold state lock
holdStateLock.await();
// Run another thread that tries to start the connection while state lock is been held
executorService.execute(() -> {
try {
beforeConnectionStopCall.countDown();
sqsConnection.stop();
passedConnectionStopCall.countDown();
} catch (JMSException e) {
e.printStackTrace();
}
});
beforeConnectionStopCall.await();
Thread.sleep(10);
// Ensure that we wait on state lock
assertFalse(passedConnectionStopCall.await(2, TimeUnit.SECONDS));
// Release the thread holding the state lock
mainRelease.countDown();
// Ensure that the session start completed
passedConnectionStopCall.await();
verify(session1).stop();
verify(session2).stop();
assertFalse(sqsConnection.isRunning());
}
/**
* Test start is a no op if already closed
*/
@Test
public void testStartNoOpIfAlreadyClosed() throws JMSException {
/*
* Set up connection
*/
sqsConnection.close();
/*
* Start connection
*/
assertThatThrownBy(() -> sqsConnection.start())
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed");
/*
* Verify results
*/
verify(session1, never()).start();
verify(session2, never()).start();
}
/**
* Test start is a no op if closing
*/
@Test
public void testStartNoOpIfClosing() throws JMSException {
/*
* Set up session
*/
sqsConnection.setClosing(true);
/*
* Start connection
*/
assertThatThrownBy(() -> sqsConnection.start())
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed or closing");
/*
* Verify results
*/
verify(session1, never()).start();
verify(session2, never()).start();
}
/**
* Test start is a no op if closing
*/
@Test
public void testStartNoOpIfRunning() throws JMSException {
/*
* Set up session
*/
sqsConnection.setRunning(true);
/*
* Start connection
*/
sqsConnection.start();
/*
* Verify results
*/
verify(session1, never()).start();
verify(session2, never()).start();
}
/**
* Test start blocks on state lock
*/
@Test
public void testStartBlocksOnStateLock() throws InterruptedException, IllegalStateException {
/*
* Set up the latches and mocks
*/
final CountDownLatch mainRelease = new CountDownLatch(1);
final CountDownLatch holdStateLock = new CountDownLatch(1);
final CountDownLatch beforeConnectionStartCall = new CountDownLatch(1);
final CountDownLatch passedConnectionStartCall = new CountDownLatch(1);
// Run a thread to hold the stateLock
executorService.execute(() -> {
try {
synchronized (sqsConnection.getStateLock()) {
holdStateLock.countDown();
mainRelease.await();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
// Waiting for the thread to hold state lock
holdStateLock.await();
// Run another thread that tries to start the connection while state lock is been held
executorService.execute(() -> {
try {
beforeConnectionStartCall.countDown();
sqsConnection.start();
passedConnectionStartCall.countDown();
} catch (JMSException e) {
e.printStackTrace();
}
});
beforeConnectionStartCall.await();
Thread.sleep(10);
// Ensure that we wait on state lock
assertFalse(passedConnectionStartCall.await(2, TimeUnit.SECONDS));
// Release the thread holding the state lock
mainRelease.countDown();
// Ensure that the connection start completed
passedConnectionStartCall.await();
verify(session1).start();
verify(session2).start();
assertTrue(sqsConnection.isRunning());
}
/**
* Test create session is a no op if already closed
*/
@Test
public void testCreateSessionNoOpIfAlreadyClosed() throws JMSException {
/*
* Set up connection
*/
sqsConnection.setClosed(true);
/*
* Create session
*/
assertThatThrownBy(() -> sqsConnection.createSession(true, 1))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed");
assertThatThrownBy(() -> sqsConnection.createSession(false, 1))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed");
/*
* Verify results
*/
verify(session1, never()).start();
verify(session2, never()).start();
}
/**
* Test create session throws correct exception when using unsupported features
*/
@Test
public void testCreateSessionUnsupportedFeatures() throws JMSException {
assertThatThrownBy(() -> sqsConnection.createSession(true, Session.AUTO_ACKNOWLEDGE))
.isInstanceOf(JMSException.class)
.hasMessage("SQSSession does not support transacted");
assertThatThrownBy(() -> sqsConnection.createSession(false, Session.SESSION_TRANSACTED))
.isInstanceOf(JMSException.class)
.hasMessage("SQSSession does not support transacted");
/*
* Verify results
*/
verify(session1, never()).start();
verify(session2, never()).start();
}
/**
* Test create session when connection is closing
*/
@Test
public void testCreateSessionWhenClosing() {
/*
* Set up connection
*/
sqsConnection.setClosing(true);
/*
* Start connection
*/
assertThatThrownBy(() -> sqsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Connection is closed or closing");
/*
* Verify results
*/
assertEquals(2, sqsConnection.getSessions().size());
}
/**
* Test create session
*/
@Test
public void testCreateSessionUnknownAckMode() {
/*
* Create session
*/
assertThatThrownBy(() -> sqsConnection.createSession(false, 42))
.isInstanceOf(JMSException.class)
.hasMessage("Unrecognized acknowledgeMode. Cannot create Session.");
/*
* Verify results
*/
assertEquals(2, sqsConnection.getSessions().size());
}
/**
* Test create session when connection running
*/
@Test
public void testCreateSessionWhenConnectionRunning() throws JMSException {
sqsConnection.setRunning(true);
SQSSession session = (SQSSession) sqsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertEquals(Session.AUTO_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertTrue(session.isRunning());
session = (SQSSession) sqsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
assertEquals(Session.CLIENT_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertTrue(session.isRunning());
session = (SQSSession) sqsConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
assertEquals(Session.DUPS_OK_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertTrue(session.isRunning());
session = (SQSSession) sqsConnection.createSession(false, SQSSession.UNORDERED_ACKNOWLEDGE);
assertTrue(session.isRunning());
assertEquals(SQSSession.UNORDERED_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertTrue(session.isRunning());
/*
* Verify results
*/
assertEquals(6, sqsConnection.getSessions().size());
}
/**
* Test create session when connection running
*/
@Test
public void testCreateSessionWhenConnectionStopped() throws JMSException {
sqsConnection.setRunning(false);
SQSSession session = (SQSSession) sqsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertEquals(Session.AUTO_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertFalse(session.isRunning());
session = (SQSSession) sqsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
assertEquals(Session.CLIENT_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertFalse(session.isRunning());
session = (SQSSession) sqsConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
assertEquals(Session.DUPS_OK_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertFalse(session.isRunning());
session = (SQSSession) sqsConnection.createSession(false, SQSSession.UNORDERED_ACKNOWLEDGE);
assertFalse(session.isRunning());
assertEquals(SQSSession.UNORDERED_ACKNOWLEDGE, session.getAcknowledgeMode());
assertEquals(sqsConnection, session.getParentConnection());
assertTrue(sqsConnection.getSessions().contains(session));
assertFalse(session.isRunning());
/*
* Verify results
*/
assertEquals(6, sqsConnection.getSessions().size());
}
/**
* Test CreateSession blocks on state lock
*/
@Test
public void testCreateSessionBlocksOnStateLock() throws InterruptedException {
/*
* Set up the latches and mocks
*/
final CountDownLatch mainRelease = new CountDownLatch(1);
final CountDownLatch holdStateLock = new CountDownLatch(1);
final CountDownLatch beforeCreateSessionStartCall = new CountDownLatch(1);
final CountDownLatch passedCreateSessionStartCall = new CountDownLatch(1);
// Run a thread to hold the stateLock
executorService.execute(() -> {
try {
synchronized (sqsConnection.getStateLock()) {
holdStateLock.countDown();
mainRelease.await();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
});
// Waiting for the thread to hold state lock
holdStateLock.await();
// Run another thread that tries to start the connection while state lock is been held
executorService.execute(() -> {
try {
beforeCreateSessionStartCall.countDown();
sqsConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
passedCreateSessionStartCall.countDown();
} catch (JMSException e) {
e.printStackTrace();
}
});
beforeCreateSessionStartCall.await();
Thread.sleep(10);
// Ensure that we wait on state lock
assertFalse(passedCreateSessionStartCall.await(2, TimeUnit.SECONDS));
assertEquals(2, sqsConnection.getSessions().size());
// Release the thread holding the state lock
mainRelease.countDown();
// Ensure that the session start completed
passedCreateSessionStartCall.await();
assertEquals(3, sqsConnection.getSessions().size());
}
}