From 346b458580377989776d4698b79dff31923de51e Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 19 Jul 2017 12:16:08 -0700 Subject: [PATCH] DATAGEODE-13 - Add additional tests for all Annotation config application properties. --- .../annotation/CacheServerConfiguration.java | 2 +- ...CacheServerPropertiesIntegrationTests.java | 112 +++++++++++++++-- ...ClientCachePropertiesIntegrationTests.java | 115 ++++++++++++++++++ .../DiskStorePropertiesIntegrationTests.java | 82 +++++++++++-- ...ableGemFirePropertiesIntegrationTests.java | 7 +- .../PeerCachePropertiesIntegrationTests.java | 64 +++++++++- 6 files changed, 351 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/config/annotation/CacheServerConfiguration.java b/src/main/java/org/springframework/data/gemfire/config/annotation/CacheServerConfiguration.java index ab12ad89..83c1b16d 100644 --- a/src/main/java/org/springframework/data/gemfire/config/annotation/CacheServerConfiguration.java +++ b/src/main/java/org/springframework/data/gemfire/config/annotation/CacheServerConfiguration.java @@ -220,7 +220,7 @@ public class CacheServerConfiguration extends PeerCacheConfiguration { 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"))); } } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java index f9dbfdf5..ef518121 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/CacheServerPropertiesIntegrationTests.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat; 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; @@ -28,18 +27,26 @@ 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 { @@ -66,8 +73,33 @@ public class CacheServerPropertiesIntegrationTests { 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") @@ -107,19 +139,67 @@ public class CacheServerPropertiesIntegrationTests { assertThat(testClientSubscriptionConfig.getEvictionPolicy()).isEqualTo("mem"); } - // TODO add more tests! + @Test + public void cacheServersConfiguration() { - @Configuration + 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(); + + 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) -> { @@ -129,4 +209,10 @@ public class CacheServerPropertiesIntegrationTests { }; } } + + @CacheServerApplication + @EnableGemFireMocking + @EnableCacheServer(name = "TestCacheServer") + static class TestCacheServersConfiguration { + } } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java index a77f2959..f1300bde 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/ClientCachePropertiesIntegrationTests.java @@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; 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; @@ -33,6 +34,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext 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; @@ -133,6 +135,106 @@ public class ClientCachePropertiesIntegrationTests { 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 @@ -141,6 +243,7 @@ public class ClientCachePropertiesIntegrationTests { 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 @@ -159,4 +262,16 @@ public class ClientCachePropertiesIntegrationTests { return mock(PdxSerializer.class); } } + + @EnableGemFireMocking + @EnablePdx(serializerBeanName = "mockPdxSerializer") + @ClientCacheApplication(name = "TestClientCache") + @SuppressWarnings("unused") + static class TestDynamicClientCacheConfiguration { + + @Bean + PdxSerializer mockPdxSerializer() { + return mock(PdxSerializer.class); + } + } } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java index 25cd3522..b5a5ea7f 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/DiskStorePropertiesIntegrationTests.java @@ -22,16 +22,14 @@ import java.util.Optional; import org.apache.geode.cache.DiskStore; import org.apache.geode.cache.DiskStoreFactory; -import org.apache.geode.cache.GemFireCache; 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.test.mock.MockGemFireObjectsSupport; +import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMocking; import org.springframework.mock.env.MockPropertySource; /** @@ -65,8 +63,26 @@ public class DiskStorePropertiesIntegrationTests { return applicationContext; } + @SuppressWarnings("all") + private void assertDiskStore(DiskStore diskStore, String name, boolean allowForceCompaction, boolean autoCompact, + int compactionThreshold, float diskUsageCriticalPercentage, float diskUsageWarningPercentage, + long maxOplogSize, int queueSize, long timeInterval, int writeBufferSize) { + + assertThat(diskStore).isNotNull(); + assertThat(diskStore.getAllowForceCompaction()).isEqualTo(allowForceCompaction); + assertThat(diskStore.getAutoCompact()).isEqualTo(autoCompact); + assertThat(diskStore.getCompactionThreshold()).isEqualTo(compactionThreshold); + assertThat(diskStore.getDiskUsageCriticalPercentage()).isEqualTo(diskUsageCriticalPercentage); + assertThat(diskStore.getDiskUsageWarningPercentage()).isEqualTo(diskUsageWarningPercentage); + assertThat(diskStore.getMaxOplogSize()).isEqualTo(maxOplogSize); + assertThat(diskStore.getName()).isEqualTo(name); + assertThat(diskStore.getQueueSize()).isEqualTo(queueSize); + assertThat(diskStore.getTimeInterval()).isEqualTo(timeInterval); + assertThat(diskStore.getWriteBufferSize()).isEqualTo(writeBufferSize); + } + @Test - public void diskStoreConfigurationIsCorrect() { + public void diskStoreConfiguration() { MockPropertySource testPropertySource = new MockPropertySource() .withProperty("spring.data.gemfire.disk.store.compaction-threshold", 85) @@ -96,19 +112,55 @@ public class DiskStorePropertiesIntegrationTests { assertThat(testDiskStore.getWriteBufferSize()).isEqualTo(DiskStoreFactory.DEFAULT_WRITE_BUFFER_SIZE); } - // TODO add more tests! + @Test + public void diskStoresConfiguration() { - @Configuration + MockPropertySource testPropertySource = new MockPropertySource() + .withProperty("spring.data.gemfire.disk.store.allow-force-compaction", true) + .withProperty("spring.data.gemfire.disk.store.auto-compact", false) + .withProperty("spring.data.gemfire.disk.store.compaction-threshold", 60) + .withProperty("spring.data.gemfire.disk.store.disk-usage-critical-percentage", 90.0f) + .withProperty("spring.data.gemfire.disk.store.disk-usage-warning-percentage", 75.0f) + .withProperty("spring.data.gemfire.disk.store.max-oplog-size", 512L) + .withProperty("spring.data.gemfire.disk.store.queue-size", 1024) + .withProperty("spring.data.gemfire.disk.store.time-interval", 500L) + .withProperty("spring.data.gemfire.disk.store.write-buffer-size", 16384) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.allow-force-compaction", true) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.auto-compact", false) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.compaction-threshold", 75) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.disk-usage-critical-percentage", 95.0f) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.disk-usage-warning-percentage", 80.0f) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.max-oplog-size", 2048L) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.queue-size", 512) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.time-interval", 250L) + .withProperty("spring.data.gemfire.disk.store.TestDiskStoreTwo.write-buffer-size", 65535); + + this.applicationContext = newApplicationContext(testPropertySource, TestDiskStoresConfiguration.class); + + assertThat(this.applicationContext).isNotNull(); + assertThat(this.applicationContext.containsBean("TestDiskStoreOne")).isTrue(); + assertThat(this.applicationContext.containsBean("TestDiskStoreTwo")).isTrue(); + + DiskStore testDiskStoreOne = this.applicationContext.getBean("TestDiskStoreOne", DiskStore.class); + + assertDiskStore(testDiskStoreOne, "TestDiskStoreOne", true, false, + 60, 90.0f, 75.0f, 512L, + 1024, 500L, 16384); + + DiskStore testDiskStoreTwo = this.applicationContext.getBean("TestDiskStoreTwo", DiskStore.class); + + assertDiskStore(testDiskStoreTwo, "TestDiskStoreTwo", true, false, + 75, 95.0f, 80.0f, 2048L, + 512, 250L, 65535); + } + + @PeerCacheApplication + @EnableGemFireMocking @EnableDiskStore(name = "TestDiskStore", allowForceCompaction = true, compactionThreshold = 65, diskUsageCriticalPercentage = 95.0f, diskUsageWarningPercentage = 75.0f, maxOplogSize = 2048L) @SuppressWarnings("unused") static class TestDiskStoreConfiguration { - @Bean("gemfireCache") - GemFireCache mockGemFireCache() { - return MockGemFireObjectsSupport.mockGemFireCache(); - } - @Bean DiskStoreConfigurer testDiskStoreConfigurer() { return (beanName, factoryBean) -> { @@ -118,4 +170,12 @@ public class DiskStorePropertiesIntegrationTests { }; } } + + @PeerCacheApplication + @EnableGemFireMocking + @EnableDiskStores(diskStores = { + @EnableDiskStore(name = "TestDiskStoreOne"), @EnableDiskStore(name = "TestDiskStoreTwo") + }) + static class TestDiskStoresConfiguration { + } } diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java index 30416233..7c48c46d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/EnableGemFirePropertiesIntegrationTests.java @@ -33,9 +33,10 @@ import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMockin import org.springframework.mock.env.MockPropertySource; /** - * Unit tests for {@link EnableAuth}, {@link EnableGemFireProperties}, {@link EnableHttpService}, {@link EnableLocator}, - * {@link EnableLogging}, {@link EnableManager}, {@link EnableMemcachedServer}, {@link EnableOffHeap}, - * {@link EnableRedisServer}, {@link EnableSecurity}, {@link EnableSsl}, {@link EnableStatistics}. + * Integration tests for {@link EnableAuth}, {@link EnableGemFireProperties}, {@link EnableHttpService}, + * {@link EnableLocator}, {@link EnableLogging}, {@link EnableManager}, {@link EnableMemcachedServer}, + * {@link EnableOffHeap}, {@link EnableRedisServer}, {@link EnableSecurity}, {@link EnableSsl}, + * {@link EnableStatistics}. * * @author John Blum * @see java.util.Properties diff --git a/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java index 15c45504..dd936c35 100644 --- a/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCachePropertiesIntegrationTests.java @@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.util.Optional; +import java.util.Properties; import org.apache.geode.cache.Cache; import org.apache.geode.cache.control.ResourceManager; @@ -31,6 +32,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; +import org.springframework.data.gemfire.CacheFactoryBean; import org.springframework.data.gemfire.test.mock.annotation.EnableGemFireMocking; import org.springframework.mock.env.MockPropertySource; @@ -106,19 +108,69 @@ public class PeerCachePropertiesIntegrationTests { assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(85.0f); } + @Test + public void dynamicPeerCacheConfiguration() { + + MockPropertySource testPropertySource = new MockPropertySource() + .withProperty("spring.data.gemfire.use-bean-factory-locator", true) + .withProperty("spring.data.gemfire.cache.copy-on-read", true) + .withProperty("spring.data.gemfire.cache.critical-heap-percentage", 95.0f) + .withProperty("spring.data.gemfire.cache.eviction-heap-percentage", 80.0f) + .withProperty("spring.data.gemfire.cache.log-level", "info") + .withProperty("spring.data.gemfire.cache.name", "XYZ012") + .withProperty("spring.data.gemfire.cache.peer.enable-auto-reconnect", true) + .withProperty("spring.data.gemfire.cache.peer.locators", "skullbox[11235]") + .withProperty("spring.data.gemfire.cache.peer.lock-lease", 180) + .withProperty("spring.data.gemfire.cache.peer.lock-timeout", 30) + .withProperty("spring.data.gemfire.cache.peer.message-sync-interval", 10) + .withProperty("spring.data.gemfire.cache.peer.search-timeout", 120) + .withProperty("spring.data.gemfire.cache.peer.use-cluster-configuration", true); + + this.applicationContext = newApplicationContext(testPropertySource, TestDynamicPeerCacheConfiguration.class); + + assertThat(this.applicationContext).isNotNull(); + assertThat(this.applicationContext.containsBean("gemfireCache")).isTrue(); + + CacheFactoryBean cacheFactoryBean = this.applicationContext.getBean("&gemfireCache", CacheFactoryBean.class); + + Cache cache = this.applicationContext.getBean("gemfireCache", Cache.class); + + assertThat(cacheFactoryBean).isNotNull(); + assertThat(cacheFactoryBean.isUseBeanFactoryLocator()).isTrue(); + assertThat(cache).isNotNull(); + assertThat(cache.getCopyOnRead()).isTrue(); + assertThat(cache.getDistributedSystem()).isNotNull(); + assertThat(cache.getLockLease()).isEqualTo(180); + assertThat(cache.getLockTimeout()).isEqualTo(30); + assertThat(cache.getMessageSyncInterval()).isEqualTo(10); + assertThat(cache.getSearchTimeout()).isEqualTo(120); + + Properties gemfireProperties = cache.getDistributedSystem().getProperties(); + + assertThat(gemfireProperties).isNotNull(); + assertThat(gemfireProperties.getProperty("log-level")).isEqualTo("info"); + assertThat(gemfireProperties.getProperty("name")).isEqualTo("XYZ012"); + assertThat(gemfireProperties.getProperty("use-cluster-configuration")).isEqualTo("true"); + + ResourceManager resourceManager = cache.getResourceManager(); + + assertThat(resourceManager).isNotNull(); + assertThat(resourceManager.getCriticalHeapPercentage()).isEqualTo(95.0f); + assertThat(resourceManager.getEvictionHeapPercentage()).isEqualTo(80.0f); + } + //TODO add more tests @EnableGemFireMocking @EnablePdx(ignoreUnreadFields = true, readSerialized = true, serializerBeanName = "mockPdxSerializer") @PeerCacheApplication(name = "TestPeerCache", criticalHeapPercentage = 90.0f, evictionHeapPercentage = 75.0f, lockLease = 300, lockTimeout = 120) + @SuppressWarnings("unused") static class TestPeerCacheConfiguration { @Bean PeerCacheConfigurer testPeerCacheConfigurer() { - return (beanName, beanFactory) -> { - beanFactory.setSearchTimeout(60); - }; + return (beanName, beanFactory) -> beanFactory.setSearchTimeout(60); } @Bean @@ -126,4 +178,10 @@ public class PeerCachePropertiesIntegrationTests { return mock(PdxSerializer.class); } } + + @EnableGemFireMocking + @PeerCacheApplication(name = "TestPeerCache") + @SuppressWarnings("unused") + static class TestDynamicPeerCacheConfiguration { + } }