Search in sources :

Example 6 with CI2

use of org.apache.ignite.internal.util.typedef.CI2 in project ignite by apache.

the class GridCacheBalancingStoreSelfTest method testLoads.

/**
 * @throws Exception If failed.
 */
@Test
public void testLoads() throws Exception {
    final int range = 300;
    final AtomicInteger cycles = new AtomicInteger();
    final AtomicReference<Exception> err = new AtomicReference<>();
    final CacheStoreBalancingWrapper<Integer, Integer> w = new CacheStoreBalancingWrapper<>(new VerifyStore(range));
    final AtomicBoolean finish = new AtomicBoolean();
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new IgniteCallable<Void>() {

        @Override
        public Void call() throws Exception {
            try {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                while (!finish.get()) {
                    int cnt = rnd.nextInt(CacheStoreBalancingWrapper.DFLT_LOAD_ALL_THRESHOLD) + 1;
                    if (cnt == 1) {
                        int key = rnd.nextInt(range);
                        assertEquals((Integer) key, w.load(key));
                    } else {
                        Collection<Integer> keys = new HashSet<>(cnt);
                        for (int i = 0; i < cnt; i++) keys.add(rnd.nextInt(range));
                        final Map<Integer, Integer> loaded = new HashMap<>();
                        w.loadAll(keys, new CI2<Integer, Integer>() {

                            @Override
                            public void apply(Integer k, Integer v) {
                                loaded.put(k, v);
                            }
                        });
                        for (Integer key : keys) assertEquals(key, loaded.get(key));
                    }
                    int c = cycles.incrementAndGet();
                    if (c > 0 && c % 2_000_000 == 0)
                        info("Finished cycles: " + c);
                }
            } catch (Exception e) {
                e.printStackTrace();
                err.compareAndSet(null, e);
            }
            return null;
        }
    }, 10, "test");
    try {
        Thread.sleep(30_000);
    } finally {
        finish.set(true);
    }
    fut.get();
    if (err.get() != null)
        throw err.get();
    info("Total: " + cycles.get());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CI2(org.apache.ignite.internal.util.typedef.CI2) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) CacheStoreBalancingWrapper(org.apache.ignite.internal.processors.cache.CacheStoreBalancingWrapper) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

CI2 (org.apache.ignite.internal.util.typedef.CI2)6 Map (java.util.Map)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteException (org.apache.ignite.IgniteException)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3 IOException (java.io.IOException)2 InvalidObjectException (java.io.InvalidObjectException)2 ObjectStreamException (java.io.ObjectStreamException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 HashSet (java.util.HashSet)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 EntryProcessorException (javax.cache.processor.EntryProcessorException)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryTest (org.apache.ignite.cache.store.jdbc.model.BinaryTest)2 Person (org.apache.ignite.cache.store.jdbc.model.Person)2 PersonComplexKey (org.apache.ignite.cache.store.jdbc.model.PersonComplexKey)2