DATAGEODE-9 - Adapt to API changes in the org.apache.geode.cache.client.Pool interface.
(cherry picked from commit d1986767f560001bfc24c14b51328865740fe4a9) Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
@@ -88,7 +88,8 @@ public abstract class PoolAdapter implements Pool {
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public boolean getPRSingleHopEnabled() {
|
||||
@Override
|
||||
public List<InetSocketAddress> getOnlineLocators() {
|
||||
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@@ -102,6 +103,11 @@ public abstract class PoolAdapter implements Pool {
|
||||
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public boolean getPRSingleHopEnabled() {
|
||||
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public QueryService getQueryService() {
|
||||
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
|
||||
@@ -176,5 +182,4 @@ public abstract class PoolAdapter implements Pool {
|
||||
public void releaseThreadLocalConnection() {
|
||||
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport<Pool> implements
|
||||
|
||||
/* (non-Javadoc) */
|
||||
public Pool getPool() {
|
||||
return (pool != null ? pool : new PoolAdapter() {
|
||||
return Optional.ofNullable(this.pool).orElseGet(() -> new PoolAdapter() {
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
Pool pool = PoolFactoryBean.this.pool;
|
||||
@@ -422,6 +422,12 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport<Pool> implements
|
||||
return PoolFactoryBean.this.locators.toInetSocketAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InetSocketAddress> getOnlineLocators() {
|
||||
return Optional.ofNullable(PoolFactoryBean.this.pool).map(Pool::getOnlineLocators)
|
||||
.orElseThrow(() -> new IllegalStateException("The Pool has not been initialized"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxConnections() {
|
||||
return PoolFactoryBean.this.maxConnections;
|
||||
@@ -445,11 +451,8 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport<Pool> implements
|
||||
|
||||
@Override
|
||||
public int getPendingEventCount() {
|
||||
Pool pool = PoolFactoryBean.this.pool;
|
||||
if (pool != null) {
|
||||
return pool.getPendingEventCount();
|
||||
}
|
||||
throw new IllegalStateException("The Pool is not initialized");
|
||||
return Optional.ofNullable(PoolFactoryBean.this.pool).map(Pool::getPendingEventCount)
|
||||
.orElseThrow(() -> new IllegalStateException("The Pool has not been initialized"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -464,11 +467,8 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport<Pool> implements
|
||||
|
||||
@Override
|
||||
public QueryService getQueryService() {
|
||||
Pool pool = PoolFactoryBean.this.pool;
|
||||
if (pool != null) {
|
||||
return pool.getQueryService();
|
||||
}
|
||||
throw new IllegalStateException("The Pool is not initialized");
|
||||
return Optional.ofNullable(PoolFactoryBean.this.pool).map(Pool::getQueryService)
|
||||
.orElseThrow(() -> new IllegalStateException("The Pool has not been initialized"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -532,26 +532,24 @@ public class PoolFactoryBean extends AbstractFactoryBeanSupport<Pool> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(final boolean keepAlive) {
|
||||
public void destroy(boolean keepAlive) {
|
||||
try {
|
||||
PoolFactoryBean.this.destroy();
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
Pool pool = PoolFactoryBean.this.pool;
|
||||
if (pool != null) {
|
||||
pool.destroy(keepAlive);
|
||||
}
|
||||
Optional.ofNullable(PoolFactoryBean.this.pool).ifPresent(pool -> pool.destroy(keepAlive));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseThreadLocalConnection() {
|
||||
Pool pool = PoolFactoryBean.this.pool;
|
||||
|
||||
if (pool != null) {
|
||||
pool.releaseThreadLocalConnection();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("The Pool is not initialized");
|
||||
throw new IllegalStateException("The Pool has not been initialized");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.gemfire.client.support;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.geode.cache.client.Pool;
|
||||
import org.apache.geode.cache.query.QueryService;
|
||||
@@ -32,7 +33,7 @@ import org.apache.geode.cache.query.QueryService;
|
||||
* when the {@link Pool} reference is <code>null</code>.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see FactoryDefaultsPoolAdapter
|
||||
* @see org.springframework.data.gemfire.client.support.FactoryDefaultsPoolAdapter
|
||||
* @see org.apache.geode.cache.client.Pool
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@@ -46,6 +47,12 @@ public abstract class DelegatingPoolAdapter extends FactoryDefaultsPoolAdapter {
|
||||
return new DelegatingPoolAdapter(delegate) { };
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of {@link DelegatingPoolAdapter} initialized with the specified {@link Pool}.
|
||||
*
|
||||
* @param delegate {@link Pool} used as the delegate; can be {@literal null}.
|
||||
* @see org.apache.geode.cache.client.Pool
|
||||
*/
|
||||
public DelegatingPoolAdapter(Pool delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
@@ -58,197 +65,178 @@ public abstract class DelegatingPoolAdapter extends FactoryDefaultsPoolAdapter {
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean isDestroyed() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.isDestroyed() : super.isDestroyed());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::isDestroyed).orElseGet(super::isDestroyed);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getFreeConnectionTimeout() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getFreeConnectionTimeout() : super.getFreeConnectionTimeout());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getFreeConnectionTimeout)
|
||||
.orElseGet(super::getFreeConnectionTimeout);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public long getIdleTimeout() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getIdleTimeout() : super.getIdleTimeout());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getIdleTimeout).orElseGet(super::getIdleTimeout);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getLoadConditioningInterval() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getLoadConditioningInterval() : super.getLoadConditioningInterval());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getLoadConditioningInterval)
|
||||
.orElseGet(super::getLoadConditioningInterval);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public List<InetSocketAddress> getLocators() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getLocators() : super.getLocators());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getLocators).orElseGet(super::getLocators);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getMaxConnections() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getMaxConnections() : super.getMaxConnections());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getMaxConnections).orElseGet(super::getMaxConnections);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getMinConnections() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getMinConnections() : super.getMinConnections());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getMinConnections).orElseGet(super::getMinConnections);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getMultiuserAuthentication() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getMultiuserAuthentication() : super.getMultiuserAuthentication());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getMultiuserAuthentication)
|
||||
.orElseGet(super::getMultiuserAuthentication);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public String getName() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getName() : super.getName());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getName).orElseGet(super::getName);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getPRSingleHopEnabled() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getPRSingleHopEnabled() : super.getPRSingleHopEnabled());
|
||||
public List<InetSocketAddress> getOnlineLocators() {
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getOnlineLocators).orElseGet(super::getOnlineLocators);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getPendingEventCount() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getPendingEventCount() : 0);
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getPendingEventCount).orElse(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public long getPingInterval() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getPingInterval() : super.getPingInterval());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getPingInterval).orElseGet(super::getPingInterval);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getPRSingleHopEnabled() {
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getPRSingleHopEnabled)
|
||||
.orElseGet(super::getPRSingleHopEnabled);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public QueryService getQueryService() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getQueryService() : super.getQueryService());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getQueryService).orElseGet(super::getQueryService);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getReadTimeout() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getReadTimeout() : super.getReadTimeout());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getReadTimeout).orElseGet(super::getReadTimeout);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getRetryAttempts() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getRetryAttempts() : super.getRetryAttempts());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getRetryAttempts).orElseGet(super::getRetryAttempts);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public String getServerGroup() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getServerGroup() : super.getServerGroup());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getServerGroup).orElseGet(super::getServerGroup);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public List<InetSocketAddress> getServers() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getServers() : super.getServers());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getServers).orElseGet(super::getServers);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getSocketBufferSize() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getSocketBufferSize() : super.getSocketBufferSize());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getSocketBufferSize).orElseGet(super::getSocketBufferSize);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getStatisticInterval() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getStatisticInterval() : super.getStatisticInterval());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getStatisticInterval)
|
||||
.orElseGet(super::getStatisticInterval);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getSubscriptionAckInterval() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getSubscriptionAckInterval() : super.getSubscriptionAckInterval());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getSubscriptionAckInterval)
|
||||
.orElseGet(super::getSubscriptionAckInterval);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getSubscriptionEnabled() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getSubscriptionEnabled() : super.getSubscriptionEnabled());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getSubscriptionEnabled)
|
||||
.orElseGet(super::getSubscriptionEnabled);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getSubscriptionMessageTrackingTimeout() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getSubscriptionMessageTrackingTimeout()
|
||||
: super.getSubscriptionMessageTrackingTimeout());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getSubscriptionMessageTrackingTimeout)
|
||||
.orElseGet(super::getSubscriptionMessageTrackingTimeout);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public int getSubscriptionRedundancy() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getSubscriptionRedundancy() : super.getSubscriptionRedundancy());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getSubscriptionRedundancy)
|
||||
.orElseGet(super::getSubscriptionRedundancy);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getThreadLocalConnections() {
|
||||
Pool delegate = getDelegate();
|
||||
return (delegate != null ? delegate.getThreadLocalConnections() : super.getThreadLocalConnections());
|
||||
return Optional.ofNullable(getDelegate()).map(Pool::getThreadLocalConnections)
|
||||
.orElseGet(super::getThreadLocalConnections);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public void destroy() {
|
||||
Pool delegate = getDelegate();
|
||||
if (delegate != null) {
|
||||
delegate.destroy();
|
||||
}
|
||||
Optional.ofNullable(getDelegate()).ifPresent(Pool::destroy);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public void destroy(final boolean keepAlive) {
|
||||
Pool delegate = getDelegate();
|
||||
if (delegate != null) {
|
||||
delegate.destroy(keepAlive);
|
||||
}
|
||||
public void destroy(boolean keepAlive) {
|
||||
Optional.ofNullable(getDelegate()).ifPresent(delegate -> delegate.destroy(keepAlive));
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public void releaseThreadLocalConnection() {
|
||||
Pool delegate = getDelegate();
|
||||
if (delegate != null) {
|
||||
delegate.releaseThreadLocalConnection();
|
||||
}
|
||||
Optional.ofNullable(getDelegate()).ifPresent(Pool::releaseThreadLocalConnection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ public abstract class FactoryDefaultsPoolAdapter extends PoolAdapter {
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getPRSingleHopEnabled() {
|
||||
return PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED;
|
||||
public List<InetSocketAddress> getOnlineLocators() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@@ -105,6 +105,12 @@ public abstract class FactoryDefaultsPoolAdapter extends PoolAdapter {
|
||||
return PoolFactory.DEFAULT_PING_INTERVAL;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public boolean getPRSingleHopEnabled() {
|
||||
return PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
public QueryService getQueryService() {
|
||||
@@ -181,5 +187,4 @@ public abstract class FactoryDefaultsPoolAdapter extends PoolAdapter {
|
||||
public void destroy() {
|
||||
destroy(DEFAULT_KEEP_ALIVE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ public class PoolFactoryBeanTest {
|
||||
public void getPoolPendingEventCountWithoutPoolThrowsIllegalStateException() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool is not initialized");
|
||||
exception.expectMessage("The Pool has not been initialized");
|
||||
|
||||
new PoolFactoryBean().getPool().getPendingEventCount();
|
||||
}
|
||||
@@ -451,7 +451,7 @@ public class PoolFactoryBeanTest {
|
||||
public void getPoolQueryServiceWithoutPoolThrowsIllegalStateException() {
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool is not initialized");
|
||||
exception.expectMessage("The Pool has not been initialized");
|
||||
|
||||
new PoolFactoryBean().getPool().getQueryService();
|
||||
}
|
||||
@@ -530,7 +530,7 @@ public class PoolFactoryBeanTest {
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage("The Pool is not initialized");
|
||||
exception.expectMessage("The Pool has not been initialized");
|
||||
|
||||
pool.releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
@@ -17,10 +17,17 @@
|
||||
|
||||
package org.springframework.data.gemfire.client.support;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
@@ -38,8 +45,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
|
||||
/**
|
||||
* The DefaultableDelegatingPoolAdapterTest class is a default suite of default cases testing the contract and functionality
|
||||
* of the {@link DefaultableDelegatingPoolAdapter} class.
|
||||
* Additional unit tests for {@link DefaultableDelegatingPoolAdapter} testing defaults.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Rule
|
||||
@@ -68,22 +74,22 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
@Mock
|
||||
private DefaultableDelegatingPoolAdapter.ValueProvider mockValueProvider;
|
||||
|
||||
protected static InetSocketAddress newSocketAddress(String host, int port) {
|
||||
private static InetSocketAddress newSocketAddress(String host, int port) {
|
||||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupMockPool() {
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(5000);
|
||||
when(mockPool.getIdleTimeout()).thenReturn(120000l);
|
||||
when(mockPool.getIdleTimeout()).thenReturn(120000L);
|
||||
when(mockPool.getLoadConditioningInterval()).thenReturn(300000);
|
||||
when(mockPool.getLocators()).thenReturn(Collections.<InetSocketAddress>emptyList());
|
||||
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.getPingInterval()).thenReturn(15000L);
|
||||
when(mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(mockPool.getQueryService()).thenReturn(null);
|
||||
when(mockPool.getReadTimeout()).thenReturn(30000);
|
||||
@@ -138,47 +144,51 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersDefaultUsesDefault() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((String) poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("default")));
|
||||
assertThat(poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("default")));
|
||||
|
||||
verifyZeroInteractions(mockValueProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersDefaultUsesPoolValueWhenDefaultIsNull() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn("pool");
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((String) poolAdapter.defaultIfNull(null, mockValueProvider), is(equalTo("pool")));
|
||||
assertThat(poolAdapter.defaultIfNull(null, mockValueProvider), is(equalTo("pool")));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersPoolUsesPoolValue() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn("pool");
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((String) poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("pool")));
|
||||
assertThat(poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("pool")));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void defaultIfNullWhenPrefersPoolUsesDefaultWhenPoolValueIsNull() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(null);
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((String) poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("default")));
|
||||
assertThat(poolAdapter.defaultIfNull("default", mockValueProvider), is(equalTo("default")));
|
||||
|
||||
verify(mockValueProvider, times(1)).getValue();
|
||||
}
|
||||
@@ -188,7 +198,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
public void defaultIfEmptyWhenPrefersDefaultUsesDefault() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
List<Object> defaultList = Collections.<Object>singletonList("default");
|
||||
List<Object> defaultList = Collections.singletonList("default");
|
||||
|
||||
assertThat(poolAdapter.prefersDefault(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(defaultList, mockValueProvider), is(equalTo(defaultList)));
|
||||
@@ -201,7 +211,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
public void defaultIfEmptyWhenPrefersDefaultUsesPoolValueWhenDefaultIsNull() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
List<Object> poolList = Collections.<Object>singletonList("pool");
|
||||
List<Object> poolList = Collections.singletonList("pool");
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(poolList);
|
||||
|
||||
@@ -216,7 +226,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
public void defaultIfEmptyWhenPrefersDefaultUsesPoolValueWhenDefaultIsEmpty() {
|
||||
poolAdapter = poolAdapter.preferDefault();
|
||||
|
||||
List<Object> poolList = Collections.<Object>singletonList("pool");
|
||||
List<Object> poolList = Collections.singletonList("pool");
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(poolList);
|
||||
|
||||
@@ -232,7 +242,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
public void defaultIfEmptyWhenPrefersPoolUsesPoolValue() {
|
||||
poolAdapter = poolAdapter.preferPool();
|
||||
|
||||
List<Object> poolList = Collections.<Object>singletonList("pool");
|
||||
List<Object> poolList = Collections.singletonList("pool");
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(poolList);
|
||||
|
||||
@@ -250,7 +260,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(null);
|
||||
|
||||
List<Object> defaultList = Collections.<Object>singletonList("default");
|
||||
List<Object> defaultList = Collections.singletonList("default");
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(defaultList, mockValueProvider),
|
||||
@@ -266,7 +276,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
|
||||
when(mockValueProvider.getValue()).thenReturn(Collections.emptyList());
|
||||
|
||||
List<Object> defaultList = Collections.<Object>singletonList("default");
|
||||
List<Object> defaultList = Collections.singletonList("default");
|
||||
|
||||
assertThat(poolAdapter.prefersPool(), is(true));
|
||||
assertThat((List<Object>) poolAdapter.defaultIfEmpty(defaultList, mockValueProvider),
|
||||
@@ -285,7 +295,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
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.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)));
|
||||
@@ -293,7 +303,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
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.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)));
|
||||
@@ -323,7 +333,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
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.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)));
|
||||
@@ -331,7 +341,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
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.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)));
|
||||
@@ -372,7 +382,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
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.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)));
|
||||
@@ -380,7 +390,7 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
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.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)));
|
||||
@@ -429,16 +439,15 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
List<InetSocketAddress> poolServer = Collections.singletonList(newSocketAddress("localhost", 40404));
|
||||
|
||||
assertThat(poolAdapter.getFreeConnectionTimeout(15000), is(equalTo(5000)));
|
||||
assertThat(poolAdapter.getIdleTimeout(60000l), is(equalTo(120000l)));
|
||||
assertThat(poolAdapter.getIdleTimeout(60000L), is(equalTo(120000L)));
|
||||
assertThat(poolAdapter.getLoadConditioningInterval(180000), is(equalTo(300000)));
|
||||
assertThat(poolAdapter.getLocators(Collections.<InetSocketAddress>emptyList()),
|
||||
is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
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.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)));
|
||||
@@ -513,5 +522,4 @@ public class DefaultableDelegatingPoolAdapterTest {
|
||||
|
||||
verify(mockPool, times(2)).releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class DelegatingPoolAdapterTest {
|
||||
@Mock
|
||||
private QueryService mockQueryService;
|
||||
|
||||
protected InetSocketAddress newSocketAddress(String host, int port) {
|
||||
private InetSocketAddress newSocketAddress(String host, int port) {
|
||||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
@@ -81,15 +81,16 @@ public class DelegatingPoolAdapterTest {
|
||||
public void setup() {
|
||||
when(mockPool.isDestroyed()).thenReturn(false);
|
||||
when(mockPool.getFreeConnectionTimeout()).thenReturn(10000);
|
||||
when(mockPool.getIdleTimeout()).thenReturn(120000l);
|
||||
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.getPingInterval()).thenReturn(15000L);
|
||||
when(mockPool.getPRSingleHopEnabled()).thenReturn(true);
|
||||
when(mockPool.getQueryService()).thenReturn(mockQueryService);
|
||||
when(mockPool.getReadTimeout()).thenReturn(30000);
|
||||
@@ -116,15 +117,16 @@ public class DelegatingPoolAdapterTest {
|
||||
|
||||
assertThat(pool.isDestroyed(), is(equalTo(false)));
|
||||
assertThat(pool.getFreeConnectionTimeout(), is(equalTo(10000)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(120000l)));
|
||||
assertThat(pool.getIdleTimeout(), is(equalTo(120000L)));
|
||||
assertThat(pool.getLoadConditioningInterval(), is(equalTo(300000)));
|
||||
assertThat(pool.getMaxConnections(), is(equalTo(500)));
|
||||
assertThat(pool.getMinConnections(), is(equalTo(50)));
|
||||
assertThat(pool.getMultiuserAuthentication(), is(equalTo(true)));
|
||||
assertThat(pool.getLocators(), is(equalTo(Collections.singletonList(newSocketAddress("skullbox", 11235)))));
|
||||
assertThat(pool.getName(), is(equalTo("MockPool")));
|
||||
assertThat(pool.getOnlineLocators(), is(equalTo(Collections.singletonList(newSocketAddress("trinity", 10101)))));
|
||||
assertThat(pool.getPendingEventCount(), is(equalTo(2)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000l)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(15000L)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(true)));
|
||||
assertThat(pool.getQueryService(), is(equalTo(mockQueryService)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(30000)));
|
||||
@@ -193,6 +195,7 @@ public class DelegatingPoolAdapterTest {
|
||||
assertThat(pool.getMaxConnections(), is(equalTo(PoolFactory.DEFAULT_MAX_CONNECTIONS)));
|
||||
assertThat(pool.getMinConnections(), is(equalTo(PoolFactory.DEFAULT_MIN_CONNECTIONS)));
|
||||
assertThat(pool.getMultiuserAuthentication(), is(equalTo(PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION)));
|
||||
assertThat(pool.getOnlineLocators(), is(equalTo(Collections.EMPTY_LIST)));
|
||||
assertThat(pool.getPingInterval(), is(equalTo(PoolFactory.DEFAULT_PING_INTERVAL)));
|
||||
assertThat(pool.getPRSingleHopEnabled(), is(equalTo(PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED)));
|
||||
assertThat(pool.getReadTimeout(), is(equalTo(PoolFactory.DEFAULT_READ_TIMEOUT)));
|
||||
@@ -261,5 +264,4 @@ public class DelegatingPoolAdapterTest {
|
||||
DelegatingPoolAdapter.from(null).releaseThreadLocalConnection();
|
||||
verify(mockPool, never()).releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,14 +32,13 @@ import org.junit.rules.ExpectedException;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
|
||||
/**
|
||||
* The FactoryDefaultsPoolAdapterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the {@link FactoryDefaultsPoolAdapter} class.
|
||||
* Unit tests for {@link FactoryDefaultsPoolAdapter}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.rules.ExpectedException
|
||||
* @see FactoryDefaultsPoolAdapter
|
||||
* @see org.springframework.data.gemfire.client.support.FactoryDefaultsPoolAdapter
|
||||
* @see org.apache.geode.cache.client.Pool
|
||||
* @see org.apache.geode.cache.client.PoolFactory
|
||||
* @since 1.8.0
|
||||
@@ -81,22 +80,27 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorsEqualsEmptyList() {
|
||||
public void locatorsReturnsEmptyList() {
|
||||
assertThat(poolAdapter.getLocators(), is(equalTo(Collections.<InetSocketAddress>emptyList())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nameEqualsDefault() {
|
||||
public void nameReturnsDefault() {
|
||||
assertThat(poolAdapter.getName(), is(equalTo(FactoryDefaultsPoolAdapter.DEFAULT_POOL_NAME)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onlineLocatorsIsEmptyList() {
|
||||
assertThat(poolAdapter.getOnlineLocators(), is(equalTo(Collections.EMPTY_LIST)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryServiceIsNull() {
|
||||
assertThat(poolAdapter.getQueryService(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serversEqualsLocalhostListeningOnDefaultCacheServerPort() {
|
||||
public void serversReturnsLocalhostListeningOnDefaultCacheServerPort() {
|
||||
assertThat(poolAdapter.getServers(), is(equalTo(Collections.singletonList(
|
||||
newSocketAddress("localhost", DEFAULT_CACHE_SERVER_PORT)))));
|
||||
}
|
||||
@@ -106,6 +110,7 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.isDestroyed();
|
||||
}
|
||||
|
||||
@@ -114,6 +119,7 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.getPendingEventCount();
|
||||
}
|
||||
|
||||
@@ -122,6 +128,7 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.destroy();
|
||||
}
|
||||
|
||||
@@ -130,6 +137,7 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.destroy(false);
|
||||
}
|
||||
|
||||
@@ -138,7 +146,7 @@ public class FactoryDefaultsPoolAdapterTest {
|
||||
exception.expect(UnsupportedOperationException.class);
|
||||
exception.expectCause(is(nullValue(Throwable.class)));
|
||||
exception.expectMessage(FactoryDefaultsPoolAdapter.NOT_IMPLEMENTED);
|
||||
|
||||
poolAdapter.releaseThreadLocalConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user