@@ -52,7 +52,7 @@ public void noPrivilegeEscalationThroughBrokerRelease() throws EXistException {
52
52
//take a broker with the guest user
53
53
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
54
54
final Subject guestUser = pool .getSecurityManager ().getGuestSubject ();
55
- try (final DBBroker broker1 = pool .get (Optional .of (guestUser ))) {
55
+ try (final DBBroker broker1 = pool .get (Optional .of (guestUser ))) {
56
56
57
57
assertEquals ("Expected `guest` user, but was: " + broker1 .getCurrentSubject ().getName (), guestUser .getId (), broker1 .getCurrentSubject ().getId ());
58
58
@@ -72,7 +72,7 @@ public void privilegeStableWhenSubjectNull() throws EXistException {
72
72
//take a broker with the SYSTEM user
73
73
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
74
74
final Subject sysUser = pool .getSecurityManager ().getSystemSubject ();
75
- try (final DBBroker broker1 = pool .get (Optional .of (sysUser ))) {
75
+ try (final DBBroker broker1 = pool .get (Optional .of (sysUser ))) {
76
76
77
77
assertEquals ("Expected `SYSTEM` user, but was: " + broker1 .getCurrentSubject ().getName (), sysUser .getId (), broker1 .getCurrentSubject ().getId ());
78
78
@@ -90,7 +90,7 @@ public void privilegeStableWhenSubjectNull() throws EXistException {
90
90
public void guestDefaultPriviledge () throws EXistException {
91
91
//take a broker with default perms
92
92
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
93
- try (final DBBroker broker1 = pool .getBroker ()) {
93
+ try (final DBBroker broker1 = pool .getBroker ()) {
94
94
95
95
final Subject guestUser = pool .getSecurityManager ().getGuestSubject ();
96
96
@@ -111,7 +111,7 @@ public void noPrivilegeEscalationThroughBrokerRelease_xmldb() throws EXistExcept
111
111
//take a broker with the guest user
112
112
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
113
113
final Subject guestUser = pool .getSecurityManager ().getGuestSubject ();
114
- try (final DBBroker broker1 = pool .get (Optional .of (guestUser ))) {
114
+ try (final DBBroker broker1 = pool .get (Optional .of (guestUser ))) {
115
115
116
116
assertEquals ("Expected `guest` user, but was: " + broker1 .getCurrentSubject ().getName (), guestUser .getId (), broker1 .getCurrentSubject ().getId ());
117
117
@@ -179,15 +179,15 @@ public void canReleaseWhenSaturated() throws InterruptedException, ExecutionExce
179
179
executor .shutdown ();
180
180
} finally {
181
181
// release all brokers from brokerUsers
182
- if (firstBrokerReleaseLatch .getCount () == 1 ) {
182
+ if (firstBrokerReleaseLatch .getCount () == 1 ) {
183
183
firstBrokerReleaseLatch .countDown ();
184
184
}
185
185
releaseLatch .countDown ();
186
186
assertTrue (executor .awaitTermination (1 , TimeUnit .SECONDS ));
187
187
for (Future <Void > task : tasks ) {
188
188
task .get ();
189
189
}
190
- for (Runnable task : executor .shutdownNow ()) {
190
+ for (Runnable task : executor .shutdownNow ()) {
191
191
assertNotNull (task );
192
192
}
193
193
}
@@ -197,32 +197,38 @@ public void canReleaseWhenSaturated() throws InterruptedException, ExecutionExce
197
197
public void concurrentShutdownAndUse () throws InterruptedException , ExecutionException {
198
198
final BrokerPool pool = existEmbeddedServer .getBrokerPool ();
199
199
final int maxBrokers = pool .getMax ();
200
+ final int taskAmount = maxBrokers * 50 ;
200
201
201
202
// test requires at least 5 leasedBrokers to prove the issue
202
203
assertTrue (maxBrokers > 4 );
203
204
204
205
final CountDownLatch readyLatch = new CountDownLatch (1 );
205
206
final CountDownLatch executeLatch = new CountDownLatch (1 );
206
- final ExecutorService executor = Executors .newFixedThreadPool (maxBrokers );
207
- final List <Future <Void >> tasks = new ArrayList <>(maxBrokers );
207
+ final ExecutorService executor = Executors .newFixedThreadPool (taskAmount );
208
+ final List <Future <Void >> tasks = new ArrayList <>(taskAmount );
208
209
final Consumer <BrokerPool > brokerAquire = brokerPool -> {
209
210
try (final DBBroker broker = brokerPool .getBroker ()) {
211
+ TimeUnit .SECONDS .sleep (1 );
210
212
} catch (EXistException e ) {
211
- throw new RuntimeException (e );
213
+ throw new IllegalStateException (e );
214
+ } catch (InterruptedException e ) {
215
+ Thread .currentThread ().interrupt ();
216
+ throw new IllegalStateException (e );
212
217
}
213
218
};
214
- for (int count = 0 ; count < maxBrokers ; count ++) {
215
- tasks .add (executor .submit (new PoolAction (pool , readyLatch , executeLatch , count == 0 ? BrokerPool ::shutdown : brokerAquire )));
219
+ for (int count = 0 ; count < taskAmount ; count ++) {
220
+ tasks .add (executor .submit (new PoolAction (pool , readyLatch , executeLatch , ( count % 2 == 0 ) ? BrokerPool ::shutdown : brokerAquire )));
216
221
}
222
+ executor .shutdown ();
217
223
218
- TimeUnit .SECONDS .sleep (1 );
224
+ TimeUnit .SECONDS .sleep (2 );
219
225
readyLatch .countDown ();
220
226
221
227
assertTrue (executor .awaitTermination (1 , TimeUnit .MINUTES ));
222
228
for (Future <Void > task : tasks ) {
223
229
task .get ();
224
230
}
225
- for (Runnable task : executor .shutdownNow ()) {
231
+ for (Runnable task : executor .shutdownNow ()) {
226
232
assertNotNull (task );
227
233
}
228
234
}
@@ -239,6 +245,7 @@ static class PoolAction implements Callable<Void> {
239
245
this .excuteLatch = excuteLatch ;
240
246
this .action = action ;
241
247
}
248
+
242
249
@ Override
243
250
public Void call () throws InterruptedException {
244
251
readyLatch .await ();
@@ -261,7 +268,7 @@ public BrokerUser(final BrokerPool brokerPool, final CountDownLatch acquiredLatc
261
268
262
269
@ Override
263
270
public Void call () throws EXistException , InterruptedException {
264
- try (final DBBroker broker = brokerPool .getBroker ()) {
271
+ try (final DBBroker broker = brokerPool .getBroker ()) {
265
272
266
273
// signal that we have acquired the broker
267
274
acquiredLatch .countDown ();
0 commit comments