use of org.springframework.data.redis.core.RedisOperations in project spring-session by spring-projects.
the class RedisHttpSessionConfigurationTests method primaryConnectionFactoryRedisConfig.
@Test
public void primaryConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class, PrimaryConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context.getBean("primaryRedisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")).isEqualTo(redisConnectionFactory);
}
use of org.springframework.data.redis.core.RedisOperations in project spring-session by spring-projects.
the class RedisHttpSessionConfigurationTests method namedConnectionFactoryRedisConfig.
@Test
public void namedConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class, NamedConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context.getBean("redisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")).isEqualTo(redisConnectionFactory);
}
use of org.springframework.data.redis.core.RedisOperations in project spring-session by spring-projects.
the class RedisHttpSessionConfigurationTests method qualifiedConnectionFactoryRedisConfig.
@Test
public void qualifiedConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class, QualifiedConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context.getBean("qualifiedRedisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")).isEqualTo(redisConnectionFactory);
}
use of org.springframework.data.redis.core.RedisOperations in project spring-session by spring-projects.
the class RedisHttpSessionConfigurationTests method qualifiedAndPrimaryConnectionFactoryRedisConfig.
@Test
public void qualifiedAndPrimaryConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class, QualifiedAndPrimaryConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context.getBean("qualifiedRedisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory")).isEqualTo(redisConnectionFactory);
}
use of org.springframework.data.redis.core.RedisOperations in project redisson by redisson.
the class RedissonMultiConnectionTest method testBroken.
@Test
public void testBroken() throws InterruptedException {
StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(new RedissonConnectionFactory(redisson));
ExecutorService e = Executors.newFixedThreadPool(32);
AtomicBoolean hasErrors = new AtomicBoolean();
for (int i = 0; i < 10; i++) {
e.submit(() -> {
stringRedisTemplate.execute(new SessionCallback<Void>() {
@Override
public Void execute(RedisOperations operations) throws DataAccessException {
try {
ValueOperations<String, String> valueOps = operations.opsForValue();
operations.multi();
valueOps.set("test3", "value");
} catch (Exception e) {
e.printStackTrace();
hasErrors.set(true);
}
return null;
}
});
stringRedisTemplate.execute(new SessionCallback<Void>() {
@Override
public Void execute(RedisOperations operations) throws DataAccessException {
try {
ValueOperations<String, String> valueOps = operations.opsForValue();
valueOps.set("test1", "value");
assertThat(valueOps.get("test1")).isEqualTo("value");
} catch (Exception e) {
e.printStackTrace();
hasErrors.set(true);
}
return null;
}
});
});
}
e.shutdown();
e.awaitTermination(1, TimeUnit.MINUTES);
assertThat(hasErrors).isFalse();
}
Aggregations