assertThat(loadProperties(dir.file("cache.properties")), equalTo(properties));
}
@Test
public void rebuildsCacheWhenInitialiserFailedOnPreviousOpen() {
TestFile dir = tmpDir.getTestDirectory().file("dir").createDir();
final RuntimeException failure = new RuntimeException();
context.checking(new Expectations() {{
one(action).execute(with(notNullValue(PersistentCache.class)));
will(throwException(failure));
}});
try {
new DefaultPersistentDirectoryCache(dir, "<display-name>", validator, properties, mode(LockMode.Shared), action, lockManager).open();
fail();
} catch (CacheOpenException e) {
assertThat(e.getCause(), sameInstance((Throwable) failure));
}
context.checking(new Expectations() {{
one(action).execute(with(notNullValue(PersistentCache.class)));
}});
DefaultPersistentDirectoryCache cache = new DefaultPersistentDirectoryCache(dir, "<display-name>", validator, properties, mode(LockMode.Shared), action, lockManager);
cache.open();
assertThat(loadProperties(dir.file("cache.properties")), equalTo(properties));
}