Change tests to ensure test dir clean
This commit is contained in:
Jan Bartel 2017-03-23 12:10:37 +11:00
parent a3c52d7a3f
commit b242f1e902
2 changed files with 13 additions and 12 deletions

View File

@ -230,7 +230,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
try (FileInputStream in = new FileInputStream(file))
{
SessionData data = load(in);
SessionData data = load(in, id);
data.setLastSaved(file.lastModified());
reference.set(data);
}
@ -590,13 +590,14 @@ public class FileSessionDataStore extends AbstractSessionDataStore
/**
* @param is inputstream containing session data
* @param expectedId the id we've been told to load
* @return the session data
* @throws Exception
*/
private SessionData load (InputStream is)
private SessionData load (InputStream is, String expectedId)
throws Exception
{
String id = null;
String id = null; //the actual id from inside the file
try
{
@ -629,7 +630,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
}
catch (Exception e)
{
throw new UnreadableSessionDataException(id, _context, e);
throw new UnreadableSessionDataException(expectedId, _context, e);
}
}

View File

@ -85,7 +85,7 @@ public class FileSessionManagerTest
handler.setSessionCache(ss);
ss.setSessionDataStore(ds);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs();
FS.ensureEmpty(testDir);
ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr);
handler.start();
@ -125,8 +125,9 @@ public class FileSessionManagerTest
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionCache(ss);
ss.setSessionDataStore(ds);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs();
FS.ensureEmpty(testDir);
ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr);
handler.start();
@ -135,7 +136,7 @@ public class FileSessionManagerTest
String name1 = "100__0.0.0.0_abc";
File f1 = new File(testDir, name1);
if (f1.exists())
f1.delete();
Assert.assertTrue(f1.delete());
f1.createNewFile();
Thread.currentThread().sleep(20);
@ -143,7 +144,7 @@ public class FileSessionManagerTest
String name2 = "101__0.0.0.0_abc";
File f2 = new File(testDir, name2);
if (f2.exists())
f2.delete();
Assert.assertTrue(f2.delete());
f2.createNewFile();
Thread.currentThread().sleep(20);
@ -151,7 +152,7 @@ public class FileSessionManagerTest
String name3 = "102__0.0.0.0_abc";
File f3 = new File(testDir, name3);
if (f3.exists())
f3.delete();
Assert.assertTrue(f3.delete());
f3.createNewFile();
Thread.currentThread().sleep(20);
@ -202,8 +203,7 @@ public class FileSessionManagerTest
public void testHashSession() throws Exception
{
File testDir = MavenTestingUtils.getTargetTestingDir("saved");
IO.delete(testDir);
testDir.mkdirs();
FS.ensureEmpty(testDir);
Server server = new Server();
SessionHandler handler = new SessionHandler();
@ -286,7 +286,7 @@ public class FileSessionManagerTest
handler.setSessionCache(ss);
ss.setSessionDataStore(ds);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs();
FS.ensureEmpty(testDir);
ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr);
handler.start();