@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
private static ConfigStore initStore(String name, String...contents) { return ConfigMemoryStore.create().build().update(name, contents); } }
private static ConfigStore initStore(String name, String...contents) { return ConfigMemoryStore.create().build().update(name, contents); }
private Config init(String...lines) { ConfigMemoryStore.DEFAULT.update("Test.cfg", lines); return cb.build().rollback(); }
@Test public void testUpdate() throws Exception { ConfigMemoryStore fs = ConfigMemoryStore.create().build(); final CountDownLatch latch = new CountDownLatch(2); fs.register("X", new ConfigStoreListener() { @Override public void onChange(String contents) { if ("xxx".equals(contents)) latch.countDown(); } }); fs.register("Y", new ConfigStoreListener() { @Override public void onChange(String contents) { if ("yyy".equals(contents)) latch.countDown(); } }); fs.update("X", "xxx"); fs.update("Y", "yyy"); if (! latch.await(10, TimeUnit.SECONDS)) throw new Exception("CountDownLatch never reached zero."); }