Package de.javakaffee.web.msm

Examples of de.javakaffee.web.msm.NodeIdList


        manager.setMemcachedNodes(memcachedNodes);
        manager.getMemcachedSessionService().setSessionBackupAsync(false);

        waitForReconnect(manager.getMemcachedSessionService().getMemcached(), 3, 1000);

        final NodeIdList nodeIdList = NodeIdList.create(NODE_ID_1, NODE_ID_2, NODE_ID_3);
        final Map<String, MemCacheDaemon<?>> memcachedsByNodeId = new HashMap<String, MemCacheDaemon<?>>();
        memcachedsByNodeId.put(NODE_ID_1, _daemon1);
        memcachedsByNodeId.put(NODE_ID_2, _daemon2);
        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();
View Full Code Here


        manager.setMemcachedNodes(memcachedNodes);
        manager.getMemcachedSessionService().setSessionBackupAsync(false);

        waitForReconnect(manager.getMemcachedSessionService().getMemcached(), 3, 1000);

        final NodeIdList nodeIdList = NodeIdList.create(NODE_ID_1, NODE_ID_2, NODE_ID_3);
        final Map<String, MemCacheDaemon<?>> memcachedsByNodeId = new HashMap<String, MemCacheDaemon<?>>();
        memcachedsByNodeId.put(NODE_ID_1, _daemon1);
        memcachedsByNodeId.put(NODE_ID_2, _daemon2);
        memcachedsByNodeId.put(NODE_ID_3, _daemon3);

        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();
View Full Code Here

TOP

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

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.