/** * Related to issue/feature 105 (single memcached node without node id): the session must be found * on a second request. */ @Test( enabled = true, groups = GROUP_WITHOUT_NODE_ID, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testSessionFoundIfSingleNodeWithNoMemcachedNodeIdConfigured( final SessionAffinityMode sessionAffinity) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String key = "foo"; final String value = "bar"; final String sessionId1 = post(_httpClient, _portTomcat1, null, key, value).getSessionId(); assertNotNull(sessionId1, "No session created."); final Response response = get(_httpClient, _portTomcat1, sessionId1); final String sessionId2 = response.getSessionId(); assertEquals(sessionId2, sessionId1); /* check session attributes could be read */ final String actualValue = response.get(key); assertEquals(value, actualValue); }
/** * Test for issue 174: sessions lost on Tomcat 7 reload * http://code.google.com/p/memcached-session-manager/issues/detail?id=174 */ @Test(enabled = true) public void testContextReload() throws IOException, InterruptedException, HttpException { final String sessionId1 = post(_httpClient, _portTomcat1, null, "foo", "bar").getSessionId(); assertNotNull(sessionId1, "No session created."); _tomcat1.getContext().reload(); final Response response = get(_httpClient, _portTomcat1, sessionId1); final String actualValue = response.get("foo"); assertEquals("bar", actualValue); }
@Test(enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testSessionAvailableInMemcachedWithCookiesDisabled( final SessionAffinityMode sessionAffinity) throws Exception { _tomcat1.stop(); _tomcat1 = tcBuilder() .sticky(sessionAffinity.isSticky()) .cookies(false) .jvmRoute("app1") .buildAndStart(); final Response response = get(_httpClient, _portTomcat1, null); final String sessionId = response.get(TestServlet.ID); assertNotNull(sessionId, "No session created."); Thread.sleep(50); assertNotNull(_memcached.get(sessionId), "Session not available in memcached."); }
/** * Test for issue 106: Session not updated in memcached when only a session attribute was removed * http://code.google.com/p/memcached-session-manager/issues/detail?id=106 */ @Test(enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testSessionUpdatedInMemcachedWhenSessionAttributeIsRemovedIssue106( final SessionAffinityMode sessionAffinity) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String key = "foo"; final String value = "bar"; final String sessionId1 = post(_httpClient, _portTomcat1, null, key, value).getSessionId(); assertNotNull(sessionId1, "No session created."); Response response = get(_httpClient, _portTomcat1, sessionId1); assertEquals(response.getSessionId(), sessionId1); assertEquals(response.get(key), value); final Map<String, String> params = asMap(PARAM_REMOVE, key); response = get(_httpClient, _portTomcat1, "/", sessionId1, params); assertEquals(response.getSessionId(), sessionId1); assertNull(response.get(key)); // also the next request must not include this session attribute response = get(_httpClient, _portTomcat1, sessionId1); assertEquals(response.getSessionId(), sessionId1); assertNull(response.get(key)); }
@Test(enabled = true, dataProviderClass = TestUtils.class, dataProvider = STICKYNESS_PROVIDER) public void testInvalidatedSessionRemovedFromMemcached( @Nonnull final SessionAffinityMode sessionAffinity) throws IOException, InterruptedException, HttpException { setStickyness(sessionAffinity); final String sessionId1 = makeRequest(_httpClient, _portTomcat1, null); assertNotNull(sessionId1, "No session created."); final Response response = get(_httpClient, _portTomcat1, PATH_INVALIDATE, sessionId1); assertNull(response.getResponseSessionId()); assertEquals(_daemon.getCache().getGetMisses(), 1); // 1 is ok assertNull(_memcached.get(sessionId1), "Invalidated session still existing in memcached"); if (!sessionAffinity.isSticky()) { assertNull( _memcached.get(createValidityInfoKeyName(sessionId1)), "ValidityInfo for invalidated session still exists in memcached."); } }