You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/04/17 15:36:22 UTC
[geode] branch develop updated: GEODE-4858: add test for custom
cache elements not properly registered (#1806)
This is an automated email from the ASF dual-hosted git repository.
jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 828e0c2 GEODE-4858: add test for custom cache elements not properly registered (#1806)
828e0c2 is described below
commit 828e0c232a3e5e717ea3bcb1c00d127ac380e934
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Tue Apr 17 08:36:16 2018 -0700
GEODE-4858: add test for custom cache elements not properly registered (#1806)
---
.../distributed/ClusterConfigurationService.java | 1 +
.../InternalClusterConfigurationServiceTest.java | 38 ++++++++++++++++++++--
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/ClusterConfigurationService.java b/geode-core/src/main/java/org/apache/geode/distributed/ClusterConfigurationService.java
index 751f48e..2033f0d 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/ClusterConfigurationService.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/ClusterConfigurationService.java
@@ -64,6 +64,7 @@ public interface ClusterConfigurationService {
default <T extends CacheElement> T getCustomCacheElement(String group, String id,
Class<T> classT) {
+ registerBindClass(classT);
CacheConfig cacheConfig = getCacheConfig(group);
if (cacheConfig == null) {
return null;
diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalClusterConfigurationServiceTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalClusterConfigurationServiceTest.java
index ce3b87f..e18bda4 100644
--- a/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalClusterConfigurationServiceTest.java
+++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/InternalClusterConfigurationServiceTest.java
@@ -47,17 +47,22 @@ import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class InternalClusterConfigurationServiceTest {
- private InternalClusterConfigurationService service;
+ private InternalClusterConfigurationService service, service2;
private Configuration configuration;
@Before
public void setUp() throws Exception {
service = spy(InternalClusterConfigurationService.class);
+ service2 = spy(InternalClusterConfigurationService.class);
configuration = new Configuration("cluster");
- doReturn(configuration).when(service).getConfiguration("cluster");
+ doReturn(configuration).when(service).getConfiguration(any());
+ doReturn(configuration).when(service2).getConfiguration(any());
doReturn(mock(Region.class)).when(service).getConfigurationRegion();
+ doReturn(mock(Region.class)).when(service2).getConfigurationRegion();
doReturn(true).when(service).lockSharedConfiguration();
+ doReturn(true).when(service2).lockSharedConfiguration();
doNothing().when(service).unlockSharedConfiguration();
+ doNothing().when(service2).unlockSharedConfiguration();
}
@Test
@@ -110,6 +115,35 @@ public class InternalClusterConfigurationServiceTest {
}
@Test
+ public void xmlWithCustomElementsCanBeUnMarshalledByAnotherService() {
+ service.saveCustomCacheElement("cluster", new ElementOne("one"));
+ service.saveCustomCacheElement("cluster", new ElementTwo("two"));
+
+ String prettyXml = configuration.getCacheXmlContent();
+ System.out.println(prettyXml);
+
+ // the xml is sent to another locator, and can interpreted ocrrectly
+ service2.updateCacheConfig("cluster", cc -> cc);
+
+ ElementOne elementOne = service2.getCustomCacheElement("cluster", "one", ElementOne.class);
+ assertThat(elementOne.getId()).isEqualTo("one");
+
+ String uglyXml = configuration.getCacheXmlContent();
+ System.out.println(uglyXml);
+ assertThat(uglyXml).isNotEqualTo(prettyXml);
+
+ // the xml can be unmarshalled correctly by the first locator
+ CacheConfig cacheConfig = service.getCacheConfig("cluster");
+ service.updateCacheConfig("cluster", cc -> cc);
+ assertThat(cacheConfig.getCustomCacheElements()).hasSize(2);
+ assertThat(cacheConfig.getCustomCacheElements().get(0)).isInstanceOf(ElementOne.class);
+ assertThat(cacheConfig.getCustomCacheElements().get(1)).isInstanceOf(ElementTwo.class);
+
+ assertThat(configuration.getCacheXmlContent()).isEqualTo(prettyXml);
+ }
+
+
+ @Test
public void updateCustomCacheElement() {
ElementOne customOne = new ElementOne("testOne");
service.saveCustomCacheElement("cluster", customOne);
--
To stop receiving notification emails like this one, please contact
jinmeiliao@apache.org.