You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/04/19 15:08:58 UTC
[2/7] ignite git commit: IGNITE-2594: Cached web session requires
setAttribute() to be called on each update. This closes #654 Reviewed and
merged by Denis Magda (dmagda@gridgain.com)
IGNITE-2594: Cached web session requires setAttribute() to be called on each update. This closes #654
Reviewed and merged by Denis Magda (dmagda@gridgain.com)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3779fe46
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3779fe46
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3779fe46
Branch: refs/heads/ignite-2926
Commit: 3779fe46cbeb67a6bef4b29941f1780b9e602011
Parents: 2b5c441
Author: Vladislav Pyatkov <vl...@gmail.com>
Authored: Tue Apr 19 06:54:43 2016 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue Apr 19 06:54:43 2016 +0300
----------------------------------------------------------------------
.../ignite/cache/websession/WebSession.java | 7 +-
.../internal/websession/WebSessionSelfTest.java | 88 +++++++++++++++++++-
2 files changed, 93 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/3779fe46/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
----------------------------------------------------------------------
diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
index 5e0d49b..675c4ca 100644
--- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
+++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSession.java
@@ -240,7 +240,12 @@ class WebSession implements HttpSession, Externalizable {
if (!isValid)
throw new IllegalStateException("Call on invalidated session!");
- return attrs.get(name);
+ Object val = attrs.get(name);
+
+ if (val != null && updates != null)
+ updates.add(new T2<>(name, val));
+
+ return val;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/3779fe46/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
index 8706e1f..ccf0852 100644
--- a/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
+++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/WebSessionSelfTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.websession;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.Serializable;
import java.net.URL;
import java.net.URLConnection;
import java.util.Random;
@@ -27,6 +28,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
import javax.servlet.ServletException;
@@ -86,6 +88,13 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
/**
* @throws Exception If failed.
*/
+ public void testImplicitlyAttributeModification() throws Exception {
+ testImplicitlyModification("ignite-webapp-config.xml");
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testClientReconnectRequest() throws Exception {
testClientReconnectRequest("/modules/core/src/test/config/websession/example-cache.xml",
"/modules/core/src/test/config/websession/example-cache2.xml",
@@ -155,7 +164,50 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
}
/**
- * Tests single request to a server. Checks the presence of session in cache.
+ * Tests implicitly modification attribute in session. Checks the presence of session in cache.
+ *
+ * @param cfg Configuration.
+ * @throws Exception If failed.
+ */
+ private void testImplicitlyModification(String cfg) throws Exception {
+ Server srv = null;
+
+ try {
+ srv = startServer(TEST_JETTY_PORT, cfg, null, new SessionCreateServlet());
+
+ String sesId = sendRequestAndCheckMarker("marker1", null);
+ sendRequestAndCheckMarker("test_string", sesId);
+ sendRequestAndCheckMarker("ignite_test_attribute", sesId);
+ }
+ finally {
+ stopServer(srv);
+ }
+ }
+
+ private String sendRequestAndCheckMarker(String reqMarker, String sesId) throws IOException {
+ URLConnection conn = new URL("http://localhost:" + TEST_JETTY_PORT +
+ "/ignitetest/test?marker=" + reqMarker).openConnection();
+ conn.addRequestProperty("Cookie", "JSESSIONID=" + sesId);
+
+ conn.connect();
+
+ try (BufferedReader rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
+ sesId = rdr.readLine();
+
+ IgniteCache<String, HttpSession> cache = G.ignite().cache(getCacheName());
+
+ assertNotNull(cache);
+
+ HttpSession ses = cache.get(sesId);
+
+ assertNotNull(ses);
+ assertEquals(reqMarker, ((Profile)ses.getAttribute("profile")).getMarker());
+ }
+ return sesId;
+ }
+
+ /**
+ * Tests single request to a server. Checks modification attribute in cache.
*
* @param cfg Configuration.
* @throws Exception If failed.
@@ -533,6 +585,15 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
ses.setAttribute("key1", "val1");
ses.setAttribute("key2", "val2");
+ Profile p = (Profile)ses.getAttribute("profile");
+
+ if (p == null) {
+ p = new Profile();
+ ses.setAttribute("profile", p);
+ }
+
+ p.setMarker(req.getParameter("marker"));
+
X.println(">>>", "Created session: " + ses.getId(), ">>>");
res.getWriter().write(ses.getId());
@@ -542,6 +603,31 @@ public class WebSessionSelfTest extends GridCommonAbstractTest {
}
/**
+ * Complex class for stored in session.
+ */
+ private static class Profile implements Serializable {
+
+ /**
+ * Marker string.
+ */
+ String marker;
+
+ /**
+ * @return marker
+ */
+ public String getMarker() {
+ return marker;
+ }
+
+ /**
+ * @param marker
+ */
+ public void setMarker(String marker) {
+ this.marker = marker;
+ }
+ }
+
+ /**
* Test for invalidated sessions.
*/
private static class InvalidatedSessionServlet extends HttpServlet {