Search in sources :

Example 1 with RedisOperations

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);
}
Also used : RedisOperations(org.springframework.data.redis.core.RedisOperations) RedisOperationsSessionRepository(org.springframework.session.data.redis.RedisOperationsSessionRepository) SpringSessionRedisConnectionFactory(org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Example 2 with RedisOperations

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);
}
Also used : RedisOperations(org.springframework.data.redis.core.RedisOperations) RedisOperationsSessionRepository(org.springframework.session.data.redis.RedisOperationsSessionRepository) SpringSessionRedisConnectionFactory(org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Example 3 with RedisOperations

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);
}
Also used : RedisOperations(org.springframework.data.redis.core.RedisOperations) RedisOperationsSessionRepository(org.springframework.session.data.redis.RedisOperationsSessionRepository) SpringSessionRedisConnectionFactory(org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Example 4 with RedisOperations

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);
}
Also used : RedisOperations(org.springframework.data.redis.core.RedisOperations) RedisOperationsSessionRepository(org.springframework.session.data.redis.RedisOperationsSessionRepository) SpringSessionRedisConnectionFactory(org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Test(org.junit.Test)

Example 5 with RedisOperations

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RedisOperations(org.springframework.data.redis.core.RedisOperations) ExecutorService(java.util.concurrent.ExecutorService) DataAccessException(org.springframework.dao.DataAccessException) DataAccessException(org.springframework.dao.DataAccessException) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) ValueOperations(org.springframework.data.redis.core.ValueOperations) BaseTest(org.redisson.BaseTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 RedisOperations (org.springframework.data.redis.core.RedisOperations)5 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)4 RedisOperationsSessionRepository (org.springframework.session.data.redis.RedisOperationsSessionRepository)4 SpringSessionRedisConnectionFactory (org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory)4 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BaseTest (org.redisson.BaseTest)1 DataAccessException (org.springframework.dao.DataAccessException)1 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)1 ValueOperations (org.springframework.data.redis.core.ValueOperations)1