Search in sources :

Example 6 with DataConversion

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));
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataContainer(org.infinispan.container.DataContainer) WrappedBytes(org.infinispan.commons.marshall.WrappedBytes)

Example 7 with DataConversion

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)));
    }
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 8 with DataConversion

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)));
    }
}
Also used : DataConversion(org.infinispan.encoding.DataConversion)

Example 9 with DataConversion

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;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) MVCCEntry(org.infinispan.container.entries.MVCCEntry) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 10 with DataConversion

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;
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) Consumer(java.util.function.Consumer) MVCCEntry(org.infinispan.container.entries.MVCCEntry)

Aggregations

DataConversion (org.infinispan.encoding.DataConversion)41 MVCCEntry (org.infinispan.container.entries.MVCCEntry)9 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)9 ArrayList (java.util.ArrayList)8 AdvancedCache (org.infinispan.AdvancedCache)8 Util (org.infinispan.commons.util.Util)8 EnumUtil (org.infinispan.commons.util.EnumUtil)7 InvocationContext (org.infinispan.context.InvocationContext)7 Completable (io.reactivex.rxjava3.core.Completable)6 Flowable (io.reactivex.rxjava3.core.Flowable)6 Set (java.util.Set)6 CompletionStage (java.util.concurrent.CompletionStage)6 Function (java.util.function.Function)6 Transaction (javax.transaction.Transaction)6 TransactionManager (javax.transaction.TransactionManager)6 MediaType (org.infinispan.commons.dataconversion.MediaType)6 TimeService (org.infinispan.commons.time.TimeService)6 Configuration (org.infinispan.configuration.cache.Configuration)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 FlagBitSets (org.infinispan.context.impl.FlagBitSets)6