/** * Gets called when the watcher service on this store is triggered with a file system change. * * @param e The file system event. * @throws IOException */ protected synchronized void onFileEvent(WatchEvent<Path> e) throws IOException { String fn = e.context().getFileName().toString(); String oldContents = cache.get(fn); cache.remove(fn); String newContents = read(fn); if (! isEquals(oldContents, newContents)) { update(fn, newContents); } } }
/** * Gets called when the watcher service on this store is triggered with a file system change. * * @param e The file system event. * @throws IOException */ protected synchronized void onFileEvent(WatchEvent<Path> e) throws IOException { String fn = e.context().getFileName().toString(); String oldContents = cache.get(fn); cache.remove(fn); String newContents = read(fn); if (! isEquals(oldContents, newContents)) { update(fn, newContents); } } }
/** * Gets called when the watcher service on this store is triggered with a file system change. * * @param e The file system event. * @throws IOException */ protected synchronized void onFileEvent(WatchEvent<Path> e) throws IOException { String fn = e.context().getFileName().toString(); String oldContents = cache.get(fn); cache.remove(fn); String newContents = read(fn); if (! isEquals(oldContents, newContents)) { update(fn, newContents); } } }
@Test public void testFailOnMismatchNoExtension() throws Exception { assertFileNotExists("X.cfg"); ConfigFileStore fs = ConfigFileStore.create().directory(DIR).build(); assertNotNull(fs.write("X", "xxx", "foo")); assertFileNotExists("X.cfg"); assertEquals("", fs.read("X")); assertEquals("", fs.read("X.cfg")); assertFileNotExists("X.cfg"); assertNull(fs.write("X", null, "foo")); assertEquals("foo", fs.read("X")); assertEquals("foo", fs.read("X.cfg")); assertNotNull(fs.write("X", "xxx", "foo")); assertEquals("foo", fs.read("X")); assertEquals("foo", fs.read("X.cfg")); assertNull(fs.write("X", "foo", "bar")); assertEquals("bar", fs.read("X")); assertEquals("bar", fs.read("X.cfg")); }
@Test public void testFailOnMismatch() throws Exception { assertFileNotExists("X.cfg"); ConfigFileStore fs = ConfigFileStore.create().directory(DIR).build(); assertNotNull(fs.write("X.cfg", "xxx", "foo")); assertFileNotExists("X.cfg"); assertEquals("", fs.read("X.cfg")); assertFileNotExists("X.cfg"); assertNull(fs.write("X.cfg", null, "foo")); assertEquals("foo", fs.read("X.cfg")); assertNotNull(fs.write("X.cfg", "xxx", "foo")); assertEquals("foo", fs.read("X.cfg")); assertNull(fs.write("X.cfg", "foo", "bar")); assertEquals("bar", fs.read("X.cfg")); }
@Test public void testNoFile() throws Exception { ConfigFileStore fs = ConfigFileStore.create().directory(DIR).build(); assertEquals("", fs.read("X.cfg")); assertFileNotExists("X.cfg"); }
@Test public void testDifferentExtension() throws Exception { ConfigFileStore fs = ConfigFileStore.create().directory(DIR).build(); assertEquals("", fs.read("X.xxx")); assertFileNotExists("X.xxx"); }
@Test public void testSimpleCreateAndDelete() throws Exception { ConfigFileStore fs = ConfigFileStore.create().directory(DIR).build(); assertNull(fs.write("X.cfg", null, "foo")); assertEquals("foo", fs.read("X.cfg")); assertFileExists("X.cfg"); fs.write("X.cfg", "foo", null); assertFileNotExists("X.cfg"); }
@Test public void testSimpleCreateAndDeleteWithNoExtension() throws Exception { ConfigFileStore fs = ConfigFileStore.create().directory(DIR).build(); assertNull(fs.write("X", null, "foo")); assertEquals("foo", fs.read("X")); assertFileExists("X.cfg"); fs.write("X", "foo", null); assertFileNotExists("X.cfg"); }
@Test public void testSimpleCreateAndDeleteWithNonStandardExtension() throws Exception { ConfigFileStore fs = ConfigFileStore.create().directory(DIR).extensions("xxx").build(); assertNull(fs.write("X", null, "foo")); assertEquals("foo", fs.read("X")); assertFileExists("X.xxx"); fs.write("X", "foo", null); assertFileNotExists("X.xxx"); }
@Test public void testSimpleCreateAndDeleteWithMultipleSpecialExtension() throws Exception { ConfigFileStore fs = ConfigFileStore.create().directory(DIR).extensions("foo1","foo2").build(); assertNull(fs.write("X", null, "foo")); assertEquals("foo", fs.read("X")); assertFileExists("X.foo1"); fs.write("X", "foo", null); assertFileNotExists("X.foo1"); }