Search in sources :

Example 26 with CollectionConfiguration

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

the class IgniteClientReconnectCollectionsTest method testQueueReconnect.

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

Example 27 with CollectionConfiguration

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

the class IgniteClientReconnectCollectionsTest method testCollectionsReconnectClusterRestart.

/**
     * @throws Exception If failed.
     */
public void testCollectionsReconnectClusterRestart() throws Exception {
    CollectionConfiguration colCfg = new CollectionConfiguration();
    colCfg.setCacheMode(PARTITIONED);
    colCfg.setAtomicityMode(TRANSACTIONAL);
    Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    final IgniteQueue<Object> queue = client.queue("q", 0, colCfg);
    final IgniteSet<Object> set = client.set("s", colCfg);
    Ignite srv = grid(0);
    reconnectServersRestart(log, client, Collections.singleton(srv), new Callable<Collection<Ignite>>() {

        @Override
        public Collection<Ignite> call() throws Exception {
            return Collections.singleton((Ignite) startGrid(0));
        }
    });
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            queue.add(1);
            return null;
        }
    }, IllegalStateException.class, null);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            set.add(1);
            return null;
        }
    }, IllegalStateException.class, null);
    try (IgniteQueue<Object> queue2 = client.queue("q", 0, colCfg)) {
        queue2.add(1);
    }
    try (IgniteSet<Object> set2 = client.set("s", colCfg)) {
        set2.add(1);
    }
}
Also used : Collection(java.util.Collection) Ignite(org.apache.ignite.Ignite) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 28 with CollectionConfiguration

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

the class GridCacheQueueApiSelfAbstractTest method testAffinityRun.

/**
     * @throws Exception If failed.
     */
public void testAffinityRun() throws Exception {
    final CollectionConfiguration colCfg = collectionConfiguration();
    colCfg.setCollocated(false);
    colCfg.setCacheMode(CacheMode.PARTITIONED);
    try (final IgniteQueue<Integer> queue1 = grid(0).queue("Queue1", 0, colCfg)) {
        GridTestUtils.assertThrows(log, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                queue1.affinityRun(new IgniteRunnable() {

                    @Override
                    public void run() {
                    // No-op.
                    }
                });
                return null;
            }
        }, IgniteException.class, "Failed to execute affinityRun() for non-collocated queue: " + queue1.name() + ". This operation is supported only for collocated queues.");
    }
    colCfg.setCollocated(true);
    try (final IgniteQueue<Integer> queue2 = grid(0).queue("Queue2", 0, colCfg)) {
        queue2.add(100);
        queue2.affinityRun(new IgniteRunnable() {

            @IgniteInstanceResource
            private IgniteEx ignite;

            @Override
            public void run() {
                assertTrue(ignite.cachex("datastructures_0").affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Queue2"));
                assertEquals(100, queue2.take().intValue());
            }
        });
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 29 with CollectionConfiguration

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

the class GridCacheSetAbstractSelfTest method testIteratorClose.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
@SuppressWarnings({ "BusyWait", "ErrorNotRethrown" })
private void testIteratorClose(boolean collocated) throws Exception {
    CollectionConfiguration colCfg = config(collocated);
    IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg);
    for (int i = 0; i < 5000; i++) assertTrue(set0.add(i));
    createIterators(set0);
    System.gc();
    for (int i = 0; i < 10; i++) {
        try {
            // Trigger weak queue poll.
            set0.size();
            assertSetIteratorsCleared();
        } catch (AssertionFailedError e) {
            if (i == 9)
                throw e;
            log.info("Set iterators not cleared, will wait");
            Thread.sleep(500);
        }
    }
    // Check iterators are closed on set remove.
    createIterators(set0);
    int idx = gridCount() > 1 ? 1 : 0;
    grid(idx).set(SET_NAME, null).close();
    for (int i = 0; i < 10; i++) {
        try {
            assertSetIteratorsCleared();
        } catch (AssertionFailedError e) {
            if (i == 9)
                throw e;
            log.info("Set iterators not cleared, will wait");
            Thread.sleep(500);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertionFailedError(junit.framework.AssertionFailedError) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 30 with CollectionConfiguration

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

the class GridCacheSetAbstractSelfTest method testCreateRemove.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
private void testCreateRemove(boolean collocated) throws Exception {
    for (int i = 0; i < gridCount(); i++) assertNull(grid(i).set(SET_NAME, null));
    CollectionConfiguration colCfg0 = config(collocated);
    IgniteSet<Integer> set0 = grid(0).set(SET_NAME, colCfg0);
    assertNotNull(set0);
    for (int i = 0; i < gridCount(); i++) {
        CollectionConfiguration colCfg = config(collocated);
        IgniteSet<Integer> set = grid(i).set(SET_NAME, colCfg);
        assertNotNull(set);
        assertTrue(set.isEmpty());
        assertEquals(0, set.size());
        assertEquals(SET_NAME, set.name());
        if (collectionCacheMode() == PARTITIONED)
            assertEquals(collocated, set.collocated());
    }
    set0.close();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            try {
                for (int i = 0; i < gridCount(); i++) {
                    if (grid(i).set(SET_NAME, null) != null)
                        return false;
                }
                return true;
            } catch (Exception e) {
                fail("Unexpected exception: " + e);
                return true;
            }
        }
    }, 1000);
    for (int i = 0; i < gridCount(); i++) assertNull(grid(i).set(SET_NAME, null));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

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