Package de.javakaffee.web.msm.integration.TestUtils

Examples of de.javakaffee.web.msm.integration.TestUtils.Response


        Thread.sleep( 100 );

        final String key3 = "k3";
        final String value3 = "v3";
        LOG.info( "Start request 2" );
        final Response response2 = post( _httpClient, TC_PORT_2, sessionId, key3, value3 );

        assertEquals( response1.get().getSessionId(), sessionId );
        assertEquals( response2.getSessionId(), sessionId );

        /* The next request should contain all session data
         */
        final Response response3 = get( _httpClient, TC_PORT_1, sessionId );
        assertEquals( response3.getSessionId(), sessionId );

        LOG.info( "Got response for request 2" );
        assertEquals( response3.get( key1 ), value1 );
        assertEquals( response3.get( key2 ), value2 );
        assertEquals( response3.get( key3 ), value3 ); // failed without session locking

    }
View Full Code Here


        assertNotNull( sessionId );

        // perform a readonly request without waiting, we perform this one later again
        final String path = "/mypath";
        final Map<String, String> params = asMap( "foo", "bar" );
        final Response response0 = get( _httpClient, TC_PORT_1, path, sessionId, params );
        assertEquals( response0.getSessionId(), sessionId );

        // perform a readonly, waiting request that we can perform again later
        final long timeToWaitInMillis = 500;
        final Map<String, String> paramsWait = asMap( PARAM_MILLIS, String.valueOf( timeToWaitInMillis ) );
        final Response response1 = get( _httpClient, TC_PORT_1, PATH_WAIT, sessionId, paramsWait );
        assertEquals( response1.getSessionId(), sessionId );

        // now do it again, now in the background, and in parallel start another readonly request,
        // both should not block each other
        final long start = System.currentTimeMillis();
        final Future<Response> response2 = _executor.submit( new Callable<Response>() {
            @Override
            public Response call() throws Exception {
                return get( _httpClient, TC_PORT_1, PATH_WAIT, sessionId, paramsWait );
            }
        });
        final Future<Response> response3 = _executor.submit( new Callable<Response>() {
            @Override
            public Response call() throws Exception {
                return get( _httpClient, TC_PORT_1, PATH_WAIT, sessionId, paramsWait );
            }
        });
        response2.get();
        response3.get();
        assertTrue ( ( System.currentTimeMillis() - start ) < ( 2 * timeToWaitInMillis ),
                "The time for both requests should be less than 2 * the wait time if they don't block each other." );
        assertEquals( response2.get().getSessionId(), sessionId );
        assertEquals( response3.get().getSessionId(), sessionId );

        // now perform a modifying request and a readonly in parallel which should not be blocked
        final Future<Response> response4 = _executor.submit( new Callable<Response>() {
            @Override
            public Response call() throws Exception {
                return post( _httpClient, TC_PORT_1, PATH_WAIT, sessionId, asMap( PARAM_MILLIS, "500", "foo", "bar" ) );
            }
        });
        Thread.sleep( 50 );
        final Response response5 = get( _httpClient, TC_PORT_1, path, sessionId, params );
        assertEquals( response5.getSessionId(), sessionId );
        assertFalse( response4.isDone(), "The readonly request should return before the long, session locking one" );
        assertEquals( response4.get().getSessionId(), sessionId );

    }
View Full Code Here

            public Response call() throws Exception {
                return get( _httpClient, TC_PORT_1, pathToLock, sessionId, paramsWait );
            }
        });
        Thread.sleep( 50 );
        final Response response5 = get( _httpClient, TC_PORT_1, "/pathNotMatchingLockUriPattern", sessionId );
        assertEquals( response5.getSessionId(), sessionId );
        assertFalse( response4.isDone(), "The non locking request should return before the long, session locking one" );
        assertEquals( response4.get().getSessionId(), sessionId );

    }
View Full Code Here

        _tomcat1.getManager().setLockingMode( LockingMode.ALL, null, true );

        final String sessionId = get( _httpClient, TC_PORT_1, null ).getSessionId();
        assertNotNull( sessionId );

        Response response = get( _httpClient, TC_PORT_1, PATH_GET_REQUESTED_SESSION_INFO, sessionId, sessionTrackingMode, null, null );
        assertEquals( response.getSessionId(), sessionId );
        assertEquals( response.get( KEY_REQUESTED_SESSION_ID ), sessionId );
        assertEquals( Boolean.parseBoolean( response.get( KEY_IS_REQUESTED_SESSION_ID_VALID ) ), true );
        Thread.sleep( 100 );

        response = get( _httpClient, TC_PORT_1, PATH_GET_REQUESTED_SESSION_INFO, sessionId, sessionTrackingMode, null, null );
        assertEquals( response.getSessionId(), sessionId );
        assertEquals( response.get( KEY_REQUESTED_SESSION_ID ), sessionId );
        assertEquals( Boolean.parseBoolean( response.get( KEY_IS_REQUESTED_SESSION_ID_VALID ) ), true );

    }
View Full Code Here

        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

        // 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

        _tomcat1 = startTomcat( TC_PORT_1, NODE_ID_1 + ":localhost:" + MEMCACHED_PORT_1, LockingMode.AUTO );
        _tomcat2 = startTomcat( TC_PORT_2, NODE_ID_1 + ":localhost:" + MEMCACHED_PORT_1, LockingMode.AUTO );

        /* tomcat1: request secured resource and check that secured resource is accessable
         */
        final Response tc1Response1 = post( _httpClient, TC_PORT_1, "/", null, asMap( "foo", "bar" ));
        final String sessionId = tc1Response1.getSessionId();
        assertNotNull(sessionId);

        // 0 gets
        assertEquals( _daemon1.getCache().getGetHits(), 0 );
        // 2 sets for session and validity
        assertEquals( _daemon1.getCache().getSetCmds(), 2 );

        // a request on the static (ignored) resource should not pull the session from memcached
        // and should not update the session in memcached.
        final Response tc1Response2 = get(_httpClient, TC_PORT_1, "/pixel.gif", sessionId);
        assertNull(tc1Response2.getResponseSessionId());

        // gets/sets unchanged
        assertEquals( _daemon1.getCache().getGetHits(), 0 );
        assertEquals( _daemon1.getCache().getSetCmds(), 2 );

        /* another session change on tomcat1, with a hanging session (wrong refcount due to ignored request)
         * this change would not be written to memcached
         */
        final Response tc1Response3 = post( _httpClient, TC_PORT_1, "/", sessionId, asMap( "bar", "baz" ));
        assertEquals(tc1Response3.getSessionId(), sessionId);
        assertNull(tc1Response3.getResponseSessionId());

        /*
         * on tomcat2, we now should be able to get the session with all session attribues
         */
        final Response tc2Response1 = get( _httpClient, TC_PORT_2, sessionId );
        assertEquals(tc2Response1.getSessionId(), sessionId);
        assertEquals( tc2Response1.get( TestServlet.ID ), sessionId );
        assertEquals( tc2Response1.get( "foo" ), "bar" );
        assertEquals( tc2Response1.get( "bar" ), "baz" );

    }
View Full Code Here

        _tomcat1.setChangeSessionIdOnAuth( false );
        _tomcat2.setChangeSessionIdOnAuth( false );

        /* tomcat1: request secured resource, login and check that secured resource is accessable
         */
        final Response tc1Response1 = post( _httpClient, TC_PORT_1, "/", null, asMap( "foo", "bar" ),
                new UsernamePasswordCredentials( TestUtils.USER_NAME, TestUtils.PASSWORD ), true );
        final String sessionId = tc1Response1.getSessionId();
        assertNotNull( sessionId );

        /* tomcat1 failover "simulation":
         * 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 );
        assertEquals( sessionId, tc2Response1.get( TestServlet.ID ) );
        assertEquals( tc2Response1.get( "foo" ), "bar" );

    }
View Full Code Here

         */
        final String sessionId = loginWithForm(_httpClient, TC_PORT_1);

        /* tomcat1: request secured resource and check that secured resource is accessable
         */
        final Response tc1Response1 = post( _httpClient, TC_PORT_1, "/", sessionId, asMap( "foo", "bar" ));
        assertEquals(tc1Response1.getSessionId(), sessionId);

        // 6 gets for session and validity (4 login + 2 from previous post)
        assertEquals( _daemon1.getCache().getGetHits(), 6 );
        // 8 sets for session and validity
        assertEquals( _daemon1.getCache().getSetCmds(), 8 );

        // a request on the static (ignored) resource should not pull the session from memcached
        // and should not update the session in memcached.
        final Response tc1Response2 = get(_httpClient, TC_PORT_1, "/pixel.gif", sessionId);
        assertNull(tc1Response2.getResponseSessionId());

        // load session + validity info for pixel.gif
        assertEquals( _daemon1.getCache().getGetHits(), 8 );
        // ignored resource -> no validity update
        assertEquals( _daemon1.getCache().getSetCmds(), 8 );

        /* another session change on tomcat1, with a hanging session (wrong refcount due to ignored request)
         * this change would not be written to memcached
         */
        final Response tc1Response3 = post( _httpClient, TC_PORT_1, "/", sessionId, asMap( "bar", "baz" ));
        assertEquals(tc1Response3.getSessionId(), sessionId);
        assertNull(tc1Response3.getResponseSessionId());

        /* tomcat1 failover "simulation":
         * 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 );
        assertEquals(tc2Response1.getSessionId(), sessionId);
        assertNull(tc2Response1.getResponseSessionId());
        assertEquals( tc2Response1.get( TestServlet.ID ), sessionId );
        assertEquals( tc2Response1.get( "foo" ), "bar" );
        assertEquals( tc2Response1.get( "bar" ), "baz" );

    }
View Full Code Here

                sid2,
                sid1.substring( 0, sid1.indexOf( "-" ) + 1 ) + expectedNode,
                "Unexpected sessionId, sid1: " + sid1 + ", sid2: " + sid2 );

        // we must get the same session back
        final Response response2 = get( _httpClient, _portTomcat1, sid2 );
        assertEquals( response2.getSessionId(), sid2, "We should keep the sessionId." );
        final MemCacheDaemon<?> activeNode = getFailoverInfo( secondNode ).activeNode;
        assertNotNull( activeNode.getCache().get( key( sid2 ) )[0], "The session should exist in memcached." );
        assertEquals( response2.get( paramKey ), paramValue, "The session should still contain the previously stored value." );

        // some more checks in sticky mode
        if ( sessionAffinity.isSticky() ) {
            final Session session = _tomcat1.getManager().findSession( sid2 );
            assertFalse( session.getNoteNames().hasNext(), "Some notes are set: " + toArray( session.getNoteNames() ) );
View Full Code Here

TOP

Related Classes of de.javakaffee.web.msm.integration.TestUtils.Response

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.