diff --git a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java old mode 100644 new mode 100755 index a273b659e..e172da819 --- a/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java +++ b/src/main/java/net/openhft/chronicle/map/FilePerKeyMap.java @@ -203,12 +203,19 @@ public class FilePerKeyMap implements Map, Closeable { } catch (IOException e) { throw new AssertionError(e); } - tmpFile.renameTo(file); + try { + Files.move(tmpFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); + } catch (IOException e) { + throw new IllegalStateException(e); + } } private void deleteFile(Path path) { - File key = path.toFile(); - key.delete(); + try { + Files.deleteIfExists(path); + } catch (IOException e) { + throw new IllegalStateException(e); + } } public void close() { @@ -297,7 +304,7 @@ public class FilePerKeyMap implements Map, Closeable { continue; } - if (kind == StandardWatchEventKinds.ENTRY_CREATE) { + if (kind == StandardWatchEventKinds.ENTRY_CREATE) { Path p = dirPath.resolve(fileName); try { String mapVal = getFileContents0(p); diff --git a/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java b/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java old mode 100644 new mode 100755 index 8ec390f60..42ed147d8 --- a/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java +++ b/src/test/java/net/openhft/chronicle/map/FilePerKeyMapTest.java @@ -31,13 +31,15 @@ public class FilePerKeyMapTest { public void testMapMethods() throws InterruptedException { String val = map.put("one", "test1"); assertEquals(val, null); - Thread.sleep(5); + Thread.sleep(10); //After the entry has been written the value returned should be //the previous value val = map.put("one", "test2"); assertEquals(val, "test1"); + Thread.sleep(10); + //Check that get returns the latest value val = map.get("one"); assertEquals("test2", val);