Search in sources :

Example 1 with ImmortalCacheEntry

use of org.infinispan.container.entries.ImmortalCacheEntry in project infinispan by infinispan.

the class L1WriteSynchronizerTest method testSpawnedThreadBlockingValueTimeWait.

@Test
public void testSpawnedThreadBlockingValueTimeWait() throws InterruptedException, ExecutionException, TimeoutException {
    Object value = new Object();
    Future future = fork(() -> sync.get(5, TimeUnit.SECONDS));
    // This should not return since we haven't signaled the sync yet
    try {
        future.get(50, TimeUnit.MILLISECONDS);
        fail("Should have thrown a timeout exception");
    } catch (TimeoutException e) {
    // This should time out exception
    }
    InternalCacheEntry ice = new ImmortalCacheEntry(value, value);
    sync.runL1UpdateIfPossible(ice);
    assertEquals(ice, future.get(1, TimeUnit.SECONDS));
}
Also used : InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) Future(java.util.concurrent.Future) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 2 with ImmortalCacheEntry

use of org.infinispan.container.entries.ImmortalCacheEntry in project infinispan by infinispan.

the class L1WriteSynchronizerTest method testGetReturnValueTimeWait.

@Test
public void testGetReturnValueTimeWait() throws InterruptedException, ExecutionException, TimeoutException {
    Object value = new Object();
    InternalCacheEntry ice = new ImmortalCacheEntry(value, value);
    sync.runL1UpdateIfPossible(ice);
    assertEquals(ice, sync.get(1, TimeUnit.SECONDS));
}
Also used : InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 3 with ImmortalCacheEntry

use of org.infinispan.container.entries.ImmortalCacheEntry in project infinispan by infinispan.

the class L1WriteSynchronizerTest method testGetReturnValueWait.

@Test
public void testGetReturnValueWait() throws InterruptedException, ExecutionException, TimeoutException {
    Object value = new Object();
    InternalCacheEntry ice = new ImmortalCacheEntry(value, value);
    sync.runL1UpdateIfPossible(ice);
    assertEquals(ice, sync.get());
}
Also used : InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 4 with ImmortalCacheEntry

use of org.infinispan.container.entries.ImmortalCacheEntry in project infinispan by infinispan.

the class BaseStreamTest method testObjReduce2.

public void testObjReduce2() {
    Cache<Integer, String> cache = getCache(0);
    int range = 10;
    // First populate the cache with a bunch of values
    IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
    CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet();
    // This isn't the best usage of this, but should be a usable example
    Map.Entry<Integer, String> result = createStream(entrySet).reduce(new ImmortalCacheEntry(0, ""), (e1, e2) -> new ImmortalCacheEntry(e1.getKey() + e2.getKey(), e1.getValue() + e2.getValue()));
    assertEquals((range - 1) * (range / 2), result.getKey().intValue());
    assertEquals(range * 7, result.getValue().length());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TreeMap(java.util.TreeMap)

Example 5 with ImmortalCacheEntry

use of org.infinispan.container.entries.ImmortalCacheEntry in project infinispan by infinispan.

the class BaseSetupStreamIteratorTest method generateEntriesPerSegment.

protected Map<Integer, Set<Map.Entry<Object, String>>> generateEntriesPerSegment(KeyPartitioner keyPartitioner, Iterable<Map.Entry<Object, String>> entries) {
    Map<Integer, Set<Map.Entry<Object, String>>> returnMap = new HashMap<>();
    for (Map.Entry<Object, String> value : entries) {
        int segment = keyPartitioner.getSegment(value.getKey());
        Set<Map.Entry<Object, String>> set = returnMap.computeIfAbsent(segment, k -> new LinkedHashSet<>());
        set.add(new ImmortalCacheEntry(value.getKey(), value.getValue()));
    }
    return returnMap;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashMap(java.util.HashMap) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)35 Test (org.testng.annotations.Test)13 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)12 CacheEntry (org.infinispan.container.entries.CacheEntry)10 ArrayList (java.util.ArrayList)8 TransientMortalCacheEntry (org.infinispan.container.entries.TransientMortalCacheEntry)8 Map (java.util.Map)7 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)6 HashMap (java.util.HashMap)4 IntSet (org.infinispan.commons.util.IntSet)4 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)4 Address (org.infinispan.remoting.transport.Address)4 List (java.util.List)3 Set (java.util.Set)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 Future (java.util.concurrent.Future)3 Cache (org.infinispan.Cache)3