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/04 17:27:11 UTC
[geode] branch develop updated: GEODE-4893: add test to make sure
the callbacks will be loaded correctly (#1729)
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 111b51d GEODE-4893: add test to make sure the callbacks will be loaded correctly (#1729)
111b51d is described below
commit 111b51d8d4ea391bdf7ed327c0b6703f98964886
Author: jinmeiliao <ji...@pivotal.io>
AuthorDate: Wed Apr 4 10:27:07 2018 -0700
GEODE-4893: add test to make sure the callbacks will be loaded correctly (#1729)
---
.../internal/cli/domain/MyCacheListener.java | 36 ++++++++
.../internal/cli/domain/MyCacheLoader.java | 46 ++++++++++
.../internal/cli/domain/MyCacheWriter.java | 3 +-
.../ClusterConfigWithCallbacksDUnitTest.java | 97 ++++++++++++++++++++++
4 files changed, 181 insertions(+), 1 deletion(-)
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheListener.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheListener.java
new file mode 100644
index 0000000..9c1fbe4
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheListener.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geode.management.internal.cli.domain;
+
+import java.util.Properties;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.util.CacheListenerAdapter;
+
+public class MyCacheListener extends CacheListenerAdapter<String, String> {
+ Properties properties;
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+ this.properties = properties;
+ };
+}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheLoader.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheLoader.java
new file mode 100644
index 0000000..7bab81b
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheLoader.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geode.management.internal.cli.domain;
+
+import java.util.Properties;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheLoader;
+import org.apache.geode.cache.CacheLoaderException;
+import org.apache.geode.cache.LoaderHelper;
+
+public class MyCacheLoader implements CacheLoader<String, String> {
+ Properties properties;
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ @Override
+ public void initialize(Cache cache, Properties properties) {
+ this.properties = properties;
+ }
+
+ @Override
+ public String load(LoaderHelper<String, String> helper) throws CacheLoaderException {
+ return null;
+ }
+
+ @Override
+ public void close() {}
+}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheWriter.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheWriter.java
index fe30a95..8b4bcd0 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheWriter.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/domain/MyCacheWriter.java
@@ -17,6 +17,7 @@ package org.apache.geode.management.internal.cli.domain;
import java.util.Properties;
+import org.apache.geode.cache.Cache;
import org.apache.geode.cache.util.CacheWriterAdapter;
public class MyCacheWriter extends CacheWriterAdapter {
@@ -27,7 +28,7 @@ public class MyCacheWriter extends CacheWriterAdapter {
}
@Override
- public void init(Properties properties) {
+ public void initialize(Cache cache, Properties properties) {
this.properties = properties;
}
}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithCallbacksDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithCallbacksDUnitTest.java
new file mode 100644
index 0000000..d1609c1
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigWithCallbacksDUnitTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geode.management.internal.configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.management.internal.cli.domain.MyCacheListener;
+import org.apache.geode.management.internal.cli.domain.MyCacheWriter;
+import org.apache.geode.management.internal.configuration.utils.ZipUtils;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+
+@Category(DistributedTest.class)
+public class ClusterConfigWithCallbacksDUnitTest {
+ @Rule
+ public ClusterStartupRule cluster = new ClusterStartupRule();
+
+ @Rule
+ public GfshCommandRule gfsh = new GfshCommandRule();
+
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ private MemberVM locator, server;
+ private File clusterConfigZip;
+
+ @Before
+ public void buildClusterConfigZip() throws Exception {
+ File clusterConfigDir = tempFolder.newFolder("cluster_config");
+ File clusterDir = new File(clusterConfigDir, "cluster");
+ clusterDir.mkdir();
+
+ String clusterXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ + "<cache xmlns=\"http://geode.apache.org/schema/cache\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" copy-on-read=\"false\" is-server=\"false\" lock-lease=\"120\" lock-timeout=\"60\" search-timeout=\"300\" version=\"1.0\" xsi:schemaLocation=\"http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd\">\n"
+ + "<region name=\"regionForCluster\">\n"
+ + " <region-attributes data-policy=\"replicate\" scope=\"distributed-ack\">\n"
+ + " <cache-writer><class-name>org.apache.geode.management.internal.cli.domain.MyCacheWriter</class-name><parameter name=\"key\"><string>value</string></parameter></cache-writer>\n"
+ + " <cache-listener><class-name>org.apache.geode.management.internal.cli.domain.MyCacheListener</class-name><parameter name=\"key\"><string>value</string></parameter></cache-listener>\n"
+ + " </region-attributes>\n" + "</region></cache>";
+ File xmlFile = new File(clusterDir, "cluster.xml");
+ FileUtils.writeStringToFile(xmlFile, clusterXml, Charset.defaultCharset());
+
+ clusterConfigZip = new File(tempFolder.getRoot(), "cluster_config.zip");
+ ZipUtils.zipDirectory(clusterConfigDir.getAbsolutePath(), clusterConfigZip.getAbsolutePath());
+ }
+
+ @Test
+ public void importCCWithCallbacks() throws Exception {
+ locator = cluster.startLocatorVM(0);
+ server = cluster.startServerVM(1, locator.getPort());
+
+ gfsh.connectAndVerify(locator);
+
+ // import cluster configuration with a running server
+ gfsh.executeAndAssertThat(
+ "import cluster-configuration --zip-file-name=" + clusterConfigZip.getAbsolutePath())
+ .statusIsSuccess()
+ .containsOutput("Successfully applied the imported cluster configuration on server-1");
+
+ // assert that the callbacks are properly hooked up with the region
+ server.invoke(() -> {
+ Region region = ClusterStartupRule.getCache().getRegion("/regionForCluster");
+ MyCacheWriter writer = (MyCacheWriter) region.getAttributes().getCacheWriter();
+ MyCacheListener listener = (MyCacheListener) region.getAttributes().getCacheListeners()[0];
+ assertThat(writer.getProperties().getProperty("key")).isEqualTo("value");
+ assertThat(listener.getProperties().getProperty("key")).isEqualTo("value");
+ });
+ }
+}
--
To stop receiving notification emails like this one, please contact
jinmeiliao@apache.org.