use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCacheQueueMultiNodeAbstractSelfTest method testPutPollCollocated.
/**
* @throws Exception If failed.
*/
public void testPutPollCollocated() throws Exception {
try {
final String queueName = UUID.randomUUID().toString();
info("Queue name: " + queueName);
grid(0).queue(queueName, 5, config(true));
final CountDownLatch latch = new CountDownLatch(1);
final Ignite g = startGrid(GRID_CNT + 1);
IgniteInternalFuture<Object> fut1 = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
info(">>> Executing put callable [node=" + g.cluster().localNode().id() + ", thread=" + Thread.currentThread().getName() + ']');
IgniteQueue<Integer> q = g.queue(queueName, 5, config(true));
assertTrue(q.isEmpty());
for (int i = 0; i < ITEMS_CNT; i++) {
if (i == q.capacity()) {
info(">>> Opening latch...");
latch.countDown();
}
put(q, i);
}
info(">>> Finished put callable on node: " + g.cluster().localNode().id());
return null;
}
});
latch.await();
final Ignite g1 = startGrid(GRID_CNT + 2);
IgniteInternalFuture<Object> fut2 = GridTestUtils.runAsync(new Callable<Object>() {
@SuppressWarnings("BusyWait")
@Override
public Object call() throws Exception {
try {
info(">>> Executing poll callable [node=" + g1.cluster().localNode().id() + ", thread=" + Thread.currentThread().getName() + ']');
IgniteQueue<Integer> q = g1.queue(queueName, 5, config(true));
int cnt = 0;
int nullCnt = 0;
do {
Integer i = q.poll();
info("Polled value: " + i);
if (i != null) {
cnt++;
nullCnt = 0;
} else {
if (nullCnt == 3)
throw new Exception("Failed to poll non-null value within 3 attempts.");
nullCnt++;
Thread.sleep(1000);
}
} while (cnt < ITEMS_CNT);
info("Finished poll callable on node: " + g1.cluster().localNode().id());
return null;
} finally {
info("Poll callable finished.");
}
}
});
fut1.get();
fut2.get();
grid(0).queue(queueName, 0, null).close();
} finally {
stopGrid(GRID_CNT + 1);
stopGrid(GRID_CNT + 2);
checkTopology(GRID_CNT);
awaitPartitionMapExchange();
}
}
use of org.apache.ignite.IgniteQueue 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.IgniteQueue 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));
}
use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCacheQueueApiSelfAbstractTest method testPrepareQueue.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testPrepareQueue() throws Exception {
// Random sequence names.
String queueName1 = UUID.randomUUID().toString();
String queueName2 = UUID.randomUUID().toString();
CollectionConfiguration colCfg = config(false);
IgniteQueue queue1 = grid(0).queue(queueName1, 0, colCfg);
IgniteQueue queue2 = grid(0).queue(queueName2, 0, colCfg);
IgniteQueue queue3 = grid(0).queue(queueName1, 0, colCfg);
assertNotNull(queue1);
assertNotNull(queue2);
assertNotNull(queue3);
assert queue1.equals(queue3);
assert queue3.equals(queue1);
assert !queue3.equals(queue2);
queue1.close();
queue2.close();
queue3.close();
assertNull(grid(0).queue(queueName1, 0, null));
assertNull(grid(0).queue(queueName2, 0, null));
}
use of org.apache.ignite.IgniteQueue in project ignite by apache.
the class GridCacheQueueApiSelfAbstractTest method testQueueRemoveMultithreadBounded.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testQueueRemoveMultithreadBounded() throws Exception {
// Random queue name.
final String queueName = UUID.randomUUID().toString();
final IgniteQueue<String> queue = grid(0).queue(queueName, QUEUE_CAPACITY, config(false));
final CountDownLatch putLatch = new CountDownLatch(THREAD_NUM);
final CountDownLatch clearLatch = new CountDownLatch(THREAD_NUM);
IgniteInternalFuture<?> offerFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
if (log.isDebugEnabled())
log.debug("Thread has been started." + Thread.currentThread().getName());
try {
// Thread must be blocked on put operation.
for (int i = 0; i < (QUEUE_CAPACITY * THREAD_NUM); i++) queue.offer("anything", 3, TimeUnit.MINUTES);
fail("Queue failed");
} catch (IgniteException | IllegalStateException e) {
putLatch.countDown();
assert e.getMessage().contains("removed");
assert queue.removed();
}
if (log.isDebugEnabled())
log.debug("Thread has been stopped." + Thread.currentThread().getName());
return null;
}
}, THREAD_NUM, "offer-thread");
IgniteInternalFuture<?> closeFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
IgniteQueue<String> queue = grid(0).queue(queueName, 0, null);
if (queue != null)
queue.close();
} catch (Exception e) {
fail("Unexpected exception: " + e);
} finally {
clearLatch.countDown();
}
return null;
}
}, THREAD_NUM, "close-thread");
assert putLatch.await(3, TimeUnit.MINUTES);
assert clearLatch.await(3, TimeUnit.MINUTES);
offerFut.get();
closeFut.get();
try {
assert queue.isEmpty() : queue.size();
fail("Queue must be removed.");
} catch (IgniteException | IllegalStateException e) {
assert e.getMessage().contains("removed");
assert queue.removed();
}
}
Aggregations