From 7aeac15055b6612c4b3bc78a1f3f5c782dd9e8a4 Mon Sep 17 00:00:00 2001 From: Simon Bernard Date: Tue, 14 Jan 2025 15:44:07 +0100 Subject: [PATCH] GH-1658: Use Custom Prefix for Redis Tests --- .../tests/RedisMultiEndpointsTest.java | 15 ++------------- .../integration/tests/RedisRegistrationTest.java | 14 +------------- .../tests/observe/RedisDynamicIPObserveTest.java | 14 +------------- .../tests/observe/RedisObserveTest.java | 14 +------------- .../integration/tests/security/RedisPskTest.java | 16 +--------------- .../integration/tests/security/RedisRpkTest.java | 16 +--------------- .../tests/security/RedisRpkX509Test.java | 16 +--------------- .../tests/security/RedisSecurityStoreTest.java | 16 +--------------- .../tests/security/RedisX509Test.java | 16 +--------------- .../server/redis/RedisRegistrationStoreTest.java | 3 +-- .../tests/util/LeshanTestServerBuilder.java | 5 +++++ .../integration/tests/util/RedisTestUtil.java | 8 ++++++++ 12 files changed, 24 insertions(+), 129 deletions(-) diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisMultiEndpointsTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisMultiEndpointsTest.java index ffa99426ba..249230b616 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisMultiEndpointsTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisMultiEndpointsTest.java @@ -17,24 +17,13 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisRegistrationStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisMultiEndpointsTest extends MultiEndpointsTest { @Override public LeshanTestServerBuilder givenServerWithTwoEndpoint(Protocol givenProtocol, String givenServerEndpointProvider) { - LeshanTestServerBuilder builder = super.givenServerWithTwoEndpoint(givenProtocol, givenServerEndpointProvider); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - - return builder; + return super.givenServerWithTwoEndpoint(givenProtocol, givenServerEndpointProvider) + .withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisRegistrationTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisRegistrationTest.java index bf8bf018f6..1c56117cb5 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisRegistrationTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RedisRegistrationTest.java @@ -17,23 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisRegistrationStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisRegistrationTest extends RegistrationTest { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisDynamicIPObserveTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisDynamicIPObserveTest.java index f0411c49f7..48394d7c89 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisDynamicIPObserveTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisDynamicIPObserveTest.java @@ -17,23 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisRegistrationStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisDynamicIPObserveTest extends DynamicIPObserveTest { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisObserveTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisObserveTest.java index e9368b3a3a..e649d845bf 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisObserveTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/observe/RedisObserveTest.java @@ -17,23 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisRegistrationStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisObserveTest extends ObserveTest { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisPskTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisPskTest.java index c114b88394..902e5ab6ba 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisPskTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisPskTest.java @@ -17,25 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisSecurityStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisPskTest extends PskTest { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - - // TODO should we also use RedisRegistrationStore ? - // builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - builder.setSecurityStore(new RedisSecurityStore(jedis)); - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkTest.java index 73760cf34c..dc5c9040b2 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkTest.java @@ -17,25 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisSecurityStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisRpkTest extends RpkTest { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - - // TODO should we also use RedisRegistrationStore ? - // builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - builder.setSecurityStore(new RedisSecurityStore(jedis)); - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkX509Test.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkX509Test.java index a7bbe37628..14e7c4a69a 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkX509Test.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisRpkX509Test.java @@ -17,25 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisSecurityStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisRpkX509Test extends RpkX509Test { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - - // TODO should we also use RedisRegistrationStore ? - // builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - builder.setSecurityStore(new RedisSecurityStore(jedis)); - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisSecurityStoreTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisSecurityStoreTest.java index 5b0e0823ac..2736f3c9d2 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisSecurityStoreTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisSecurityStoreTest.java @@ -17,25 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisSecurityStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisSecurityStoreTest extends SecurityStoreTest { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - - // TODO should we also use RedisRegistrationStore ? - // builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - builder.setSecurityStore(new RedisSecurityStore(jedis)); - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisX509Test.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisX509Test.java index 20f10d872d..602cb57c24 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisX509Test.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/security/RedisX509Test.java @@ -17,25 +17,11 @@ import org.eclipse.leshan.core.endpoint.Protocol; import org.eclipse.leshan.integration.tests.util.LeshanTestServerBuilder; -import org.eclipse.leshan.integration.tests.util.RedisTestUtil; -import org.eclipse.leshan.server.redis.RedisSecurityStore; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.util.Pool; public class RedisX509Test extends X509Test { @Override protected LeshanTestServerBuilder givenServerUsing(Protocol givenProtocol) { - LeshanTestServerBuilder builder = super.givenServerUsing(givenProtocol); - - // Create redis store - Pool jedis = RedisTestUtil.createJedisPool(); - // TODO use custom key when https://github.com/eclipse/leshan/issues/1249 will be available - - // TODO should we also use RedisRegistrationStore ? - // builder.setRegistrationStore(new RedisRegistrationStore(jedis)); - builder.setSecurityStore(new RedisSecurityStore(jedis)); - return builder; + return super.givenServerUsing(givenProtocol).withRedisRegistrationStore(); } } diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/server/redis/RedisRegistrationStoreTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/server/redis/RedisRegistrationStoreTest.java index 7627e708ac..6194398429 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/server/redis/RedisRegistrationStoreTest.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/server/redis/RedisRegistrationStoreTest.java @@ -55,7 +55,6 @@ import org.eclipse.leshan.server.endpoint.EffectiveEndpointUriProvider; import org.eclipse.leshan.server.observation.LwM2mNotificationReceiver; import org.eclipse.leshan.server.profile.ClientProfile; -import org.eclipse.leshan.server.redis.RedisRegistrationStore; import org.eclipse.leshan.server.registration.Registration; import org.eclipse.leshan.server.registration.RegistrationStore; import org.eclipse.leshan.transport.californium.ObserveUtil; @@ -86,7 +85,7 @@ public class RedisRegistrationStoreTest { @BeforeEach public void setUp() throws UnknownHostException { address = InetAddress.getLocalHost(); - store = new RedisRegistrationStore(RedisTestUtil.createJedisPool()); + store = RedisTestUtil.createRedisRegistrationStore(); observationStore = new LwM2mObservationStore(new EffectiveEndpointUriProvider() { @Override public EndpointUri getEndpointUri() { diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestServerBuilder.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestServerBuilder.java index 06751f59a1..076c187a2e 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestServerBuilder.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/LeshanTestServerBuilder.java @@ -220,6 +220,11 @@ public LeshanTestServerBuilder withUpdateOnSendOperation() { return this; } + public LeshanTestServerBuilder withRedisRegistrationStore() { + setRegistrationStore(RedisTestUtil.createRedisRegistrationStore()); + return this; + } + protected ServerProtocolProvider getCaliforniumProtocolProvider(Protocol protocol) { if (protocol.equals(Protocol.COAP)) { return new CoapServerProtocolProvider(); diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/RedisTestUtil.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/RedisTestUtil.java index e23f358fcc..7224fcd098 100644 --- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/RedisTestUtil.java +++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/util/RedisTestUtil.java @@ -15,6 +15,8 @@ *******************************************************************************/ package org.eclipse.leshan.integration.tests.util; +import org.eclipse.leshan.server.redis.RedisRegistrationStore; + import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.util.Pool; @@ -28,4 +30,10 @@ public static Pool createJedisPool() { return new JedisPool(); } } + + public static RedisRegistrationStore createRedisRegistrationStore() { + return new RedisRegistrationStore.Builder(RedisTestUtil.createJedisPool()) // + .setPrefix("LESHAN_TEST_REGSTORE#") // + .build(); + } }