public void setUp() throws Exception {
writeToFile(TEXT_1);
}
public void testRegistry() throws Exception {
Registry reg = new SimpleURLRegistry();
reg.addConfigProperty("root", "file:./");
reg.addConfigProperty("cachableDuration", "1500");
Property prop = new Property();
prop.setType(Property.DYNAMIC_TYPE);
prop.setKey(FILE);
// initial load of file from registry
assertEquals(TEXT_1, reg.getProperty(prop).toString());
// sleep 1 sec
Thread.sleep(1000);
assertEquals(TEXT_1, reg.getProperty(prop).toString());
// sleep another 1 sec, has expired in cache, but content hasnt changed
Thread.sleep(1000);
assertEquals(TEXT_1, reg.getProperty(prop).toString());
// the renewed cache should be valid for another 1.5 secs
// change the file now and change next cache duration
writeToFile(TEXT_2);
reg.addConfigProperty("cachableDuration", "100");
// still cached content should be available and valid
assertEquals(TEXT_1, reg.getProperty(prop).toString());
// now sleep 1 sec, still cache should be valid
Thread.sleep(1000);
assertEquals(TEXT_1, reg.getProperty(prop).toString());
// sleep another 1 sec.. cache should expire and new content should be loaded
Thread.sleep(1000);
assertEquals(TEXT_2, reg.getProperty(prop).toString());
// change content back to original
writeToFile(TEXT_1);
// sleep for .5 sec, now the new content should be loaded as new expiry time
// is .1 sec
Thread.sleep(500);
assertEquals(TEXT_1, reg.getProperty(prop).toString());
}