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();
}
}
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);
}
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()));
}
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());
}
}
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));
}
Aggregations