@@ -52,7 +52,7 @@ public void noPrivilegeEscalationThroughBrokerRelease() throws EXistException {
5252        //take a broker with the guest user 
5353        final  BrokerPool  pool  = existEmbeddedServer .getBrokerPool ();
5454        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 ))) {
5656
5757            assertEquals ("Expected `guest` user, but was: "  + broker1 .getCurrentSubject ().getName (), guestUser .getId (), broker1 .getCurrentSubject ().getId ());
5858
@@ -72,7 +72,7 @@ public void privilegeStableWhenSubjectNull() throws EXistException {
7272        //take a broker with the SYSTEM user 
7373        final  BrokerPool  pool  = existEmbeddedServer .getBrokerPool ();
7474        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 ))) {
7676
7777            assertEquals ("Expected `SYSTEM` user, but was: "  + broker1 .getCurrentSubject ().getName (), sysUser .getId (), broker1 .getCurrentSubject ().getId ());
7878
@@ -90,7 +90,7 @@ public void privilegeStableWhenSubjectNull() throws EXistException {
9090    public  void  guestDefaultPriviledge () throws  EXistException  {
9191        //take a broker with default perms 
9292        final  BrokerPool  pool  = existEmbeddedServer .getBrokerPool ();
93-         try (final  DBBroker  broker1  = pool .getBroker ()) {
93+         try   (final  DBBroker  broker1  = pool .getBroker ()) {
9494
9595            final  Subject  guestUser  = pool .getSecurityManager ().getGuestSubject ();
9696
@@ -111,7 +111,7 @@ public void noPrivilegeEscalationThroughBrokerRelease_xmldb() throws EXistExcept
111111        //take a broker with the guest user 
112112        final  BrokerPool  pool  = existEmbeddedServer .getBrokerPool ();
113113        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 ))) {
115115
116116            assertEquals ("Expected `guest` user, but was: "  + broker1 .getCurrentSubject ().getName (), guestUser .getId (), broker1 .getCurrentSubject ().getId ());
117117
@@ -179,15 +179,15 @@ public void canReleaseWhenSaturated() throws InterruptedException, ExecutionExce
179179            executor .shutdown ();
180180        } finally  {
181181            // release all brokers from brokerUsers 
182-             if (firstBrokerReleaseLatch .getCount () == 1 ) {
182+             if   (firstBrokerReleaseLatch .getCount () == 1 ) {
183183                firstBrokerReleaseLatch .countDown ();
184184            }
185185            releaseLatch .countDown ();
186186            assertTrue (executor .awaitTermination (1 , TimeUnit .SECONDS ));
187187            for  (Future <Void > task  : tasks ) {
188188                task .get ();
189189            }
190-             for  (Runnable  task : executor .shutdownNow ()) {
190+             for  (Runnable  task   : executor .shutdownNow ()) {
191191                assertNotNull (task );
192192            }
193193        }
@@ -197,32 +197,38 @@ public void canReleaseWhenSaturated() throws InterruptedException, ExecutionExce
197197    public  void  concurrentShutdownAndUse () throws  InterruptedException , ExecutionException  {
198198        final  BrokerPool  pool  = existEmbeddedServer .getBrokerPool ();
199199        final  int  maxBrokers  = pool .getMax ();
200+         final  int  taskAmount  = maxBrokers  * 50 ;
200201
201202        // test requires at least 5 leasedBrokers to prove the issue 
202203        assertTrue (maxBrokers  > 4 );
203204
204205        final  CountDownLatch  readyLatch  = new  CountDownLatch (1 );
205206        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 );
208209        final  Consumer <BrokerPool > brokerAquire  = brokerPool  -> {
209210            try  (final  DBBroker  broker  = brokerPool .getBroker ()) {
211+                 TimeUnit .SECONDS .sleep (1 );
210212            } 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 );
212217            }
213218        };
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 )));
216221        }
222+         executor .shutdown ();
217223
218-         TimeUnit .SECONDS .sleep (1 );
224+         TimeUnit .SECONDS .sleep (2 );
219225        readyLatch .countDown ();
220226
221227        assertTrue (executor .awaitTermination (1 , TimeUnit .MINUTES ));
222228        for  (Future <Void > task  : tasks ) {
223229            task .get ();
224230        }
225-         for  (Runnable  task : executor .shutdownNow ()) {
231+         for  (Runnable  task   : executor .shutdownNow ()) {
226232            assertNotNull (task );
227233        }
228234    }
@@ -239,6 +245,7 @@ static class PoolAction implements Callable<Void> {
239245            this .excuteLatch  = excuteLatch ;
240246            this .action  = action ;
241247        }
248+ 
242249        @ Override 
243250        public  Void  call () throws  InterruptedException  {
244251            readyLatch .await ();
@@ -261,7 +268,7 @@ public BrokerUser(final BrokerPool brokerPool, final CountDownLatch acquiredLatc
261268
262269        @ Override 
263270        public  Void  call () throws  EXistException , InterruptedException  {
264-             try (final  DBBroker  broker  = brokerPool .getBroker ()) {
271+             try   (final  DBBroker  broker  = brokerPool .getBroker ()) {
265272
266273                // signal that we have acquired the broker 
267274                acquiredLatch .countDown ();
0 commit comments