use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridCacheAbstractRemoveFailureTest method putAndRemove.
/**
* @param duration Test duration.
* @param txConcurrency Transaction concurrency if test explicit transaction.
* @param txIsolation Transaction isolation if test explicit transaction.
* @throws Exception If failed.
*/
private void putAndRemove(long duration, final TransactionConcurrency txConcurrency, final TransactionIsolation txIsolation) throws Exception {
assertEquals(testClientNode(), (boolean) grid(0).configuration().isClientMode());
grid(0).destroyCache(DEFAULT_CACHE_NAME);
CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setCacheMode(cacheMode());
if (cacheMode() == PARTITIONED)
ccfg.setBackups(1);
ccfg.setAtomicityMode(atomicityMode());
ccfg.setNearConfiguration(nearCache());
final IgniteCache<Integer, Integer> sndCache0 = grid(0).createCache(ccfg);
final AtomicBoolean stop = new AtomicBoolean();
final AtomicLong cntr = new AtomicLong();
final AtomicLong errCntr = new AtomicLong();
// Expected values in cache.
final Map<Integer, GridTuple<Integer>> expVals = new ConcurrentHashMap<>();
final AtomicReference<CyclicBarrier> cmp = new AtomicReference<>();
IgniteInternalFuture<?> updateFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("update-thread");
ThreadLocalRandom rnd = ThreadLocalRandom.current();
IgniteTransactions txs = sndCache0.unwrap(Ignite.class).transactions();
while (!stop.get()) {
for (int i = 0; i < 100; i++) {
int key = rnd.nextInt(KEYS_CNT);
boolean put = rnd.nextInt(0, 100) > 10;
while (true) {
try {
if (put) {
boolean failed = false;
if (txConcurrency != null) {
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
sndCache0.put(key, i);
tx.commit();
} catch (CacheException | IgniteException e) {
if (!X.hasCause(e, ClusterTopologyCheckedException.class)) {
log.error("Unexpected error: " + e);
throw e;
}
failed = true;
}
} else
sndCache0.put(key, i);
if (!failed)
expVals.put(key, F.t(i));
} else {
boolean failed = false;
if (txConcurrency != null) {
try (Transaction tx = txs.txStart(txConcurrency, txIsolation)) {
sndCache0.remove(key);
tx.commit();
} catch (CacheException | IgniteException e) {
if (!X.hasCause(e, ClusterTopologyCheckedException.class)) {
log.error("Unexpected error: " + e);
throw e;
}
failed = true;
}
} else
sndCache0.remove(key);
if (!failed)
expVals.put(key, F.<Integer>t(null));
}
break;
} catch (CacheException e) {
if (put)
log.error("Put failed [key=" + key + ", val=" + i + ']', e);
else
log.error("Remove failed [key=" + key + ']', e);
errCntr.incrementAndGet();
}
}
}
cntr.addAndGet(100);
CyclicBarrier barrier = cmp.get();
if (barrier != null) {
log.info("Wait data check.");
barrier.await(60_000, TimeUnit.MILLISECONDS);
log.info("Finished wait data check.");
}
}
return null;
}
});
IgniteInternalFuture killFut = createAndRunConcurrentAction(stop, cmp);
try {
long stopTime = duration + U.currentTimeMillis();
long nextAssert = U.currentTimeMillis() + ASSERT_FREQ;
while (U.currentTimeMillis() < stopTime) {
long start = System.nanoTime();
long ops = cntr.longValue();
U.sleep(1000);
long diff = cntr.longValue() - ops;
double time = (System.nanoTime() - start) / 1_000_000_000d;
long opsPerSecond = (long) (diff / time);
log.info("Operations/second: " + opsPerSecond);
if (U.currentTimeMillis() >= nextAssert) {
CyclicBarrier barrier = new CyclicBarrier(3, new Runnable() {
@Override
public void run() {
try {
cmp.set(null);
log.info("Checking cache content.");
assertCacheContent(expVals);
log.info("Finished check cache content.");
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
});
log.info("Start cache content check.");
cmp.set(barrier);
try {
barrier.await(60_000, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
U.dumpThreads(log);
fail("Failed to check cache content: " + e);
}
log.info("Cache content check done.");
nextAssert = System.currentTimeMillis() + ASSERT_FREQ;
}
}
} finally {
stop.set(true);
}
killFut.get();
updateFut.get();
log.info("Test finished. Update errors: " + errCntr.get());
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridListenActorSelfTest method testRespondToRemote.
/**
* Testing {@link org.apache.ignite.messaging.MessagingListenActor#respond(UUID, Object)} method.
*
* @throws Exception If failed.
*/
public void testRespondToRemote() throws Exception {
startGrid(1);
try {
final ClusterNode rmt = grid(1).localNode();
grid().message().localListen(null, new MessagingListenActor<String>() {
@Override
protected void receive(UUID nodeId, String rcvMsg) throws IgniteException {
System.out.println("Local node received message: '" + rcvMsg + "'");
respond(rmt.id(), "RESPONSE");
}
});
final AtomicInteger cnt = new AtomicInteger();
// Response listener
grid(1).message().localListen(null, new MessagingListenActor<String>() {
@Override
public void receive(UUID nodeId, String rcvMsg) {
if ("RESPONSE".equals(rcvMsg)) {
System.out.println("Remote node received message: '" + rcvMsg + "'");
cnt.incrementAndGet();
}
}
});
grid().message().send(null, "REQUEST");
assert GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return cnt.intValue() == 1;
}
}, getTestTimeout());
} finally {
stopGrid(1);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridCacheQueueRotativeMultiNodeAbstractTest method testTakeRemoveRotativeNodes.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testTakeRemoveRotativeNodes() throws Exception {
lthTake = new CountDownLatch(1);
final String queueName = UUID.randomUUID().toString();
final IgniteQueue<Integer> queue = grid(0).queue(queueName, QUEUE_CAPACITY, config(true));
assertTrue(queue.isEmpty());
Thread th = new Thread(new Runnable() {
@Override
public void run() {
try {
assert grid(1).compute().call(new TakeJob(queueName, config(true)));
} catch (IgniteException e) {
error(e.getMessage(), e);
}
}
});
th.start();
assert lthTake.await(1, TimeUnit.MINUTES) : "Timeout happened.";
assertTrue(grid(2).compute().call(new RemoveQueueJob(queueName)));
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
queue.poll();
return null;
}
}, IllegalStateException.class, null);
info("Queue was removed: " + queue);
th.join();
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class CacheContinuousQueryAsyncFilterListenerTest method testNonDeadLockInFilter.
/**
* @param ccfg Cache configuration.
* @param asyncFilter Async filter.
* @param asyncLsnr Async listener.
* @param jcacheApi Use JCache api for start update listener.
* @throws Exception If failed.
*/
private void testNonDeadLockInFilter(CacheConfiguration ccfg, final boolean asyncFilter, final boolean asyncLsnr, boolean jcacheApi) throws Exception {
ignite(0).createCache(ccfg);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
try {
for (int i = 0; i < ITERATION_CNT; i++) {
log.info("Start iteration: " + i);
int nodeIdx = i % NODES;
final String cacheName = ccfg.getName();
final IgniteCache cache = grid(nodeIdx).cache(cacheName);
final QueryTestKey key = NODES - 1 != nodeIdx ? affinityKey(cache) : new QueryTestKey(1);
final QueryTestValue val0 = new QueryTestValue(1);
final QueryTestValue newVal = new QueryTestValue(2);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch evtFromLsnrLatch = new CountDownLatch(1);
IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> fltrClsr = new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
@Override
public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
if (asyncFilter) {
assertFalse("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("sys-"));
assertTrue("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("callback-"));
}
IgniteCache<Object, Object> cache0 = ignite.cache(cacheName);
QueryTestValue val = e.getValue();
if (val == null)
return;
else if (val.equals(newVal)) {
evtFromLsnrLatch.countDown();
return;
} else if (!val.equals(val0))
return;
Transaction tx = null;
try {
if (cache0.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL)
tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
assertEquals(val, val0);
cache0.put(key, newVal);
if (tx != null)
tx.commit();
latch.countDown();
} catch (Exception exp) {
log.error("Failed: ", exp);
throw new IgniteException(exp);
} finally {
if (tx != null)
tx.close();
}
}
};
IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> lsnrClsr = new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
@Override
public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
if (asyncLsnr) {
assertFalse("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("sys-"));
assertTrue("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("callback-"));
}
QueryTestValue val = e.getValue();
if (val == null || !val.equals(new QueryTestValue(1)))
return;
assertEquals(val, val0);
latch.countDown();
}
};
QueryCursor qry = null;
MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg = null;
CacheInvokeListener locLsnr = asyncLsnr ? new CacheInvokeListenerAsync(lsnrClsr) : new CacheInvokeListener(lsnrClsr);
CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> rmtFltr = asyncFilter ? new CacheTestRemoteFilterAsync(fltrClsr) : new CacheTestRemoteFilter(fltrClsr);
if (jcacheApi) {
lsnrCfg = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(locLsnr), FactoryBuilder.factoryOf(rmtFltr), true, false);
cache.registerCacheEntryListener(lsnrCfg);
} else {
ContinuousQuery<QueryTestKey, QueryTestValue> conQry = new ContinuousQuery<>();
conQry.setLocalListener(locLsnr);
conQry.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFltr));
qry = cache.query(conQry);
}
try {
if (rnd.nextBoolean())
cache.put(key, val0);
else
cache.invoke(key, new CacheEntryProcessor() {
@Override
public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException {
entry.setValue(val0);
return null;
}
});
assert U.await(latch, 3, SECONDS) : "Failed to waiting event.";
assertEquals(cache.get(key), new QueryTestValue(2));
assertTrue("Failed to waiting event from filter.", U.await(latch, 3, SECONDS));
} finally {
if (qry != null)
qry.close();
if (lsnrCfg != null)
cache.deregisterCacheEntryListener(lsnrCfg);
}
log.info("Iteration finished: " + i);
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class CacheContinuousQueryAsyncFilterListenerTest method testNonDeadLockInListener.
/**
* @param ccfg Cache configuration.
* @param asyncFltr Async filter.
* @param asyncLsnr Async listener.
* @param jcacheApi Use JCache api for registration entry update listener.
* @throws Exception If failed.
*/
private void testNonDeadLockInListener(CacheConfiguration ccfg, final boolean asyncFltr, boolean asyncLsnr, boolean jcacheApi) throws Exception {
ignite(0).createCache(ccfg);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
try {
for (int i = 0; i < ITERATION_CNT; i++) {
log.info("Start iteration: " + i);
int nodeIdx = i % NODES;
final String cacheName = ccfg.getName();
final IgniteCache cache = grid(nodeIdx).cache(cacheName);
final QueryTestKey key = NODES - 1 != nodeIdx ? affinityKey(cache) : new QueryTestKey(1);
final QueryTestValue val0 = new QueryTestValue(1);
final QueryTestValue newVal = new QueryTestValue(2);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch evtFromLsnrLatch = new CountDownLatch(1);
IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> fltrClsr = new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
@Override
public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
if (asyncFltr) {
assertFalse("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("sys-"));
assertTrue("Failed: " + Thread.currentThread().getName(), Thread.currentThread().getName().contains("callback-"));
}
}
};
IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>> lsnrClsr = new IgniteBiInClosure<Ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue>>() {
@Override
public void apply(Ignite ignite, CacheEntryEvent<? extends QueryTestKey, ? extends QueryTestValue> e) {
IgniteCache<Object, Object> cache0 = ignite.cache(cacheName);
QueryTestValue val = e.getValue();
if (val == null)
return;
else if (val.equals(newVal)) {
evtFromLsnrLatch.countDown();
return;
} else if (!val.equals(val0))
return;
Transaction tx = null;
try {
if (cache0.getConfiguration(CacheConfiguration.class).getAtomicityMode() == TRANSACTIONAL)
tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
assertEquals(val, val0);
cache0.put(key, newVal);
if (tx != null)
tx.commit();
latch.countDown();
} catch (Exception exp) {
log.error("Failed: ", exp);
throw new IgniteException(exp);
} finally {
if (tx != null)
tx.close();
}
}
};
QueryCursor qry = null;
MutableCacheEntryListenerConfiguration<QueryTestKey, QueryTestValue> lsnrCfg = null;
CacheInvokeListener locLsnr = asyncLsnr ? new CacheInvokeListenerAsync(lsnrClsr) : new CacheInvokeListener(lsnrClsr);
CacheEntryEventSerializableFilter<QueryTestKey, QueryTestValue> rmtFltr = asyncFltr ? new CacheTestRemoteFilterAsync(fltrClsr) : new CacheTestRemoteFilter(fltrClsr);
if (jcacheApi) {
lsnrCfg = new MutableCacheEntryListenerConfiguration<>(FactoryBuilder.factoryOf(locLsnr), FactoryBuilder.factoryOf(rmtFltr), true, false);
cache.registerCacheEntryListener(lsnrCfg);
} else {
ContinuousQuery<QueryTestKey, QueryTestValue> conQry = new ContinuousQuery<>();
conQry.setLocalListener(locLsnr);
conQry.setRemoteFilterFactory(FactoryBuilder.factoryOf(rmtFltr));
qry = cache.query(conQry);
}
try {
if (rnd.nextBoolean())
cache.put(key, val0);
else {
cache.invoke(key, new CacheEntryProcessor() {
@Override
public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException {
entry.setValue(val0);
return null;
}
});
}
assertTrue("Failed to waiting event.", U.await(latch, 3, SECONDS));
assertEquals(cache.get(key), new QueryTestValue(2));
assertTrue("Failed to waiting event from listener.", U.await(latch, 3, SECONDS));
} finally {
if (qry != null)
qry.close();
if (lsnrCfg != null)
cache.deregisterCacheEntryListener(lsnrCfg);
}
log.info("Iteration finished: " + i);
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
Aggregations