List of usage examples for org.springframework.data.redis ConnectionFactoryTracker add
public static void add(Object factory)
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test public void testSelectDb() { LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());//from ww w. jav a2 s . c o m factory2.setClientResources(LettuceTestClientResources.getSharedClientResources()); factory2.setShutdownTimeout(0); factory2.setDatabase(1); factory2.afterPropertiesSet(); ConnectionFactoryTracker.add(factory2); StringRedisConnection connection2 = new DefaultStringRedisConnection(factory2.getConnection()); connection2.flushDb(); // put an item in database 0 connection.set("sometestkey", "sometestvalue"); try { // there should still be nothing in database 1 assertEquals(Long.valueOf(0), connection2.dbSize()); } finally { connection2.close(); factory2.destroy(); } }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test public void testCreateFactoryWithPool() { DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.setClientResources(LettuceTestClientResources.getSharedClientResources()); pool.afterPropertiesSet();//from w w w . j a v a2 s . c o m LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.setShutdownTimeout(0); factory2.afterPropertiesSet(); ConnectionFactoryTracker.add(factory2); RedisConnection conn2 = factory2.getConnection(); conn2.close(); factory2.destroy(); pool.destroy(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Ignore("Uncomment this test to manually check connection reuse in a pool scenario") @Test//www . ja v a2s. c o m public void testLotsOfConnections() throws InterruptedException { // Running a netstat here should show only the 8 conns from the pool (plus 2 from setUp and 1 from factory2 // afterPropertiesSet for shared conn) DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.afterPropertiesSet(); ConnectionFactoryTracker.add(factory2); for (int i = 1; i < 1000; i++) { Thread th = new Thread(() -> factory2.getConnection().bRPop(50000, "foo".getBytes())); th.start(); } Thread.sleep(234234234); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-431 public void dbIndexShouldBePropagatedCorrectly() { LettuceConnectionFactory factory = new LettuceConnectionFactory(); factory.setClientResources(LettuceTestClientResources.getSharedClientResources()); factory.setDatabase(2);//from www. j a v a 2 s . c o m factory.afterPropertiesSet(); ConnectionFactoryTracker.add(factory); StringRedisConnection connectionToDbIndex2 = new DefaultStringRedisConnection(factory.getConnection()); try { String key = "key-in-db-2"; connectionToDbIndex2.set(key, "the wheel of time"); assertThat(connection.get(key), nullValue()); assertThat(connectionToDbIndex2.get(key), notNullValue()); } finally { connectionToDbIndex2.close(); } }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-462 public void factoryWorksWithoutClientResources() { LettuceConnectionFactory factory = new LettuceConnectionFactory(); factory.setShutdownTimeout(0);//from w ww. j a v a 2s .c o m factory.afterPropertiesSet(); ConnectionFactoryTracker.add(factory); StringRedisConnection connection = new DefaultStringRedisConnection(factory.getConnection()); try { assertThat(connection.ping(), is(equalTo("PONG"))); } finally { connection.close(); } }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-525 public void factoryShouldReturnReactiveConnectionWhenCorrectly() { LettuceConnectionFactory factory = new LettuceConnectionFactory(); factory.setClientResources(LettuceTestClientResources.getSharedClientResources()); factory.afterPropertiesSet();//from ww w . ja v a 2s. c o m ConnectionFactoryTracker.add(factory); assertThat(factory.getReactiveConnection().execute(BaseRedisReactiveCommands::ping).blockFirst(), is("PONG")); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-667 public void factoryCreatesPooledConnections() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder() .poolConfig(poolConfig).clientResources(LettuceTestClientResources.getSharedClientResources()) .shutdownTimeout(Duration.ZERO).build(); LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(), configuration);/*w w w . j av a 2 s .com*/ factory.setShareNativeConnection(false); factory.afterPropertiesSet(); ConnectionFactoryTracker.add(factory); RedisConnection initial = factory.getConnection(); Object initialNativeConnection = initial.getNativeConnection(); initial.close(); RedisConnection subsequent = factory.getConnection(); Object subsequentNativeConnection = subsequent.getNativeConnection(); subsequent.close(); assertThat(initialNativeConnection, is(subsequentNativeConnection)); factory.destroy(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-576 public void connectionAppliesClientName() { LettuceClientConfiguration configuration = LettuceClientConfiguration.builder() .clientResources(LettuceTestClientResources.getSharedClientResources()).clientName("clientName") .build();// ww w .j a v a 2 s .c om LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(), configuration); factory.setShareNativeConnection(false); factory.afterPropertiesSet(); ConnectionFactoryTracker.add(factory); RedisConnection connection = factory.getConnection(); assertThat(connection.getClientName(), is(equalTo("clientName"))); connection.close(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-576 public void getClientNameShouldEqualWithFactorySetting() { LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration()); factory.setClientResources(LettuceTestClientResources.getSharedClientResources()); factory.setClientName("clientName"); factory.afterPropertiesSet();//ww w . j ava 2 s .com ConnectionFactoryTracker.add(factory); RedisConnection connection = factory.getConnection(); assertThat(connection.getClientName(), equalTo("clientName")); connection.close(); }
From source file:org.springframework.data.redis.listener.SubscriptionConnectionTests.java
public SubscriptionConnectionTests(RedisConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; ConnectionFactoryTracker.add(connectionFactory); }