Search in sources :

Example 41 with CollectionConfiguration

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

the class IgniteClientDataStructuresAbstractTest method testQueue.

/**
     * @param creator Creator node.
     * @param other Other node.
     * @throws Exception If failed.
     */
private void testQueue(Ignite creator, final Ignite other) throws Exception {
    assertNull(creator.queue("q1", 0, null));
    assertNull(other.queue("q1", 0, null));
    try (IgniteQueue<Integer> queue = creator.queue("q1", 0, new CollectionConfiguration())) {
        assertNotNull(queue);
        queue.add(1);
        assertEquals(1, queue.poll().intValue());
        IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                U.sleep(1000);
                IgniteQueue<Integer> queue0 = other.queue("q1", 0, null);
                assertEquals(0, queue0.size());
                log.info("Add in queue.");
                queue0.add(2);
                return null;
            }
        });
        log.info("Try take.");
        assertEquals(2, queue.take().intValue());
        log.info("Finished take.");
        fut.get();
    }
    assertNull(creator.queue("q1", 0, null));
    assertNull(other.queue("q1", 0, null));
}
Also used : IgniteQueue(org.apache.ignite.IgniteQueue) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 42 with CollectionConfiguration

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

the class GridCacheSetAbstractSelfTest method testAffinityRun.

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

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

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

            @IgniteInstanceResource
            private IgniteEx ignite;

            @Override
            public void run() {
                assertTrue(ignite.cachex("datastructures_0").affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Set2"));
                assertEquals(100, set2.iterator().next().intValue());
            }
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 43 with CollectionConfiguration

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

the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method testAddFailover.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
private void testAddFailover(boolean collocated) throws Exception {
    CollectionConfiguration colCfg = config(collocated);
    IgniteQueue<Integer> queue = grid(0).queue(QUEUE_NAME, 0, colCfg);
    assertNotNull(queue);
    assertEquals(0, queue.size());
    int primaryNode = primaryQueueNode(queue);
    int testNodeIdx = -1;
    for (int i = 0; i < gridCount(); i++) {
        if (i != primaryNode)
            testNodeIdx = i;
    }
    log.info("Test node: " + testNodeIdx);
    log.info("Header primary node: " + primaryNode);
    queue = grid(testNodeIdx).queue(QUEUE_NAME, 0, null);
    assertNotNull(queue);
    // Kill queue header's primary node .
    testAddFailover(queue, Arrays.asList(primaryNode));
    List<Integer> killIdxs = new ArrayList<>();
    for (int i = 0; i < gridCount(); i++) {
        if (i != testNodeIdx)
            killIdxs.add(i);
    }
    // Kill random node.
    testAddFailover(queue, killIdxs);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 44 with CollectionConfiguration

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

the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method collectionConfiguration.

/** {@inheritDoc} */
@Override
protected CollectionConfiguration collectionConfiguration() {
    CollectionConfiguration colCfg = super.collectionConfiguration();
    colCfg.setBackups(1);
    return colCfg;
}
Also used : CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 45 with CollectionConfiguration

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

the class IgniteClientReconnectApiExceptionTest method dataStructureOperationsTest.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
public void dataStructureOperationsTest() throws Exception {
    clientMode = true;
    final Ignite client = startGrid(serverCount());
    doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check atomic long.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.atomicLong("testAtomic", 41, true);
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.atomicLong("testAtomic", 41, true);
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteAtomicLong atomicLong = (IgniteAtomicLong) o;
            assertEquals(42, atomicLong.incrementAndGet());
            return true;
        }
    }), // Check set.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.set("testSet", new CollectionConfiguration());
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.set("testSet", new CollectionConfiguration());
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteSet set = (IgniteSet) o;
            String val = "testVal";
            set.add(val);
            assertEquals(1, set.size());
            assertTrue(set.contains(val));
            return true;
        }
    }), // Check ignite queue.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.queue("TestQueue", 10, new CollectionConfiguration());
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.queue("TestQueue", 10, new CollectionConfiguration());
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteQueue queue = (IgniteQueue) o;
            String val = "Test";
            queue.add(val);
            assertEquals(val, queue.poll());
            return true;
        }
    })));
    clientMode = false;
}
Also used : IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteSet(org.apache.ignite.IgniteSet) IgniteQueue(org.apache.ignite.IgniteQueue) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2)

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