Package de.javakaffee.web.msm

Examples of de.javakaffee.web.msm.SessionIdFormat


     * @throws HttpException
     */
    @Test( enabled = true )
    public void testTomcatFailover() throws IOException, InterruptedException, HttpException {

        final SessionIdFormat format = new SessionIdFormat();

        final String key = "foo";
        final String value = "bar";
        final String sessionId1 = post( _httpClient, TC_PORT_1, null, key, value ).getSessionId();
        assertEquals( format.extractJvmRoute( sessionId1 ), JVM_ROUTE_1 );

        final Object session = _client.get( sessionId1 );
        assertNotNull( session, "Session not found in memcached: " + sessionId1 );

        final Response response = get( _httpClient, TC_PORT_2, sessionId1 );
        final String sessionId2 = response.getSessionId();
        assertNull( _client.get( sessionId1 ) );
        assertNotNull( _client.get( sessionId2 ) );

        assertEquals( format.stripJvmRoute( sessionId1 ), format.stripJvmRoute( sessionId2 ) );
        assertEquals( format.extractJvmRoute( sessionId2 ), JVM_ROUTE_2 );

        /* check session attributes could be read
         */
        final String actualValue = response.get( key );
        assertEquals( value, actualValue );
View Full Code Here


        final String key = "foo";
        final String value = "bar";
        final String sessionId1 = post( _httpClient, TC_PORT_1, null, key, value ).getSessionId();
        assertEquals( 1, _daemon.getCache().getSetCmds() );

        final SessionIdFormat format = new SessionIdFormat();

        /* request the session on tomcat2
         */
        final Response response = get( _httpClient, TC_PORT_2, sessionId1 );
        assertEquals( format.stripJvmRoute( sessionId1 ), format.stripJvmRoute( response.getSessionId() ) );
        assertEquals( 2, _daemon.getCache().getSetCmds() );

        /* post key/value already stored in the session again (on tomcat2)
         */
        post( _httpClient, TC_PORT_2, sessionId1, key, value );
View Full Code Here

         * on tomcat2, we now be able to access the secured resource directly
         * with the first request
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        if ( stickyness.isSticky() ) {
            assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        }
        else {
            assertEquals( tc2Response1.getSessionId(), sessionId );
        }

View Full Code Here

         * on tomcat2, we now should be able to access the secured resource directly
         * with the first request
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        if ( stickyness.isSticky() ) {
            assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        }
        else {
            assertEquals( tc2Response1.getSessionId(), sessionId );
        }

View Full Code Here

        /* on tomcat1 failover and session takeover by tomcat2, msm in tomcat2 should
         * load the session only once.
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        assertEquals( _daemon.getCache().getGetHits(), 1 );

    }
View Full Code Here

        /* on tomcat1 failover and session takeover by tomcat2, the changes made to the
         * session during this request must be available in the following request(s)
         */
        final Response tc2Response1 = post( _httpClient, TC_PORT_2, "/", sessionId, asMap( "foo", "bar" ) );
        if ( stickyness.isSticky() ) {
            assertEquals( tc2Response1.getResponseSessionId(), new SessionIdFormat().changeJvmRoute( sessionId, JVM_ROUTE_2 ) );
        }
        else {
            assertEquals( tc2Response1.getSessionId(), sessionId );
        }

View Full Code Here

        _tomcat1.getService().setMemcachedNodes(memcachedNodes);
        _tomcat1.getService().setFailoverNodes("n1");
        _tomcat2.getService().setMemcachedNodes(memcachedNodes);
        _tomcat2.getService().setFailoverNodes("n2");

        final SessionIdFormat format = new SessionIdFormat();

        final String key = "foo";
        final String value = "bar";
        final String sessionId1 = post( _httpClient, TC_PORT_1, null, key, value ).getSessionId();
        assertEquals( format.extractMemcachedId( sessionId1 ), "n2" );
        assertEquals(_daemon.getCache().getCurrentItems(), 0);
        assertEquals(daemon2.getCache().getCurrentItems(), 1);

        // failover simulation, just request the session from tomcat2
        final Response response = get( _httpClient, TC_PORT_2, sessionId1 );
        final String sessionId2 = response.getSessionId();
        assertEquals( format.extractMemcachedId( sessionId2 ), "n1" );
        assertEquals(_daemon.getCache().getCurrentItems(), 1);

        assertEquals( format.stripJvmRoute( sessionId1 ).replaceAll("n2", "n1"), format.stripJvmRoute( sessionId2 ) );

        /* check session attributes could be read
         */
        final String actualValue = response.get( key );
        assertEquals( value, actualValue );
View Full Code Here

        Response response = get(_httpClient, TC_PORT_1, sessionId);
        assertEquals(response.getSessionId(), sessionId);
        assertEquals(response.get("k1"), "v1");

        // now we shut down the primary node so that the session is loaded from the backup node
        final SessionIdFormat fmt = new SessionIdFormat();
        final String nodeId = fmt.extractMemcachedId( sessionId );
        final MemCacheDaemon<?> primary = NODE_ID_1.equals(nodeId) ? _daemon1 : _daemon2;
        primary.stop();

        Thread.sleep( 200 );

        // the session should be loaded from the backup node
        response = get(_httpClient, TC_PORT_1, sessionId);
        assertEquals(fmt.createNewSessionId(response.getSessionId(), nodeId), sessionId);
        assertEquals(response.get("k1"), "v1");
    }
View Full Code Here

        Response response = get(_httpClient, TC_PORT_1, sessionId);
        assertEquals(response.getSessionId(), sessionId);
        assertEquals(response.get("k1"), "v1");

        // now we shut down the primary node so that the session is loaded from the backup node
        final SessionIdFormat fmt = new SessionIdFormat();
        final String nodeId = fmt.extractMemcachedId( sessionId );
        final MemCacheDaemon<?> primary = NODE_ID_1.equals(nodeId) ? _daemon1 : _daemon2;
        primary.stop();

        Thread.sleep( 200 );

        // the session should be loaded from the backup node
        response = get(_httpClient, TC_PORT_1, sessionId);
        assertEquals(fmt.createNewSessionId(response.getSessionId(), nodeId), sessionId);
        assertEquals(response.get("k1"), "v1");
    }
View Full Code Here

        assertNotNull( sessionId1 );

        // the memcached client writes async, so it's ok to wait a little bit (especially on windows)
        waitForMemcachedClient( 100 );

        final SessionIdFormat fmt = new SessionIdFormat();

        final String nodeId = fmt.extractMemcachedId( sessionId1 );

        final MemCacheDaemon<?> primary = nodeId.equals( NODE_ID_1 ) ? _daemon1 : _daemon2;
        final MemCacheDaemon<?> secondary = nodeId.equals( NODE_ID_1 ) ? _daemon2 : _daemon1;

        assertNotNull( primary.getCache().get( key( sessionId1 ) )[0], sessionId1 );
        assertNotNull( primary.getCache().get( key( fmt.createValidityInfoKeyName( sessionId1 ) ) )[0], fmt.createValidityInfoKeyName( sessionId1 ) );

        // The executor needs some time to finish the backup...
        Thread.sleep( 500 );

        assertNotNull( secondary.getCache().get( key( fmt.createBackupKey( sessionId1 ) ) )[0] );
        assertNotNull( secondary.getCache().get( key( fmt.createBackupKey( fmt.createValidityInfoKeyName( sessionId1 ) ) ) )[0] );

    }
View Full Code Here

TOP

Related Classes of de.javakaffee.web.msm.SessionIdFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.