Skip to content

Commit

Permalink
DATAGEODE-13 - Add additional tests for all Annotation config applica…
Browse files Browse the repository at this point in the history
…tion properties.
  • Loading branch information
jxblum committed Jul 19, 2017
1 parent c70607a commit 346b458
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 31 deletions.
Expand Up @@ -220,7 +220,7 @@ protected void configureTheRest(AnnotationMetadata importMetadata) {
setSubscriptionEvictionPolicy(resolveProperty(cacheServerProperty("subscription-eviction-policy"),
SubscriptionEvictionPolicy.class, (SubscriptionEvictionPolicy) cacheServerApplicationAttributes.get("subscriptionEvictionPolicy")));

setTcpNoDelay(resolveProperty(cacheServerProperty("tcpNoDelay"),
setTcpNoDelay(resolveProperty(cacheServerProperty("tcp-no-delay"),
(Boolean) cacheServerApplicationAttributes.get("tcpNoDelay")));
}
}
Expand Down
Expand Up @@ -20,26 +20,33 @@

import java.util.Optional;

import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.cache.server.ClientSubscriptionConfig;
import org.junit.After;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
import org.springframework.data.gemfire.test.mock.MockGemFireObjectsSupport;
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMocking;
import org.springframework.mock.env.MockPropertySource;

/**
* The CacheServerPropertiesIntegrationTests class...
* Integration tests for {@link CacheServerApplication} and {@link EnableCacheServer}.
*
* @author John Blum
* @since 1.0.0
* @see org.junit.Test
* @see org.apache.geode.cache.server.CacheServer
* @see org.apache.geode.cache.server.ClientSubscriptionConfig
* @see org.springframework.context.ConfigurableApplicationContext
* @see org.springframework.context.annotation.Bean
* @see org.springframework.core.env.PropertySource
* @see org.springframework.data.gemfire.config.annotation.CacheServerApplication
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
* @see org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMocking
* @since 2.0.0
*/
public class CacheServerPropertiesIntegrationTests {

Expand All @@ -66,8 +73,33 @@ private ConfigurableApplicationContext newApplicationContext(PropertySource<?> t
return applicationContext;
}

private void assertCacheServer(CacheServer cacheServer, String bindAddress, String hostnameForClients,
long loadPollInterval, int maxConnections, int maxMessageCount, int maxThreads, int maxTimeBetweenPings,
int messageTimeToLive, int port, int socketBufferSize, int subscriptionCapacity,
String subscriptionDiskStoreName, SubscriptionEvictionPolicy subscriptionEvictionPolicy, boolean tcpNoDelay) {

assertThat(cacheServer).isNotNull();
assertThat(cacheServer.getBindAddress()).isEqualTo(bindAddress);
assertThat(cacheServer.getHostnameForClients()).isEqualTo(hostnameForClients);
assertThat(cacheServer.getLoadPollInterval()).isEqualTo(loadPollInterval);
assertThat(cacheServer.getMaxConnections()).isEqualTo(maxConnections);
assertThat(cacheServer.getMaximumMessageCount()).isEqualTo(maxMessageCount);
assertThat(cacheServer.getMaxThreads()).isEqualTo(maxThreads);
assertThat(cacheServer.getMaximumTimeBetweenPings()).isEqualTo(maxTimeBetweenPings);
assertThat(cacheServer.getMessageTimeToLive()).isEqualTo(messageTimeToLive);
assertThat(cacheServer.getPort()).isEqualTo(port);
assertThat(cacheServer.getSocketBufferSize()).isEqualTo(socketBufferSize);
assertThat(cacheServer.getTcpNoDelay()).isEqualTo(tcpNoDelay);

ClientSubscriptionConfig clientSubscriptionConfig = cacheServer.getClientSubscriptionConfig();

assertThat(clientSubscriptionConfig).isNotNull();
assertThat(clientSubscriptionConfig.getCapacity()).isEqualTo(subscriptionCapacity);
assertThat(clientSubscriptionConfig.getDiskStoreName()).isEqualTo(subscriptionDiskStoreName);
assertThat(clientSubscriptionConfig.getEvictionPolicy()).isEqualTo(subscriptionEvictionPolicy.toString().toLowerCase());
}
@Test
public void cacheServerConfigurationIsCorrect() {
public void cacheServerConfiguration() {

MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("gemfire.cache.server.port", "12480")
Expand Down Expand Up @@ -107,19 +139,67 @@ public void cacheServerConfigurationIsCorrect() {
assertThat(testClientSubscriptionConfig.getEvictionPolicy()).isEqualTo("mem");
}

// TODO add more tests!
@Test
public void cacheServersConfiguration() {

MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.cache.server.bind-address", "192.168.0.2")
.withProperty("spring.data.gemfire.cache.server.hostname-for-clients", "skullbox")
.withProperty("spring.data.gemfire.cache.server.load-poll-interval", 10000L)
.withProperty("spring.data.gemfire.cache.server.max-connections", 500)
.withProperty("spring.data.gemfire.cache.server.max-message-count", 451000)
.withProperty("spring.data.gemfire.cache.server.max-threads", 8)
.withProperty("spring.data.gemfire.cache.server.max-time-between-pings", 30000)
.withProperty("spring.data.gemfire.cache.server.message-time-to-live", 60)
.withProperty("spring.data.gemfire.cache.server.port", 41414)
.withProperty("spring.data.gemfire.cache.server.socket-buffer-size", 16384)
.withProperty("spring.data.gemfire.cache.server.subscription-capacity", 21)
.withProperty("spring.data.gemfire.cache.server.subscription-disk-store-name", "TestDiskStore")
.withProperty("spring.data.gemfire.cache.server.subscription-eviction-policy", "MEM")
.withProperty("spring.data.gemfire.cache.server.tcp-no-delay", false)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.bind-address", "10.121.12.1")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.hostname-for-clients", "jambox")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.load-poll-interval", "15000")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.max-connections", 200)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.max-message-count", 651000)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.max-threads", 16)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.max-time-between-pings", 15000)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.message-time-to-live", 120)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.port", 42424)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.socket-buffer-size", 65536)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-capacity", 42)
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-disk-store-name", "JunkDiskStore")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.subscription-eviction-policy", "ENTRY")
.withProperty("spring.data.gemfire.cache.server.TestCacheServer.tcp-no-delay", true);

this.applicationContext = newApplicationContext(testPropertySource, TestCacheServersConfiguration.class);

assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("TestCacheServer")).isTrue();

@Configuration
CacheServer gemfirCacheServer = this.applicationContext.getBean("gemfireCacheServer", CacheServer.class);

assertCacheServer(gemfirCacheServer, "192.168.0.2", "skullbox", 10000L,
500, 451000, 8, 30000,
60, 41414, 16384, 21,
"TestDiskStore", SubscriptionEvictionPolicy.MEM, false);

CacheServer testCacheServer = this.applicationContext.getBean("TestCacheServer", CacheServer.class);

assertCacheServer(testCacheServer, "10.121.12.1", "jambox", 15000L,
200, 651000, 16, 15000,
120, 42424, 65536, 42,
"JunkDiskStore", SubscriptionEvictionPolicy.ENTRY, true);
}

@PeerCacheApplication
@EnableGemFireMocking
@EnableCacheServer(name = "TestCacheServer", bindAddress = "192.16.0.22", hostnameForClients = "skullbox",
maxConnections = 100, maxThreads = 8, messageTimeToLive = 300, port = 11235, subscriptionCapacity = 100,
subscriptionEvictionPolicy = SubscriptionEvictionPolicy.ENTRY)
@SuppressWarnings("unused")
static class TestCacheServerConfiguration {

@Bean("gemfireCache")
GemFireCache mockGemFireCache() {
return MockGemFireObjectsSupport.mockPeerCache();
}

@Bean
CacheServerConfigurer testCacheServerConfigurer() {
return (beanName, beanFactory) -> {
Expand All @@ -129,4 +209,10 @@ CacheServerConfigurer testCacheServerConfigurer() {
};
}
}

@CacheServerApplication
@EnableGemFireMocking
@EnableCacheServer(name = "TestCacheServer")
static class TestCacheServersConfiguration {
}
}
Expand Up @@ -20,6 +20,7 @@
import static org.mockito.Mockito.mock;

import java.util.Optional;
import java.util.Properties;

import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
Expand All @@ -33,6 +34,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMocking;
import org.springframework.mock.env.MockPropertySource;

Expand Down Expand Up @@ -133,6 +135,106 @@ public void clientCacheConfiguration() {
assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(90.0f);
}

@Test
public void dynamicClientCacheConfiguration() {

MockPropertySource testPropertySource = new MockPropertySource()
.withProperty("spring.data.gemfire.cache.copy-on-read", true)
.withProperty("spring.data.gemfire.cache.critical-heap-percentage", 90.0f)
.withProperty("spring.data.gemfire.cache.eviction-heap-percentage", 75.0f)
.withProperty("spring.data.gemfire.cache.log-level", "info")
.withProperty("spring.data.gemfire.cache.name", "ABC123")
.withProperty("spring.data.gemfire.cache.client.durable-client-id", "123")
.withProperty("spring.data.gemfire.cache.client.durable-client-timeout", 600)
.withProperty("spring.data.gemfire.cache.client.keep-alive", true)
.withProperty("spring.data.gemfire.pool.default.free-connection-timeout", 5000)
.withProperty("spring.data.gemfire.pool.default.idle-timeout", 15000)
.withProperty("spring.data.gemfire.pool.default.load-conditioning-interval", 120000)
.withProperty("spring.data.gemfire.pool.default.max-connections", 100)
.withProperty("spring.data.gemfire.pool.default.min-connections", 10)
.withProperty("spring.data.gemfire.pool.default.multi-user-authentication", true)
.withProperty("spring.data.gemfire.pool.default.ping-interval", 15000L)
.withProperty("spring.data.gemfire.pool.default.pr-single-hop-enabled", false)
.withProperty("spring.data.gemfire.pool.default.read-timeout", 5000)
.withProperty("spring.data.gemfire.pool.default.ready-for-events", true)
.withProperty("spring.data.gemfire.pool.default.retry-attempts", 2)
.withProperty("spring.data.gemfire.pool.default.server-group", "testGroup")
.withProperty("spring.data.gemfire.pool.default.socket-buffer-size", 65535)
.withProperty("spring.data.gemfire.pool.default.statistic-interval", 100)
.withProperty("spring.data.gemfire.pool.default.subscription-ack-interval", 250)
.withProperty("spring.data.gemfire.pool.default.subscription-enabled", true)
.withProperty("spring.data.gemfire.pool.default.subscription-message-tracking-timeout", 300000)
.withProperty("spring.data.gemfire.pool.default.subscription-redundancy", 2)
.withProperty("spring.data.gemfire.pool.default.thread-local-connections", true)
.withProperty("spring.data.gemfire.pdx.disk-store-name", "TestPdxDiskStore")
.withProperty("spring.data.gemfire.pdx.ignore-unread-fields", false)
.withProperty("spring.data.gemfire.pdx.persistent", true)
.withProperty("spring.data.gemfire.pdx.read-serialized", true);

this.applicationContext = newApplicationContext(testPropertySource, TestDynamicClientCacheConfiguration.class);

assertThat(this.applicationContext).isNotNull();
assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue();
assertThat(this.applicationContext.containsBean("mockPdxSerializer")).isTrue();

PdxSerializer mockPdxSerializer = this.applicationContext.getBean("mockPdxSerializer", PdxSerializer.class);

ClientCacheFactoryBean clientCacheFactoryBean =
this.applicationContext.getBean("&gemfireCache", ClientCacheFactoryBean.class);

ClientCache clientCache = this.applicationContext.getBean("gemfireCache", ClientCache.class);

assertThat(mockPdxSerializer).isNotNull();
assertThat(clientCacheFactoryBean).isNotNull();
assertThat(clientCacheFactoryBean.getDurableClientId()).isEqualTo("123");
assertThat(clientCacheFactoryBean.getDurableClientTimeout()).isEqualTo(600);
assertThat(clientCacheFactoryBean.isKeepAlive()).isTrue();
assertThat(clientCacheFactoryBean.isReadyForEvents()).isTrue();
assertThat(clientCache).isNotNull();
assertThat(clientCache.getCopyOnRead()).isTrue();
assertThat(clientCache.getDistributedSystem()).isNotNull();
assertThat(clientCache.getPdxDiskStore()).isEqualTo("TestPdxDiskStore");
assertThat(clientCache.getPdxIgnoreUnreadFields()).isFalse();
assertThat(clientCache.getPdxPersistent()).isTrue();
assertThat(clientCache.getPdxReadSerialized()).isTrue();
assertThat(clientCache.getPdxSerializer()).isSameAs(mockPdxSerializer);

Properties gemfireProperties = clientCache.getDistributedSystem().getProperties();

assertThat(gemfireProperties).isNotNull();
assertThat(gemfireProperties.getProperty("log-level")).isEqualTo("info");
assertThat(gemfireProperties.getProperty("name")).isEqualTo("ABC123");

Pool defaultPool = clientCache.getDefaultPool();

assertThat(defaultPool).isNotNull();
assertThat(defaultPool.getFreeConnectionTimeout()).isEqualTo(5000);
assertThat(defaultPool.getIdleTimeout()).isEqualTo(15000L);
assertThat(defaultPool.getLoadConditioningInterval()).isEqualTo(120000);
assertThat(defaultPool.getMaxConnections()).isEqualTo(100);
assertThat(defaultPool.getMinConnections()).isEqualTo(10);
assertThat(defaultPool.getMultiuserAuthentication()).isTrue();
assertThat(defaultPool.getName()).isEqualTo("DEFAULT");
assertThat(defaultPool.getPingInterval()).isEqualTo(15000L);
assertThat(defaultPool.getPRSingleHopEnabled()).isFalse();
assertThat(defaultPool.getReadTimeout()).isEqualTo(5000);
assertThat(defaultPool.getRetryAttempts()).isEqualTo(2);
assertThat(defaultPool.getServerGroup()).isEqualTo("testGroup");
assertThat(defaultPool.getSocketBufferSize()).isEqualTo(65535);
assertThat(defaultPool.getStatisticInterval()).isEqualTo(100);
assertThat(defaultPool.getSubscriptionAckInterval()).isEqualTo(250);
assertThat(defaultPool.getSubscriptionEnabled()).isTrue();
assertThat(defaultPool.getSubscriptionMessageTrackingTimeout()).isEqualTo(300000);
assertThat(defaultPool.getSubscriptionRedundancy()).isEqualTo(2);
assertThat(defaultPool.getThreadLocalConnections()).isTrue();

ResourceManager resourceManager = clientCache.getResourceManager();

assertThat(resourceManager).isNotNull();
assertThat(resourceManager.getCriticalHeapPercentage()).isEqualTo(90.0f);
assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(75.0f);
}

// TODO add more tests!

@EnableGemFireMocking
Expand All @@ -141,6 +243,7 @@ public void clientCacheConfiguration() {
criticalHeapPercentage = 95.0f, evictionHeapPercentage = 80.0f, idleTimeout = 15000L,
maxConnections = 100, minConnections = 10, pingInterval = 15000L, readTimeout = 15000, retryAttempts = 1,
subscriptionEnabled = true, subscriptionRedundancy = 1)
@SuppressWarnings("unused")
static class TestClientCacheConfiguration {

@Bean
Expand All @@ -159,4 +262,16 @@ PdxSerializer mockPdxSerializer() {
return mock(PdxSerializer.class);
}
}

@EnableGemFireMocking
@EnablePdx(serializerBeanName = "mockPdxSerializer")
@ClientCacheApplication(name = "TestClientCache")
@SuppressWarnings("unused")
static class TestDynamicClientCacheConfiguration {

@Bean
PdxSerializer mockPdxSerializer() {
return mock(PdxSerializer.class);
}
}
}

0 comments on commit 346b458

Please sign in to comment.