Start making unit tests work.
This commit is contained in:
parent
c5489bd7b2
commit
84239bc7f2
|
@ -243,6 +243,7 @@ public abstract class AbstractSessionIdManager extends AbstractLifeCycle impleme
|
|||
}
|
||||
|
||||
_scavenger.start();
|
||||
System.err.println("Started scavenger "+_scavenger);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -130,14 +130,17 @@ public abstract class AbstractSessionStore extends AbstractLifeCycle implements
|
|||
{
|
||||
//look locally
|
||||
Session session = doGet(key);
|
||||
|
||||
|
||||
//not in session store, load the data for the session if possible
|
||||
if (session == null && _sessionDataStore != null)
|
||||
{
|
||||
SessionData data = _sessionDataStore.load(key);
|
||||
session = newSession(data);
|
||||
session.setSessionManager(_manager);
|
||||
doPut(key, session);
|
||||
if (data != null)
|
||||
{
|
||||
session = newSession(data);
|
||||
session.setSessionManager(_manager);
|
||||
doPut(key, session);
|
||||
}
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
|
|||
if (_storeDir != null)
|
||||
{
|
||||
file = new File(_storeDir, key.toString());
|
||||
if (file.exists())
|
||||
if (file.exists() && file.getParentFile().equals(_storeDir))
|
||||
{
|
||||
file.delete();
|
||||
return true;
|
||||
|
@ -150,13 +150,12 @@ public class FileSessionDataStore extends AbstractSessionDataStore
|
|||
}
|
||||
catch (UnreadableSessionDataException e)
|
||||
{
|
||||
if (isDeleteUnrestorableFiles() && file.exists())
|
||||
if (isDeleteUnrestorableFiles() && file.exists() && file.getParentFile().equals(_storeDir));
|
||||
{
|
||||
file.delete();
|
||||
LOG.warn("Deleted unrestorable file for session {}", key);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
/**
|
||||
* FileHashSessionManager
|
||||
*
|
||||
* Session manager that stores its sessions in files on disk
|
||||
*
|
||||
*/
|
||||
public class FileSessionManager extends SessionManager
|
||||
{
|
||||
protected FileSessionDataStore _sessionDataStore = new FileSessionDataStore();
|
||||
|
||||
|
||||
@Override
|
||||
public void doStart() throws Exception
|
||||
{
|
||||
_sessionStore = new MemorySessionStore();
|
||||
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
|
||||
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doStop() throws Exception
|
||||
{
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SessionDataStore to configure it
|
||||
* @return
|
||||
*/
|
||||
public FileSessionDataStore getSessionDataStore()
|
||||
{
|
||||
return _sessionDataStore;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,11 +22,12 @@ package org.eclipse.jetty.server.session;
|
|||
/**
|
||||
* HashSessionManager
|
||||
*
|
||||
*
|
||||
* In memory-only session manager.
|
||||
*
|
||||
*/
|
||||
public class HashSessionManager extends SessionManager
|
||||
{
|
||||
protected FileSessionDataStore _sessionDataStore = new FileSessionDataStore();
|
||||
protected NullSessionDataStore _sessionDataStore = new NullSessionDataStore();
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -44,13 +45,4 @@ public class HashSessionManager extends SessionManager
|
|||
super.doStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SessionDataStore to configure it
|
||||
* @return
|
||||
*/
|
||||
public FileSessionDataStore getSessionDataStore()
|
||||
{
|
||||
return _sessionDataStore;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -199,6 +199,7 @@ public class MemorySessionStore extends AbstractSessionStore
|
|||
@Override
|
||||
public Session newSession(SessionKey key, long created, long accessed, long lastAccessed, long maxInactiveMs)
|
||||
{
|
||||
//TODO - how to tell that the session is new?!
|
||||
return new MemorySession(_sessionDataStore.newSessionData(key, created, accessed, lastAccessed, maxInactiveMs));
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@ public class SessionKey
|
|||
|
||||
public static String getContextPath (Context context)
|
||||
{
|
||||
if (context == null)
|
||||
return "";
|
||||
return canonicalize (context.getContextPath());
|
||||
}
|
||||
|
||||
|
|
|
@ -621,6 +621,7 @@ public class SessionManager extends ContainerLifeCycle implements org.eclipse.je
|
|||
Session session = _sessionStore.newSession(key, created, created, created, (_dftMaxIdleSecs>0?_dftMaxIdleSecs*1000L:-1));
|
||||
session.setExtendedId(_sessionIdManager.getExtendedId(id,request));
|
||||
session.setSessionManager(this);
|
||||
session.setLastNode(_sessionIdManager.getWorkerName());
|
||||
|
||||
if (request.isSecure())
|
||||
session.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE);
|
||||
|
|
|
@ -167,6 +167,9 @@ public class SessionScavenger extends AbstractLifeCycle
|
|||
if (isStopping() || isStopped())
|
||||
return;
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Scavenging sessions");
|
||||
|
||||
//find the session managers
|
||||
Handler[] contexts = ((AbstractSessionIdManager)_sessionIdManager).getServer().getChildHandlersByClass(ContextHandler.class);
|
||||
for (int i=0; contexts!=null && i<contexts.length; i++)
|
||||
|
@ -199,4 +202,13 @@ public class SessionScavenger extends AbstractLifeCycle
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return super.toString()+"[interval="+_scavengeIntervalMs+", ownscheduler="+_ownScheduler+"]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -25,62 +25,110 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.StdErrLog;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HashSessionManagerTest
|
||||
public class FileSessionManagerTest
|
||||
{
|
||||
private static StdErrLog _log;
|
||||
private static boolean _stacks;
|
||||
|
||||
|
||||
// @BeforeClass
|
||||
public static void beforeClass ()
|
||||
{
|
||||
_log = ((StdErrLog)Log.getLogger("org.eclipse.jetty.server.session"));
|
||||
_stacks = _log.isHideStacks();
|
||||
_log.setHideStacks(true);
|
||||
}
|
||||
|
||||
//@AfterClass
|
||||
public static void afterClass()
|
||||
{
|
||||
_log.setHideStacks(_stacks);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDangerousSessionIdRemoval() throws Exception
|
||||
{
|
||||
final HashSessionManager manager = new HashSessionManager();
|
||||
Server server = new Server();
|
||||
SessionHandler handler = new SessionHandler();
|
||||
handler.setServer(server);
|
||||
final HashSessionIdManager idmgr = new HashSessionIdManager();
|
||||
idmgr.setServer(server);
|
||||
server.setSessionIdManager(idmgr);
|
||||
|
||||
final FileSessionManager manager = new FileSessionManager();
|
||||
manager.getSessionDataStore().setDeleteUnrestorableFiles(true);
|
||||
//manager.setLazyLoad(true);
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
|
||||
testDir.mkdirs();
|
||||
manager.getSessionDataStore().setStoreDir(testDir);
|
||||
|
||||
MavenTestingUtils.getTargetFile("dangerFile.session").createNewFile();
|
||||
manager.setSessionIdManager(idmgr);
|
||||
handler.setSessionManager(manager);
|
||||
manager.start();
|
||||
|
||||
Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile("dangerFile.session").exists());
|
||||
|
||||
manager.getSession("../../dangerFile.session");
|
||||
String expectedFilename = "../../_0.0.0.0_dangerFile";
|
||||
|
||||
Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile("dangerFile.session").exists());
|
||||
MavenTestingUtils.getTargetFile(expectedFilename).createNewFile();
|
||||
|
||||
Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile(expectedFilename).exists());
|
||||
|
||||
manager.getSession("../../_0.0.0.0_dangerFile");
|
||||
|
||||
Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile(expectedFilename).exists());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void testValidSessionIdRemoval() throws Exception
|
||||
{
|
||||
final HashSessionManager manager = new HashSessionManager();
|
||||
{
|
||||
Server server = new Server();
|
||||
SessionHandler handler = new SessionHandler();
|
||||
handler.setServer(server);
|
||||
final HashSessionIdManager idmgr = new HashSessionIdManager();
|
||||
idmgr.setServer(server);
|
||||
server.setSessionIdManager(idmgr);
|
||||
final FileSessionManager manager = new FileSessionManager();
|
||||
manager.getSessionDataStore().setDeleteUnrestorableFiles(true);
|
||||
// manager.setLazyLoad(true);
|
||||
manager.setSessionIdManager(idmgr);
|
||||
handler.setSessionManager(manager);
|
||||
// manager.setLazyLoad(true);
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
|
||||
FS.ensureEmpty(testDir);
|
||||
|
||||
|
||||
manager.getSessionDataStore().setStoreDir(testDir);
|
||||
manager.start();
|
||||
|
||||
Assert.assertTrue(new File(testDir, "validFile.session").createNewFile());
|
||||
//See SessionKey.getKey()
|
||||
String expectedFilename = "_0.0.0.0_validFile123";
|
||||
|
||||
Assert.assertTrue("File should exist!", new File(testDir, "validFile.session").exists());
|
||||
|
||||
manager.getSession("validFile.session");
|
||||
Assert.assertTrue(new File(testDir, expectedFilename).createNewFile());
|
||||
|
||||
Assert.assertTrue("File shouldn't exist!", !new File(testDir,"validFile.session").exists());
|
||||
Assert.assertTrue("File should exist!", new File(testDir, expectedFilename).exists());
|
||||
|
||||
manager.getSession("validFile123");
|
||||
|
||||
Assert.assertTrue("File shouldn't exist!", !new File(testDir,expectedFilename).exists());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHashSession() throws Exception
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("saved");
|
||||
IO.delete(testDir);
|
||||
testDir.mkdirs();
|
||||
|
||||
|
||||
Server server = new Server();
|
||||
SessionHandler handler = new SessionHandler();
|
||||
handler.setServer(server);
|
||||
HashSessionManager manager = new HashSessionManager();
|
||||
FileSessionManager manager = new FileSessionManager();
|
||||
manager.getSessionDataStore().setStoreDir(testDir);
|
||||
manager.setMaxInactiveInterval(5);
|
||||
Assert.assertTrue(testDir.exists());
|
||||
|
@ -88,6 +136,7 @@ public class HashSessionManagerTest
|
|||
handler.setSessionManager(manager);
|
||||
|
||||
AbstractSessionIdManager idManager = new HashSessionIdManager();
|
||||
idManager.setServer(server);
|
||||
idManager.setWorkerName("foo");
|
||||
manager.setSessionIdManager(idManager);
|
||||
server.setSessionIdManager(idManager);
|
||||
|
@ -105,7 +154,11 @@ public class HashSessionManagerTest
|
|||
manager.setMaxInactiveInterval(30); // change max inactive interval for *new* sessions
|
||||
manager.stop();
|
||||
|
||||
Assert.assertTrue("File should exist!", new File(testDir, session.getId()).exists());
|
||||
for (String f: testDir.list())
|
||||
System.err.println(f);
|
||||
|
||||
String expectedFilename = "_0.0.0.0_"+session.getId();
|
||||
Assert.assertTrue("File should exist!", new File(testDir, expectedFilename).exists());
|
||||
|
||||
|
||||
manager.start();
|
|
@ -32,6 +32,7 @@
|
|||
<modules>
|
||||
<module>test-sessions-common</module>
|
||||
<module>test-hash-sessions</module>
|
||||
<module>test-file-sessions</module>
|
||||
<module>test-jdbc-sessions</module>
|
||||
<module>test-mongodb-sessions</module>
|
||||
<module>test-infinispan-sessions</module>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/target/
|
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
// ========================================================================
|
||||
// Copyright (c) Webtide LLC
|
||||
//
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-parent</artifactId>
|
||||
<version>9.3.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-file-sessions</artifactId>
|
||||
<name>Jetty Tests :: Sessions :: File</name>
|
||||
<url>http://www.eclipse.org/jetty</url>
|
||||
<properties>
|
||||
<bundle-symbolic-name>${project.groupId}.sessions.file</bundle-symbolic-name>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- DO NOT DEPLOY (or Release) -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-sessions-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
<!-- Leaving at compile scope for intellij bug reasons -->
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClientCrossContextSessionTest extends AbstractClientCrossContextSessionTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new FileTestServer(port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossContextDispatch() throws Exception
|
||||
{
|
||||
super.testCrossContextDispatch();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.server.SessionIdManager;
|
||||
import org.eclipse.jetty.server.SessionManager;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
||||
/**
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class FileTestServer extends AbstractTestServer
|
||||
{
|
||||
static int __workers=0;
|
||||
static File _tmpDir;
|
||||
|
||||
public static void setup ()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
_tmpDir = File.createTempFile("file", null);
|
||||
_tmpDir.delete();
|
||||
_tmpDir.mkdirs();
|
||||
_tmpDir.deleteOnExit();
|
||||
}
|
||||
|
||||
|
||||
public static void teardown ()
|
||||
{
|
||||
IO.delete(_tmpDir);
|
||||
_tmpDir = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public FileTestServer(int port)
|
||||
{
|
||||
super(port, 30, 10);
|
||||
}
|
||||
|
||||
public FileTestServer(int port, int maxInactivePeriod, int scavengePeriod)
|
||||
{
|
||||
super(port, maxInactivePeriod, scavengePeriod);
|
||||
}
|
||||
|
||||
|
||||
public SessionIdManager newSessionIdManager(Object config)
|
||||
{
|
||||
HashSessionIdManager mgr = new HashSessionIdManager();
|
||||
mgr.setWorkerName("worker"+(__workers++));
|
||||
return mgr;
|
||||
}
|
||||
|
||||
public SessionManager newSessionManager()
|
||||
{
|
||||
FileSessionManager manager = new FileSessionManager();
|
||||
manager.getSessionDataStore().setStoreDir(_tmpDir);
|
||||
return manager;
|
||||
}
|
||||
|
||||
public SessionHandler newSessionHandler(SessionManager sessionManager)
|
||||
{
|
||||
return new SessionHandler(sessionManager);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,10 +19,6 @@
|
|||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.server.SessionManager;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -34,47 +30,23 @@ import org.junit.Test;
|
|||
*/
|
||||
public class ForwardedSessionTest extends AbstractForwardedSessionTest
|
||||
{
|
||||
File tmpDir;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
tmpDir = File.createTempFile("hash-session-forward-test", null);
|
||||
tmpDir.delete();
|
||||
tmpDir.mkdirs();
|
||||
tmpDir.deleteOnExit();
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
IO.delete(tmpDir);
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new HashTestServer(port)
|
||||
{
|
||||
|
||||
@Override
|
||||
public SessionManager newSessionManager()
|
||||
{
|
||||
HashSessionManager sessionManager = (HashSessionManager)super.newSessionManager();
|
||||
sessionManager.setSavePeriod(2);
|
||||
|
||||
try
|
||||
{
|
||||
sessionManager.setStoreDirectory(tmpDir);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return sessionManager;
|
||||
}
|
||||
|
||||
};
|
||||
return new FileTestServer(port);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class ImmortalSessionTest extends AbstractImmortalSessionTest
|
||||
{
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* NewSessionTest
|
||||
*/
|
||||
public class NewSessionTest extends AbstractNewSessionTest
|
||||
{
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
System.setProperty("org.eclipse.jetty.server.session.LEVEL", "DEBUG");
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewSession() throws Exception
|
||||
{
|
||||
super.testNewSession();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* OrphanedSessionTest
|
||||
*/
|
||||
public class OrphanedSessionTest extends AbstractOrphanedSessionTest
|
||||
{
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrphanedSession() throws Exception
|
||||
{
|
||||
super.testOrphanedSession();
|
||||
}
|
||||
}
|
|
@ -23,6 +23,8 @@ import java.io.File;
|
|||
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -32,40 +34,29 @@ import org.junit.Test;
|
|||
*/
|
||||
public class ProxySerializationTest extends AbstractProxySerializationTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractProxySerializationTest#createServer(int, int, int)
|
||||
*/
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new HashTestServer(port,max,scavenge);
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void customizeContext(ServletContextHandler c)
|
||||
{
|
||||
if (c == null)
|
||||
return;
|
||||
|
||||
//Ensure that the HashSessionManager will persist sessions on passivation
|
||||
HashSessionManager manager = (HashSessionManager)c.getSessionHandler().getSessionManager();
|
||||
manager.setLazyLoad(false);
|
||||
manager.setIdleSavePeriod(1);
|
||||
try
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("foo");
|
||||
testDir.mkdirs();
|
||||
manager.setStoreDirectory(testDir);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -75,4 +66,14 @@ public class ProxySerializationTest extends AbstractProxySerializationTest
|
|||
super.testProxySerialization();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractProxySerializationTest#customizeContext(org.eclipse.jetty.servlet.ServletContextHandler)
|
||||
*/
|
||||
@Override
|
||||
public void customizeContext(ServletContextHandler c)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* ReentrantRequestSessionTest
|
||||
*/
|
||||
public class ReentrantRequestSessionTest extends AbstractReentrantRequestSessionTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new FileTestServer(port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReentrantRequestSession() throws Exception
|
||||
{
|
||||
super.testReentrantRequestSession();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RemoveSessionTest extends AbstractRemoveSessionTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveSession() throws Exception
|
||||
{
|
||||
super.testRemoveSession();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* ScatterGunLoadTest
|
||||
*/
|
||||
public class ScatterGunLoadTest extends AbstractScatterGunLoadTest
|
||||
{
|
||||
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new FileTestServer(port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLightLoad() throws Exception
|
||||
{
|
||||
super.testLightLoad();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ServerCrossContextSessionTest extends AbstractServerCrossContextSessionTest
|
||||
{
|
||||
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new FileTestServer(port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossContextDispatch() throws Exception
|
||||
{
|
||||
super.testCrossContextDispatch();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class SessionCookieTest extends AbstractSessionCookieTest
|
||||
{
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port, max, scavenge);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SessionInvalidateAndCreateTest extends AbstractSessionInvalidateAndCreateTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionScavenge() throws Exception
|
||||
{
|
||||
super.testSessionScavenge();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.server.SessionManager;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SessionRenewTest extends AbstractSessionRenewTest
|
||||
{
|
||||
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port, max, scavenge);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionRenewal() throws Exception
|
||||
{
|
||||
super.testSessionRenewal();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public class SessionValueSharedSaving extends AbstractSessionValueSavingTest
|
||||
{
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
FileTestServer.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
FileTestServer.teardown();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new FileTestServer(port,max,scavenge);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,14 +18,16 @@
|
|||
|
||||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ClientCrossContextSessionTest extends AbstractClientCrossContextSessionTest
|
||||
{
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new HashTestServer(port);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCrossContextDispatch() throws Exception
|
||||
|
@ -33,4 +35,13 @@ public class ClientCrossContextSessionTest extends AbstractClientCrossContextSes
|
|||
super.testCrossContextDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.session.AbstractClientCrossContextSessionTest#createServer(int)
|
||||
*/
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port)
|
||||
{
|
||||
return new HashTestServer(port);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ import org.eclipse.jetty.server.SessionManager;
|
|||
*/
|
||||
public class HashTestServer extends AbstractTestServer
|
||||
{
|
||||
|
||||
static int __workers=0;
|
||||
|
||||
public HashTestServer(int port)
|
||||
{
|
||||
super(port, 30, 10);
|
||||
|
@ -40,13 +41,14 @@ public class HashTestServer extends AbstractTestServer
|
|||
|
||||
public SessionIdManager newSessionIdManager(Object config)
|
||||
{
|
||||
return new HashSessionIdManager();
|
||||
HashSessionIdManager mgr = new HashSessionIdManager();
|
||||
mgr.setWorkerName("worker"+(__workers++));
|
||||
return mgr;
|
||||
}
|
||||
|
||||
public SessionManager newSessionManager()
|
||||
{
|
||||
HashSessionManager manager = new HashSessionManager();
|
||||
manager.setScavengePeriod(_scavengePeriod);
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ import org.junit.Test;
|
|||
* IdleSessionTest
|
||||
*
|
||||
* Checks that a session can be idled and de-idled on the next request if it hasn't expired.
|
||||
*
|
||||
* TODO support session idling in FileSessionDataStore?
|
||||
*
|
||||
*/
|
||||
public class IdleSessionTest
|
||||
|
@ -67,17 +69,10 @@ public class IdleSessionTest
|
|||
@Override
|
||||
public SessionManager newSessionManager()
|
||||
{
|
||||
try
|
||||
{
|
||||
HashSessionManager manager = (HashSessionManager)super.newSessionManager();
|
||||
manager.setStoreDirectory(_storeDir);
|
||||
manager.setIdleSavePeriod(_idlePeriod);
|
||||
return manager;
|
||||
}
|
||||
catch ( IOException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
HashSessionManager manager = (HashSessionManager)super.newSessionManager();
|
||||
//manager.getSessionDataStore().setStoreDir(_storeDir);
|
||||
//manager.setIdleSavePeriod(_idlePeriod);
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,7 +98,6 @@ public class IdleSessionTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionIdle() throws Exception
|
||||
{
|
||||
String contextPath = "";
|
||||
|
@ -111,7 +105,7 @@ public class IdleSessionTest
|
|||
int inactivePeriod = 200;
|
||||
int scavengePeriod = 3;
|
||||
int idlePeriod = 5;
|
||||
((StdErrLog)Log.getLogger(org.eclipse.jetty.server.session.HashedSession.class)).setHideStacks(true);
|
||||
((StdErrLog)Log.getLogger("org.eclipse.jetty.server.session")).setHideStacks(true);
|
||||
System.setProperty("org.eclipse.jetty.STACKS", "false");
|
||||
File storeDir = new File (System.getProperty("java.io.tmpdir"), "idle-test");
|
||||
storeDir.deleteOnExit();
|
||||
|
@ -229,7 +223,7 @@ public class IdleSessionTest
|
|||
HttpSession session = request.getSession(true);
|
||||
session.setAttribute("test", "test");
|
||||
originalId = session.getId();
|
||||
assertTrue(!((HashedSession)session).isIdled());
|
||||
// assertTrue(!((HashedSession)session).isIdled());
|
||||
}
|
||||
else if ("test".equals(action))
|
||||
{
|
||||
|
@ -237,7 +231,7 @@ public class IdleSessionTest
|
|||
assertTrue(session != null);
|
||||
assertTrue(originalId.equals(session.getId()));
|
||||
assertEquals("test", session.getAttribute("test"));
|
||||
assertTrue(!((HashedSession)session).isIdled());
|
||||
// assertTrue(!((HashedSession)session).isIdled());
|
||||
}
|
||||
else if ("testfail".equals(action))
|
||||
{
|
||||
|
|
|
@ -28,47 +28,11 @@ import org.junit.Test;
|
|||
|
||||
public class SessionRenewTest extends AbstractSessionRenewTest
|
||||
{
|
||||
File tmpDir;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
tmpDir = File.createTempFile("hash-session-renew-test", null);
|
||||
tmpDir.delete();
|
||||
tmpDir.mkdirs();
|
||||
tmpDir.deleteOnExit();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after()
|
||||
{
|
||||
IO.delete(tmpDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTestServer createServer(int port, int max, int scavenge)
|
||||
{
|
||||
return new HashTestServer(port, max, scavenge)
|
||||
{
|
||||
|
||||
@Override
|
||||
public SessionManager newSessionManager()
|
||||
{
|
||||
HashSessionManager sessionManager = (HashSessionManager)super.newSessionManager();
|
||||
sessionManager.setSavePeriod(2);
|
||||
|
||||
try
|
||||
{
|
||||
sessionManager.setStoreDirectory(tmpDir);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
return sessionManager;
|
||||
}
|
||||
|
||||
};
|
||||
return new HashTestServer(port, max, scavenge);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -46,7 +46,9 @@ public abstract class AbstractNewSessionTest
|
|||
{
|
||||
try
|
||||
{
|
||||
System.err.println("Sleeping "+(scavenge * 2500L));
|
||||
Thread.sleep(scavenge * 2500L);
|
||||
System.err.println("Sleeping "+(scavenge * 2500L));
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
|
|
|
@ -131,7 +131,7 @@ public abstract class AbstractSessionRenewTest
|
|||
String beforeSessionId = beforeSession.getId();
|
||||
|
||||
|
||||
((AbstractSession)beforeSession).renewId(request);
|
||||
((Session)beforeSession).renewId(request);
|
||||
|
||||
HttpSession afterSession = request.getSession(false);
|
||||
assertTrue(afterSession != null);
|
||||
|
@ -140,7 +140,7 @@ public abstract class AbstractSessionRenewTest
|
|||
assertTrue(beforeSession==afterSession);
|
||||
assertFalse(beforeSessionId.equals(afterSessionId));
|
||||
|
||||
AbstractSessionManager sessionManager = (AbstractSessionManager)((AbstractSession)afterSession).getSessionManager();
|
||||
SessionManager sessionManager = ((Session)afterSession).getSessionManager();
|
||||
AbstractSessionIdManager sessionIdManager = (AbstractSessionIdManager)sessionManager.getSessionIdManager();
|
||||
|
||||
assertTrue(sessionIdManager.isIdInUse(afterSessionId));
|
||||
|
@ -151,7 +151,7 @@ public abstract class AbstractSessionRenewTest
|
|||
session = sessionManager.getSession(beforeSessionId);
|
||||
assertNull(session);
|
||||
|
||||
if (((AbstractSession)afterSession).isIdChanged())
|
||||
if (((Session)afterSession).isIdChanged())
|
||||
{
|
||||
((org.eclipse.jetty.server.Response)response).addCookie(sessionManager.getSessionCookie(afterSession, request.getContextPath(), request.isSecure()));
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public abstract class AbstractTestServer
|
|||
protected final int _scavengePeriod;
|
||||
protected final ContextHandlerCollection _contexts;
|
||||
protected SessionIdManager _sessionIdManager;
|
||||
private SessionScavenger _scavenger;
|
||||
|
||||
|
||||
|
||||
|
@ -81,6 +82,10 @@ public abstract class AbstractTestServer
|
|||
_contexts = new ContextHandlerCollection();
|
||||
_sessionIdManager = newSessionIdManager(sessionIdMgrConfig);
|
||||
_server.setSessionIdManager(_sessionIdManager);
|
||||
((AbstractSessionIdManager) _sessionIdManager).setServer(_server);
|
||||
_scavenger = new SessionScavenger();
|
||||
_scavenger.setScavengeIntervalSec(scavengePeriod);
|
||||
((AbstractSessionIdManager)_sessionIdManager).setSessionScavenger(_scavenger);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue