use of info.evelio.carbonite.cache.CacheType in project carbonite by eveliotc.
the class KeyBuildingTest method testBuildsProperlyForClassWithoutCache.
@Test
public void testBuildsProperlyForClassWithoutCache() {
CacheType[] types = values();
for (CacheType type : types) {
final String key = CarboniteImp.buildKey(type, TARGET_CLASS, null);
assertKey(type, key, GIVEN_KEY);
}
}
use of info.evelio.carbonite.cache.CacheType in project carbonite by eveliotc.
the class KeyBuildingTest method testBuildsProperlyForClassWithCache.
@Test
public void testBuildsProperlyForClassWithCache() {
final CarboniteImp.KeyCache cache = new CarboniteImp.KeyCache();
CacheType[] types = values();
for (CacheType type : types) {
final String key = CarboniteImp.buildKey(type, TARGET_CLASS, cache);
assertKey(type, key, GIVEN_KEY);
// Ensure cache keeps same cached keys
assertEquals(key, cache.get(type).get(TARGET_CLASS));
}
}
use of info.evelio.carbonite.cache.CacheType in project carbonite by eveliotc.
the class CacheFactoryImp method buildDefault.
@SuppressWarnings("unchecked")
private Cache<String, T> buildDefault(CacheBuilder options) {
final CacheType cacheType = options.cacheType();
switch(cacheType) {
case MEMORY:
return new MemoryLruCache<String, T>(new MemoryLruCache.Options(LRU_SIZE));
case STORAGE:
// TODO yikes a builder or something, plus kryo needs more config
final Class type = options.type();
final File dir = buildCacheDir(options.context(), type);
final Serializer<T> serializer = new KryoSerializer<T>(new Kryo(), type);
final Options storageOpts = new Options(dir, MINIMAL_CAPACITY, type, serializer);
return new StorageLruCache<T>(storageOpts);
default:
illegalState(true, "Not yet implemented cache type " + cacheType);
return null;
}
}
use of info.evelio.carbonite.cache.CacheType in project carbonite by eveliotc.
the class DefaultCacheBuilderTest method andSpawnsNewOptionsAndSameRetaining.
@Test
public void andSpawnsNewOptionsAndSameRetaining() {
final CacheBuilder opts = new DefaultCacheBuilder(mockBuilder(), CLASS_TO_RETAIN);
for (CacheType type : CacheType.values()) {
final CacheBuilder anotherOptions = opts.and(type);
assertThat(opts).isNotEqualTo(anotherOptions);
assertThat(opts.type() == anotherOptions.type()).isTrue();
}
}
use of info.evelio.carbonite.cache.CacheType in project carbonite by eveliotc.
the class KeyBuildingTest method testBuildsProperlyForName.
@Test
public void testBuildsProperlyForName() {
final String actualKey = "key";
CacheType[] types = values();
for (CacheType type : types) {
final String key = CarboniteImp.buildKey(type, actualKey);
assertKey(type, key, actualKey);
}
}
Aggregations