@@ -100,11 +100,11 @@ public void checkCloseableConnections() throws Exception {
100100
101101 JedisSentinelPool pool = new JedisSentinelPool (MASTER_NAME , sentinels , config , 1000 ,
102102 "default" ,"foobared" , 2 );
103- Jedis jedis = pool .getResource ();
104- jedis .auth ("default" , "foobared" );
105- jedis .set ("foo" , "bar" );
106- assertEquals ("bar" , jedis .get ("foo" ));
107- jedis . close ();
103+ try ( Jedis jedis = pool .getResource ()){
104+ jedis .auth ("default" , "foobared" );
105+ jedis .set ("foo" , "bar" );
106+ assertEquals ("bar" , jedis .get ("foo" ));
107+ }
108108 pool .close ();
109109 assertTrue (pool .isClosed ());
110110 }
@@ -128,24 +128,23 @@ public void returnResourceShouldResetState() {
128128 GenericObjectPoolConfig config = new GenericObjectPoolConfig ();
129129 config .setMaxTotal (1 );
130130 config .setBlockWhenExhausted (false );
131- JedisSentinelPool pool = new JedisSentinelPool (MASTER_NAME , sentinels , config , 1000 ,
132- "default" , "foobared" , 2 );
133131
134- Jedis jedis = pool .getResource ();
135- try {
136- jedis .set ("hello" , "jedis" );
137- Transaction t = jedis .multi ();
138- t .set ("hello" , "world" );
139- jedis .close ();
132+ try (JedisSentinelPool pool = new JedisSentinelPool (MASTER_NAME , sentinels , config , 1000 ,
133+ "default" , "foobared" , 2 )){
134+ Jedis jedis ;
135+ try (Jedis jedis1 = pool .getResource ()){
136+ jedis = jedis1 ;
137+ jedis1 .set ("hello" , "jedis" );
138+ Transaction t = jedis1 .multi ();
139+ t .set ("hello" , "world" );
140+ jedis1 .close ();
141+ }
140142
141143 try (Jedis jedis2 = pool .getResource ()) {
142-
144+
143145 assertSame (jedis , jedis2 );
144146 assertEquals ("jedis" , jedis2 .get ("hello" ));
145147 }
146- } finally {
147-
148- pool .destroy ();
149148 }
150149 }
151150
@@ -157,11 +156,10 @@ public void checkResourceIsCloseable() {
157156 try (JedisSentinelPool pool = new JedisSentinelPool (MASTER_NAME , sentinels , config , 1000 ,
158157 "default" , "foobared" , 2 )){
159158
160- Jedis jedis = pool .getResource ();
161- try {
162- jedis .set ("hello" , "jedis" );
163- } finally {
164- jedis .close ();
159+ Jedis jedis ;
160+ try (Jedis jedis1 = pool .getResource ()){
161+ jedis = jedis1 ;
162+ jedis1 .set ("hello" , "jedis" );
165163 }
166164
167165 try (Jedis jedis2 = pool .getResource ()){
@@ -178,12 +176,9 @@ public void customClientName() {
178176 JedisSentinelPool pool = new JedisSentinelPool (MASTER_NAME , sentinels , config , 1000 ,
179177 "default" , "foobared" , 0 , "my_shiny_client_name" );
180178
181- Jedis jedis = pool .getResource ();
182-
183- try {
179+ try (Jedis jedis = pool .getResource ()){
184180 assertEquals ("my_shiny_client_name" , jedis .clientGetname ());
185181 } finally {
186- jedis .close ();
187182 pool .destroy ();
188183 }
189184
0 commit comments