Guard against accessing Pool.pendingEventCount when client is not durable.

This commit is contained in:
John Blum
2018-09-21 15:08:56 -07:00
parent e5f31b56d4
commit a1a64e7470
2 changed files with 26 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolManager;
import org.springframework.boot.actuate.health.Health;
@@ -94,7 +95,6 @@ public class GeodePoolsHealthIndicator extends AbstractGeodeHealthIndicator {
.withDetail(poolKey(poolName, "min-connections"), pool.getMinConnections())
.withDetail(poolKey(poolName, "multi-user-authentication"), toYesNoString(pool.getMultiuserAuthentication()))
.withDetail(poolKey(poolName, "online-locators"), toCommaDelimitedHostAndPortsString(pool.getOnlineLocators()))
.withDetail(poolKey(poolName, "pending-event-count"), pool.getPendingEventCount())
.withDetail(poolKey(poolName, "ping-interval"), pool.getPingInterval())
.withDetail(poolKey(poolName, "pr-single-hop-enabled"), toYesNoString(pool.getPRSingleHopEnabled()))
.withDetail(poolKey(poolName, "read-timeout"), pool.getReadTimeout())
@@ -108,6 +108,11 @@ public class GeodePoolsHealthIndicator extends AbstractGeodeHealthIndicator {
.withDetail(poolKey(poolName, "subscription-message-tracking-timeout"), pool.getSubscriptionMessageTrackingTimeout())
.withDetail(poolKey(poolName, "subscription-redundancy"), pool.getSubscriptionRedundancy())
.withDetail(poolKey(poolName, "thread-local-connections"), toYesNoString(pool.getThreadLocalConnections()));
getGemFireCache()
.map(ClientCache.class::cast)
.filter(CacheUtils::isDurable)
.ifPresent(it -> builder.withDetail(poolKey(poolName, "pending-event-count"), pool.getPendingEventCount()));
});
builder.up();

View File

@@ -28,11 +28,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.distributed.DistributedSystem;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +43,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.data.gemfire.tests.mock.PoolMockObjects;
import org.springframework.data.gemfire.util.CacheUtils;
/**
* Unit tests for {@link GeodePoolsHealthIndicator}.
@@ -54,6 +57,7 @@ import org.springframework.data.gemfire.tests.mock.PoolMockObjects;
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.client.ClientCache
* @see org.apache.geode.cache.client.Pool
* @see org.apache.geode.distributed.DistributedSystem
* @see org.springframework.boot.actuate.health.Health
* @see org.springframework.boot.actuate.health.HealthIndicator
* @see org.springframework.data.gemfire.tests.mock.PoolMockObjects
@@ -70,7 +74,22 @@ public class GeodePoolsHealthIndicatorUnitTests {
@Before
public void setup() {
this.poolsHealthIndicator = spy(new GeodePoolsHealthIndicator(this.mockClientCache));
this.poolsHealthIndicator = spy(new GeodePoolsHealthIndicator(mockDurableClient(this.mockClientCache)));
}
private ClientCache mockDurableClient(ClientCache mockClientCache) {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty(CacheUtils.DURABLE_CLIENT_ID_PROPERTY_NAME, "test-durable-client");
DistributedSystem mockDistributedSystem = mock(DistributedSystem.class);
when(mockDistributedSystem.isConnected()).thenReturn(true);
when(mockDistributedSystem.getProperties()).thenReturn(gemfireProperties);
when(mockClientCache.getDistributedSystem()).thenReturn(mockDistributedSystem);
return mockClientCache;
}
private InetSocketAddress testSocketAddress(String hostname, int port) {