Package de.javakaffee.web.msm

Examples of de.javakaffee.web.msm.SessionIdFormat


        memcachedsByNodeId.put(NODE_ID_3, _daemon3);

        final String sessionId1 = post( _httpClient, TC_PORT_1, null, "key", "v1" ).getSessionId();
        assertNotNull( sessionId1 );

        final SessionIdFormat fmt = new SessionIdFormat();
        final String nodeId = fmt.extractMemcachedId( sessionId1 );
        final MemCacheDaemon<?> first = memcachedsByNodeId.get(nodeId);

        // the memcached client writes async, so it's ok to wait a little bit (especially on windows)
        assertNotNullElementWaitingWithProxy(0, 100, first.getCache()).get( key( sessionId1 ) );
        assertNotNullElementWaitingWithProxy(0, 100, first.getCache()).get( key( fmt.createValidityInfoKeyName( sessionId1 ) ) );

        // The executor needs some time to finish the backup...
        final MemCacheDaemon<?> second = memcachedsByNodeId.get(nodeIdList.getNextNodeId(nodeId));
        assertNotNullElementWaitingWithProxy(0, 4000, second.getCache()).get( key( fmt.createBackupKey( sessionId1 ) ) );
        assertNotNullElementWaitingWithProxy(0, 200, second.getCache()).get( key( fmt.createBackupKey( fmt.createValidityInfoKeyName( sessionId1 ) ) ) );

        // Shutdown the secondary memcached, so that the next backup should got to the next node
        second.stop();

        // Wait for update of nodeAvailabilityNodeCache
        Thread.sleep(100l);

        // Request / Update
        final String sessionId2 = post( _httpClient, TC_PORT_1, sessionId1, "key", "v2" ).getSessionId();
        assertEquals( sessionId2, sessionId1 );

        final MemCacheDaemon<?> third = memcachedsByNodeId.get(nodeIdList.getNextNodeId(nodeIdList.getNextNodeId(nodeId)));
        assertNotNullElementWaitingWithProxy(0, 4000, third.getCache()).get( key( fmt.createBackupKey( sessionId1 ) ) );
        assertNotNullElementWaitingWithProxy(0, 200, third.getCache()).get( key( fmt.createBackupKey( fmt.createValidityInfoKeyName( sessionId1 ) ) ) );

        // Shutdown the first node, so it should be loaded from the 3rd memcached
        first.stop();

        // Wait for update of nodeAvailabilityNodeCache
        Thread.sleep(100l);

        final Response response3 = get(_httpClient, TC_PORT_1, sessionId1);
        final String sessionId3 = response3.getResponseSessionId();
        assertNotNull(sessionId3);
        assertFalse(sessionId3.equals(sessionId1));
        assertEquals(sessionId3, fmt.createNewSessionId(sessionId1, fmt.extractMemcachedId(sessionId3)));

        assertEquals(response3.get("key"), "v2");

    }
View Full Code Here


        final String sessionId1 = post( _httpClient, TC_PORT_1, null, "key", "v1" ).getSessionId();
        assertNotNull( sessionId1 );

        // the memcached client writes async, so it's ok to wait a little bit (especially on windows)
        final SessionIdFormat fmt = new SessionIdFormat();
        final String nodeId = fmt.extractMemcachedId( sessionId1 );
        final MemCacheDaemon<?> first = memcachedsByNodeId.get(nodeId);

        assertNotNullElementWaitingWithProxy(0, 100, first.getCache()).get( key( sessionId1 ) );
        assertNotNullElementWaitingWithProxy(0, 100, first.getCache()).get( key( fmt.createValidityInfoKeyName( sessionId1 ) ) );

        // The executor needs some time to finish the backup...
        final MemCacheDaemon<?> second = memcachedsByNodeId.get(nodeIdList.getNextNodeId(nodeId));
        assertNotNullElementWaitingWithProxy(0, 4000, second.getCache()).get( key( fmt.createBackupKey( sessionId1 ) ) );
        assertNotNullElementWaitingWithProxy(0, 200, second.getCache()).get( key( fmt.createBackupKey( fmt.createValidityInfoKeyName( sessionId1 ) ) ) );

        // Shutdown the secondary memcached, so that the next backup should got to the next node
        second.stop();

        Thread.sleep(100);

        // Request / Update
        final String sessionId2 = get( _httpClient, TC_PORT_1, sessionId1 ).getSessionId();
        assertEquals( sessionId2, sessionId1 );

        final MemCacheDaemon<?> third = memcachedsByNodeId.get(nodeIdList.getNextNodeId(nodeIdList.getNextNodeId(nodeId)));
        assertNotNullElementWaitingWithProxy(0, 4000, third.getCache()).get( key( fmt.createBackupKey( sessionId1 ) ) );
        assertNotNullElementWaitingWithProxy(0, 200, third.getCache()).get( key( fmt.createBackupKey( fmt.createValidityInfoKeyName( sessionId1 ) ) ) );

        // Shutdown the first node, so it should be loaded from the 3rd memcached
        first.stop();
        Thread.sleep(100);

        final Response response3 = get(_httpClient, TC_PORT_1, sessionId1);
        final String sessionId3 = response3.getResponseSessionId();
        assertNotNull(sessionId3);
        assertFalse(sessionId3.equals(sessionId1));
        assertEquals(sessionId3, fmt.createNewSessionId(sessionId1, fmt.extractMemcachedId(sessionId3)));

        assertEquals(response3.get("key"), "v1");

    }
View Full Code Here


        final SessionManager manager1 = _tomcat1.getManager();
        final SessionManager manager2 = _tomcat2.getManager();

        final SessionIdFormat format = new SessionIdFormat();

        final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId();
        assertEquals( format.extractJvmRoute( sessionId1 ), JVM_ROUTE_1 );

        final MemcachedBackupSession session = (MemcachedBackupSession) manager1.findSession( sessionId1 );
        session.setAttribute( "listener", new RecordingSessionActivationListener() );

        get( _httpClient, TC_PORT_1, sessionId1 );

        final String sessionId2 = get( _httpClient, TC_PORT_2, sessionId1 ).getSessionId();
        assertEquals( format.stripJvmRoute( sessionId2 ), format.stripJvmRoute( sessionId1 ) );
        assertEquals( format.extractJvmRoute( sessionId2 ), JVM_ROUTE_2 );

        final MemcachedBackupSession loaded = (MemcachedBackupSession) manager2.findSession( sessionId2 );
        assertNotNull( loaded );
        final RecordingSessionActivationListener listener = (RecordingSessionActivationListener) loaded.getAttribute( "listener" );
        assertNotNull( listener );
View Full Code Here

        _tomcat2 = startTomcat( TC_PORT_2, null );

        final SessionManager manager1 = _tomcat1.getManager();
        final SessionManager manager2 = _tomcat2.getManager();

        final SessionIdFormat format = new SessionIdFormat();

        final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId();
        assertNull( format.extractJvmRoute( sessionId1 ) );

        final MemcachedBackupSession session = (MemcachedBackupSession) manager1.findSession( sessionId1 );
        session.setAttribute( "listener", new RecordingSessionActivationListener() );

        get( _httpClient, TC_PORT_1, sessionId1 );
View Full Code Here

        assertNotNull( sessionId1, "No session created." );

        final Response response = get( _httpClient, TC_PORT_1, PATH_INVALIDATE, sessionId1 );
        assertNull( response.getResponseSessionId() );
        assertNull(_client.get( sessionId1 ), "Invalidated session should be removed from memcached");
        assertNull(_client.get(new SessionIdFormat().createLockName(sessionId1)), "Lock should be released.");
    }
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.