Search in sources :

Example 1 with CacheSet

use of org.infinispan.CacheSet in project infinispan by infinispan.

the class BaseStreamTest method testLongFlatMapObjConsumerForEach.

public void testLongFlatMapObjConsumerForEach() {
    Cache<Long, String> cache = getCache(0);
    String cacheName = cache.getName();
    int range = 10;
    // First populate the cache with a bunch of values
    LongStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value"));
    CacheSet<Map.Entry<Long, String>> entrySet = cache.entrySet();
    int offset = populateNextForEachStructure(new AtomicLong());
    try {
        createStream(entrySet).distributedBatchSize(5).mapToLong(toLong).flatMap(i -> LongStream.of(i, 2)).forEach((c, e) -> {
            assertEquals(cacheName, c.getName());
            AtomicLong atomic = getForEachObject(offset);
            atomic.addAndGet(e);
        });
        AtomicLong atomic = getForEachObject(offset);
        assertEquals((range - 1) * (range / 2) + 2 * range, atomic.get());
    } finally {
        clearForEachObject(offset);
    }
}
Also used : Arrays(java.util.Arrays) CacheStream(org.infinispan.CacheStream) IntSets(org.infinispan.commons.util.IntSets) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Spliterators(java.util.Spliterators) ObjectOutput(java.io.ObjectOutput) IntConsumer(java.util.function.IntConsumer) Test(org.testng.annotations.Test) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) DoubleConsumer(java.util.function.DoubleConsumer) SerializableToIntFunction(org.infinispan.util.function.SerializableToIntFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) SerializableToLongFunction(org.infinispan.util.function.SerializableToLongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CacheSet(org.infinispan.CacheSet) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) Queue(java.util.Queue) SerializeWith(org.infinispan.commons.marshall.SerializeWith) Spliterator(java.util.Spliterator) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) Supplier(java.util.function.Supplier) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SerializableToDoubleFunction(org.infinispan.util.function.SerializableToDoubleFunction) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheCollection(org.infinispan.CacheCollection) StreamSupport(java.util.stream.StreamSupport) LongSummaryStatistics(java.util.LongSummaryStatistics) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) ToIntFunction(java.util.function.ToIntFunction) TransactionMode(org.infinispan.transaction.TransactionMode) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) AssertJUnit.fail(org.testng.AssertJUnit.fail) LongConsumer(java.util.function.LongConsumer) PrimitiveIterator(java.util.PrimitiveIterator) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) IntSummaryStatistics(java.util.IntSummaryStatistics) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 2 with CacheSet

use of org.infinispan.CacheSet in project infinispan by infinispan.

the class BaseStreamTest method testDoubleFlatMapObjConsumerForEach.

public void testDoubleFlatMapObjConsumerForEach() {
    Cache<Double, String> cache = getCache(0);
    String cacheName = cache.getName();
    int range = 10;
    // First populate the cache with a bunch of values
    DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
    CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
    int offset = populateNextForEachStructure(new DoubleSummaryStatistics());
    try {
        createStream(entrySet).distributedBatchSize(5).mapToDouble(toDouble).flatMap(e -> DoubleStream.of(e, 2.25)).forEach((c, e) -> {
            assertEquals(cacheName, c.getName());
            DoubleSummaryStatistics stats = getForEachObject(offset);
            synchronized (stats) {
                stats.accept(e);
            }
        });
        DoubleSummaryStatistics stats = getForEachObject(offset);
        assertEquals(2.25, stats.getAverage());
        assertEquals(0.0, stats.getMin());
        assertEquals(4.5, stats.getMax());
        assertEquals(20, stats.getCount());
        assertEquals(45.0, stats.getSum());
    } finally {
        clearForEachObject(offset);
    }
}
Also used : Arrays(java.util.Arrays) CacheStream(org.infinispan.CacheStream) IntSets(org.infinispan.commons.util.IntSets) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Spliterators(java.util.Spliterators) ObjectOutput(java.io.ObjectOutput) IntConsumer(java.util.function.IntConsumer) Test(org.testng.annotations.Test) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) DoubleConsumer(java.util.function.DoubleConsumer) SerializableToIntFunction(org.infinispan.util.function.SerializableToIntFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) SerializableToLongFunction(org.infinispan.util.function.SerializableToLongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CacheSet(org.infinispan.CacheSet) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) Queue(java.util.Queue) SerializeWith(org.infinispan.commons.marshall.SerializeWith) Spliterator(java.util.Spliterator) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) Supplier(java.util.function.Supplier) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SerializableToDoubleFunction(org.infinispan.util.function.SerializableToDoubleFunction) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheCollection(org.infinispan.CacheCollection) StreamSupport(java.util.stream.StreamSupport) LongSummaryStatistics(java.util.LongSummaryStatistics) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) ToIntFunction(java.util.function.ToIntFunction) TransactionMode(org.infinispan.transaction.TransactionMode) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) AssertJUnit.fail(org.testng.AssertJUnit.fail) LongConsumer(java.util.function.LongConsumer) PrimitiveIterator(java.util.PrimitiveIterator) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) IntSummaryStatistics(java.util.IntSummaryStatistics) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics)

Example 3 with CacheSet

use of org.infinispan.CacheSet in project infinispan by infinispan.

the class BaseStreamTest method testIntFlatMapForEach.

public void testIntFlatMapForEach() {
    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();
    int offset = populateNextForEachStructure(new AtomicInteger());
    try {
        createStream(entrySet).distributedBatchSize(5).mapToInt(toInt).flatMap(i -> IntStream.of(i, 2)).forEach(e -> {
            AtomicInteger atomic = getForEachObject(offset);
            atomic.addAndGet(e);
        });
        AtomicInteger atomic = getForEachObject(offset);
        assertEquals((range - 1) * (range / 2) + 2 * range, atomic.get());
    } finally {
        clearForEachObject(offset);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) CacheStream(org.infinispan.CacheStream) IntSets(org.infinispan.commons.util.IntSets) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Spliterators(java.util.Spliterators) ObjectOutput(java.io.ObjectOutput) IntConsumer(java.util.function.IntConsumer) Test(org.testng.annotations.Test) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) DoubleConsumer(java.util.function.DoubleConsumer) SerializableToIntFunction(org.infinispan.util.function.SerializableToIntFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) SerializableToLongFunction(org.infinispan.util.function.SerializableToLongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CacheSet(org.infinispan.CacheSet) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) Queue(java.util.Queue) SerializeWith(org.infinispan.commons.marshall.SerializeWith) Spliterator(java.util.Spliterator) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) Supplier(java.util.function.Supplier) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SerializableToDoubleFunction(org.infinispan.util.function.SerializableToDoubleFunction) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheCollection(org.infinispan.CacheCollection) StreamSupport(java.util.stream.StreamSupport) LongSummaryStatistics(java.util.LongSummaryStatistics) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) ToIntFunction(java.util.function.ToIntFunction) TransactionMode(org.infinispan.transaction.TransactionMode) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) AssertJUnit.fail(org.testng.AssertJUnit.fail) LongConsumer(java.util.function.LongConsumer) PrimitiveIterator(java.util.PrimitiveIterator) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) IntSummaryStatistics(java.util.IntSummaryStatistics) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 4 with CacheSet

use of org.infinispan.CacheSet in project infinispan by infinispan.

the class BaseStreamTest method testIntFlatMapObjConsumerForEach.

public void testIntFlatMapObjConsumerForEach() {
    Cache<Integer, String> cache = getCache(0);
    String cacheName = cache.getName();
    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();
    int offset = populateNextForEachStructure(new AtomicInteger());
    try {
        createStream(entrySet).distributedBatchSize(5).mapToInt(toInt).flatMap(i -> IntStream.of(i, 2)).forEach((c, e) -> {
            assertEquals(cacheName, c.getName());
            AtomicInteger atomic = getForEachObject(offset);
            atomic.addAndGet(e);
        });
        AtomicInteger atomic = getForEachObject(offset);
        assertEquals((range - 1) * (range / 2) + 2 * range, atomic.get());
    } finally {
        clearForEachObject(offset);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) CacheStream(org.infinispan.CacheStream) IntSets(org.infinispan.commons.util.IntSets) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Spliterators(java.util.Spliterators) ObjectOutput(java.io.ObjectOutput) IntConsumer(java.util.function.IntConsumer) Test(org.testng.annotations.Test) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) DoubleConsumer(java.util.function.DoubleConsumer) SerializableToIntFunction(org.infinispan.util.function.SerializableToIntFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) SerializableToLongFunction(org.infinispan.util.function.SerializableToLongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CacheSet(org.infinispan.CacheSet) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) Queue(java.util.Queue) SerializeWith(org.infinispan.commons.marshall.SerializeWith) Spliterator(java.util.Spliterator) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) Supplier(java.util.function.Supplier) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SerializableToDoubleFunction(org.infinispan.util.function.SerializableToDoubleFunction) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheCollection(org.infinispan.CacheCollection) StreamSupport(java.util.stream.StreamSupport) LongSummaryStatistics(java.util.LongSummaryStatistics) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) ToIntFunction(java.util.function.ToIntFunction) TransactionMode(org.infinispan.transaction.TransactionMode) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) AssertJUnit.fail(org.testng.AssertJUnit.fail) LongConsumer(java.util.function.LongConsumer) PrimitiveIterator(java.util.PrimitiveIterator) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) IntSummaryStatistics(java.util.IntSummaryStatistics) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with CacheSet

use of org.infinispan.CacheSet in project infinispan by infinispan.

the class BaseStreamTest method testObjSortedCollector.

public void testObjSortedCollector() {
    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();
    List<Map.Entry<Integer, String>> list = createStream(entrySet).sorted((e1, e2) -> Integer.compare(e1.getKey(), e2.getKey())).collect(Collectors::<Map.Entry<Integer, String>>toList);
    assertEquals(cache.size(), list.size());
    AtomicInteger i = new AtomicInteger();
    list.forEach(e -> {
        assertEquals(i.getAndIncrement(), e.getKey().intValue());
        assertEquals(cache.get(e.getKey()), e.getValue());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) CacheStream(org.infinispan.CacheStream) IntSets(org.infinispan.commons.util.IntSets) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Spliterators(java.util.Spliterators) ObjectOutput(java.io.ObjectOutput) IntConsumer(java.util.function.IntConsumer) Test(org.testng.annotations.Test) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) Cache(org.infinispan.Cache) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) DoubleConsumer(java.util.function.DoubleConsumer) SerializableToIntFunction(org.infinispan.util.function.SerializableToIntFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) SerializableToLongFunction(org.infinispan.util.function.SerializableToLongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) CacheSet(org.infinispan.CacheSet) Collectors(java.util.stream.Collectors) DoubleStream(java.util.stream.DoubleStream) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) Queue(java.util.Queue) SerializeWith(org.infinispan.commons.marshall.SerializeWith) Spliterator(java.util.Spliterator) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) Supplier(java.util.function.Supplier) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) SerializableToDoubleFunction(org.infinispan.util.function.SerializableToDoubleFunction) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheCollection(org.infinispan.CacheCollection) StreamSupport(java.util.stream.StreamSupport) LongSummaryStatistics(java.util.LongSummaryStatistics) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) ToIntFunction(java.util.function.ToIntFunction) TransactionMode(org.infinispan.transaction.TransactionMode) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) IOException(java.io.IOException) AssertJUnit.fail(org.testng.AssertJUnit.fail) LongConsumer(java.util.function.LongConsumer) PrimitiveIterator(java.util.PrimitiveIterator) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) IntSummaryStatistics(java.util.IntSummaryStatistics) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Collectors(java.util.stream.Collectors) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TreeMap(java.util.TreeMap)

Aggregations

Cache (org.infinispan.Cache)15 CacheSet (org.infinispan.CacheSet)15 Map (java.util.Map)14 PrimitiveIterator (java.util.PrimitiveIterator)14 Set (java.util.Set)14 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)14 Collectors (java.util.stream.Collectors)14 IntStream (java.util.stream.IntStream)14 IOException (java.io.IOException)13 ObjectInput (java.io.ObjectInput)13 ObjectOutput (java.io.ObjectOutput)13 ArrayList (java.util.ArrayList)13 Arrays (java.util.Arrays)13 DoubleSummaryStatistics (java.util.DoubleSummaryStatistics)13 HashSet (java.util.HashSet)13 IntSummaryStatistics (java.util.IntSummaryStatistics)13 Iterator (java.util.Iterator)13 List (java.util.List)13 LongSummaryStatistics (java.util.LongSummaryStatistics)13 Optional (java.util.Optional)13