use of io.lettuce.core.api.StatefulRedisConnection in project ratelimitj by mokies.
the class RateLimitApplication method run.
@Override
public void run(Configuration configuration, Environment environment) {
environment.jersey().register(new LoginResource());
environment.jersey().register(new UserResource());
environment.jersey().register(new TrekResource());
environment.jersey().register(new AuthDynamicFeature(new OAuthCredentialAuthFilter.Builder<PrincipalImpl>().setAuthenticator(new TestOAuthAuthenticator()).setPrefix("Bearer").buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class));
// TODO move this cleanup into the tests
environment.lifecycle().manage(new Managed() {
@Override
public void start() {
}
@Override
public void stop() {
flushRedis();
}
private void flushRedis() {
try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
connection.sync().flushdb();
}
redisClient.shutdownAsync();
}
});
}
use of io.lettuce.core.api.StatefulRedisConnection in project jetcache by alibaba.
the class RedisLettuceCacheFailTest method setup.
@BeforeEach
public void setup() {
client = mock(RedisClient.class);
StatefulRedisConnection connection = mock(StatefulRedisConnection.class);
asyncCommands = mock(RedisAsyncCommands.class);
when(client.connect((JetCacheCodec) any())).thenReturn(connection);
when(connection.sync()).thenReturn(null);
when(connection.async()).thenReturn(asyncCommands);
cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder().redisClient(client).keyPrefix("fail_test").buildCache();
}
use of io.lettuce.core.api.StatefulRedisConnection in project jetcache by alibaba.
the class RedisLettuceStarterTest method tests.
@Test
public void tests() throws Exception {
if (RedisLettuceCacheTest.checkOS()) {
System.setProperty("spring.profiles.active", "redislettuce-cluster");
} else {
System.setProperty("spring.profiles.active", "redislettuce");
}
context = SpringApplication.run(RedisLettuceStarterTest.class);
doTest();
A bean = context.getBean(A.class);
bean.test();
RedisClient t1 = (RedisClient) context.getBean("defaultClient");
RedisClient t2 = (RedisClient) context.getBean("a1Client");
Assert.assertNotNull(t1);
Assert.assertNotNull(t2);
Assert.assertNotSame(t1, t2);
AutoConfigureBeans acb = context.getBean(AutoConfigureBeans.class);
String key = "remote.A1";
Assert.assertTrue(new LettuceFactory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
Assert.assertTrue(new LettuceFactory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
Assert.assertTrue(new LettuceFactory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
Assert.assertTrue(new LettuceFactory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);
if (RedisLettuceCacheTest.checkOS()) {
key = "remote.A2";
Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);
key = "remote.A2_slave";
Assert.assertTrue(new LettuceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
}
}
Aggregations