use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class OffHeapSingleNodeTest method testExpiredEntryCompute.
public void testExpiredEntryCompute() throws IOException, InterruptedException {
Cache<Object, Object> cache = cache(0);
String key = "key";
cache.put(key, "value", 10, TimeUnit.MILLISECONDS);
timeService.advance(20);
DataConversion keyDataConversion = cache.getAdvancedCache().getKeyDataConversion();
WrappedBytes keyWB = (WrappedBytes) keyDataConversion.toStorage(key);
AtomicBoolean invoked = new AtomicBoolean(false);
DataContainer container = cache.getAdvancedCache().getDataContainer();
container.compute(keyWB, (k, e, f) -> {
invoked.set(true);
// Just leave it in there
return e;
});
// Should not have invoked, due to expiration
assertTrue(invoked.get());
assertNotNull(container.peek(keyWB));
// Actually reading it shouldn't return though and actually remove
assertNull(cache.get(key));
// Now that we did a get, the peek shouldn't return anything
assertNull(container.peek(keyWB));
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class LocalModePassivationTest method testKeySetWithEvictedEntriesAndFlags.
public void testKeySetWithEvictedEntriesAndFlags() {
final int numKeys = 300;
for (int i = 0; i < numKeys; i++) {
cache.put(i, i);
}
AdvancedCache<Object, Object> flagCache = cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD);
DataContainer<Object, Object> dc = flagCache.getDataContainer();
assertFalse("Data Container should not have all keys", numKeys == dc.size());
Set<Object> keySet = flagCache.keySet();
assertEquals(dc.size(), keySet.size());
DataConversion conversion = flagCache.getValueDataConversion();
for (InternalCacheEntry<Object, Object> entry : dc) {
Object key = entry.getKey();
assertTrue("Key: " + key + " was not found!", keySet.contains(conversion.fromStorage(key)));
}
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class LocalModePassivationTest method testValuesWithEvictedEntriesAndFlags.
public void testValuesWithEvictedEntriesAndFlags() {
final int numKeys = 300;
for (int i = 0; i < numKeys; i++) {
cache.put(i, i);
}
AdvancedCache<Object, Object> flagCache = cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD);
DataContainer<Object, Object> dc = flagCache.getDataContainer();
assertFalse("Data Container should not have all keys", numKeys == dc.size());
Collection<Object> values = flagCache.values();
assertEquals(dc.size(), values.size());
for (InternalCacheEntry<Object, Object> entry : dc) {
Object dcValue = entry.getValue();
DataConversion valueDataConversion = flagCache.getValueDataConversion();
assertTrue("Value: " + dcValue + " was not found!", values.contains(valueDataConversion.fromStorage(dcValue)));
}
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class CallInterceptor method visitWriteOnlyManyEntriesCommand.
@Override
public Object visitWriteOnlyManyEntriesCommand(InvocationContext ctx, WriteOnlyManyEntriesCommand command) throws Throwable {
Map<Object, Object> arguments = command.getArguments();
DataConversion valueDataConversion = command.getValueDataConversion();
for (Map.Entry entry : arguments.entrySet()) {
MVCCEntry cacheEntry = (MVCCEntry) ctx.lookupEntry(entry.getKey());
// Could be that the key is not local, 'null' is how this is signalled
if (cacheEntry == null) {
throw new IllegalStateException();
}
updateStoreFlags(command, cacheEntry);
Object decodedValue = valueDataConversion.fromStorage(entry.getValue());
command.getBiConsumer().accept(decodedValue, EntryViews.writeOnly(cacheEntry, valueDataConversion));
}
return null;
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class CallInterceptor method visitWriteOnlyManyCommand.
@Override
public Object visitWriteOnlyManyCommand(InvocationContext ctx, WriteOnlyManyCommand command) throws Throwable {
Consumer consumer = command.getConsumer();
DataConversion valueDataConversion = command.getValueDataConversion();
for (Object k : command.getAffectedKeys()) {
MVCCEntry cacheEntry = (MVCCEntry) ctx.lookupEntry(k);
if (cacheEntry == null) {
throw new IllegalStateException();
}
updateStoreFlags(command, cacheEntry);
consumer.accept(EntryViews.writeOnly(cacheEntry, valueDataConversion));
}
return null;
}
Aggregations