Search in sources :

Example 6 with CollectionConfiguration

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

the class GridCacheQueueMultiNodeAbstractSelfTest method testAddPollMultinode.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
private void testAddPollMultinode(final boolean collocated) throws Exception {
    final String queueName = UUID.randomUUID().toString();
    info("Queue name: " + queueName + ", collocated: " + collocated);
    try {
        Collection<IgniteInternalFuture> putFuts = new ArrayList<>();
        Collection<IgniteInternalFuture> pollFuts = new ArrayList<>();
        final int PUT_THREADS_PER_NODE = 3;
        final int POLL_THREADS_PER_NODE = 2;
        final int ITEMS_PER_THREAD = 1000;
        final AtomicBoolean stopPoll = new AtomicBoolean();
        Collection<int[]> pollData = new ArrayList<>();
        for (int i = 0; i < GRID_CNT; i++) {
            final int idx = i;
            putFuts.add(GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    CollectionConfiguration colCfg = config(collocated);
                    IgniteQueue<Integer> queue = grid(idx).queue(queueName, 0, colCfg);
                    for (int i = 0; i < ITEMS_PER_THREAD; i++) assertTrue(queue.add(i));
                    return null;
                }
            }, PUT_THREADS_PER_NODE, "testAddPollMultinode"));
            for (int j = 0; j < POLL_THREADS_PER_NODE; j++) {
                final int[] items = new int[ITEMS_PER_THREAD];
                pollData.add(items);
                pollFuts.add(GridTestUtils.runAsync(new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        CollectionConfiguration colCfg = config(collocated);
                        IgniteQueue<Integer> queue = grid(idx).queue(queueName, 0, colCfg);
                        while (!stopPoll.get()) {
                            Integer val = queue.poll();
                            if (val != null)
                                items[val]++;
                        }
                        return null;
                    }
                }));
            }
        }
        for (IgniteInternalFuture fut : putFuts) fut.get();
        stopPoll.set(true);
        for (IgniteInternalFuture fut : pollFuts) fut.get();
        CollectionConfiguration colCfg = config(collocated);
        IgniteQueue<Integer> queue = grid(0).queue(queueName, 0, colCfg);
        int[] resItems = new int[ITEMS_PER_THREAD];
        Integer item;
        while ((item = queue.poll()) != null) resItems[item]++;
        for (int[] items : pollData) {
            for (int i = 0; i < ITEMS_PER_THREAD; i++) resItems[i] += items[i];
        }
        for (int i = 0; i < ITEMS_PER_THREAD; i++) assertEquals(PUT_THREADS_PER_NODE * GRID_CNT, resItems[i]);
        assertTrue(queue.isEmpty());
    } finally {
        grid(0).queue(queueName, 0, null).close();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 7 with CollectionConfiguration

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

the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method testPollFailover.

/**
     * @param collocated Collocation flag.
     * @throws Exception If failed.
     */
private void testPollFailover(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("Primary node: " + primaryNode);
    queue = grid(testNodeIdx).queue(QUEUE_NAME, 0, null);
    assertNotNull(queue);
    // Kill queue header's primary node .
    testPollFailover(queue, Arrays.asList(primaryQueueNode(queue)));
    List<Integer> killIdxs = new ArrayList<>();
    for (int i = 0; i < gridCount(); i++) {
        if (i != testNodeIdx)
            killIdxs.add(i);
    }
    // Kill random node.
    testPollFailover(queue, killIdxs);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

Example 8 with CollectionConfiguration

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

the class GridCacheQueueApiSelfAbstractTest method testSystemCache.

/**
     * @throws Exception If failed.
     */
public void testSystemCache() throws Exception {
    CollectionConfiguration colCfg = collectionConfiguration();
    IgniteQueue queue = grid(0).queue("Queue1", 0, colCfg);
    final CacheConfiguration ccfg = getQueueCache(queue);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            grid(0).cache(ccfg.getName());
            return null;
        }
    }, IllegalStateException.class, "Failed to get cache because it is a system cache");
    assertNotNull(((IgniteKernal) grid(0)).internalCache(ccfg.getName()));
}
Also used : IgniteQueue(org.apache.ignite.IgniteQueue) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteException(org.apache.ignite.IgniteException)

Example 9 with CollectionConfiguration

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

the class GridCacheQueueApiSelfAbstractTest method testAffinityCall.

/**
     * @throws Exception If failed.
     */
public void testAffinityCall() 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.affinityCall(new IgniteCallable<Object>() {

                    @Override
                    public Object call() {
                        return null;
                    }
                });
                return null;
            }
        }, IgniteException.class, "Failed to execute affinityCall() 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);
        Integer res = queue2.affinityCall(new IgniteCallable<Integer>() {

            @IgniteInstanceResource
            private IgniteEx ignite;

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

Example 10 with CollectionConfiguration

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

the class GridCacheQueueApiSelfAbstractTest method testFilterNode.

/**
     * @throws Exception If failed.
     */
public void testFilterNode() throws Exception {
    CollectionConfiguration colCfg1 = collectionConfiguration();
    CollectionConfiguration colCfg2 = collectionConfiguration();
    colCfg2.setNodeFilter(CacheConfiguration.ALL_NODES);
    IgniteQueue queue1 = grid(0).queue("Queue1", 0, colCfg1);
    IgniteQueue queue2 = grid(0).queue("Queue2", 0, colCfg2);
    assertNotSame(getQueueCache(queue1), getQueueCache(queue2));
    colCfg1.setNodeFilter(CacheConfiguration.ALL_NODES);
    IgniteQueue queue3 = grid(0).queue("Queue3", 0, colCfg1);
    assertEquals(getQueueCache(queue2), getQueueCache(queue3));
}
Also used : IgniteQueue(org.apache.ignite.IgniteQueue) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration)

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