@@ -24,9 +24,8 @@ void shouldWriteAndReadEntry() {
2424 .withSnapshotting (3 , 1 )
2525 ) {
2626 valkeyContainer .start ();
27- JedisPool jedisPool = new JedisPool (valkeyContainer .createConnectionUrl ());
28-
29- try (Jedis jedis = jedisPool .getResource ()) {
27+ try (JedisPool jedisPool = new JedisPool (valkeyContainer .createConnectionUrl ());
28+ Jedis jedis = jedisPool .getResource ()) {
3029 jedis .set ("key" , "value" );
3130 assertThat (jedis .get ("key" )).isEqualTo ("value" );
3231 }
@@ -36,20 +35,22 @@ void shouldWriteAndReadEntry() {
3635 @ Test
3736 void shouldConfigureServiceWithAuthentication () {
3837 try (
39- ValkeyContainer valkeyContainer = new ValkeyContainer ().withUsername ("testuser" ).withPassword ("testpass" )
38+ ValkeyContainer valkeyContainer = new ValkeyContainer ().withUsername ("testuser" )
39+ .withPassword ("testpass" )
4040 ) {
4141 valkeyContainer .start ();
4242 String url = valkeyContainer .createConnectionUrl ();
4343 assertThat (url ).contains ("testuser:testpass" );
4444
45- JedisPool jedisPool = new JedisPool (url );
46- try ( Jedis jedis = jedisPool .getResource ()) {
45+ try ( JedisPool jedisPool = new JedisPool (url );
46+ Jedis jedis = jedisPool .getResource ()) {
4747 jedis .set ("k1" , "v2" );
4848 assertThat (jedis .get ("k1" )).isEqualTo ("v2" );
4949 }
5050 }
5151 }
5252
53+
5354 @ Test
5455 void shouldPersistData () {
5556 Path dataDir = tempDir .resolve ("valkey-data" );
@@ -61,18 +62,21 @@ void shouldPersistData() {
6162 .withSnapshotting (1 , 1 )
6263 ) {
6364 valkeyContainer .start ();
64- JedisPool jedisPool = new JedisPool (valkeyContainer .createConnectionUrl ());
6565
66- try (Jedis jedis = jedisPool .getResource ()) {
66+ String containerConnectionUrl = valkeyContainer .createConnectionUrl ();
67+ try (JedisPool jedisPool = new JedisPool (containerConnectionUrl );
68+ Jedis jedis = jedisPool .getResource ()) {
6769 jedis .set ("persistKey" , "persistValue" );
6870 }
6971
7072 valkeyContainer .stop ();
71- try (ValkeyContainer restarted = new ValkeyContainer ().withPersistenceVolume (dataDir .toString ())) {
73+ try (ValkeyContainer restarted = new ValkeyContainer ().withPersistenceVolume (
74+ dataDir .toString ())) {
7275 restarted .start ();
73- JedisPool restartedPool = new JedisPool ( restarted .createConnectionUrl () );
76+ String connectionUrl = restarted .createConnectionUrl ();
7477
75- try (Jedis jedis = restartedPool .getResource ()) {
78+ try (JedisPool restartedPool = new JedisPool (connectionUrl );
79+ Jedis jedis = restartedPool .getResource ()) {
7680 assertThat (jedis .get ("persistKey" )).isEqualTo ("persistValue" );
7781 }
7882 }
@@ -83,11 +87,13 @@ void shouldPersistData() {
8387 void shouldInitializeDatabaseWithPayload () throws Exception {
8488 Path importFile = Paths .get (getClass ().getResource ("/initData.valkey" ).toURI ());
8589
86- try (ValkeyContainer valkeyContainer = new ValkeyContainer ().withInitialData (importFile .toString ())) {
90+ try (ValkeyContainer valkeyContainer = new ValkeyContainer ().withInitialData (
91+ importFile .toString ())) {
8792 valkeyContainer .start ();
88- JedisPool jedisPool = new JedisPool ( valkeyContainer .createConnectionUrl () );
93+ String connectionUrl = valkeyContainer .createConnectionUrl ();
8994
90- try (Jedis jedis = jedisPool .getResource ()) {
95+ try (JedisPool jedisPool = new JedisPool (
96+ connectionUrl ); Jedis jedis = jedisPool .getResource ()) {
9197 assertThat (jedis .get ("key1" )).isEqualTo ("value1" );
9298 assertThat (jedis .get ("key2" )).isEqualTo ("value2" );
9399 }
@@ -109,12 +115,13 @@ void shouldExecuteContainerCmdAndReturnResult() {
109115 void shouldMountValkeyConfigToContainer () throws Exception {
110116 Path configFile = Paths .get (getClass ().getResource ("/valkey.conf" ).toURI ());
111117
112- try (ValkeyContainer valkeyContainer = new ValkeyContainer ().withConfigFile (configFile .toString ())) {
118+ try (ValkeyContainer valkeyContainer = new ValkeyContainer ().withConfigFile (
119+ configFile .toString ())) {
113120 valkeyContainer .start ();
114121
115- JedisPool jedisPool = new JedisPool ( valkeyContainer .createConnectionUrl () );
116-
117- try ( Jedis jedis = jedisPool .getResource ()) {
122+ String connectionUrl = valkeyContainer .createConnectionUrl ();
123+ try ( JedisPool jedisPool = new JedisPool ( connectionUrl );
124+ Jedis jedis = jedisPool .getResource ()) {
118125 String maxMemory = jedis .configGet ("maxmemory" ).get ("maxmemory" );
119126
120127 assertThat (maxMemory ).isEqualTo ("2097152" );
@@ -124,13 +131,14 @@ void shouldMountValkeyConfigToContainer() throws Exception {
124131
125132 @ Test
126133 void shouldValidateSnapshottingConfiguration () {
127- ValkeyContainer container = new ValkeyContainer ();
128- assertThatThrownBy (() -> container .withSnapshotting (0 , 10 ))
129- .isInstanceOf (IllegalArgumentException .class )
130- .hasMessageContaining ("seconds must be greater than 0" );
131-
132- assertThatThrownBy (() -> container .withSnapshotting (10 , 0 ))
133- .isInstanceOf (IllegalArgumentException .class )
134- .hasMessageContaining ("changedKeys must be non-negative" );
134+ try (ValkeyContainer container = new ValkeyContainer ()) {
135+ assertThatThrownBy (() -> container .withSnapshotting (0 , 10 ))
136+ .isInstanceOf (IllegalArgumentException .class )
137+ .hasMessageContaining ("seconds must be greater than 0" );
138+
139+ assertThatThrownBy (() -> container .withSnapshotting (10 , 0 ))
140+ .isInstanceOf (IllegalArgumentException .class )
141+ .hasMessageContaining ("changedKeys must be non-negative" );
142+ }
135143 }
136144}
0 commit comments