You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by GitBox <gi...@apache.org> on 2019/01/14 20:52:37 UTC
[geode] Diff for: [GitHub] jdeppe-pivotal merged pull request #3074:
GEODE-6270: Correctly set up user-provided client cache regions for session
modules
diff --git a/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCache.java b/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCache.java
index 86722769e60..95142a4e44e 100644
--- a/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCache.java
+++ b/extensions/geode-modules/src/main/java/org/apache/geode/modules/session/catalina/ClientServerSessionCache.java
@@ -14,12 +14,14 @@
*/
package org.apache.geode.modules.session.catalina;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpSession;
+import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.InterestResultPolicy;
import org.apache.geode.cache.Region;
@@ -194,9 +196,24 @@ protected void createOrRetrieveRegion() {
if (getSessionManager().getLogger().isDebugEnabled()) {
getSessionManager().getLogger().debug("Retrieved session region: " + this.sessionRegion);
}
+
+ // Check that we have our expiration listener attached
+ if (!regionHasExpirationListenerAttached(sessionRegion)) {
+ sessionRegion.getAttributesMutator().addCacheListener(new SessionExpirationCacheListener());
+ }
+
+ // This is true for PROXY regions
+ if (sessionRegion.getAttributes().getDataPolicy() == DataPolicy.EMPTY) {
+ sessionRegion.registerInterest("ALL_KEYS", InterestResultPolicy.KEYS);
+ }
}
}
+ private boolean regionHasExpirationListenerAttached(Region<?, ?> region) {
+ return Arrays.stream(region.getAttributes().getCacheListeners())
+ .anyMatch(x -> x instanceof SessionExpirationCacheListener);
+ }
+
private void createSessionRegionOnServers() {
// Create the RegionConfiguration
RegionConfiguration configuration = createRegionConfiguration();
diff --git a/geode-assembly/build.gradle b/geode-assembly/build.gradle
index 33da4a219b7..004200b1137 100755
--- a/geode-assembly/build.gradle
+++ b/geode-assembly/build.gradle
@@ -102,7 +102,7 @@ configurations {
}
gfshDependencies
- //Configurations used to download and cache web application servers for session module testing
+ // Configurations used to download and cache web application servers for session module testing
webServerTomcat6
webServerTomcat7
webServerTomcat8
@@ -119,6 +119,9 @@ def webServersDir = "$buildDir/generated-resources/webservers"
sourceSets {
distributedTest {
+ resources {
+ srcDirs webServersDir
+ }
output.dir(webServersDir, builtBy: 'downloadWebServers')
}
}
diff --git a/geode-assembly/geode-assembly-test/src/main/java/org/apache/geode/session/tests/ServerContainer.java b/geode-assembly/geode-assembly-test/src/main/java/org/apache/geode/session/tests/ServerContainer.java
index 4f508740e8a..602ae91dcb4 100644
--- a/geode-assembly/geode-assembly-test/src/main/java/org/apache/geode/session/tests/ServerContainer.java
+++ b/geode-assembly/geode-assembly-test/src/main/java/org/apache/geode/session/tests/ServerContainer.java
@@ -429,7 +429,7 @@ private void updateLocator() throws IOException {
attributes.put("host", locatorAddress);
attributes.put("port", Integer.toString(locatorPort));
- ContainerInstall.editXMLFile(getSystemProperty("cache-xml-file"), "locator", "pool",
+ ContainerInstall.editXMLFile(cacheXMLFile.getAbsolutePath(), "locator", "pool",
attributes, true);
} else {
setSystemProperty("locators", locatorAddress + "[" + locatorPort + "]");
diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/CargoTestBase.java b/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/CargoTestBase.java
index f0a87e5616c..3a710b2a0a9 100644
--- a/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/CargoTestBase.java
+++ b/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/CargoTestBase.java
@@ -87,8 +87,12 @@ public void setup() throws Exception {
install.setDefaultLocatorPort(locatorVM.getPort());
manager.addContainers(2, install);
+
+ customizeContainers();
}
+ public void customizeContainers() throws Exception {}
+
/**
* Stops all containers that were previously started and cleans up their configurations
*/
@@ -187,8 +191,7 @@ public void failureShouldStillAllowOtherContainersDataAccess()
* Test that invalidating a session in one container invalidates the session in all containers.
*/
@Test
- public void invalidationShouldRemoveValueAccessForAllContainers()
- throws IOException, URISyntaxException {
+ public void invalidationShouldRemoveValueAccessForAllContainers() throws Exception {
manager.startAllInactiveContainers();
String key = "value_testInvalidate";
@@ -335,7 +338,7 @@ public void containersShouldShareDataRemovals() throws IOException, URISyntaxExc
* data.
*/
@Test
- public void newContainersShouldShareDataAccess() throws IOException, URISyntaxException {
+ public void newContainersShouldShareDataAccess() throws Exception {
manager.startAllInactiveContainers();
String key = "value_testSessionAdd";
@@ -349,6 +352,8 @@ public void newContainersShouldShareDataAccess() throws IOException, URISyntaxEx
int numContainers = manager.numContainers();
// Add and start new container
manager.addContainer(install);
+ customizeContainers();
+
manager.startAllInactiveContainers();
// Check that a container was added
assertEquals(numContainers + 1, manager.numContainers());
diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/Tomcat8ClientServerCustomCacheXmlTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/Tomcat8ClientServerCustomCacheXmlTest.java
new file mode 100644
index 00000000000..d34db0c7509
--- /dev/null
+++ b/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/Tomcat8ClientServerCustomCacheXmlTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.session.tests;
+
+import java.util.HashMap;
+
+public class Tomcat8ClientServerCustomCacheXmlTest extends Tomcat8ClientServerTest {
+
+ @Override
+ public void customizeContainers() throws Exception {
+ for (int i = 0; i < manager.numContainers(); i++) {
+ ServerContainer container = manager.getContainer(i);
+
+ HashMap<String, String> regionAttributes = new HashMap<>();
+ regionAttributes.put("refid", "PROXY");
+ regionAttributes.put("name", "gemfire_modules_sessions");
+
+ ContainerInstall.editXMLFile(
+ container.cacheXMLFile.getAbsolutePath(),
+ null,
+ "region",
+ "client-cache",
+ regionAttributes);
+ }
+ }
+
+ @Override
+ public void afterStartServers() throws Exception {
+ gfsh.connect(locatorVM);
+ gfsh.executeAndAssertThat("create region --name=gemfire_modules_sessions --type=PARTITION")
+ .statusIsSuccess();
+ }
+
+}
diff --git a/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/TomcatClientServerTest.java b/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/TomcatClientServerTest.java
index 8b0679406bf..b01c6ab0727 100644
--- a/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/TomcatClientServerTest.java
+++ b/geode-assembly/src/distributedTest/java/org/apache/geode/session/tests/TomcatClientServerTest.java
@@ -49,8 +49,12 @@
public void startServer() throws Exception {
serverName1 = startAServer(1);
serverName2 = startAServer(2);
+
+ afterStartServers();
}
+ public void afterStartServers() throws Exception {}
+
private String startAServer(int serverNumber) {
// List of all the jars for tomcat to put on the server classpath
String libDirJars = install.getHome() + "/lib/*";
With regards,
Apache Git Services