Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Custom Prefix for Redis Tests #1689

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading