Finally worked out what was wrong with the test.
This commit is contained in:
Jan Bartel 2017-03-23 15:20:47 +11:00
parent 8059b8553b
commit 08ee1b62d4
2 changed files with 32 additions and 9 deletions

View File

@ -575,24 +575,46 @@ public class FileSessionDataStore extends AbstractSessionDataStore
//delete all but the most recent file
File file = null;
File newest = null;
for (File f:files)
{
try
{
if (file == null)
file = f;
if (newest == null)
{
//haven't looked at any files yet
newest = f;
}
else
{
//accept the newest file
if (f.lastModified() > file.lastModified())
if (f.lastModified() > newest.lastModified())
{
Files.deleteIfExists(file.toPath());
file = f;
//this file is more recent
Files.deleteIfExists(newest.toPath());
newest = f;
}
else if (f.lastModified() < newest.lastModified())
{
//this file is older
Files.deleteIfExists(f.toPath());
}
else
{
Files.deleteIfExists(f.toPath());
//files have same last modified times, decide based on latest expiry time
long exp1 = getExpiryFromFile(newest);
long exp2 = getExpiryFromFile(f);
if (exp2 >= exp1)
{
//this file has a later expiry date
Files.deleteIfExists(newest.toPath());
newest = f;
}
else
{
//this file has an earlier expiry date
Files.deleteIfExists(f.toPath());
}
}
}
}
@ -602,7 +624,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
}
}
return file;
return newest;
}

View File

@ -157,6 +157,7 @@ public class FileSessionManagerTest
Thread.currentThread().sleep(20);
Session session = handler.getSession("abc");
Assert.assertTrue(!f1.exists());
Assert.assertTrue(!f2.exists());