@@ -31,94 +31,94 @@ class AmazonSnsThreadPoolExecutorTest {
3131
3232 @ Test
3333 void testSuccessCounters () throws Exception {
34- try ( final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 )) {
35- assertThat ( amazonSnsThreadPoolExecutor . getActiveTaskCount (), is ( 0 ));
36- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
37- assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (0 ));
38- assertThat (amazonSnsThreadPoolExecutor .getCorePoolSize (), is (0 ));
39- }
34+ final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 );
35+
36+ assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (0 ));
37+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
38+ assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (0 ));
39+ assertThat ( amazonSnsThreadPoolExecutor . getCorePoolSize (), is ( 0 ));
4040 }
4141
4242 @ Test
4343 void testSuccessSucceededTaskCount () throws Exception {
44- try (final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 )) {
45- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
44+ final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 );
4645
47- for (int i = 0 ; i < 300 ; i ++) {
48- amazonSnsThreadPoolExecutor .execute (() -> {
49- await ().pollDelay (1 , TimeUnit .MILLISECONDS ).until (() -> true );
50- });
51- }
46+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
5247
53- amazonSnsThreadPoolExecutor .shutdown ();
48+ for (int i = 0 ; i < 300 ; i ++) {
49+ amazonSnsThreadPoolExecutor .execute (() -> {
50+ await ().pollDelay (1 , TimeUnit .MILLISECONDS ).until (() -> true );
51+ });
52+ }
5453
55- if (!amazonSnsThreadPoolExecutor .awaitTermination (10 , TimeUnit .SECONDS )) {
56- amazonSnsThreadPoolExecutor .shutdownNow ();
57- }
54+ amazonSnsThreadPoolExecutor .shutdown ();
5855
59- assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (0 ));
60- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (300 ));
61- assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (0 ));
56+ if (!amazonSnsThreadPoolExecutor .awaitTermination (10 , TimeUnit .SECONDS )) {
57+ amazonSnsThreadPoolExecutor .shutdownNow ();
6258 }
59+
60+ assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (0 ));
61+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (300 ));
62+ assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (0 ));
6363 }
6464
6565 @ Test
6666 void testSuccessFailedTaskCount () throws Exception {
67- try (final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 )) {
68- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
67+ final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 );
6968
70- for (int i = 0 ; i < 300 ; i ++) {
71- amazonSnsThreadPoolExecutor .execute (() -> { throw new RuntimeException (); });
72- }
69+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
7370
74- amazonSnsThreadPoolExecutor .shutdown ();
71+ for (int i = 0 ; i < 300 ; i ++) {
72+ amazonSnsThreadPoolExecutor .execute (() -> { throw new RuntimeException (); });
73+ }
7574
76- if (!amazonSnsThreadPoolExecutor .awaitTermination (10 , TimeUnit .SECONDS )) {
77- amazonSnsThreadPoolExecutor .shutdownNow ();
78- }
75+ amazonSnsThreadPoolExecutor .shutdown ();
7976
80- assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (0 ));
81- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
82- assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (300 ));
77+ if (!amazonSnsThreadPoolExecutor .awaitTermination (10 , TimeUnit .SECONDS )) {
78+ amazonSnsThreadPoolExecutor .shutdownNow ();
8379 }
80+
81+ assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (0 ));
82+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
83+ assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (300 ));
8484 }
8585
8686 @ Test
8787 void testSuccessActiveTaskCount () throws Exception {
88- try (final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 )) {
89- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
90-
91- for (int i = 0 ; i < 10 ; i ++) {
92- amazonSnsThreadPoolExecutor .execute (() -> {
93- while (true ) {
94- await ().pollDelay (1 , TimeUnit .MILLISECONDS ).until (() -> true );
95- }
96- });
97- }
88+ final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (10 );
9889
99- amazonSnsThreadPoolExecutor .shutdown ();
100-
101- if (!amazonSnsThreadPoolExecutor .awaitTermination (10 , TimeUnit .SECONDS )) {
102- amazonSnsThreadPoolExecutor .shutdownNow ();
103- }
90+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
10491
105- assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (10 ));
106- assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
107- assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (0 ));
108- }
109- }
110-
111- @ Test
112- void testSuccessBlockingSubmissionPolicy () throws Exception {
113- try (final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (1 )) {
92+ for (int i = 0 ; i < 10 ; i ++) {
11493 amazonSnsThreadPoolExecutor .execute (() -> {
11594 while (true ) {
11695 await ().pollDelay (1 , TimeUnit .MILLISECONDS ).until (() -> true );
11796 }
11897 });
98+ }
11999
120- catchThrowableOfType (() -> amazonSnsThreadPoolExecutor .execute (() -> { }), RejectedExecutionException .class );
100+ amazonSnsThreadPoolExecutor .shutdown ();
101+
102+ if (!amazonSnsThreadPoolExecutor .awaitTermination (10 , TimeUnit .SECONDS )) {
103+ amazonSnsThreadPoolExecutor .shutdownNow ();
121104 }
105+
106+ assertThat (amazonSnsThreadPoolExecutor .getActiveTaskCount (), is (10 ));
107+ assertThat (amazonSnsThreadPoolExecutor .getSucceededTaskCount (), is (0 ));
108+ assertThat (amazonSnsThreadPoolExecutor .getFailedTaskCount (), is (0 ));
109+ }
110+
111+ @ Test
112+ void testSuccessBlockingSubmissionPolicy () throws Exception {
113+ final AmazonSnsThreadPoolExecutor amazonSnsThreadPoolExecutor = new AmazonSnsThreadPoolExecutor (1 );
114+
115+ amazonSnsThreadPoolExecutor .execute (() -> {
116+ while (true ) {
117+ await ().pollDelay (1 , TimeUnit .MILLISECONDS ).until (() -> true );
118+ }
119+ });
120+
121+ catchThrowableOfType (() -> amazonSnsThreadPoolExecutor .execute (() -> { }), RejectedExecutionException .class );
122122 }
123123
124124}
0 commit comments