Search in sources :

Example 1 with CacheType

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);
    }
}
Also used : CacheType(info.evelio.carbonite.cache.CacheType) Test(org.junit.Test)

Example 2 with CacheType

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));
    }
}
Also used : CacheType(info.evelio.carbonite.cache.CacheType) Test(org.junit.Test)

Example 3 with CacheType

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;
    }
}
Also used : MemoryLruCache(info.evelio.carbonite.cache.MemoryLruCache) Options(info.evelio.carbonite.cache.StorageLruCache.Options) CacheOptions(info.evelio.carbonite.cache.CacheOptions) StorageLruCache(info.evelio.carbonite.cache.StorageLruCache) File(java.io.File) Kryo(com.esotericsoftware.kryo.Kryo) CacheType(info.evelio.carbonite.cache.CacheType) KryoSerializer(info.evelio.carbonite.serialization.KryoSerializer)

Example 4 with CacheType

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();
    }
}
Also used : DefaultCacheBuilder(info.evelio.carbonite.CarboniteBuilderBaseImp.DefaultCacheBuilder) CacheBuilder(info.evelio.carbonite.CarboniteApi.CacheBuilder) DefaultCacheBuilder(info.evelio.carbonite.CarboniteBuilderBaseImp.DefaultCacheBuilder) CacheType(info.evelio.carbonite.cache.CacheType) Test(org.junit.Test)

Example 5 with CacheType

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);
    }
}
Also used : CacheType(info.evelio.carbonite.cache.CacheType) Test(org.junit.Test)

Aggregations

CacheType (info.evelio.carbonite.cache.CacheType)5 Test (org.junit.Test)4 Kryo (com.esotericsoftware.kryo.Kryo)1 CacheBuilder (info.evelio.carbonite.CarboniteApi.CacheBuilder)1 DefaultCacheBuilder (info.evelio.carbonite.CarboniteBuilderBaseImp.DefaultCacheBuilder)1 CacheOptions (info.evelio.carbonite.cache.CacheOptions)1 MemoryLruCache (info.evelio.carbonite.cache.MemoryLruCache)1 StorageLruCache (info.evelio.carbonite.cache.StorageLruCache)1 Options (info.evelio.carbonite.cache.StorageLruCache.Options)1 KryoSerializer (info.evelio.carbonite.serialization.KryoSerializer)1 File (java.io.File)1