_tomcat2.setChangeSessionIdOnAuth( false );
waitForReconnect(_tomcat1.getService().getMemcached(), 1, 1000);
waitForReconnect(_tomcat2.getService().getMemcached(), 1, 1000);
final Response response1 = get( _httpClient, TC_PORT_1, null );
final String sessionId = response1.getSessionId();
assertNotNull( sessionId );
assertTrue(response1.getContent().contains("j_security_check"), "IllegalState: /j_security_check not found, app is not properly initialized");
// Wait some time so that the GET is finished
Thread.sleep(200);
final Map<String, String> params = new HashMap<String, String>();
params.put( LoginServlet.J_USERNAME, TestUtils.USER_NAME );
params.put( LoginServlet.J_PASSWORD, TestUtils.PASSWORD );
final Response response2 = post( _httpClient, TC_PORT_2, "/j_security_check", sessionId, params, null, true );
assertNull(response2.getResponseSessionId());
assertEquals(response2.getStatusCode(), 200, response2.getContent());
assertEquals(response2.get( TestServlet.ID ), sessionId);
final Response response3 = post( _httpClient, TC_PORT_2, "/", sessionId, asMap( "foo", "bar" ));
assertEquals(response3.getSessionId(), sessionId);
final Response response4 = get(_httpClient, TC_PORT_1, sessionId);
assertEquals(response4.getSessionId(), sessionId);
assertEquals(response4.get( TestServlet.ID ), sessionId);
assertEquals(response4.get( "foo" ), "bar");
}