Search in sources :

Example 16 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.

the class IgniteClientReconnectCollectionsTest method testQueueReconnectInProgress.

/**
     * @throws Exception If failed.
     */
public void testQueueReconnectInProgress() throws Exception {
    CollectionConfiguration colCfg = new CollectionConfiguration();
    colCfg.setCacheMode(PARTITIONED);
    colCfg.setAtomicityMode(TRANSACTIONAL);
    queueReconnectInProgress(colCfg);
    colCfg = new CollectionConfiguration();
    colCfg.setCacheMode(PARTITIONED);
    colCfg.setAtomicityMode(ATOMIC);
    queueReconnectInProgress(colCfg);
}
Also used : CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 17 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.

the class IgniteClientReconnectCollectionsTest method testSetReconnectRemoved.

/**
     * @throws Exception If failed.
     */
public void testSetReconnectRemoved() throws Exception {
    CollectionConfiguration colCfg = new CollectionConfiguration();
    colCfg.setCacheMode(PARTITIONED);
    colCfg.setAtomicityMode(ATOMIC);
    setReconnectRemove(colCfg);
    colCfg = new CollectionConfiguration();
    colCfg.setCacheMode(PARTITIONED);
    colCfg.setAtomicityMode(TRANSACTIONAL);
    setReconnectRemove(colCfg);
}
Also used : CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 18 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.

the class GridCacheSetAbstractSelfTest method testCleanup.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
@SuppressWarnings("WhileLoopReplaceableByForEach")
private void testCleanup(boolean collocated) throws Exception {
    CollectionConfiguration colCfg = config(collocated);
    final IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg);
    assertNotNull(set0);
    final Collection<Set<Integer>> sets = new ArrayList<>();
    for (int i = 0; i < gridCount(); i++) {
        IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
        assertNotNull(set);
        sets.add(set);
    }
    Collection<Integer> items = new ArrayList<>(10_000);
    for (int i = 0; i < 10_000; i++) items.add(i);
    set0.addAll(items);
    assertEquals(10_000, set0.size());
    final AtomicBoolean stop = new AtomicBoolean();
    final AtomicInteger val = new AtomicInteger(10_000);
    IgniteInternalFuture<?> fut;
    try {
        fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                try {
                    while (!stop.get()) {
                        for (Set<Integer> set : sets) set.add(val.incrementAndGet());
                    }
                } catch (IllegalStateException e) {
                    log.info("Set removed: " + e);
                }
                return null;
            }
        }, 5, "set-add-thread");
        set0.close();
    } finally {
        stop.set(true);
    }
    fut.get();
    int cnt = 0;
    GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx");
    for (int i = 0; i < gridCount(); i++) {
        Iterator<GridCacheMapEntry> entries = (grid(i)).context().cache().internalCache(cctx.name()).map().entries().iterator();
        while (entries.hasNext()) {
            GridCacheEntryEx entry = entries.next();
            if (entry.hasValue()) {
                cnt++;
                log.info("Unexpected entry: " + entry);
            }
        }
    }
    assertEquals("Found unexpected cache entries", 0, cnt);
    for (final Set<Integer> set : sets) {
        GridTestUtils.assertThrows(log, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                set.add(10);
                return null;
            }
        }, IllegalStateException.class, null);
    }
}
Also used : HashSet(java.util.HashSet) IgniteSet(org.apache.ignite.IgniteSet) Set(java.util.Set) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) ArrayList(java.util.ArrayList) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry)

Example 19 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.

the class GridCacheSetAbstractSelfTest method testNodeJoinsAndLeaves.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
private void testNodeJoinsAndLeaves(boolean collocated) throws Exception {
    CollectionConfiguration colCfg = config(collocated);
    Set<Integer> set0 = grid(0).set(SET_NAME, colCfg);
    final int ITEMS = 10_000;
    for (int i = 0; i < ITEMS; i++) set0.add(i);
    startGrid(gridCount());
    try {
        IgniteSet<Integer> set1 = grid(0).set(SET_NAME, null);
        assertNotNull(set1);
        for (int i = 0; i < gridCount() + 1; i++) {
            IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
            assertEquals(ITEMS, set.size());
            assertSetContent(set, ITEMS);
        }
    } finally {
        stopGrid(gridCount());
    }
    for (int i = 0; i < gridCount(); i++) {
        IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
        assertSetContent(set, ITEMS);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 20 with CollectionConfiguration

use of org.apache.ignite.configuration.CollectionConfiguration in project ignite by apache.

the class GridCacheSetAbstractSelfTest method testIterator.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
@SuppressWarnings("deprecation")
private void testIterator(boolean collocated) throws Exception {
    CollectionConfiguration colCfg = config(collocated);
    final IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg);
    for (int i = 0; i < gridCount(); i++) {
        IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
        assertFalse(set.iterator().hasNext());
    }
    int cnt = 0;
    for (int i = 0; i < gridCount(); i++) {
        Set<Integer> set = grid(i).set(SET_NAME, null);
        for (int j = 0; j < 100; j++) assertTrue(set.add(cnt++));
    }
    for (int i = 0; i < gridCount(); i++) {
        IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
        assertSetContent(set, cnt);
    }
    // Try to do not use hasNext.
    Collection<Integer> data = new HashSet<>(cnt);
    Iterator<Integer> iter = set0.iterator();
    for (int i = 0; i < cnt; i++) assertTrue(data.add(iter.next()));
    assertFalse(iter.hasNext());
    assertEquals(cnt, data.size());
    for (int i = 0; i < cnt; i++) assertTrue(data.contains(i));
    // Iterator for empty set.
    set0.clear();
    for (int i = 0; i < gridCount(); i++) {
        IgniteSet<Integer> set = grid(i).set(SET_NAME, null);
        assertFalse(set.iterator().hasNext());
    }
    for (int i = 0; i < 10; i++) assertTrue(set0.add(i));
    iter = set0.iterator();
    while (iter.hasNext()) {
        Integer val = iter.next();
        if (val % 2 == 0)
            iter.remove();
    }
    for (int i = 0; i < gridCount(); i++) {
        Set<Integer> set = grid(i).set(SET_NAME, null);
        assertEquals(i % 2 != 0, set.contains(i));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) HashSet(java.util.HashSet)

Aggregations

CollectionConfiguration (org.apache.ignite.configuration.CollectionConfiguration)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 ArrayList (java.util.ArrayList)8 IgniteException (org.apache.ignite.IgniteException)8 IgniteQueue (org.apache.ignite.IgniteQueue)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7 Test (org.junit.Test)6 Callable (java.util.concurrent.Callable)5 Ignite (org.apache.ignite.Ignite)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgniteQueueEndpoint (org.apache.camel.component.ignite.queue.IgniteQueueEndpoint)3 IgniteSetEndpoint (org.apache.camel.component.ignite.set.IgniteSetEndpoint)3 IgniteSet (org.apache.ignite.IgniteSet)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 HashSet (java.util.HashSet)2 JndiRegistry (org.apache.camel.impl.JndiRegistry)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2