DATAGEODE-55 - Adapt to Apache Geode PoolFactory and Pool API changes.
Add support for the PoolFactory.setSocketConnectTimeout(..) and Pool.getSocketConnectTimeout() methods.
This commit is contained in:
@@ -115,10 +115,11 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenDistributedSystemIsConnected() {
|
||||
|
||||
Properties gemfireProperties = createProperties("gf", "test");
|
||||
Properties distributedSystemProperties = createProperties("ds", "mock");
|
||||
|
||||
final DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
when(mockDistributedSystem.isConnected()).thenReturn(true);
|
||||
when(mockDistributedSystem.getProperties()).thenReturn(distributedSystemProperties);
|
||||
@@ -148,13 +149,14 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenDistributedSystemIsConnectedAndClientIsDurable() {
|
||||
|
||||
Properties gemfireProperties = DistributedSystemUtils.configureDurableClient(
|
||||
createProperties("gf", "test"), "123", 600);
|
||||
|
||||
Properties distributedSystemProperties = DistributedSystemUtils.configureDurableClient(
|
||||
createProperties("ds", "mock"), "987", 300);
|
||||
|
||||
final DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
when(mockDistributedSystem.isConnected()).thenReturn(true);
|
||||
when(mockDistributedSystem.getProperties()).thenReturn(distributedSystemProperties);
|
||||
@@ -186,10 +188,11 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenDistributedSystemIsDisconnected() {
|
||||
|
||||
Properties gemfireProperties = createProperties("gf", "test");
|
||||
Properties distributedSystemProperties = createProperties("ds", "mock");
|
||||
|
||||
final DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
|
||||
when(mockDistributedSystem.isConnected()).thenReturn(false);
|
||||
when(mockDistributedSystem.getProperties()).thenReturn(distributedSystemProperties);
|
||||
@@ -212,6 +215,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePropertiesWhenDistributedSystemIsNull() {
|
||||
|
||||
Properties gemfireProperties = createProperties("gf", "test");
|
||||
|
||||
assertThat(gemfireProperties.size(), is(equalTo(1)));
|
||||
@@ -236,6 +240,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createClientCacheFactory() {
|
||||
|
||||
Properties gemfireProperties = new Properties();
|
||||
|
||||
Object clientCacheFactoryReference = new ClientCacheFactoryBean().createFactory(gemfireProperties);
|
||||
@@ -253,8 +258,9 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void prepareClientCacheFactoryCallsInitializePdxAndInitializePool() {
|
||||
final AtomicBoolean initializePdxCalled = new AtomicBoolean(false);
|
||||
final AtomicBoolean initializePoolCalled = new AtomicBoolean(false);
|
||||
|
||||
AtomicBoolean initializePdxCalled = new AtomicBoolean(false);
|
||||
AtomicBoolean initializePoolCalled = new AtomicBoolean(false);
|
||||
|
||||
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
|
||||
|
||||
@@ -281,6 +287,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void initializePdxWithAllPdxOptions() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
PdxSerializer mockPdxSerializer = mock(PdxSerializer.class);
|
||||
@@ -311,6 +318,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void initializePdxWithPartialPdxOptions() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactoryBean.setPdxReadSerialized(true);
|
||||
@@ -336,6 +344,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void initializePdxWithNoPdxOptions() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getPdxDiskStoreName(), is(nullValue()));
|
||||
@@ -354,6 +363,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void initializePoolWithPool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(10000);
|
||||
@@ -369,6 +379,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
when(mockPool.getRetryAttempts()).thenReturn(1);
|
||||
when(mockPool.getServerGroup()).thenReturn("TestGroup");
|
||||
when(mockPool.getSocketBufferSize()).thenReturn(8192);
|
||||
when(mockPool.getSocketConnectTimeout()).thenReturn(5000);
|
||||
when(mockPool.getStatisticInterval()).thenReturn(5000);
|
||||
when(mockPool.getSubscriptionAckInterval()).thenReturn(500);
|
||||
when(mockPool.getSubscriptionEnabled()).thenReturn(true);
|
||||
@@ -398,6 +409,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
assertThat(clientCacheFactoryBean.getServerGroup(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getServers().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getSocketBufferSize(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSocketConnectTimeout(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getStatisticsInterval(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionAckInterval(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionEnabled(), is(nullValue()));
|
||||
@@ -424,6 +436,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockPool, times(1)).getServerGroup();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, times(1)).getSocketBufferSize();
|
||||
verify(mockPool, times(1)).getSocketConnectTimeout();
|
||||
verify(mockPool, times(1)).getStatisticInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionEnabled();
|
||||
@@ -442,6 +455,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockClientCacheFactory, times(1)).setPoolRetryAttempts(eq(1));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolServerGroup(eq("TestGroup"));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSocketBufferSize(eq(8192));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSocketConnectTimeout(eq(5000));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolStatisticInterval(eq(5000));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSubscriptionAckInterval(eq(500));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSubscriptionEnabled(eq(true));
|
||||
@@ -455,6 +469,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void initializePoolWithFactory() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
@@ -472,6 +487,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
clientCacheFactoryBean.setRetryAttempts(2);
|
||||
clientCacheFactoryBean.setServerGroup("TestGroup");
|
||||
clientCacheFactoryBean.setSocketBufferSize(16384);
|
||||
clientCacheFactoryBean.setSocketConnectTimeout(5000);
|
||||
clientCacheFactoryBean.setStatisticsInterval(1000);
|
||||
clientCacheFactoryBean.setSubscriptionAckInterval(100);
|
||||
clientCacheFactoryBean.setSubscriptionEnabled(true);
|
||||
@@ -497,6 +513,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
assertThat(clientCacheFactoryBean.getServerGroup(), is(equalTo("TestGroup")));
|
||||
assertThat(clientCacheFactoryBean.getServers().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getSocketBufferSize(), is(equalTo(16384)));
|
||||
assertThat(clientCacheFactoryBean.getSocketConnectTimeout(), is(equalTo(5000)));
|
||||
assertThat(clientCacheFactoryBean.getStatisticsInterval(), is(equalTo(1000)));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionAckInterval(), is(equalTo(100)));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionEnabled(), is(equalTo(true)));
|
||||
@@ -522,6 +539,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockClientCacheFactory, times(1)).setPoolRetryAttempts(eq(2));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolServerGroup(eq("TestGroup"));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSocketBufferSize(eq(16384));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSocketConnectTimeout(eq(5000));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolStatisticInterval(eq(1000));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSubscriptionAckInterval(eq(100));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSubscriptionEnabled(eq(true));
|
||||
@@ -535,6 +553,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void initializePoolWithFactoryAndPoolButFactoryOverridesPool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(5000);
|
||||
@@ -551,6 +570,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
when(mockPool.getServerGroup()).thenReturn("TestServerGroup");
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(new InetSocketAddress("localhost", 12480)));
|
||||
when(mockPool.getSocketBufferSize()).thenReturn(8192);
|
||||
when(mockPool.getSocketConnectTimeout()).thenReturn(5000);
|
||||
when(mockPool.getStatisticInterval()).thenReturn(5000);
|
||||
when(mockPool.getSubscriptionAckInterval()).thenReturn(1000);
|
||||
when(mockPool.getSubscriptionEnabled()).thenReturn(false);
|
||||
@@ -568,6 +588,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
clientCacheFactoryBean.setPrSingleHopEnabled(true);
|
||||
clientCacheFactoryBean.setServerGroup("TestGroup");
|
||||
clientCacheFactoryBean.setSocketBufferSize(16384);
|
||||
clientCacheFactoryBean.setSocketConnectTimeout(10000);
|
||||
clientCacheFactoryBean.setStatisticsInterval(500);
|
||||
clientCacheFactoryBean.setSubscriptionAckInterval(100);
|
||||
clientCacheFactoryBean.setSubscriptionEnabled(true);
|
||||
@@ -591,6 +612,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
assertThat(clientCacheFactoryBean.getServerGroup(), is(equalTo("TestGroup")));
|
||||
assertThat(clientCacheFactoryBean.getServers().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getSocketBufferSize(), is(equalTo(16384)));
|
||||
assertThat(clientCacheFactoryBean.getSocketConnectTimeout(), is(equalTo(10000)));
|
||||
assertThat(clientCacheFactoryBean.getStatisticsInterval(), is(equalTo(500)));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionAckInterval(), is(equalTo(100)));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionEnabled(), is(true));
|
||||
@@ -617,6 +639,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockPool, never()).getServerGroup();
|
||||
verify(mockPool, never()).getServers();
|
||||
verify(mockPool, never()).getSocketBufferSize();
|
||||
verify(mockPool, never()).getSocketConnectTimeout();
|
||||
verify(mockPool, never()).getStatisticInterval();
|
||||
verify(mockPool, never()).getSubscriptionAckInterval();
|
||||
verify(mockPool, never()).getSubscriptionEnabled();
|
||||
@@ -635,6 +658,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockClientCacheFactory, times(1)).setPoolRetryAttempts(eq(1));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolServerGroup(eq("TestGroup"));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSocketBufferSize(eq(16384));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSocketConnectTimeout(eq(10000));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolStatisticInterval(eq(500));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSubscriptionAckInterval(eq(100));
|
||||
verify(mockClientCacheFactory, times(1)).setPoolSubscriptionEnabled(eq(true));
|
||||
@@ -644,35 +668,9 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockClientCacheFactory, never()).addPoolServer(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializePoolWithFactoryServer() {
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getLocators()).thenReturn(Collections.singletonList(new InetSocketAddress("localhost", 21668)));
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(new InetSocketAddress("localhost", 41414)));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactoryBean.setPool(mockPool);
|
||||
clientCacheFactoryBean.addServers(newConnectionEndpoint("skullbox", 12480));
|
||||
|
||||
assertThat(clientCacheFactoryBean.getLocators().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPool(), is(sameInstance(mockPool)));
|
||||
assertThat(clientCacheFactoryBean.getServers().size(), is(equalTo(1)));
|
||||
|
||||
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
|
||||
|
||||
assertThat(clientCacheFactoryBean.initializePool(mockClientCacheFactory),
|
||||
is(sameInstance(mockClientCacheFactory)));
|
||||
|
||||
verify(mockPool, never()).getLocators();
|
||||
verify(mockPool, never()).getServers();
|
||||
verify(mockClientCacheFactory, never()).addPoolLocator(anyString(), anyInt());
|
||||
verify(mockClientCacheFactory, times(1)).addPoolServer(eq("skullbox"), eq(12480));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializePoolWithFactoryLocator() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getLocators()).thenReturn(Collections.singletonList(new InetSocketAddress("localhost", 21668)));
|
||||
@@ -699,19 +697,21 @@ public class ClientCacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializePoolWithPoolServer() {
|
||||
public void initializePoolWithFactoryServer() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getLocators()).thenReturn(Collections.emptyList());
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(new InetSocketAddress("boombox", 41414)));
|
||||
when(mockPool.getLocators()).thenReturn(Collections.singletonList(new InetSocketAddress("localhost", 21668)));
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(new InetSocketAddress("localhost", 41414)));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactoryBean.setPool(mockPool);
|
||||
clientCacheFactoryBean.addServers(newConnectionEndpoint("skullbox", 12480));
|
||||
|
||||
assertThat(clientCacheFactoryBean.getLocators().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPool(), is(sameInstance(mockPool)));
|
||||
assertThat(clientCacheFactoryBean.getServers().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getServers().size(), is(equalTo(1)));
|
||||
|
||||
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
|
||||
|
||||
@@ -719,13 +719,14 @@ public class ClientCacheFactoryBeanTest {
|
||||
is(sameInstance(mockClientCacheFactory)));
|
||||
|
||||
verify(mockPool, never()).getLocators();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, never()).getServers();
|
||||
verify(mockClientCacheFactory, never()).addPoolLocator(anyString(), anyInt());
|
||||
verify(mockClientCacheFactory, times(1)).addPoolServer(eq("boombox"), eq(41414));
|
||||
verify(mockClientCacheFactory, times(1)).addPoolServer(eq("skullbox"), eq(12480));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializePoolWithPoolLocator() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getLocators()).thenReturn(Collections.singletonList(new InetSocketAddress("skullbox", 21668)));
|
||||
@@ -750,8 +751,36 @@ public class ClientCacheFactoryBeanTest {
|
||||
verify(mockClientCacheFactory, never()).addPoolServer(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializePoolWithPoolServer() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getLocators()).thenReturn(Collections.emptyList());
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(new InetSocketAddress("boombox", 41414)));
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactoryBean.setPool(mockPool);
|
||||
|
||||
assertThat(clientCacheFactoryBean.getLocators().isEmpty(), is(true));
|
||||
assertThat(clientCacheFactoryBean.getPool(), is(sameInstance(mockPool)));
|
||||
assertThat(clientCacheFactoryBean.getServers().isEmpty(), is(true));
|
||||
|
||||
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
|
||||
|
||||
assertThat(clientCacheFactoryBean.initializePool(mockClientCacheFactory),
|
||||
is(sameInstance(mockClientCacheFactory)));
|
||||
|
||||
verify(mockPool, never()).getLocators();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockClientCacheFactory, never()).addPoolLocator(anyString(), anyInt());
|
||||
verify(mockClientCacheFactory, times(1)).addPoolServer(eq("boombox"), eq(41414));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializePoolWithDefaultServer() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override Pool resolvePool() {
|
||||
return null;
|
||||
@@ -774,7 +803,9 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void createCache() {
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCacheFactory mockClientCacheFactory = mock(ClientCacheFactory.class);
|
||||
|
||||
when(mockClientCacheFactory.create()).thenReturn(mockClientCache);
|
||||
@@ -789,6 +820,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePoolByReturningProvidedPool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
@@ -803,7 +835,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvesPoolByName() {
|
||||
final Pool mockPool = mock(Pool.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override Pool findPool(String name) {
|
||||
@@ -823,7 +856,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvesPoolByDefaultName() {
|
||||
final Pool mockPool = mock(Pool.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override Pool findPool(String name) {
|
||||
@@ -841,8 +875,11 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvesNamedPoolFromBeanFactory() {
|
||||
|
||||
ListableBeanFactory mockBeanFactory = mock(ListableBeanFactory.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean mockPoolFactoryBean = mock(PoolFactoryBean.class);
|
||||
|
||||
Map<String, PoolFactoryBean> beans = Collections.singletonMap("&TestPool", mockPoolFactoryBean);
|
||||
@@ -867,8 +904,11 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvesUnnamedPoolFromBeanFactory() {
|
||||
|
||||
ListableBeanFactory mockBeanFactory = mock(ListableBeanFactory.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean mockPoolFactoryBean = mock(PoolFactoryBean.class);
|
||||
|
||||
Map<String, PoolFactoryBean> beans = Collections.singletonMap("&gemfirePool", mockPoolFactoryBean);
|
||||
@@ -892,6 +932,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePoolReturnsNullWhenNoBeansOfTypePoolFactoryBeanExists() {
|
||||
|
||||
ListableBeanFactory mockBeanFactory = mock(ListableBeanFactory.class);
|
||||
|
||||
Map<String, PoolFactoryBean> beans = Collections.emptyMap();
|
||||
@@ -912,8 +953,11 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePoolReturnsNullWhenNoBeansOfTypePoolFactoryBeanExistsWithPoolName() {
|
||||
|
||||
ListableBeanFactory mockBeanFactory = mock(ListableBeanFactory.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean mockPoolFactoryBean = mock(PoolFactoryBean.class);
|
||||
|
||||
Map<String, PoolFactoryBean> beans = Collections.singletonMap("&swimPool", mockPoolFactoryBean);
|
||||
@@ -938,7 +982,9 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void resolvePoolReturnsNullWhenBeanFactoryIsNotAListableBeanFactory() {
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
clientCacheFactoryBean.setBeanFactory(mockBeanFactory);
|
||||
@@ -954,7 +1000,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onApplicationEventCallsClientCacheReadyForEvents() {
|
||||
final ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -974,7 +1021,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onApplicationEventDoesNotCallClientCacheReadyForEventsWhenClientCacheFactoryBeanReadyForEventsIsFalse() {
|
||||
final ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
doThrow(new RuntimeException("test")).when(mockClientCache).readyForEvents();
|
||||
|
||||
@@ -996,7 +1044,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onApplicationEventHandlesIllegalStateException() {
|
||||
final ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
doThrow(new IllegalStateException("test")).when(mockClientCache).readyForEvents();
|
||||
|
||||
@@ -1017,6 +1066,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void onApplicationEventHandlesCacheClosedException() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
throw new CacheClosedException("test");
|
||||
@@ -1032,6 +1082,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void closeClientCacheWithKeepAlive() {
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
@@ -1047,6 +1098,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void closeClientCacheWithoutKeepAlive() {
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
@@ -1066,7 +1118,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void enableAutoReconnect() {
|
||||
public void autoReconnectEnabled() {
|
||||
new ClientCacheFactoryBean().setEnableAutoReconnect(true);
|
||||
}
|
||||
|
||||
@@ -1076,12 +1128,13 @@ public class ClientCacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void useClusterConfiguration() {
|
||||
public void usesClusterConfiguration() {
|
||||
new ClientCacheFactoryBean().setUseClusterConfiguration(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGetKeepAlive() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getKeepAlive(), is(false));
|
||||
@@ -1100,7 +1153,9 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void setAndGetPool() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
assertThat(clientCacheFactoryBean.getPool(), is(nullValue()));
|
||||
@@ -1116,6 +1171,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void setAndGetPoolName() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getPoolName(), is(nullValue()));
|
||||
@@ -1131,6 +1187,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void setAndGetPoolSettings() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getFreeConnectionTimeout(), is(nullValue()));
|
||||
@@ -1145,6 +1202,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
assertThat(clientCacheFactoryBean.getRetryAttempts(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getServerGroup(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSocketBufferSize(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSocketConnectTimeout(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getStatisticsInterval(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionAckInterval(), is(nullValue()));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionEnabled(), is(nullValue()));
|
||||
@@ -1164,6 +1222,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
clientCacheFactoryBean.setRetryAttempts(1);
|
||||
clientCacheFactoryBean.setServerGroup("test");
|
||||
clientCacheFactoryBean.setSocketBufferSize(16384);
|
||||
clientCacheFactoryBean.setSocketConnectTimeout(5000);
|
||||
clientCacheFactoryBean.setStatisticsInterval(500);
|
||||
clientCacheFactoryBean.setSubscriptionAckInterval(200);
|
||||
clientCacheFactoryBean.setSubscriptionEnabled(true);
|
||||
@@ -1183,6 +1242,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
assertThat(clientCacheFactoryBean.getRetryAttempts(), is(equalTo(1)));
|
||||
assertThat(clientCacheFactoryBean.getServerGroup(), is(equalTo("test")));
|
||||
assertThat(clientCacheFactoryBean.getSocketBufferSize(), is(16384));
|
||||
assertThat(clientCacheFactoryBean.getSocketConnectTimeout(), is(5000));
|
||||
assertThat(clientCacheFactoryBean.getStatisticsInterval(), is(equalTo(500)));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionAckInterval(), is(equalTo(200)));
|
||||
assertThat(clientCacheFactoryBean.getSubscriptionEnabled(), is(equalTo(true)));
|
||||
@@ -1193,6 +1253,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void setAndGetReadyForEvents() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getReadyForEvents(), is(nullValue()));
|
||||
@@ -1211,6 +1272,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
}
|
||||
|
||||
private ClientCache mockClientCache(String durableClientId) {
|
||||
|
||||
ClientCache mockClientCache = mock(ClientCache.class);
|
||||
|
||||
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
|
||||
@@ -1230,7 +1292,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void isReadyForEventsIsTrueWhenClientCacheFactoryBeanReadyForEventsIsTrue() {
|
||||
final ClientCache mockClientCache = mockClientCache("");
|
||||
|
||||
ClientCache mockClientCache = mockClientCache("");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -1249,7 +1312,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void isReadyForEventsIsFalseWhenClientCacheFactoryBeanReadyForEventsIsFalse() {
|
||||
final ClientCache mockClientCache = mockClientCache("TestDurableClientId");
|
||||
|
||||
ClientCache mockClientCache = mockClientCache("TestDurableClientId");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -1267,6 +1331,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void isReadyForEventsIsFalseWhenClientCacheNotInitialized() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
throw new CacheClosedException("test");
|
||||
@@ -1280,7 +1345,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void isReadyForEventsIsTrueWhenDurableClientIdIsSet() {
|
||||
final ClientCache mockClientCache = mockClientCache("TestDurableClientId");
|
||||
|
||||
ClientCache mockClientCache = mockClientCache("TestDurableClientId");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -1297,7 +1363,8 @@ public class ClientCacheFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void isReadyForEventsIsFalseWhenDurableClientIdIsNotSet() {
|
||||
final ClientCache mockClientCache = mockClientCache(" ");
|
||||
|
||||
ClientCache mockClientCache = mockClientCache(" ");
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean() {
|
||||
@Override protected <T extends GemFireCache> T fetchCache() {
|
||||
@@ -1313,6 +1380,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void addSetAndGetLocators() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getLocators(), is(notNullValue()));
|
||||
@@ -1348,6 +1416,7 @@ public class ClientCacheFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void addSetAndGetServers() {
|
||||
|
||||
ClientCacheFactoryBean clientCacheFactoryBean = new ClientCacheFactoryBean();
|
||||
|
||||
assertThat(clientCacheFactoryBean.getServers(), is(notNullValue()));
|
||||
|
||||
@@ -79,11 +79,12 @@ public class PoolFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
BeanFactory mockBeanFactory = mock(BeanFactory.class);
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
final PoolFactory mockPoolFactory = mock(PoolFactory.class);
|
||||
PoolFactory mockPoolFactory = mock(PoolFactory.class);
|
||||
|
||||
when(mockPoolFactory.create(eq("GemFirePool"))).thenReturn(mockPool);
|
||||
|
||||
@@ -100,20 +101,21 @@ public class PoolFactoryBeanTest {
|
||||
poolFactoryBean.setBeanName("GemFirePool");
|
||||
poolFactoryBean.setName(null);
|
||||
poolFactoryBean.setFreeConnectionTimeout(60000);
|
||||
poolFactoryBean.setIdleTimeout(120000l);
|
||||
poolFactoryBean.setIdleTimeout(120000L);
|
||||
poolFactoryBean.setKeepAlive(false);
|
||||
poolFactoryBean.setLoadConditioningInterval(15000);
|
||||
poolFactoryBean.setLocators(Collections.singletonList(newConnectionEndpoint("localhost", 54321)));
|
||||
poolFactoryBean.setMaxConnections(50);
|
||||
poolFactoryBean.setMinConnections(5);
|
||||
poolFactoryBean.setMultiUserAuthentication(false);
|
||||
poolFactoryBean.setPingInterval(5000l);
|
||||
poolFactoryBean.setPingInterval(5000L);
|
||||
poolFactoryBean.setPrSingleHopEnabled(true);
|
||||
poolFactoryBean.setReadTimeout(30000);
|
||||
poolFactoryBean.setRetryAttempts(10);
|
||||
poolFactoryBean.setServerGroup("TestServerGroup");
|
||||
poolFactoryBean.setServers(Collections.singletonList(newConnectionEndpoint("localhost", 12345)));
|
||||
poolFactoryBean.setSocketBufferSize(32768);
|
||||
poolFactoryBean.setSocketConnectTimeout(5000);
|
||||
poolFactoryBean.setStatisticInterval(1000);
|
||||
poolFactoryBean.setSubscriptionAckInterval(500);
|
||||
poolFactoryBean.setSubscriptionEnabled(true);
|
||||
@@ -127,17 +129,18 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
verify(mockBeanFactory, times(1)).getBean(eq(ClientCache.class));
|
||||
verify(mockPoolFactory, times(1)).setFreeConnectionTimeout(eq(60000));
|
||||
verify(mockPoolFactory, times(1)).setIdleTimeout(eq(120000l));
|
||||
verify(mockPoolFactory, times(1)).setIdleTimeout(eq(120000L));
|
||||
verify(mockPoolFactory, times(1)).setLoadConditioningInterval(eq(15000));
|
||||
verify(mockPoolFactory, times(1)).setMaxConnections(eq(50));
|
||||
verify(mockPoolFactory, times(1)).setMinConnections(eq(5));
|
||||
verify(mockPoolFactory, times(1)).setMultiuserAuthentication(eq(false));
|
||||
verify(mockPoolFactory, times(1)).setPingInterval(eq(5000l));
|
||||
verify(mockPoolFactory, times(1)).setPingInterval(eq(5000L));
|
||||
verify(mockPoolFactory, times(1)).setPRSingleHopEnabled(eq(true));
|
||||
verify(mockPoolFactory, times(1)).setReadTimeout(eq(30000));
|
||||
verify(mockPoolFactory, times(1)).setRetryAttempts(eq(10));
|
||||
verify(mockPoolFactory, times(1)).setServerGroup(eq("TestServerGroup"));
|
||||
verify(mockPoolFactory, times(1)).setSocketBufferSize(eq(32768));
|
||||
verify(mockPoolFactory, times(1)).setSocketConnectTimeout(eq(5000));
|
||||
verify(mockPoolFactory, times(1)).setStatisticInterval(eq(1000));
|
||||
verify(mockPoolFactory, times(1)).setSubscriptionAckInterval(eq(500));
|
||||
verify(mockPoolFactory, times(1)).setSubscriptionEnabled(eq(true));
|
||||
@@ -150,7 +153,9 @@ public class PoolFactoryBeanTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("all")
|
||||
public void afterPropertiesSetWithUnspecifiedName() throws Exception {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName(null);
|
||||
@@ -168,6 +173,7 @@ public class PoolFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSetUsesName() throws Exception {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("gemfirePool");
|
||||
@@ -184,6 +190,7 @@ public class PoolFactoryBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void afterPropertiesSetDefaultsToBeanName() throws Exception {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("swimPool");
|
||||
@@ -199,6 +206,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void destroy() throws Exception {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.isDestroyed()).thenReturn(false);
|
||||
@@ -216,6 +224,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void destroyWithNonSpringBasedPool() throws Exception {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
@@ -231,6 +240,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void destroyWithUninitializedPool() throws Exception {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setPool(null);
|
||||
@@ -249,6 +259,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void addGetAndSetLocators() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
assertThat(poolFactoryBean.getLocators(), is(notNullValue()));
|
||||
@@ -284,6 +295,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void addGetAndSetServers() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
assertThat(poolFactoryBean.getServers(), is(notNullValue()));
|
||||
@@ -319,7 +331,9 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolWhenPoolIsSetIsThePool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setPool(mockPool);
|
||||
@@ -329,22 +343,24 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolWhenPoolIsUnsetIsThePoolFactoryBean() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setFreeConnectionTimeout(5000);
|
||||
poolFactoryBean.setIdleTimeout(120000l);
|
||||
poolFactoryBean.setIdleTimeout(120000L);
|
||||
poolFactoryBean.setLoadConditioningInterval(300000);
|
||||
poolFactoryBean.setLocators(ArrayUtils.asArray(newConnectionEndpoint("skullbox", 11235)));
|
||||
poolFactoryBean.setMaxConnections(500);
|
||||
poolFactoryBean.setMinConnections(50);
|
||||
poolFactoryBean.setMultiUserAuthentication(true);
|
||||
poolFactoryBean.setPingInterval(15000l);
|
||||
poolFactoryBean.setPingInterval(15000L);
|
||||
poolFactoryBean.setPrSingleHopEnabled(true);
|
||||
poolFactoryBean.setReadTimeout(30000);
|
||||
poolFactoryBean.setRetryAttempts(1);
|
||||
poolFactoryBean.setServerGroup("TestGroup");
|
||||
poolFactoryBean.setServers(ArrayUtils.asArray(newConnectionEndpoint("boombox", 12480)));
|
||||
poolFactoryBean.setSocketBufferSize(16384);
|
||||
poolFactoryBean.setSocketConnectTimeout(5000);
|
||||
poolFactoryBean.setStatisticInterval(500);
|
||||
poolFactoryBean.setSubscriptionAckInterval(200);
|
||||
poolFactoryBean.setSubscriptionEnabled(true);
|
||||
@@ -357,20 +373,21 @@ public class PoolFactoryBeanTest {
|
||||
assertThat(pool, is(instanceOf(PoolAdapter.class)));
|
||||
assertThat(pool.isDestroyed(), is(false));
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(5000)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(120000l)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(120000L)));
|
||||
assertThat(pool.getLoadConditioningInterval(), is(equalTo(300000)));
|
||||
assertThat(pool.getLocators(), is(equalTo(Collections.singletonList(newSocketAddress("skullbox", 11235)))));
|
||||
assertThat(pool.getMaxConnections(), is(equalTo(500)));
|
||||
assertThat(pool.getMinConnections(), is(equalTo(50)));
|
||||
assertThat(pool.getMultiuserAuthentication(), is(equalTo(true)));
|
||||
assertThat(pool.getName(), is(nullValue()));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000l)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000L)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(30000)));
|
||||
assertThat(pool.getRetryAttempts(), is(equalTo(1)));
|
||||
assertThat(pool.getServerGroup(), is(equalTo("TestGroup")));
|
||||
assertThat(pool.getServers(), is(equalTo(Collections.singletonList(newSocketAddress("boombox", 12480)))));
|
||||
assertThat(pool.getSocketBufferSize(), is(equalTo(16384)));
|
||||
assertThat(pool.getSocketConnectTimeout(), is(equalTo(5000)));
|
||||
assertThat(pool.getStatisticInterval(), is(equalTo(500)));
|
||||
assertThat(pool.getSubscriptionAckInterval(), is(equalTo(200)));
|
||||
assertThat(pool.getSubscriptionEnabled(), is(equalTo(true)));
|
||||
@@ -381,6 +398,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolNameWhenBeanNameSet() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("PoolBean");
|
||||
@@ -391,6 +409,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolNameWhenBeanNameAndNameSet() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
poolFactoryBean.setBeanName("PoolBean");
|
||||
@@ -401,11 +420,13 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolPendingEventCountWithPool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
when(mockPool.getPendingEventCount()).thenReturn(2);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
assertThat(pool, is(not(sameInstance(mockPool))));
|
||||
@@ -420,6 +441,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolPendingEventCountWithoutPoolThrowsIllegalStateException() {
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool has not been initialized");
|
||||
@@ -429,7 +451,9 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolQueryServiceWithPool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
QueryService mockQueryService = mock(QueryService.class);
|
||||
|
||||
when(mockPool.getQueryService()).thenReturn(mockQueryService);
|
||||
@@ -449,6 +473,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolQueryServiceWithoutPoolThrowsIllegalStateException() {
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool has not been initialized");
|
||||
@@ -458,6 +483,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolAndDestroyWithPool() {
|
||||
|
||||
Pool mockPool = mock(Pool.class);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean() {
|
||||
@@ -481,7 +507,8 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolAndDestroyWithoutPool() {
|
||||
final AtomicBoolean destroyCalled = new AtomicBoolean(false);
|
||||
|
||||
AtomicBoolean destroyCalled = new AtomicBoolean(false);
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean() {
|
||||
@Override public void destroy() throws Exception {
|
||||
@@ -506,6 +533,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolAndReleaseThreadLocalConnectionWithPool() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
@@ -522,6 +550,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
@Test
|
||||
public void getPoolAndReleaseThreadLocalConnectionWithoutPool() {
|
||||
|
||||
PoolFactoryBean poolFactoryBean = new PoolFactoryBean();
|
||||
|
||||
Pool pool = poolFactoryBean.getPool();
|
||||
|
||||
@@ -80,46 +80,49 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
|
||||
@Before
|
||||
public void setupMockPool() {
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(5000);
|
||||
when(mockPool.getIdleTimeout()).thenReturn(120000L);
|
||||
when(mockPool.getLoadConditioningInterval()).thenReturn(300000);
|
||||
when(mockPool.getLocators()).thenReturn(Collections.emptyList());
|
||||
when(mockPool.getMaxConnections()).thenReturn(500);
|
||||
when(mockPool.getMinConnections()).thenReturn(50);
|
||||
when(mockPool.getMultiuserAuthentication()).thenReturn(true);
|
||||
when(mockPool.getName()).thenReturn("TestPool");
|
||||
when(mockPool.getPendingEventCount()).thenReturn(2);
|
||||
when(mockPool.getPingInterval()).thenReturn(15000L);
|
||||
when(mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(mockPool.getQueryService()).thenReturn(null);
|
||||
when(mockPool.getReadTimeout()).thenReturn(30000);
|
||||
when(mockPool.getRetryAttempts()).thenReturn(1);
|
||||
when(mockPool.getServerGroup()).thenReturn("TestGroup");
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(
|
||||
|
||||
when(this.mockPool.getFreeConnectionTimeout()).thenReturn(5000);
|
||||
when(this.mockPool.getIdleTimeout()).thenReturn(120000L);
|
||||
when(this.mockPool.getLoadConditioningInterval()).thenReturn(300000);
|
||||
when(this.mockPool.getLocators()).thenReturn(Collections.emptyList());
|
||||
when(this.mockPool.getMaxConnections()).thenReturn(500);
|
||||
when(this.mockPool.getMinConnections()).thenReturn(50);
|
||||
when(this.mockPool.getMultiuserAuthentication()).thenReturn(true);
|
||||
when(this.mockPool.getName()).thenReturn("TestPool");
|
||||
when(this.mockPool.getPendingEventCount()).thenReturn(2);
|
||||
when(this.mockPool.getPingInterval()).thenReturn(15000L);
|
||||
when(this.mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(this.mockPool.getQueryService()).thenReturn(null);
|
||||
when(this.mockPool.getReadTimeout()).thenReturn(30000);
|
||||
when(this.mockPool.getRetryAttempts()).thenReturn(1);
|
||||
when(this.mockPool.getServerGroup()).thenReturn("TestGroup");
|
||||
when(this.mockPool.getServers()).thenReturn(Collections.singletonList(
|
||||
newSocketAddress("localhost", GemfireUtils.DEFAULT_CACHE_SERVER_PORT)));
|
||||
when(mockPool.getSocketBufferSize()).thenReturn(16384);
|
||||
when(mockPool.getStatisticInterval()).thenReturn(1000);
|
||||
when(mockPool.getSubscriptionAckInterval()).thenReturn(200);
|
||||
when(mockPool.getSubscriptionEnabled()).thenReturn(true);
|
||||
when(mockPool.getSubscriptionMessageTrackingTimeout()).thenReturn(20000);
|
||||
when(mockPool.getSubscriptionRedundancy()).thenReturn(2);
|
||||
when(mockPool.getThreadLocalConnections()).thenReturn(false);
|
||||
when(this.mockPool.getSocketBufferSize()).thenReturn(16384);
|
||||
when(this.mockPool.getSocketConnectTimeout()).thenReturn(5000);
|
||||
when(this.mockPool.getStatisticInterval()).thenReturn(1000);
|
||||
when(this.mockPool.getSubscriptionAckInterval()).thenReturn(200);
|
||||
when(this.mockPool.getSubscriptionEnabled()).thenReturn(true);
|
||||
when(this.mockPool.getSubscriptionMessageTrackingTimeout()).thenReturn(20000);
|
||||
when(this.mockPool.getSubscriptionRedundancy()).thenReturn(2);
|
||||
when(this.mockPool.getThreadLocalConnections()).thenReturn(false);
|
||||
|
||||
setupPoolAdapter();
|
||||
}
|
||||
|
||||
//@Before
|
||||
public void setupPoolAdapter() {
|
||||
poolAdapter = DefaultableDelegatingPoolAdapter.from(mockPool);
|
||||
this.poolAdapter = DefaultableDelegatingPoolAdapter.from(this.mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromMockPoolAsDelegate() {
|
||||
assertThat(poolAdapter.getDelegate(), is(sameInstance(mockPool)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(sameInstance(this.mockPool)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromNullAsDelegate() {
|
||||
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("'delegate' must not be null");
|
||||
@@ -128,398 +131,426 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferenceDefaultsToPoolDelegateAndIsMutable() {
|
||||
assertThat(poolAdapter.getPreference(), is(equalTo(DefaultableDelegatingPoolAdapter.Preference.PREFER_POOL)));
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
public void prefersDefaultsToPoolDelegateAndIsMutable() {
|
||||
|
||||
poolAdapter.preferDefault();
|
||||
assertThat(this.poolAdapter.getPreference(), is(equalTo(DefaultableDelegatingPoolAdapter.Preference.PREFER_POOL)));
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
|
||||
assertThat(poolAdapter.getPreference(), is(equalTo(DefaultableDelegatingPoolAdapter.Preference.PREFER_DEFAULT)));
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
this.poolAdapter.preferDefault();
|
||||
|
||||
poolAdapter.preferPool();
|
||||
assertThat(this.poolAdapter.getPreference(), is(equalTo(DefaultableDelegatingPoolAdapter.Preference.PREFER_DEFAULT)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
|
||||
assertThat(poolAdapter.getPreference(), is(equalTo(DefaultableDelegatingPoolAdapter.Preference.PREFER_POOL)));
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
this.poolAdapter.preferPool();
|
||||
|
||||
assertThat(this.poolAdapter.getPreference(), is(equalTo(DefaultableDelegatingPoolAdapter.Preference.PREFER_POOL)));
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersDefaultUsesDefault() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("default")));
|
||||
this.poolAdapter = this.poolAdapter.preferDefault();
|
||||
|
||||
verifyZeroInteractions(mockValueProvider);
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(this.poolAdapter.defaultIfNull("default", this.mockValueProvider),
|
||||
is(equalTo("default")));
|
||||
|
||||
verifyZeroInteractions(this.mockValueProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersDefaultUsesPoolValueWhenDefaultIsNull() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn("pool");
|
||||
this.poolAdapter = this.poolAdapter.preferDefault();
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(poolAdapter.defaultIfNull(null, mockValueProvider), is(equalTo("pool")));
|
||||
when(this.mockValueProvider.getValue()).thenReturn("pool");
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(this.poolAdapter.defaultIfNull(null, this.mockValueProvider),
|
||||
is(equalTo("pool")));
|
||||
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersPoolUsesPoolValue() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
this.poolAdapter = this.poolAdapter.preferPool();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn("pool");
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat(poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("pool")));
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
assertThat(this.poolAdapter.defaultIfNull("default", this.mockValueProvider),
|
||||
is(equalTo("pool")));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersPoolUsesDefaultWhenPoolValueIsNull() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(null);
|
||||
this.poolAdapter = this.poolAdapter.preferPool();
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat(poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("default")));
|
||||
when(this.mockValueProvider.getValue()).thenReturn(null);
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
assertThat(this.poolAdapter.defaultIfNull("default", this.mockValueProvider),
|
||||
is(equalTo("default")));
|
||||
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfEmptyWhenPrefersDefaultUsesDefault() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
this.poolAdapter = this.poolAdapter.preferDefault();
|
||||
|
||||
List<Object> defaultList = Collections.singletonList("default");
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(defaultList, mockValueProvider), is(equalTo(defaultList)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) this.poolAdapter.defaultIfEmpty(defaultList, this.mockValueProvider), is(equalTo(defaultList)));
|
||||
|
||||
verifyZeroInteractions(mockValueProvider);
|
||||
verifyZeroInteractions(this.mockValueProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfEmptyWhenPrefersDefaultUsesPoolValueWhenDefaultIsNull() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
this.poolAdapter = this.poolAdapter.preferDefault();
|
||||
|
||||
List<Object> poolList = Collections.singletonList("pool");
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(poolList);
|
||||
when(this.mockValueProvider.getValue()).thenReturn(poolList);
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(null, mockValueProvider), is(equalTo(poolList)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) this.poolAdapter.defaultIfEmpty(null, this.mockValueProvider), is(equalTo(poolList)));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfEmptyWhenPrefersDefaultUsesPoolValueWhenDefaultIsEmpty() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
this.poolAdapter = this.poolAdapter.preferDefault();
|
||||
|
||||
List<Object> poolList = Collections.singletonList("pool");
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(poolList);
|
||||
when(this.mockValueProvider.getValue()).thenReturn(poolList);
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(Collections.emptyList(), mockValueProvider),
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) this.poolAdapter.defaultIfEmpty(Collections.emptyList(), this.mockValueProvider),
|
||||
is(equalTo(poolList)));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfEmptyWhenPrefersPoolUsesPoolValue() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
this.poolAdapter = this.poolAdapter.preferPool();
|
||||
|
||||
List<Object> poolList = Collections.singletonList("pool");
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(poolList);
|
||||
when(this.mockValueProvider.getValue()).thenReturn(poolList);
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(Collections.<Object>singletonList("default"), mockValueProvider),
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) this.poolAdapter.defaultIfEmpty(Collections.<Object>singletonList("default"), this.mockValueProvider),
|
||||
is(equalTo(poolList)));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfEmptyWhenPrefersPoolUsesDefaultWhenPoolValueIsNull() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(null);
|
||||
this.poolAdapter = this.poolAdapter.preferPool();
|
||||
|
||||
when(this.mockValueProvider.getValue()).thenReturn(null);
|
||||
|
||||
List<Object> defaultList = Collections.singletonList("default");
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(defaultList, mockValueProvider),
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) this.poolAdapter.defaultIfEmpty(defaultList, this.mockValueProvider),
|
||||
is(equalTo(defaultList)));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfEmptyWhenPrefersPoolUsesDefaultWhenPoolValueIsEmpty() {
|
||||
assertThat(poolAdapter.preferPool(), is(sameInstance(poolAdapter)));
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(Collections.emptyList());
|
||||
assertThat(this.poolAdapter.preferPool(), is(sameInstance(this.poolAdapter)));
|
||||
|
||||
when(this.mockValueProvider.getValue()).thenReturn(Collections.emptyList());
|
||||
|
||||
List<Object> defaultList = Collections.singletonList("default");
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(defaultList, mockValueProvider),
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) this.poolAdapter.defaultIfEmpty(defaultList, this.mockValueProvider),
|
||||
is(equalTo(defaultList)));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
verify(this.mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolAdapterPreferringDefaultsUsesNonNullDefaults() {
|
||||
assertThat(poolAdapter.preferDefault(), is(sameInstance(poolAdapter)));
|
||||
|
||||
assertThat(this.poolAdapter.preferDefault(), is(sameInstance(this.poolAdapter)));
|
||||
|
||||
List<InetSocketAddress> defaultLocator = Collections.singletonList(newSocketAddress("boombox", 21668));
|
||||
List<InetSocketAddress> defaultServer = Collections.singletonList(newSocketAddress("skullbox", 42424));
|
||||
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(10000), is(equalTo(10000)));
|
||||
assertThat(poolAdapter.getIdleTimeout(300000L), is(equalTo(300000L)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(60000), is(equalTo(60000)));
|
||||
assertThat(poolAdapter.getLocators(defaultLocator), is(equalTo(defaultLocator)));
|
||||
assertThat(poolAdapter.getMaxConnections(100), is(equalTo(100)));
|
||||
assertThat(poolAdapter.getMinConnections(10), is(equalTo(10)));
|
||||
assertThat(poolAdapter.getMultiuserAuthentication(false), is(equalTo(false)));
|
||||
assertThat(poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getPingInterval(20000L), is(equalTo(20000L)));
|
||||
assertThat(poolAdapter.getPRSingleHopEnabled(false), is(equalTo(false)));
|
||||
assertThat(poolAdapter.getQueryService(mockQueryService), is(equalTo(mockQueryService)));
|
||||
assertThat(poolAdapter.getReadTimeout(20000), is(equalTo(20000)));
|
||||
assertThat(poolAdapter.getRetryAttempts(2), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getServerGroup("MockGroup"), is(equalTo("MockGroup")));
|
||||
assertThat(poolAdapter.getServers(defaultServer), is(equalTo(defaultServer)));
|
||||
assertThat(poolAdapter.getSocketBufferSize(8192), is(equalTo(8192)));
|
||||
assertThat(poolAdapter.getStatisticInterval(2000), is(equalTo(2000)));
|
||||
assertThat(poolAdapter.getSubscriptionAckInterval(50), is(equalTo(50)));
|
||||
assertThat(poolAdapter.getSubscriptionEnabled(false), is(equalTo(false)));
|
||||
assertThat(poolAdapter.getSubscriptionMessageTrackingTimeout(15000), is(equalTo(15000)));
|
||||
assertThat(poolAdapter.getSubscriptionRedundancy(1), is(equalTo(1)));
|
||||
assertThat(poolAdapter.getThreadLocalConnections(true), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(this.poolAdapter.getFreeConnectionTimeout(10000), is(equalTo(10000)));
|
||||
assertThat(this.poolAdapter.getIdleTimeout(300000L), is(equalTo(300000L)));
|
||||
assertThat(this.poolAdapter.getLoadConditioningInterval(60000), is(equalTo(60000)));
|
||||
assertThat(this.poolAdapter.getLocators(defaultLocator), is(equalTo(defaultLocator)));
|
||||
assertThat(this.poolAdapter.getMaxConnections(100), is(equalTo(100)));
|
||||
assertThat(this.poolAdapter.getMinConnections(10), is(equalTo(10)));
|
||||
assertThat(this.poolAdapter.getMultiuserAuthentication(false), is(equalTo(false)));
|
||||
assertThat(this.poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(this.poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getPingInterval(20000L), is(equalTo(20000L)));
|
||||
assertThat(this.poolAdapter.getPRSingleHopEnabled(false), is(equalTo(false)));
|
||||
assertThat(this.poolAdapter.getQueryService(this.mockQueryService), is(equalTo(this.mockQueryService)));
|
||||
assertThat(this.poolAdapter.getReadTimeout(20000), is(equalTo(20000)));
|
||||
assertThat(this.poolAdapter.getRetryAttempts(2), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getServerGroup("MockGroup"), is(equalTo("MockGroup")));
|
||||
assertThat(this.poolAdapter.getServers(defaultServer), is(equalTo(defaultServer)));
|
||||
assertThat(this.poolAdapter.getSocketBufferSize(8192), is(equalTo(8192)));
|
||||
assertThat(this.poolAdapter.getSocketConnectTimeout(10000), is(equalTo(10000)));
|
||||
assertThat(this.poolAdapter.getStatisticInterval(2000), is(equalTo(2000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionAckInterval(50), is(equalTo(50)));
|
||||
assertThat(this.poolAdapter.getSubscriptionEnabled(false), is(equalTo(false)));
|
||||
assertThat(this.poolAdapter.getSubscriptionMessageTrackingTimeout(15000), is(equalTo(15000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionRedundancy(1), is(equalTo(1)));
|
||||
assertThat(this.poolAdapter.getThreadLocalConnections(true), is(equalTo(true)));
|
||||
|
||||
verify(mockPool, times(1)).getName();
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
verifyNoMoreInteractions(mockPool);
|
||||
verify(this.mockPool, times(1)).getName();
|
||||
verify(this.mockPool, times(1)).getPendingEventCount();
|
||||
verifyNoMoreInteractions(this.mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolAdapterPreferringDefaultsUsesPoolValuesWhenSomeDefaultValuesAreNull() {
|
||||
assertThat(poolAdapter.preferDefault(), is(sameInstance(poolAdapter)));
|
||||
|
||||
assertThat(this.poolAdapter.preferDefault(), is(sameInstance(this.poolAdapter)));
|
||||
|
||||
List<InetSocketAddress> defaultLocator = Collections.singletonList(newSocketAddress("boombox", 21668));
|
||||
List<InetSocketAddress> poolServer = Collections.singletonList(newSocketAddress("localhost", 40404));
|
||||
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(null), is(equalTo(5000)));
|
||||
assertThat(poolAdapter.getIdleTimeout(null), is(equalTo(120000L)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(60000), is(equalTo(60000)));
|
||||
assertThat(poolAdapter.getLocators(defaultLocator), is(equalTo(defaultLocator)));
|
||||
assertThat(poolAdapter.getMaxConnections(null), is(equalTo(500)));
|
||||
assertThat(poolAdapter.getMinConnections(50), is(equalTo(50)));
|
||||
assertThat(poolAdapter.getMultiuserAuthentication(null), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getPingInterval(null), is(equalTo(15000L)));
|
||||
assertThat(poolAdapter.getPRSingleHopEnabled(true), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getQueryService(null), is(nullValue()));
|
||||
assertThat(poolAdapter.getReadTimeout(20000), is(equalTo(20000)));
|
||||
assertThat(poolAdapter.getRetryAttempts(null), is(equalTo(1)));
|
||||
assertThat(poolAdapter.getServerGroup("MockGroup"), is(equalTo("MockGroup")));
|
||||
assertThat(poolAdapter.getServers(null), is(equalTo(poolServer)));
|
||||
assertThat(poolAdapter.getSocketBufferSize(32768), is(equalTo(32768)));
|
||||
assertThat(poolAdapter.getStatisticInterval(null), is(equalTo(1000)));
|
||||
assertThat(poolAdapter.getSubscriptionAckInterval(50), is(equalTo(50)));
|
||||
assertThat(poolAdapter.getSubscriptionEnabled(true), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getSubscriptionMessageTrackingTimeout(null), is(equalTo(20000)));
|
||||
assertThat(poolAdapter.getSubscriptionRedundancy(null), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getThreadLocalConnections(null), is(equalTo(false)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(this.poolAdapter.getFreeConnectionTimeout(null), is(equalTo(5000)));
|
||||
assertThat(this.poolAdapter.getIdleTimeout(null), is(equalTo(120000L)));
|
||||
assertThat(this.poolAdapter.getLoadConditioningInterval(60000), is(equalTo(60000)));
|
||||
assertThat(this.poolAdapter.getLocators(defaultLocator), is(equalTo(defaultLocator)));
|
||||
assertThat(this.poolAdapter.getMaxConnections(null), is(equalTo(500)));
|
||||
assertThat(this.poolAdapter.getMinConnections(50), is(equalTo(50)));
|
||||
assertThat(this.poolAdapter.getMultiuserAuthentication(null), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(this.poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getPingInterval(null), is(equalTo(15000L)));
|
||||
assertThat(this.poolAdapter.getPRSingleHopEnabled(true), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getQueryService(null), is(nullValue()));
|
||||
assertThat(this.poolAdapter.getReadTimeout(20000), is(equalTo(20000)));
|
||||
assertThat(this.poolAdapter.getRetryAttempts(null), is(equalTo(1)));
|
||||
assertThat(this.poolAdapter.getServerGroup("MockGroup"), is(equalTo("MockGroup")));
|
||||
assertThat(this.poolAdapter.getServers(null), is(equalTo(poolServer)));
|
||||
assertThat(this.poolAdapter.getSocketBufferSize(32768), is(equalTo(32768)));
|
||||
assertThat(this.poolAdapter.getSocketConnectTimeout(null), is(equalTo(5000)));
|
||||
assertThat(this.poolAdapter.getStatisticInterval(null), is(equalTo(1000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionAckInterval(50), is(equalTo(50)));
|
||||
assertThat(this.poolAdapter.getSubscriptionEnabled(true), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getSubscriptionMessageTrackingTimeout(null), is(equalTo(20000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionRedundancy(null), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getThreadLocalConnections(null), is(equalTo(false)));
|
||||
|
||||
verify(mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(mockPool, times(1)).getIdleTimeout();
|
||||
verify(mockPool, times(1)).getMaxConnections();
|
||||
verify(mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(mockPool, times(1)).getName();
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
verify(mockPool, times(1)).getPingInterval();
|
||||
verify(mockPool, times(1)).getQueryService();
|
||||
verify(mockPool, times(1)).getRetryAttempts();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, times(1)).getStatisticInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(mockPool, times(1)).getThreadLocalConnections();
|
||||
verifyNoMoreInteractions(mockPool);
|
||||
verify(this.mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(this.mockPool, times(1)).getIdleTimeout();
|
||||
verify(this.mockPool, times(1)).getMaxConnections();
|
||||
verify(this.mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(this.mockPool, times(1)).getName();
|
||||
verify(this.mockPool, times(1)).getPendingEventCount();
|
||||
verify(this.mockPool, times(1)).getPingInterval();
|
||||
verify(this.mockPool, times(1)).getQueryService();
|
||||
verify(this.mockPool, times(1)).getRetryAttempts();
|
||||
verify(this.mockPool, times(1)).getServers();
|
||||
verify(this.mockPool, times(1)).getSocketConnectTimeout();
|
||||
verify(this.mockPool, times(1)).getStatisticInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(this.mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(this.mockPool, times(1)).getThreadLocalConnections();
|
||||
verifyNoMoreInteractions(this.mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolAdapterPreferringDefaultsUsesPoolValuesExclusivelyWhenAllDefaultValuesAreNull() {
|
||||
assertThat(poolAdapter.preferDefault(), is(sameInstance(poolAdapter)));
|
||||
|
||||
assertThat(this.poolAdapter.preferDefault(), is(sameInstance(this.poolAdapter)));
|
||||
|
||||
List<InetSocketAddress> poolServer = Collections.singletonList(newSocketAddress("localhost", 40404));
|
||||
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(null), is(equalTo(5000)));
|
||||
assertThat(poolAdapter.getIdleTimeout(null), is(equalTo(120000L)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(null), is(equalTo(300000)));
|
||||
assertThat(poolAdapter.getLocators(null), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
assertThat(poolAdapter.getMaxConnections(null), is(equalTo(500)));
|
||||
assertThat(poolAdapter.getMinConnections(null), is(equalTo(50)));
|
||||
assertThat(poolAdapter.getMultiuserAuthentication(null), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getPingInterval(null), is(equalTo(15000L)));
|
||||
assertThat(poolAdapter.getPRSingleHopEnabled(null), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getQueryService(null), is(nullValue()));
|
||||
assertThat(poolAdapter.getReadTimeout(null), is(equalTo(30000)));
|
||||
assertThat(poolAdapter.getRetryAttempts(null), is(equalTo(1)));
|
||||
assertThat(poolAdapter.getServerGroup(null), is(equalTo("TestGroup")));
|
||||
assertThat(poolAdapter.getServers(null), is(equalTo(poolServer)));
|
||||
assertThat(poolAdapter.getSocketBufferSize(null), is(equalTo(16384)));
|
||||
assertThat(poolAdapter.getStatisticInterval(null), is(equalTo(1000)));
|
||||
assertThat(poolAdapter.getSubscriptionAckInterval(null), is(equalTo(200)));
|
||||
assertThat(poolAdapter.getSubscriptionEnabled(null), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getSubscriptionMessageTrackingTimeout(null), is(equalTo(20000)));
|
||||
assertThat(poolAdapter.getSubscriptionRedundancy(null), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getThreadLocalConnections(null), is(equalTo(false)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
assertThat(this.poolAdapter.getFreeConnectionTimeout(null), is(equalTo(5000)));
|
||||
assertThat(this.poolAdapter.getIdleTimeout(null), is(equalTo(120000L)));
|
||||
assertThat(this.poolAdapter.getLoadConditioningInterval(null), is(equalTo(300000)));
|
||||
assertThat(this.poolAdapter.getLocators(null), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
assertThat(this.poolAdapter.getMaxConnections(null), is(equalTo(500)));
|
||||
assertThat(this.poolAdapter.getMinConnections(null), is(equalTo(50)));
|
||||
assertThat(this.poolAdapter.getMultiuserAuthentication(null), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(this.poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getPingInterval(null), is(equalTo(15000L)));
|
||||
assertThat(this.poolAdapter.getPRSingleHopEnabled(null), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getQueryService(null), is(nullValue()));
|
||||
assertThat(this.poolAdapter.getReadTimeout(null), is(equalTo(30000)));
|
||||
assertThat(this.poolAdapter.getRetryAttempts(null), is(equalTo(1)));
|
||||
assertThat(this.poolAdapter.getServerGroup(null), is(equalTo("TestGroup")));
|
||||
assertThat(this.poolAdapter.getServers(null), is(equalTo(poolServer)));
|
||||
assertThat(this.poolAdapter.getSocketBufferSize(null), is(equalTo(16384)));
|
||||
assertThat(this.poolAdapter.getSocketConnectTimeout(null), is(equalTo(5000)));
|
||||
assertThat(this.poolAdapter.getStatisticInterval(null), is(equalTo(1000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionAckInterval(null), is(equalTo(200)));
|
||||
assertThat(this.poolAdapter.getSubscriptionEnabled(null), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getSubscriptionMessageTrackingTimeout(null), is(equalTo(20000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionRedundancy(null), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getThreadLocalConnections(null), is(equalTo(false)));
|
||||
|
||||
verify(mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(mockPool, times(1)).getIdleTimeout();
|
||||
verify(mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(mockPool, times(1)).getLocators();
|
||||
verify(mockPool, times(1)).getMaxConnections();
|
||||
verify(mockPool, times(1)).getMinConnections();
|
||||
verify(mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(mockPool, times(1)).getName();
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
verify(mockPool, times(1)).getPingInterval();
|
||||
verify(mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(mockPool, times(1)).getQueryService();
|
||||
verify(mockPool, times(1)).getReadTimeout();
|
||||
verify(mockPool, times(1)).getRetryAttempts();
|
||||
verify(mockPool, times(1)).getServerGroup();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, times(1)).getSocketBufferSize();
|
||||
verify(mockPool, times(1)).getStatisticInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(mockPool, times(1)).getThreadLocalConnections();
|
||||
verifyNoMoreInteractions(mockPool);
|
||||
verify(this.mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(this.mockPool, times(1)).getIdleTimeout();
|
||||
verify(this.mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(this.mockPool, times(1)).getLocators();
|
||||
verify(this.mockPool, times(1)).getMaxConnections();
|
||||
verify(this.mockPool, times(1)).getMinConnections();
|
||||
verify(this.mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(this.mockPool, times(1)).getName();
|
||||
verify(this.mockPool, times(1)).getPendingEventCount();
|
||||
verify(this.mockPool, times(1)).getPingInterval();
|
||||
verify(this.mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(this.mockPool, times(1)).getQueryService();
|
||||
verify(this.mockPool, times(1)).getReadTimeout();
|
||||
verify(this.mockPool, times(1)).getRetryAttempts();
|
||||
verify(this.mockPool, times(1)).getServerGroup();
|
||||
verify(this.mockPool, times(1)).getServers();
|
||||
verify(this.mockPool, times(1)).getSocketBufferSize();
|
||||
verify(this.mockPool, times(1)).getSocketConnectTimeout();
|
||||
verify(this.mockPool, times(1)).getStatisticInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(this.mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(this.mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(this.mockPool, times(1)).getThreadLocalConnections();
|
||||
verifyNoMoreInteractions(this.mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolAdapterPreferringPoolUsesUseNonNullPoolValues() {
|
||||
assertThat(poolAdapter.preferPool(), is(sameInstance(poolAdapter)));
|
||||
|
||||
assertThat(this.poolAdapter.preferPool(), is(sameInstance(this.poolAdapter)));
|
||||
|
||||
List<InetSocketAddress> defaultServer = Collections.singletonList(newSocketAddress("jambox", 12480));
|
||||
List<InetSocketAddress> poolServer = Collections.singletonList(newSocketAddress("localhost", 40404));
|
||||
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(15000), is(equalTo(5000)));
|
||||
assertThat(poolAdapter.getIdleTimeout(60000L), is(equalTo(120000L)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(180000), is(equalTo(300000)));
|
||||
assertThat(poolAdapter.getLocators(Collections.emptyList()), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
assertThat(poolAdapter.getMaxConnections(999), is(equalTo(500)));
|
||||
assertThat(poolAdapter.getMinConnections(99), is(equalTo(50)));
|
||||
assertThat(poolAdapter.getMultiuserAuthentication(false), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getPingInterval(20000L), is(equalTo(15000L)));
|
||||
assertThat(poolAdapter.getPRSingleHopEnabled(false), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getQueryService(null), is(nullValue()));
|
||||
assertThat(poolAdapter.getReadTimeout(20000), is(equalTo(30000)));
|
||||
assertThat(poolAdapter.getRetryAttempts(4), is(equalTo(1)));
|
||||
assertThat(poolAdapter.getServerGroup("MockGroup"), is(equalTo("TestGroup")));
|
||||
assertThat(poolAdapter.getServers(defaultServer), is(equalTo(poolServer)));
|
||||
assertThat(poolAdapter.getSocketBufferSize(8192), is(equalTo(16384)));
|
||||
assertThat(poolAdapter.getStatisticInterval(2000), is(equalTo(1000)));
|
||||
assertThat(poolAdapter.getSubscriptionAckInterval(50), is(equalTo(200)));
|
||||
assertThat(poolAdapter.getSubscriptionEnabled(false), is(equalTo(true)));
|
||||
assertThat(poolAdapter.getSubscriptionMessageTrackingTimeout(30000), is(equalTo(20000)));
|
||||
assertThat(poolAdapter.getSubscriptionRedundancy(1), is(equalTo(2)));
|
||||
assertThat(poolAdapter.getThreadLocalConnections(true), is(equalTo(false)));
|
||||
assertThat(this.poolAdapter.getFreeConnectionTimeout(15000), is(equalTo(5000)));
|
||||
assertThat(this.poolAdapter.getIdleTimeout(60000L), is(equalTo(120000L)));
|
||||
assertThat(this.poolAdapter.getLoadConditioningInterval(180000), is(equalTo(300000)));
|
||||
assertThat(this.poolAdapter.getLocators(Collections.emptyList()), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
assertThat(this.poolAdapter.getMaxConnections(999), is(equalTo(500)));
|
||||
assertThat(this.poolAdapter.getMinConnections(99), is(equalTo(50)));
|
||||
assertThat(this.poolAdapter.getMultiuserAuthentication(false), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getName(), is(equalTo("TestPool")));
|
||||
assertThat(this.poolAdapter.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getPingInterval(20000L), is(equalTo(15000L)));
|
||||
assertThat(this.poolAdapter.getPRSingleHopEnabled(false), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getQueryService(null), is(nullValue()));
|
||||
assertThat(this.poolAdapter.getReadTimeout(20000), is(equalTo(30000)));
|
||||
assertThat(this.poolAdapter.getRetryAttempts(4), is(equalTo(1)));
|
||||
assertThat(this.poolAdapter.getServerGroup("MockGroup"), is(equalTo("TestGroup")));
|
||||
assertThat(this.poolAdapter.getServers(defaultServer), is(equalTo(poolServer)));
|
||||
assertThat(this.poolAdapter.getSocketBufferSize(8192), is(equalTo(16384)));
|
||||
assertThat(this.poolAdapter.getSocketConnectTimeout(8192), is(equalTo(5000)));
|
||||
assertThat(this.poolAdapter.getStatisticInterval(2000), is(equalTo(1000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionAckInterval(50), is(equalTo(200)));
|
||||
assertThat(this.poolAdapter.getSubscriptionEnabled(false), is(equalTo(true)));
|
||||
assertThat(this.poolAdapter.getSubscriptionMessageTrackingTimeout(30000), is(equalTo(20000)));
|
||||
assertThat(this.poolAdapter.getSubscriptionRedundancy(1), is(equalTo(2)));
|
||||
assertThat(this.poolAdapter.getThreadLocalConnections(true), is(equalTo(false)));
|
||||
|
||||
verify(mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(mockPool, times(1)).getIdleTimeout();
|
||||
verify(mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(mockPool, times(1)).getLocators();
|
||||
verify(mockPool, times(1)).getMaxConnections();
|
||||
verify(mockPool, times(1)).getMinConnections();
|
||||
verify(mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(mockPool, times(1)).getName();
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
verify(mockPool, times(1)).getPingInterval();
|
||||
verify(mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(mockPool, times(1)).getQueryService();
|
||||
verify(mockPool, times(1)).getReadTimeout();
|
||||
verify(mockPool, times(1)).getRetryAttempts();
|
||||
verify(mockPool, times(1)).getServerGroup();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, times(1)).getSocketBufferSize();
|
||||
verify(mockPool, times(1)).getStatisticInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(mockPool, times(1)).getThreadLocalConnections();
|
||||
verifyNoMoreInteractions(mockPool);
|
||||
verify(this.mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(this.mockPool, times(1)).getIdleTimeout();
|
||||
verify(this.mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(this.mockPool, times(1)).getLocators();
|
||||
verify(this.mockPool, times(1)).getMaxConnections();
|
||||
verify(this.mockPool, times(1)).getMinConnections();
|
||||
verify(this.mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(this.mockPool, times(1)).getName();
|
||||
verify(this.mockPool, times(1)).getPendingEventCount();
|
||||
verify(this.mockPool, times(1)).getPingInterval();
|
||||
verify(this.mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(this.mockPool, times(1)).getQueryService();
|
||||
verify(this.mockPool, times(1)).getReadTimeout();
|
||||
verify(this.mockPool, times(1)).getRetryAttempts();
|
||||
verify(this.mockPool, times(1)).getServerGroup();
|
||||
verify(this.mockPool, times(1)).getServers();
|
||||
verify(this.mockPool, times(1)).getSocketBufferSize();
|
||||
verify(this.mockPool, times(1)).getSocketConnectTimeout();
|
||||
verify(this.mockPool, times(1)).getStatisticInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(this.mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(this.mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(this.mockPool, times(1)).getThreadLocalConnections();
|
||||
verifyNoMoreInteractions(this.mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolAdapterDestroyUsesPoolRegardlessOfPreference() {
|
||||
assertThat(poolAdapter.preferDefault(), is(sameInstance(poolAdapter)));
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
|
||||
poolAdapter.destroy();
|
||||
assertThat(this.poolAdapter.preferDefault(), is(sameInstance(this.poolAdapter)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
|
||||
assertThat(poolAdapter.preferPool(), is(sameInstance(poolAdapter)));
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
this.poolAdapter.destroy();
|
||||
|
||||
poolAdapter.destroy(true);
|
||||
assertThat(this.poolAdapter.preferPool(), is(sameInstance(this.poolAdapter)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
|
||||
verify(mockPool, times(1)).destroy();
|
||||
verify(mockPool, times(1)).destroy(anyBoolean());
|
||||
this.poolAdapter.destroy(true);
|
||||
|
||||
verify(this.mockPool, times(1)).destroy();
|
||||
verify(this.mockPool, times(1)).destroy(anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolAdapterReleaseThreadLocalConnections() {
|
||||
assertThat(poolAdapter.preferDefault(), is(sameInstance(poolAdapter)));
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
|
||||
poolAdapter.releaseThreadLocalConnection();
|
||||
assertThat(this.poolAdapter.preferDefault(), is(sameInstance(this.poolAdapter)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersDefault(), is(true));
|
||||
|
||||
assertThat(poolAdapter.preferPool(), is(sameInstance(poolAdapter)));
|
||||
assertThat(poolAdapter.getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
this.poolAdapter.releaseThreadLocalConnection();
|
||||
|
||||
poolAdapter.releaseThreadLocalConnection();
|
||||
assertThat(this.poolAdapter.preferPool(), is(sameInstance(this.poolAdapter)));
|
||||
assertThat(this.poolAdapter.getDelegate(), is(equalTo(this.mockPool)));
|
||||
assertThat(this.poolAdapter.prefersPool(), is(true));
|
||||
|
||||
verify(mockPool, times(2)).releaseThreadLocalConnection();
|
||||
this.poolAdapter.releaseThreadLocalConnection();
|
||||
|
||||
verify(this.mockPool, times(2)).releaseThreadLocalConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,41 +79,44 @@ public class DelegatingPoolAdapterTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(mockPool.isDestroyed()).thenReturn(false);
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(10000);
|
||||
when(mockPool.getIdleTimeout()).thenReturn(120000L);
|
||||
when(mockPool.getLoadConditioningInterval()).thenReturn(300000);
|
||||
when(mockPool.getLocators()).thenReturn(Collections.singletonList(newSocketAddress("skullbox", 11235)));
|
||||
when(mockPool.getMaxConnections()).thenReturn(500);
|
||||
when(mockPool.getMinConnections()).thenReturn(50);
|
||||
when(mockPool.getMultiuserAuthentication()).thenReturn(true);
|
||||
when(mockPool.getName()).thenReturn("MockPool");
|
||||
when(mockPool.getOnlineLocators()).thenReturn(Collections.singletonList(newSocketAddress("trinity", 10101)));
|
||||
when(mockPool.getPendingEventCount()).thenReturn(2);
|
||||
when(mockPool.getPingInterval()).thenReturn(15000L);
|
||||
when(mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(mockPool.getQueryService()).thenReturn(mockQueryService);
|
||||
when(mockPool.getReadTimeout()).thenReturn(30000);
|
||||
when(mockPool.getRetryAttempts()).thenReturn(1);
|
||||
when(mockPool.getServerGroup()).thenReturn("TestGroup");
|
||||
when(mockPool.getServers()).thenReturn(Collections.singletonList(newSocketAddress("xghost", 12480)));
|
||||
when(mockPool.getSocketBufferSize()).thenReturn(16384);
|
||||
when(mockPool.getStatisticInterval()).thenReturn(1000);
|
||||
when(mockPool.getSubscriptionAckInterval()).thenReturn(200);
|
||||
when(mockPool.getSubscriptionEnabled()).thenReturn(true);
|
||||
when(mockPool.getSubscriptionMessageTrackingTimeout()).thenReturn(60000);
|
||||
when(mockPool.getSubscriptionRedundancy()).thenReturn(2);
|
||||
when(mockPool.getThreadLocalConnections()).thenReturn(false);
|
||||
|
||||
when(this.mockPool.isDestroyed()).thenReturn(false);
|
||||
when(this.mockPool.getFreeConnectionTimeout()).thenReturn(10000);
|
||||
when(this.mockPool.getIdleTimeout()).thenReturn(120000L);
|
||||
when(this.mockPool.getLoadConditioningInterval()).thenReturn(300000);
|
||||
when(this.mockPool.getLocators()).thenReturn(Collections.singletonList(newSocketAddress("skullbox", 11235)));
|
||||
when(this.mockPool.getMaxConnections()).thenReturn(500);
|
||||
when(this.mockPool.getMinConnections()).thenReturn(50);
|
||||
when(this.mockPool.getMultiuserAuthentication()).thenReturn(true);
|
||||
when(this.mockPool.getName()).thenReturn("MockPool");
|
||||
when(this.mockPool.getOnlineLocators()).thenReturn(Collections.singletonList(newSocketAddress("trinity", 10101)));
|
||||
when(this.mockPool.getPendingEventCount()).thenReturn(2);
|
||||
when(this.mockPool.getPingInterval()).thenReturn(15000L);
|
||||
when(this.mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(this.mockPool.getQueryService()).thenReturn(this.mockQueryService);
|
||||
when(this.mockPool.getReadTimeout()).thenReturn(30000);
|
||||
when(this.mockPool.getRetryAttempts()).thenReturn(1);
|
||||
when(this.mockPool.getServerGroup()).thenReturn("TestGroup");
|
||||
when(this.mockPool.getServers()).thenReturn(Collections.singletonList(newSocketAddress("xghost", 12480)));
|
||||
when(this.mockPool.getSocketBufferSize()).thenReturn(16384);
|
||||
when(this.mockPool.getSocketConnectTimeout()).thenReturn(5000);
|
||||
when(this.mockPool.getStatisticInterval()).thenReturn(1000);
|
||||
when(this.mockPool.getSubscriptionAckInterval()).thenReturn(200);
|
||||
when(this.mockPool.getSubscriptionEnabled()).thenReturn(true);
|
||||
when(this.mockPool.getSubscriptionMessageTrackingTimeout()).thenReturn(60000);
|
||||
when(this.mockPool.getSubscriptionRedundancy()).thenReturn(2);
|
||||
when(this.mockPool.getThreadLocalConnections()).thenReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegateEqualsMockPool() {
|
||||
assertThat(DelegatingPoolAdapter.from(mockPool).getDelegate(), is(equalTo(mockPool)));
|
||||
assertThat(DelegatingPoolAdapter.from(this.mockPool).getDelegate(), is(equalTo(this.mockPool)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockPoolDelegateUsesMockPool() {
|
||||
Pool pool = DelegatingPoolAdapter.from(mockPool);
|
||||
|
||||
Pool pool = DelegatingPoolAdapter.from(this.mockPool);
|
||||
|
||||
assertThat(pool.isDestroyed(), is(equalTo(false)));
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(10000)));
|
||||
@@ -128,12 +131,13 @@ public class DelegatingPoolAdapterTest {
|
||||
assertThat(pool.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000L)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getQueryService(), is(equalTo(mockQueryService)));
|
||||
assertThat(pool.getQueryService(), is(equalTo(this.mockQueryService)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(30000)));
|
||||
assertThat(pool.getRetryAttempts(), is(equalTo(1)));
|
||||
assertThat(pool.getServerGroup(), is(equalTo("TestGroup")));
|
||||
assertThat(pool.getServers(), is(equalTo(Collections.singletonList(newSocketAddress("xghost", 12480)))));
|
||||
assertThat(pool.getSocketBufferSize(), is(equalTo(16384)));
|
||||
assertThat(pool.getSocketConnectTimeout(), is(equalTo(5000)));
|
||||
assertThat(pool.getStatisticInterval(), is(equalTo(1000)));
|
||||
assertThat(pool.getSubscriptionAckInterval(), is(equalTo(200)));
|
||||
assertThat(pool.getSubscriptionEnabled(), is(equalTo(true)));
|
||||
@@ -141,52 +145,54 @@ public class DelegatingPoolAdapterTest {
|
||||
assertThat(pool.getSubscriptionRedundancy(), is(equalTo(2)));
|
||||
assertThat(pool.getThreadLocalConnections(), is(equalTo(false)));
|
||||
|
||||
verify(mockPool, times(1)).isDestroyed();
|
||||
verify(mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(mockPool, times(1)).getIdleTimeout();
|
||||
verify(mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(mockPool, times(1)).getLocators();
|
||||
verify(mockPool, times(1)).getMaxConnections();
|
||||
verify(mockPool, times(1)).getMinConnections();
|
||||
verify(mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(mockPool, times(1)).getName();
|
||||
verify(mockPool, times(1)).getPendingEventCount();
|
||||
verify(mockPool, times(1)).getPingInterval();
|
||||
verify(mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(mockPool, times(1)).getQueryService();
|
||||
verify(mockPool, times(1)).getReadTimeout();
|
||||
verify(mockPool, times(1)).getRetryAttempts();
|
||||
verify(mockPool, times(1)).getServerGroup();
|
||||
verify(mockPool, times(1)).getServers();
|
||||
verify(mockPool, times(1)).getSocketBufferSize();
|
||||
verify(mockPool, times(1)).getStatisticInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(mockPool, times(1)).getThreadLocalConnections();
|
||||
verify(this.mockPool, times(1)).isDestroyed();
|
||||
verify(this.mockPool, times(1)).getFreeConnectionTimeout();
|
||||
verify(this.mockPool, times(1)).getIdleTimeout();
|
||||
verify(this.mockPool, times(1)).getLoadConditioningInterval();
|
||||
verify(this.mockPool, times(1)).getLocators();
|
||||
verify(this.mockPool, times(1)).getMaxConnections();
|
||||
verify(this.mockPool, times(1)).getMinConnections();
|
||||
verify(this.mockPool, times(1)).getMultiuserAuthentication();
|
||||
verify(this.mockPool, times(1)).getName();
|
||||
verify(this.mockPool, times(1)).getPendingEventCount();
|
||||
verify(this.mockPool, times(1)).getPingInterval();
|
||||
verify(this.mockPool, times(1)).getPRSingleHopEnabled();
|
||||
verify(this.mockPool, times(1)).getQueryService();
|
||||
verify(this.mockPool, times(1)).getReadTimeout();
|
||||
verify(this.mockPool, times(1)).getRetryAttempts();
|
||||
verify(this.mockPool, times(1)).getServerGroup();
|
||||
verify(this.mockPool, times(1)).getServers();
|
||||
verify(this.mockPool, times(1)).getSocketBufferSize();
|
||||
verify(this.mockPool, times(1)).getSocketConnectTimeout();
|
||||
verify(this.mockPool, times(1)).getStatisticInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionAckInterval();
|
||||
verify(this.mockPool, times(1)).getSubscriptionEnabled();
|
||||
verify(this.mockPool, times(1)).getSubscriptionMessageTrackingTimeout();
|
||||
verify(this.mockPool, times(1)).getSubscriptionRedundancy();
|
||||
verify(this.mockPool, times(1)).getThreadLocalConnections();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithDelegateCallsDestroy() {
|
||||
DelegatingPoolAdapter.from(mockPool).destroy();
|
||||
verify(mockPool, times(1)).destroy();
|
||||
DelegatingPoolAdapter.from(this.mockPool).destroy();
|
||||
verify(this.mockPool, times(1)).destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithKeepAliveUsingDelegateCallsDestroy() {
|
||||
DelegatingPoolAdapter.from(mockPool).destroy(true);
|
||||
verify(mockPool, times(1)).destroy(eq(true));
|
||||
DelegatingPoolAdapter.from(this.mockPool).destroy(true);
|
||||
verify(this.mockPool, times(1)).destroy(eq(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseThreadLocalConnectionWithDelegateCallsReleaseThreadLocalConnection() {
|
||||
DelegatingPoolAdapter.from(mockPool).releaseThreadLocalConnection();
|
||||
verify(mockPool, times(1)).releaseThreadLocalConnection();
|
||||
DelegatingPoolAdapter.from(this.mockPool).releaseThreadLocalConnection();
|
||||
verify(this.mockPool, times(1)).releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullDelegateUsesDefaultFactorySettings() {
|
||||
|
||||
Pool pool = DelegatingPoolAdapter.from(null);
|
||||
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT)));
|
||||
@@ -202,6 +208,7 @@ public class DelegatingPoolAdapterTest {
|
||||
assertThat(pool.getRetryAttempts(), is(equalTo(PoolFactory.DEFAULT_RETRY_ATTEMPTS)));
|
||||
assertThat(pool.getServerGroup(), is(equalTo(PoolFactory.DEFAULT_SERVER_GROUP)));
|
||||
assertThat(pool.getSocketBufferSize(), is(equalTo(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE)));
|
||||
assertThat(pool.getSocketConnectTimeout(), is(equalTo(PoolFactory.DEFAULT_SOCKET_CONNECT_TIMEOUT)));
|
||||
assertThat(pool.getStatisticInterval(), is(equalTo(PoolFactory.DEFAULT_STATISTIC_INTERVAL)));
|
||||
assertThat(pool.getSubscriptionAckInterval(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL)));
|
||||
assertThat(pool.getSubscriptionEnabled(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED)));
|
||||
@@ -209,11 +216,12 @@ public class DelegatingPoolAdapterTest {
|
||||
assertThat(pool.getSubscriptionRedundancy(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY)));
|
||||
assertThat(pool.getThreadLocalConnections(), is(equalTo(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS)));
|
||||
|
||||
verifyZeroInteractions(mockPool);
|
||||
verifyZeroInteractions(this.mockPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyedWithNullIsUnsupported() {
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(is(equalTo(DelegatingPoolAdapter.NOT_IMPLEMENTED)));
|
||||
@@ -250,18 +258,18 @@ public class DelegatingPoolAdapterTest {
|
||||
@Test
|
||||
public void destroyWithNullIsNoOp() {
|
||||
DelegatingPoolAdapter.from(null).destroy();
|
||||
verify(mockPool, never()).destroy();
|
||||
verify(this.mockPool, never()).destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyWithKeepAliveUsingNullIsNoOp() {
|
||||
DelegatingPoolAdapter.from(null).destroy(false);
|
||||
verify(mockPool, never()).destroy(anyBoolean());
|
||||
verify(this.mockPool, never()).destroy(anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseThreadLocalConnectionWithNullIsNoOp() {
|
||||
DelegatingPoolAdapter.from(null).releaseThreadLocalConnection();
|
||||
verify(mockPool, never()).releaseThreadLocalConnection();
|
||||
verify(this.mockPool, never()).releaseThreadLocalConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,95 +58,102 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
|
||||
@Test
|
||||
public void defaultPoolAdapterConfigurationPropertiesReturnDefaultFactorySettings() {
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(), is(equalTo(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT)));
|
||||
assertThat(poolAdapter.getIdleTimeout(), is(equalTo(PoolFactory.DEFAULT_IDLE_TIMEOUT)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(), is(equalTo(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL)));
|
||||
assertThat(poolAdapter.getMaxConnections(), is(equalTo(PoolFactory.DEFAULT_MAX_CONNECTIONS)));
|
||||
assertThat(poolAdapter.getMinConnections(), is(equalTo(PoolFactory.DEFAULT_MIN_CONNECTIONS)));
|
||||
assertThat(poolAdapter.getMultiuserAuthentication(), is(equalTo(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION)));
|
||||
assertThat(poolAdapter.getPRSingleHopEnabled(), is(equalTo(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED)));
|
||||
assertThat(poolAdapter.getPingInterval(), is(equalTo(PoolFactory.DEFAULT_PING_INTERVAL)));
|
||||
assertThat(poolAdapter.getReadTimeout(), is(equalTo(PoolFactory.DEFAULT_READ_TIMEOUT)));
|
||||
assertThat(poolAdapter.getRetryAttempts(), is(equalTo(PoolFactory.DEFAULT_RETRY_ATTEMPTS)));
|
||||
assertThat(poolAdapter.getServerGroup(), is(equalTo(PoolFactory.DEFAULT_SERVER_GROUP)));
|
||||
assertThat(poolAdapter.getSocketBufferSize(), is(equalTo(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE)));
|
||||
assertThat(poolAdapter.getStatisticInterval(), is(equalTo(PoolFactory.DEFAULT_STATISTIC_INTERVAL)));
|
||||
assertThat(poolAdapter.getSubscriptionAckInterval(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL)));
|
||||
assertThat(poolAdapter.getSubscriptionEnabled(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED)));
|
||||
assertThat(poolAdapter.getSubscriptionMessageTrackingTimeout(),
|
||||
|
||||
assertThat(this.poolAdapter.getFreeConnectionTimeout(), is(equalTo(PoolFactory.DEFAULT_FREE_CONNECTION_TIMEOUT)));
|
||||
assertThat(this.poolAdapter.getIdleTimeout(), is(equalTo(PoolFactory.DEFAULT_IDLE_TIMEOUT)));
|
||||
assertThat(this.poolAdapter.getLoadConditioningInterval(), is(equalTo(PoolFactory.DEFAULT_LOAD_CONDITIONING_INTERVAL)));
|
||||
assertThat(this.poolAdapter.getMaxConnections(), is(equalTo(PoolFactory.DEFAULT_MAX_CONNECTIONS)));
|
||||
assertThat(this.poolAdapter.getMinConnections(), is(equalTo(PoolFactory.DEFAULT_MIN_CONNECTIONS)));
|
||||
assertThat(this.poolAdapter.getMultiuserAuthentication(), is(equalTo(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION)));
|
||||
assertThat(this.poolAdapter.getPRSingleHopEnabled(), is(equalTo(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED)));
|
||||
assertThat(this.poolAdapter.getPingInterval(), is(equalTo(PoolFactory.DEFAULT_PING_INTERVAL)));
|
||||
assertThat(this.poolAdapter.getReadTimeout(), is(equalTo(PoolFactory.DEFAULT_READ_TIMEOUT)));
|
||||
assertThat(this.poolAdapter.getRetryAttempts(), is(equalTo(PoolFactory.DEFAULT_RETRY_ATTEMPTS)));
|
||||
assertThat(this.poolAdapter.getServerGroup(), is(equalTo(PoolFactory.DEFAULT_SERVER_GROUP)));
|
||||
assertThat(this.poolAdapter.getSocketBufferSize(), is(equalTo(PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE)));
|
||||
assertThat(this.poolAdapter.getSocketConnectTimeout(), is(equalTo(PoolFactory.DEFAULT_SOCKET_CONNECT_TIMEOUT)));
|
||||
assertThat(this.poolAdapter.getStatisticInterval(), is(equalTo(PoolFactory.DEFAULT_STATISTIC_INTERVAL)));
|
||||
assertThat(this.poolAdapter.getSubscriptionAckInterval(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL)));
|
||||
assertThat(this.poolAdapter.getSubscriptionEnabled(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED)));
|
||||
assertThat(this.poolAdapter.getSubscriptionMessageTrackingTimeout(),
|
||||
is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT)));
|
||||
assertThat(poolAdapter.getSubscriptionRedundancy(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY)));
|
||||
assertThat(poolAdapter.getThreadLocalConnections(), is(equalTo(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS)));
|
||||
assertThat(this.poolAdapter.getSubscriptionRedundancy(), is(equalTo(PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY)));
|
||||
assertThat(this.poolAdapter.getThreadLocalConnections(), is(equalTo(PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorsReturnsEmptyList() {
|
||||
assertThat(poolAdapter.getLocators(), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
assertThat(this.poolAdapter.getLocators(), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nameReturnsDefault() {
|
||||
assertThat(poolAdapter.getName(), is(equalTo(FactoryDefaultsPoolAdapter.DEFAULT_POOL_NAME)));
|
||||
assertThat(this.poolAdapter.getName(), is(equalTo(FactoryDefaultsPoolAdapter.DEFAULT_POOL_NAME)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlineLocatorsIsEmptyList() {
|
||||
assertThat(poolAdapter.getOnlineLocators(), is(equalTo(Collections.EMPTY_LIST)));
|
||||
assertThat(this.poolAdapter.getOnlineLocators(), is(equalTo(Collections.EMPTY_LIST)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryServiceIsNull() {
|
||||
assertThat(poolAdapter.getQueryService(), is(nullValue()));
|
||||
assertThat(this.poolAdapter.getQueryService(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serversReturnsLocalhostListeningOnDefaultCacheServerPort() {
|
||||
assertThat(poolAdapter.getServers(), is(equalTo(Collections.singletonList(
|
||||
assertThat(this.poolAdapter.getServers(), is(equalTo(Collections.singletonList(
|
||||
newSocketAddress("localhost", DEFAULT_CACHE_SERVER_PORT)))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDestroyedIsUnsupported() {
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.isDestroyed();
|
||||
this.poolAdapter.isDestroyed();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPendingEventCountIsUnsupported() {
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.getPendingEventCount();
|
||||
this.poolAdapter.getPendingEventCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyedIsUnsupported() {
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.destroy();
|
||||
this.poolAdapter.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyedWithKeepAliveIsUnsupported() {
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.destroy(false);
|
||||
this.poolAdapter.destroy(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseThreadLocalConnectionsIsUnsupported() {
|
||||
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.releaseThreadLocalConnection();
|
||||
this.poolAdapter.releaseThreadLocalConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
@@ -73,16 +72,21 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
PoolParser.INFRASTRUCTURE_COMPONENTS_REGISTERED.set(true);
|
||||
|
||||
parser = new PoolParser() {
|
||||
@Override BeanDefinitionRegistry getRegistry(ParserContext parserContext) {
|
||||
return mockRegistry;
|
||||
this.parser = new PoolParser() {
|
||||
|
||||
@Override
|
||||
BeanDefinitionRegistry resolveRegistry(ParserContext parserContext) {
|
||||
return PoolParserUnitTests.this.mockRegistry;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
protected void assertBeanDefinition(BeanDefinition beanDefinition, String expectedHost, String expectedPort) {
|
||||
|
||||
assertThat(beanDefinition).isNotNull();
|
||||
assertThat(beanDefinition.getBeanClassName()).isEqualTo(ConnectionEndpoint.class.getName());
|
||||
assertThat(beanDefinition.getConstructorArgumentValues().getArgumentCount()).isEqualTo(2);
|
||||
@@ -100,6 +104,7 @@ public class PoolParserUnitTests {
|
||||
assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isTrue();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
protected void assertPropertyValue(BeanDefinition beanDefinition, String propertyName, Object propertyValue) {
|
||||
assertThat(beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue())
|
||||
.isEqualTo(propertyValue);
|
||||
@@ -113,37 +118,36 @@ public class PoolParserUnitTests {
|
||||
return String.format("%1$s%2$s%3$d", beanClassName, BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR, 0);
|
||||
}
|
||||
|
||||
protected Answer<Void> newAnswer(final String beanReference, final String targetMethod,
|
||||
final String host, final String port) {
|
||||
@SuppressWarnings("all")
|
||||
protected Answer<Void> newAnswer(String beanReference, String targetMethod, String host, String port) {
|
||||
|
||||
return new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
String generatedName = invocation.getArgument(0);
|
||||
BeanDefinition methodInvokingBeanDefinition = invocation.getArgument(1);
|
||||
return invocation -> {
|
||||
|
||||
assertThat(methodInvokingBeanDefinition).isNotNull();
|
||||
assertThat(methodInvokingBeanDefinition.getBeanClassName()).isEqualTo(MethodInvokingBean.class.getName());
|
||||
assertThat(generatedName).isEqualTo(generateBeanName(methodInvokingBeanDefinition.getBeanClassName()));
|
||||
assertPropertyValue(methodInvokingBeanDefinition, "targetObject", new RuntimeBeanReference(beanReference));
|
||||
assertPropertyValue(methodInvokingBeanDefinition, "targetMethod", targetMethod);
|
||||
String generatedName = invocation.getArgument(0);
|
||||
|
||||
BeanDefinition argumentsDefinition = getPropertyValue(methodInvokingBeanDefinition, "arguments");
|
||||
BeanDefinition methodInvokingBeanDefinition = invocation.getArgument(1);
|
||||
|
||||
assertThat(argumentsDefinition.getBeanClassName()).isEqualTo(ConnectionEndpointList.class.getName());
|
||||
assertThat(methodInvokingBeanDefinition).isNotNull();
|
||||
assertThat(methodInvokingBeanDefinition.getBeanClassName()).isEqualTo(MethodInvokingBean.class.getName());
|
||||
assertThat(generatedName).isEqualTo(generateBeanName(methodInvokingBeanDefinition.getBeanClassName()));
|
||||
assertPropertyValue(methodInvokingBeanDefinition, "targetObject", new RuntimeBeanReference(beanReference));
|
||||
assertPropertyValue(methodInvokingBeanDefinition, "targetMethod", targetMethod);
|
||||
|
||||
ConstructorArgumentValues constructorArguments = argumentsDefinition.getConstructorArgumentValues();
|
||||
BeanDefinition argumentsDefinition = getPropertyValue(methodInvokingBeanDefinition, "arguments");
|
||||
|
||||
assertThat(constructorArguments.getArgumentCount()).isEqualTo(2);
|
||||
assertThat(constructorArguments.getArgumentValue(0, Integer.class).getValue()).isEqualTo(port);
|
||||
assertThat(constructorArguments.getArgumentValue(1, String.class).getValue()).isEqualTo(host);
|
||||
assertThat(argumentsDefinition.getBeanClassName()).isEqualTo(ConnectionEndpointList.class.getName());
|
||||
|
||||
return null;
|
||||
}
|
||||
ConstructorArgumentValues constructorArguments = argumentsDefinition.getConstructorArgumentValues();
|
||||
|
||||
assertThat(constructorArguments.getArgumentCount()).isEqualTo(2);
|
||||
assertThat(constructorArguments.getArgumentValue(0, Integer.class).getValue()).isEqualTo(port);
|
||||
assertThat(constructorArguments.getArgumentValue(1, String.class).getValue()).isEqualTo(host);
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("all")
|
||||
protected <T> T getPropertyValue(BeanDefinition beanDefinition, String propertyName) {
|
||||
return (T) beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue();
|
||||
}
|
||||
@@ -155,6 +159,7 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void doParse() {
|
||||
|
||||
Element mockPoolElement = mock(Element.class, "testDoParse.MockPoolElement");
|
||||
Element mockLocatorElementOne = mock(Element.class, "testDoParse.MockLocatorElementOne");
|
||||
Element mockLocatorElementTwo = mock(Element.class, "testDoParse.MockLocatorElementTwo");
|
||||
@@ -175,6 +180,7 @@ public class PoolParserUnitTests {
|
||||
when(mockPoolElement.getAttribute(eq("retry-attempts"))).thenReturn("1");
|
||||
when(mockPoolElement.getAttribute(eq("server-group"))).thenReturn("TestGroup");
|
||||
when(mockPoolElement.getAttribute(eq("socket-buffer-size"))).thenReturn("16384");
|
||||
when(mockPoolElement.getAttribute(eq("socket-connect-timeout"))).thenReturn("5000");
|
||||
when(mockPoolElement.getAttribute(eq("statistic-interval"))).thenReturn("500");
|
||||
when(mockPoolElement.getAttribute(eq("subscription-ack-interval"))).thenReturn("200");
|
||||
when(mockPoolElement.getAttribute(eq("subscription-enabled"))).thenReturn("true");
|
||||
@@ -198,10 +204,10 @@ public class PoolParserUnitTests {
|
||||
when(mockServerElement.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("skullbox");
|
||||
when(mockServerElement.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn("65535");
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
BeanDefinitionBuilder builder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(this.parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, null, builder);
|
||||
this.parser.doParse(mockPoolElement, null, builder);
|
||||
|
||||
BeanDefinition poolDefinition = builder.getBeanDefinition();
|
||||
|
||||
@@ -220,6 +226,7 @@ public class PoolParserUnitTests {
|
||||
assertPropertyValue(poolDefinition, "retryAttempts", "1");
|
||||
assertPropertyValue(poolDefinition, "serverGroup", "TestGroup");
|
||||
assertPropertyValue(poolDefinition, "socketBufferSize", "16384");
|
||||
assertPropertyValue(poolDefinition, "socketConnectTimeout", "5000");
|
||||
assertPropertyValue(poolDefinition, "statisticInterval", "500");
|
||||
assertPropertyValue(poolDefinition, "subscriptionAckInterval", "200");
|
||||
assertPropertyValue(poolDefinition, "subscriptionEnabled", "true");
|
||||
@@ -255,6 +262,7 @@ public class PoolParserUnitTests {
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("retry-attempts"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("server-group"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("socket-buffer-size"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("socket-connect-timeout"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("statistic-interval"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("subscription-ack-interval"));
|
||||
verify(mockPoolElement, times(1)).getAttribute(eq("subscription-enabled"));
|
||||
@@ -281,7 +289,9 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void doParseWithNoLocatorsAndNoServersConfigured() {
|
||||
|
||||
Element mockPoolElement = mock(Element.class);
|
||||
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn("");
|
||||
@@ -289,10 +299,10 @@ public class PoolParserUnitTests {
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
BeanDefinitionBuilder poolBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(this.parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
this.parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
|
||||
BeanDefinition poolDefinition = poolBuilder.getBeanDefinition();
|
||||
|
||||
@@ -319,7 +329,9 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void doParseWithLocatorsAttributeConfiguredAsSpELExpression() {
|
||||
|
||||
Element mockPoolElement = mock(Element.class);
|
||||
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
when(mockPoolElement.getAttribute(PoolParser.ID_ATTRIBUTE)).thenReturn("TestPool");
|
||||
@@ -328,19 +340,19 @@ public class PoolParserUnitTests {
|
||||
when(mockPoolElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn("");
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
when(this.mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addLocators",
|
||||
"#{T(example.app.config.GemFireProperties).locatorHostsPorts()}",
|
||||
String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
|
||||
doAnswer(answer).when(mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
doAnswer(answer).when(this.mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
BeanDefinitionBuilder poolBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(this.parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
this.parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
|
||||
BeanDefinition poolDefinition = poolBuilder.getBeanDefinition();
|
||||
|
||||
@@ -354,14 +366,16 @@ public class PoolParserUnitTests {
|
||||
verify(mockPoolElement, times(1)).getChildNodes();
|
||||
verify(mockNodeList, times(1)).getLength();
|
||||
verify(mockNodeList, never()).item(anyInt());
|
||||
verify(mockRegistry, times(1)).containsBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
verify(this.mockRegistry, times(1)).containsBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)));
|
||||
verify(this.mockRegistry, times(1)).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
isA(BeanDefinition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doParseWithServersAttributeConfiguredAsPropertyPlaceholder() {
|
||||
|
||||
Element mockPoolElement = mock(Element.class);
|
||||
|
||||
NodeList mockNodeList = mock(NodeList.class);
|
||||
|
||||
when(mockPoolElement.getAttribute(PoolParser.ID_ATTRIBUTE)).thenReturn("TestPool");
|
||||
@@ -370,18 +384,18 @@ public class PoolParserUnitTests {
|
||||
"${gemfire.server.hosts-and-ports}");
|
||||
when(mockPoolElement.getChildNodes()).thenReturn(mockNodeList);
|
||||
when(mockNodeList.getLength()).thenReturn(0);
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
when(this.mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addServers", "${gemfire.server.hosts-and-ports}",
|
||||
String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addServers",
|
||||
"${gemfire.server.hosts-and-ports}", String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
|
||||
doAnswer(answer).when(mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
doAnswer(answer).when(this.mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
parser.getBeanClass(mockPoolElement));
|
||||
BeanDefinitionBuilder poolBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(this.parser.getBeanClass(mockPoolElement));
|
||||
|
||||
parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
this.parser.doParse(mockPoolElement, null, poolBuilder);
|
||||
|
||||
BeanDefinition poolDefinition = poolBuilder.getBeanDefinition();
|
||||
|
||||
@@ -395,30 +409,32 @@ public class PoolParserUnitTests {
|
||||
verify(mockPoolElement, times(1)).getChildNodes();
|
||||
verify(mockNodeList, times(1)).getLength();
|
||||
verify(mockNodeList, never()).item(anyInt());
|
||||
verify(mockRegistry, times(1)).containsBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
verify(this.mockRegistry, times(1)).containsBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)));
|
||||
verify(this.mockRegistry, times(1)).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
isA(BeanDefinition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildConnection() {
|
||||
assertBeanDefinition(parser.buildConnection("earth", "1234", true), "earth", "1234");
|
||||
assertBeanDefinition(parser.buildConnection("mars", " ", true), "mars",
|
||||
|
||||
assertBeanDefinition(this.parser.buildConnection("earth", "1234", true), "earth", "1234");
|
||||
assertBeanDefinition(this.parser.buildConnection("mars", " ", true), "mars",
|
||||
String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
assertBeanDefinition(parser.buildConnection(" ", "1234", true), PoolParser.DEFAULT_HOST, "1234");
|
||||
assertBeanDefinition(parser.buildConnection(" ", "", true), PoolParser.DEFAULT_HOST,
|
||||
assertBeanDefinition(this.parser.buildConnection(" ", "1234", true), PoolParser.DEFAULT_HOST, "1234");
|
||||
assertBeanDefinition(this.parser.buildConnection(" ", "", true), PoolParser.DEFAULT_HOST,
|
||||
String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
assertBeanDefinition(parser.buildConnection("jupiter", "9876", false), "jupiter", "9876");
|
||||
assertBeanDefinition(parser.buildConnection("saturn", null, false), "saturn",
|
||||
assertBeanDefinition(this.parser.buildConnection("jupiter", "9876", false), "jupiter", "9876");
|
||||
assertBeanDefinition(this.parser.buildConnection("saturn", null, false), "saturn",
|
||||
String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
assertBeanDefinition(parser.buildConnection(null, "9876", false), PoolParser.DEFAULT_HOST, "9876");
|
||||
assertBeanDefinition(parser.buildConnection("", " ", false), PoolParser.DEFAULT_HOST,
|
||||
assertBeanDefinition(this.parser.buildConnection(null, "9876", false), PoolParser.DEFAULT_HOST, "9876");
|
||||
assertBeanDefinition(this.parser.buildConnection("", " ", false), PoolParser.DEFAULT_HOST,
|
||||
String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildConnectionsUsingLocator() {
|
||||
BeanDefinition beanDefinition = parser.buildConnections("${locators}", false);
|
||||
|
||||
BeanDefinition beanDefinition = this.parser.buildConnections("${locators}", false);
|
||||
|
||||
assertThat(beanDefinition).isNotNull();
|
||||
assertThat(beanDefinition.getBeanClassName()).isEqualTo(ConnectionEndpointList.class.getName());
|
||||
@@ -434,7 +450,8 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void buildConnectionsUsingServer() {
|
||||
BeanDefinition beanDefinition = parser.buildConnections("#{servers}", true);
|
||||
|
||||
BeanDefinition beanDefinition = this.parser.buildConnections("#{servers}", true);
|
||||
|
||||
assertThat(beanDefinition).isNotNull();
|
||||
assertThat(beanDefinition.getBeanClassName()).isEqualTo(ConnectionEndpointList.class.getName());
|
||||
@@ -450,29 +467,32 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void defaultHost() {
|
||||
assertThat(parser.defaultHost("skullbox")).isEqualTo("skullbox");
|
||||
assertThat(parser.defaultHost(" ")).isEqualTo("localhost");
|
||||
assertThat(parser.defaultHost("")).isEqualTo("localhost");
|
||||
assertThat(parser.defaultHost(null)).isEqualTo("localhost");
|
||||
|
||||
assertThat(this.parser.defaultHost("skullbox")).isEqualTo("skullbox");
|
||||
assertThat(this.parser.defaultHost(" ")).isEqualTo("localhost");
|
||||
assertThat(this.parser.defaultHost("")).isEqualTo("localhost");
|
||||
assertThat(this.parser.defaultHost(null)).isEqualTo("localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPort() {
|
||||
assertThat(parser.defaultPort("1234", true)).isEqualTo("1234");
|
||||
assertThat(parser.defaultPort("9876", false)).isEqualTo("9876");
|
||||
assertThat(parser.defaultPort(" ", true)).isEqualTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
assertThat(parser.defaultPort("", false)).isEqualTo(String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
assertThat(parser.defaultPort(null, true)).isEqualTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
|
||||
assertThat(this.parser.defaultPort("1234", true)).isEqualTo("1234");
|
||||
assertThat(this.parser.defaultPort("9876", false)).isEqualTo("9876");
|
||||
assertThat(this.parser.defaultPort(" ", true)).isEqualTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
assertThat(this.parser.defaultPort("", false)).isEqualTo(String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
assertThat(this.parser.defaultPort(null, true)).isEqualTo(String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLocator() {
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME))).thenReturn("skullbox");
|
||||
when(mockElement.getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME))).thenReturn("1234");
|
||||
|
||||
assertBeanDefinition(parser.parseLocator(mockElement), "skullbox", "1234");
|
||||
assertBeanDefinition(this.parser.parseLocator(mockElement), "skullbox", "1234");
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME));
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME));
|
||||
@@ -480,12 +500,13 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void parseLocatorWithNoHostPort() {
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(PoolParser.HOST_ATTRIBUTE_NAME)).thenReturn("");
|
||||
when(mockElement.getAttribute(PoolParser.PORT_ATTRIBUTE_NAME)).thenReturn(null);
|
||||
|
||||
assertBeanDefinition(parser.parseLocator(mockElement), PoolParser.DEFAULT_HOST,
|
||||
assertBeanDefinition(this.parser.parseLocator(mockElement), PoolParser.DEFAULT_HOST,
|
||||
String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME));
|
||||
@@ -494,38 +515,40 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void parseLocators() {
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.ID_ATTRIBUTE))).thenReturn("TestPool");
|
||||
when(mockElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME))).thenReturn(
|
||||
"jupiter, saturn[1234], [9876] ");
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
when(mockElement.getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME)))
|
||||
.thenReturn("jupiter, saturn[1234], [9876] ");
|
||||
when(this.mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addLocators", "jupiter, saturn[1234], [9876] ",
|
||||
String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addLocators",
|
||||
"jupiter, saturn[1234], [9876] ", String.valueOf(PoolParser.DEFAULT_LOCATOR_PORT));
|
||||
|
||||
doAnswer(answer).when(mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
doAnswer(answer).when(this.mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
assertThat(parser.parseLocators(mockElement, poolBuilder, mockRegistry)).isTrue();
|
||||
assertThat(this.parser.parseLocators(mockElement, poolBuilder, mockRegistry)).isTrue();
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.ID_ATTRIBUTE));
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.LOCATORS_ATTRIBUTE_NAME));
|
||||
verify(mockRegistry, times(1)).containsBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)));
|
||||
verify(mockRegistry, times(1)).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
verify(this.mockRegistry, times(1)).containsBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)));
|
||||
verify(this.mockRegistry, times(1)).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
isA(BeanDefinition.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseServer() {
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME))).thenReturn("pluto");
|
||||
when(mockElement.getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME))).thenReturn("9876");
|
||||
|
||||
assertBeanDefinition(parser.parseServer(mockElement), "pluto", "9876");
|
||||
assertBeanDefinition(this.parser.parseServer(mockElement), "pluto", "9876");
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME));
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME));
|
||||
@@ -533,12 +556,13 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void parseServerWithNoHostPort() {
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME))).thenReturn(" ");
|
||||
when(mockElement.getAttribute(eq(PoolParser.PORT_ATTRIBUTE_NAME))).thenReturn("");
|
||||
|
||||
assertBeanDefinition(parser.parseServer(mockElement), PoolParser.DEFAULT_HOST,
|
||||
assertBeanDefinition(this.parser.parseServer(mockElement), PoolParser.DEFAULT_HOST,
|
||||
String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.HOST_ATTRIBUTE_NAME));
|
||||
@@ -547,21 +571,22 @@ public class PoolParserUnitTests {
|
||||
|
||||
@Test
|
||||
public void parseServers() {
|
||||
|
||||
Element mockElement = mock(Element.class);
|
||||
|
||||
when(mockElement.getAttribute(eq(PoolParser.ID_ATTRIBUTE))).thenReturn("TestPool");
|
||||
when(mockElement.getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME))).thenReturn("mars[], venus[9876]");
|
||||
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
when(this.mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
|
||||
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addServers", "mars[], venus[9876]",
|
||||
String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
Answer<Void> answer = newAnswer("&TestPool", "addServers",
|
||||
"mars[], venus[9876]", String.valueOf(PoolParser.DEFAULT_SERVER_PORT));
|
||||
|
||||
doAnswer(answer).when(mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
doAnswer(answer).when(this.mockRegistry).registerBeanDefinition(eq(generateBeanName(MethodInvokingBean.class)),
|
||||
any(BeanDefinition.class));
|
||||
|
||||
BeanDefinitionBuilder poolBuilder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
assertThat(parser.parseServers(mockElement, poolBuilder, mockRegistry)).isTrue();
|
||||
assertThat(this.parser.parseServers(mockElement, poolBuilder, this.mockRegistry)).isTrue();
|
||||
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.ID_ATTRIBUTE));
|
||||
verify(mockElement, times(1)).getAttribute(eq(PoolParser.SERVERS_ATTRIBUTE_NAME));
|
||||
|
||||
Reference in New Issue
Block a user