JedisSessionRepositoryFactory extends AbstractRedisSessionRepositoryFactory { @Override protected RedisFacade getRedisFacade(RedisConfiguration config) { JedisPoolConfig poolConfig = configurePool(config); switch (config.clusterMode) { case "SINGLE": return singleInstance(poolConfig, config); case "SENTINEL": return sentinelFacade(poolConfig, config); case "CLUSTER": return clusterFacade(poolConfig, config); default: throw new IllegalArgumentException("Unsupported redis mode: " + config); } }    }
@Test public void testSingleRedisFacade() { JedisSessionRepositoryFactory factory = spy(new JedisSessionRepositoryFactory()); SessionConfiguration sessionConfig = spy(new SessionConfiguration()); RedisConfiguration config = spy(new RedisConfiguration(sessionConfig)); config.clusterMode = "SINGLE"; RedisFacade facade = factory.getRedisFacade(config); assertThat(facade, instanceOf(JedisPoolFacade.class)); }
@Test public void testSingleRedisFacadeWithPort() { JedisSessionRepositoryFactory factory = spy(new JedisSessionRepositoryFactory()); SessionConfiguration sessionConfig = spy(new SessionConfiguration()); RedisConfiguration config = spy(new RedisConfiguration(sessionConfig)); config.server = "1.2.3.4:1"; config.clusterMode = "SINGLE"; RedisFacade facade = factory.getRedisFacade(config); assertThat(facade, instanceOf(JedisPoolFacade.class)); }
@Test(expected = IllegalArgumentException.class) public void testUnknwonRedisFacade() { JedisSessionRepositoryFactory factory = spy(new JedisSessionRepositoryFactory()); SessionConfiguration sessionConfig = spy(new SessionConfiguration()); RedisConfiguration config = spy(new RedisConfiguration(sessionConfig)); config.clusterMode = "SOMETHING"; factory.getRedisFacade(config); }