From b242f1e9028f56e384ca5ecc24b6a033c6e638d8 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 23 Mar 2017 12:10:37 +1100 Subject: [PATCH] Issue #1386 Change tests to ensure test dir clean --- .../server/session/FileSessionDataStore.java | 9 +++++---- .../server/session/FileSessionManagerTest.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java index d26c6a3febf..b10742db933 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java @@ -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); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java index f5d9bf4d173..fd045fd5dd8 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/FileSessionManagerTest.java @@ -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();