@@ -25,123 +25,111 @@ public void someLibraryMethodReturnsTrue() {
25
25
26
26
@ Test
27
27
@ Order (2 )
28
- @ RunMode (ExecutionMode .CONCURRENT )
29
- public void concurrentLibraryTest () throws InterruptedException {
28
+ @ RunMode (ExecutionMode .SEQUENTIAL )
29
+ public void sequentialLibraryTest () {
30
30
ListSynchronization classUnderTest = new ListSynchronization ();
31
31
int iterations = 10 ;
32
- CountDownLatch latch = new CountDownLatch (iterations );
33
- ThreadPool threadPool = new ThreadPool (Runtime .getRuntime ().availableProcessors ());
34
32
AtomicBoolean hasFailed = new AtomicBoolean (false );
35
33
36
34
long startTime = System .nanoTime ();
37
35
for (int i = 0 ; i < iterations ; i ++) {
38
- threadPool .submitTask (() -> {
39
- try {
40
- if (!classUnderTest .delayedMethod (5000 )) {
41
- hasFailed .set (true );
42
- }
43
- } finally {
44
- latch .countDown ();
45
- }
46
- });
36
+ if (!classUnderTest .add (5000 )) {
37
+ hasFailed .set (true );
38
+ }
47
39
}
48
-
49
- latch .await ();
50
- threadPool .shutdown ();
51
40
long endTime = System .nanoTime ();
52
41
53
42
double executionTime = (endTime - startTime ) / 1_000_000.0 ;
54
- System .out .printf ("Concurrent test with %d threads completed in %.2f ms%n" , Runtime . getRuntime (). availableProcessors () , executionTime );
43
+ System .out .printf ("Sequential test completed in %.2f ms%n" , executionTime );
55
44
56
- assertFalse ("Concurrent test should not have any failures" , hasFailed .get ());
57
- assertTrue ("Concurrent test should complete in a reasonable time" , executionTime < 60000 );
45
+ assertFalse ("Sequential test should not have any failures" , hasFailed .get ());
46
+ assertTrue ("Sequential test should complete in a reasonable time" , executionTime < 60000 );
58
47
}
59
48
60
49
@ Test
61
50
@ Order (3 )
62
51
@ RunMode (ExecutionMode .SEQUENTIAL )
63
- public void sequentialLibraryTest () {
52
+ public void sequentialLibraryTestShortDelay () {
64
53
ListSynchronization classUnderTest = new ListSynchronization ();
65
- int iterations = 10 ;
54
+ int iterations = 10 ;
66
55
AtomicBoolean hasFailed = new AtomicBoolean (false );
67
56
68
57
long startTime = System .nanoTime ();
69
58
for (int i = 0 ; i < iterations ; i ++) {
70
- if (!classUnderTest .delayedMethod ( 5000 )) {
59
+ if (!classUnderTest .update ( 1000 )) {
71
60
hasFailed .set (true );
72
61
}
73
62
}
74
63
long endTime = System .nanoTime ();
75
64
76
65
double executionTime = (endTime - startTime ) / 1_000_000.0 ;
77
- System .out .printf ("Sequential test completed in %.2f ms%n" , executionTime );
66
+ System .out .printf ("Sequential test with short delay completed in %.2f ms%n" , executionTime );
78
67
79
- assertFalse ("Sequential test should not have any failures" , hasFailed .get ());
80
- assertTrue ("Sequential test should complete in a reasonable time" , executionTime < 60000 );
68
+ assertFalse ("Sequential test with short delay should not have any failures" , hasFailed .get ());
69
+ assertTrue ("Sequential test with short delay should complete in a reasonable time" , executionTime < 60000 );
81
70
}
82
71
83
-
84
72
@ Test
85
73
@ Order (4 )
86
- @ RunMode (ExecutionMode .CONCURRENT )
87
- public void concurrentLibraryTestShortDelay () throws InterruptedException {
74
+ @ RunMode (ExecutionMode .SEQUENTIAL )
75
+ public void sequentialLibraryTestMediumDelay () {
88
76
ListSynchronization classUnderTest = new ListSynchronization ();
89
77
int iterations = 10 ;
90
- CountDownLatch latch = new CountDownLatch (iterations );
91
- ThreadPool threadPool = new ThreadPool (Runtime .getRuntime ().availableProcessors ());
92
78
AtomicBoolean hasFailed = new AtomicBoolean (false );
93
79
94
80
long startTime = System .nanoTime ();
95
81
for (int i = 0 ; i < iterations ; i ++) {
96
- threadPool .submitTask (() -> {
97
- try {
98
- if (!classUnderTest .delayedMethod (1000 )) {
99
- hasFailed .set (true );
100
- }
101
- } finally {
102
- latch .countDown ();
103
- }
104
- });
82
+ if (!classUnderTest .delete (3000 )) {
83
+ hasFailed .set (true );
84
+ }
105
85
}
106
-
107
- latch .await ();
108
- threadPool .shutdown ();
109
86
long endTime = System .nanoTime ();
110
87
111
88
double executionTime = (endTime - startTime ) / 1_000_000.0 ;
112
- System .out .printf ("Concurrent test with short delay and %d threads completed in %.2f ms%n" , Runtime . getRuntime (). availableProcessors () , executionTime );
89
+ System .out .printf ("Sequential test with medium delay completed in %.2f ms%n" , executionTime );
113
90
114
- assertFalse ("Concurrent test with short delay should not have any failures" , hasFailed .get ());
115
- assertTrue ("Concurrent test with short delay should complete in a reasonable time" , executionTime < 60000 );
91
+ assertFalse ("Sequential test with medium delay should not have any failures" , hasFailed .get ());
92
+ assertTrue ("Sequential test with medium delay should complete in a reasonable time" , executionTime < 60000 );
116
93
}
117
94
118
95
@ Test
119
96
@ Order (5 )
120
- @ RunMode (ExecutionMode .SEQUENTIAL )
121
- public void sequentialLibraryTestShortDelay () {
97
+ @ RunMode (ExecutionMode .CONCURRENT )
98
+ public void concurrentLibraryTestMediumDelay () throws InterruptedException {
122
99
ListSynchronization classUnderTest = new ListSynchronization ();
123
100
int iterations = 10 ;
101
+ CountDownLatch latch = new CountDownLatch (iterations );
102
+ ThreadPool threadPool = new ThreadPool (Runtime .getRuntime ().availableProcessors ());
124
103
AtomicBoolean hasFailed = new AtomicBoolean (false );
125
104
126
105
long startTime = System .nanoTime ();
127
106
for (int i = 0 ; i < iterations ; i ++) {
128
- if (!classUnderTest .delayedMethod (1000 )) {
129
- hasFailed .set (true );
130
- }
107
+ threadPool .submitTask (() -> {
108
+ try {
109
+ if (!classUnderTest .add (5000 )) {
110
+ hasFailed .set (true );
111
+ }
112
+ } finally {
113
+ latch .countDown ();
114
+ }
115
+ });
131
116
}
117
+
118
+ latch .await ();
119
+ threadPool .shutdown ();
132
120
long endTime = System .nanoTime ();
133
121
134
122
double executionTime = (endTime - startTime ) / 1_000_000.0 ;
135
- System .out .printf ("Sequential test with short delay completed in %.2f ms%n" , executionTime );
123
+ System .out .printf ("Concurrent test with medium delay and %d threads completed in %.2f ms%n" , Runtime . getRuntime (). availableProcessors () , executionTime );
136
124
137
- assertFalse ("Sequential test with short delay should not have any failures" , hasFailed .get ());
138
- assertTrue ("Sequential test with short delay should complete in a reasonable time" , executionTime < 60000 );
125
+ assertFalse ("Concurrent test with medium delay should not have any failures" , hasFailed .get ());
126
+ assertTrue ("Concurrent test with medium delay should complete in a reasonable time" , executionTime < 60000 );
139
127
}
140
128
141
129
@ Test
142
130
@ Order (6 )
143
131
@ RunMode (ExecutionMode .CONCURRENT )
144
- public void concurrentLibraryTestMediumDelay () throws InterruptedException {
132
+ public void concurrentLibraryTestShortDelay () throws InterruptedException {
145
133
ListSynchronization classUnderTest = new ListSynchronization ();
146
134
int iterations = 10 ;
147
135
CountDownLatch latch = new CountDownLatch (iterations );
@@ -152,7 +140,7 @@ public void concurrentLibraryTestMediumDelay() throws InterruptedException {
152
140
for (int i = 0 ; i < iterations ; i ++) {
153
141
threadPool .submitTask (() -> {
154
142
try {
155
- if (!classUnderTest .delayedMethod ( 3000 )) {
143
+ if (!classUnderTest .update ( 1000 )) {
156
144
hasFailed .set (true );
157
145
}
158
146
} finally {
@@ -166,32 +154,43 @@ public void concurrentLibraryTestMediumDelay() throws InterruptedException {
166
154
long endTime = System .nanoTime ();
167
155
168
156
double executionTime = (endTime - startTime ) / 1_000_000.0 ;
169
- System .out .printf ("Concurrent test with medium delay and %d threads completed in %.2f ms%n" , Runtime .getRuntime ().availableProcessors (), executionTime );
157
+ System .out .printf ("Concurrent test with short delay and %d threads completed in %.2f ms%n" , Runtime .getRuntime ().availableProcessors (), executionTime );
170
158
171
- assertFalse ("Concurrent test with medium delay should not have any failures" , hasFailed .get ());
172
- assertTrue ("Concurrent test with medium delay should complete in a reasonable time" , executionTime < 60000 );
159
+ assertFalse ("Concurrent test with short delay should not have any failures" , hasFailed .get ());
160
+ assertTrue ("Concurrent test with short delay should complete in a reasonable time" , executionTime < 60000 );
173
161
}
174
162
175
163
@ Test
176
164
@ Order (7 )
177
- @ RunMode (ExecutionMode .SEQUENTIAL )
178
- public void sequentialLibraryTestMediumDelay () {
165
+ @ RunMode (ExecutionMode .CONCURRENT )
166
+ public void concurrentLibraryTest () throws InterruptedException {
179
167
ListSynchronization classUnderTest = new ListSynchronization ();
180
- int iterations = 10 ;
168
+ int iterations = 10 ;
169
+ CountDownLatch latch = new CountDownLatch (iterations );
170
+ ThreadPool threadPool = new ThreadPool (Runtime .getRuntime ().availableProcessors ());
181
171
AtomicBoolean hasFailed = new AtomicBoolean (false );
182
172
183
173
long startTime = System .nanoTime ();
184
174
for (int i = 0 ; i < iterations ; i ++) {
185
- if (!classUnderTest .delayedMethod (3000 )) {
186
- hasFailed .set (true );
187
- }
175
+ threadPool .submitTask (() -> {
176
+ try {
177
+ if (!classUnderTest .delete (3000 )) {
178
+ hasFailed .set (true );
179
+ }
180
+ } finally {
181
+ latch .countDown ();
182
+ }
183
+ });
188
184
}
185
+
186
+ latch .await ();
187
+ threadPool .shutdown ();
189
188
long endTime = System .nanoTime ();
190
189
191
190
double executionTime = (endTime - startTime ) / 1_000_000.0 ;
192
- System .out .printf ("Sequential test with medium delay completed in %.2f ms%n" , executionTime );
191
+ System .out .printf ("Concurrent test with %d threads completed in %.2f ms%n" , Runtime . getRuntime (). availableProcessors () , executionTime );
193
192
194
- assertFalse ("Sequential test with medium delay should not have any failures" , hasFailed .get ());
195
- assertTrue ("Sequential test with medium delay should complete in a reasonable time" , executionTime < 60000 );
193
+ assertFalse ("Concurrent test should not have any failures" , hasFailed .get ());
194
+ assertTrue ("Concurrent test should complete in a reasonable time" , executionTime < 60000 );
196
195
}
197
196
}
0 commit comments