6161 */
6262public class ShutdownHookLeakTest {
6363
64- private final int ITERATIONS = 1000 ;
64+ private static final int ITERATIONS = 4000 ;
6565
6666 @ Test
6767 public void testShutdownHookDoesNotLeak () throws Exception {
@@ -71,27 +71,23 @@ public void testShutdownHookDoesNotLeak() throws Exception {
7171 final Collection shutdownHooks = getShutdownHooks (client );
7272
7373 for (int i = 0 ; i < ITERATIONS ; i ++) {
74- WebTarget target2 = target .property ("Washington" , "Irving" );
75- Builder req = target2 .request ().property ("how" , "now" ).property ("and" , "what" );
76- req .buildGet ().property ("Irving" , "Washington" ).property ("Thomas" , "Alva" );
74+ // Create/Initialize client runtime.
75+ target .property ("Washington" , "Irving" )
76+ .request ()
77+ .property ("how" , "now" )
78+ .buildGet ()
79+ .property ("Irving" , "Washington" );
7780 }
7881
7982 assertThat (
8083 "shutdown hook deque size should not copy number of property invocation" ,
8184 // 66 % seems like a reasonable threshold for this test to keep it stable
82- shutdownHooks .size (), is (lessThan (2 * ITERATIONS / 3 )));
83-
84- client .close ();
85-
86- assertThat (
87- "shutdown hook deque size should be empty after Client closed" ,
88- shutdownHooks .size (), is (equalTo (0 )));
89-
85+ shutdownHooks .size (), is (lessThan (ITERATIONS * 2 / 3 )));
9086 }
9187
92- private Collection getShutdownHooks (javax . ws . rs . client . Client client ) throws NoSuchFieldException , IllegalAccessException {
93- JerseyClient jerseyClient = (JerseyClient ) client ;
94- Field shutdownHooksField = JerseyClient .class .getDeclaredField ("shutdownHooks" );
88+ private Collection getShutdownHooks (final Client client ) throws NoSuchFieldException , IllegalAccessException {
89+ final JerseyClient jerseyClient = (JerseyClient ) client ;
90+ final Field shutdownHooksField = JerseyClient .class .getDeclaredField ("shutdownHooks" );
9591 shutdownHooksField .setAccessible (true );
9692 return (Collection ) shutdownHooksField .get (jerseyClient );
9793 }
0 commit comments