use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class ClusteredStatsTest method primaryKeysCount.
@Override
protected long primaryKeysCount(Cache<?, ?> cache) {
DistributionManager dm = TestingUtil.extractComponent(cache, DistributionManager.class);
long count = 0;
for (int i = 0; i < TOTAL_ENTRIES; i++) {
DataConversion keyDataConversion = cache.getAdvancedCache().getKeyDataConversion();
if (dm.getCacheTopology().getDistribution(keyDataConversion.toStorage("key" + i)).isPrimary()) {
count++;
}
}
return count;
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class EncoderCache method withEncoding.
@Override
public AdvancedCache<K, V> withEncoding(Class<? extends Encoder> keyEncoderClass, Class<? extends Encoder> valueEncoderClass) {
checkSubclass(keyEncoderClass, Encoder.class);
checkSubclass(valueEncoderClass, Encoder.class);
DataConversion newKeyDataConversion = keyDataConversion.withEncoding(keyEncoderClass);
DataConversion newValueDataConversion = valueDataConversion.withEncoding(valueEncoderClass);
EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, newValueDataConversion);
encoderCache.lookupEncoderWrapper();
return encoderCache;
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class EncoderCache method withMediaType.
@Override
public AdvancedCache<K, V> withMediaType(MediaType kType, MediaType vType) {
DataConversion newKeyDataConversion = keyDataConversion.withRequestMediaType(kType);
DataConversion newValueDataConversion = valueDataConversion.withRequestMediaType(vType);
EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, newValueDataConversion);
encoderCache.lookupEncoderWrapper();
return encoderCache;
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class EncoderCache method withWrapping.
@Override
public AdvancedCache<K, V> withWrapping(Class<? extends Wrapper> keyWrapperClass, Class<? extends Wrapper> valueWrapperClass) {
checkSubclass(keyWrapperClass, Wrapper.class);
checkSubclass(valueWrapperClass, Wrapper.class);
DataConversion newKeyDataConversion = keyDataConversion.withWrapping(keyWrapperClass);
DataConversion newValueDataConversion = valueDataConversion.withWrapping(valueWrapperClass);
EncoderCache<K, V> encoderCache = new EncoderCache<>(cache, entryFactory, componentRegistry, newKeyDataConversion, newValueDataConversion);
encoderCache.lookupEncoderWrapper();
return encoderCache;
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class OffHeapSingleNodeExpirationEvictionTest method testEnsureCorrectStorage.
public void testEnsureCorrectStorage() {
Cache<String, String> cache = cache(0);
long beforeInsert = timeService.wallClockTime();
cache.put("k", "v");
timeService.advance(10);
DataConversion dataConversion = cache.getAdvancedCache().getKeyDataConversion();
Object convertedKey = dataConversion.toStorage("k");
assertNotNull(cache.getAdvancedCache().getDataContainer().get(convertedKey));
CacheEntry<String, String> entry = cache.getAdvancedCache().getDataContainer().peek(convertedKey);
assertNotNull(entry);
long storedTime = TimeUnit.MINUTES.toMillis(10);
switch(expirationType) {
case MORTAL:
assertEquals(storedTime, entry.getLifespan());
assertEquals(-1, entry.getMaxIdle());
assertEquals(beforeInsert, entry.getCreated());
assertEquals(-1, entry.getLastUsed());
break;
case TRANSIENT:
assertEquals(-1, entry.getLifespan());
assertEquals(storedTime, entry.getMaxIdle());
assertEquals(-1, entry.getCreated());
assertEquals(beforeInsert, entry.getLastUsed());
break;
case TRANSIENT_MORTAL:
assertEquals(storedTime, entry.getLifespan());
assertEquals(storedTime, entry.getMaxIdle());
assertEquals(beforeInsert, entry.getCreated());
assertEquals(beforeInsert, entry.getLastUsed());
break;
}
}
Aggregations