Skip to content

Commit

Permalink
GH-1658: Use Custom Prefix for Redis Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 20, 2025
1 parent 388a4d0 commit 7aeac15
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,4 +30,10 @@ public static Pool<Jedis> createJedisPool() {
return new JedisPool();
}
}

public static RedisRegistrationStore createRedisRegistrationStore() {
return new RedisRegistrationStore.Builder(RedisTestUtil.createJedisPool()) //
.setPrefix("LESHAN_TEST_REGSTORE#") //
.build();
}
}

0 comments on commit 7aeac15

Please sign in to comment.