You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2019/01/14 20:52:45 UTC
[geode] branch develop updated: GEODE-6270: Correctly set up
user-provided client cache regions for session modules (#3074)
This is an automated email from the ASF dual-hosted git repository.
jensdeppe 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 777d1cd GEODE-6270: Correctly set up user-provided client cache regions for session modules (#3074)
777d1cd is described below
commit 777d1cddaf019a29e4a6ee3c13c7a3fc206608dd
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Mon Jan 14 12:52:35 2019 -0800
GEODE-6270: Correctly set up user-provided client cache regions for session modules (#3074)
- If a user provides their own client cache xml, we need to ensure that the
SessionExpirationCacheListener, as well as any necessary interest
registration, has been set up.
- Update build.xml so that these tests can be run from IntelliJ
---
.../session/catalina/ClientServerSessionCache.java | 17 ++++++++
geode-assembly/build.gradle | 5 ++-
.../geode/session/tests/ServerContainer.java | 2 +-
.../apache/geode/session/tests/CargoTestBase.java | 11 +++--
.../Tomcat8ClientServerCustomCacheXmlTest.java | 47 ++++++++++++++++++++++
.../session/tests/TomcatClientServerTest.java | 4 ++
6 files changed, 81 insertions(+), 5 deletions(-)
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 8672276..95142a4 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 @@ public class ClientServerSessionCache extends AbstractSessionCache {
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 33da4a2..004200b 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 4f50874..602ae91 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 @@ public abstract class ServerContainer {
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 f0a87e5..3a710b2 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 abstract class CargoTestBase {
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 abstract class CargoTestBase {
* 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 abstract class CargoTestBase {
* data.
*/
@Test
- public void newContainersShouldShareDataAccess() throws IOException, URISyntaxException {
+ public void newContainersShouldShareDataAccess() throws Exception {
manager.startAllInactiveContainers();
String key = "value_testSessionAdd";
@@ -349,6 +352,8 @@ public abstract class CargoTestBase {
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 0000000..d34db0c
--- /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 8b06794..b01c6ab 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 abstract class TomcatClientServerTest extends CargoTestBase {
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/*";