use of javax.cache.CacheException in project ignite by apache.
the class IgniteTxConfigCacheSelfTest method checkExplicitTxTimeout.
/**
* Success if explicit tx fails.
*
* @param cache Cache name.
* @param ignite Ignite instance.
* @throws Exception If failed.
*/
protected void checkExplicitTxTimeout(final IgniteCache<Object, Object> cache, final Ignite ignite) throws Exception {
try (final Transaction tx = ignite.transactions().txStart()) {
assert tx != null;
sleepForTxFailure();
cache.put("key", "val");
fail("Timeout exception must be thrown");
} catch (CacheException e) {
assert e.getCause() instanceof TransactionTimeoutException;
}
assert !cache.containsKey("key");
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteCachePutRetryAtomicSelfTest method testPutInsideTransaction.
/**
* @throws Exception If failed.
*/
public void testPutInsideTransaction() throws Exception {
ignite(0).createCache(cacheConfiguration(false, false));
CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setName("tx-cache");
ccfg.setAtomicityMode(TRANSACTIONAL);
try (IgniteCache<Integer, Integer> txCache = ignite(0).getOrCreateCache(ccfg)) {
final AtomicBoolean finished = new AtomicBoolean();
IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
stopGrid(3);
U.sleep(300);
startGrid(3);
}
return null;
}
});
try {
IgniteTransactions txs = ignite(0).transactions();
IgniteCache<Object, Object> cache = ignite(0).cache(DEFAULT_CACHE_NAME);
long stopTime = System.currentTimeMillis() + 60_000;
while (System.currentTimeMillis() < stopTime) {
for (int i = 0; i < 10_000; i++) {
try {
try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
txCache.put(0, 0);
cache.put(i, i);
tx.commit();
}
} catch (IgniteException | CacheException e) {
log.info("Ignore exception: " + e);
}
}
}
finished.set(true);
fut.get();
} finally {
finished.set(true);
}
}
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteFutureImplTest method testChainError.
/**
* @throws Exception If failed.
*/
public void testChainError() throws Exception {
{
GridFutureAdapter<String> fut0 = new GridFutureAdapter<>();
IgniteFutureImpl<String> fut = createFuture(fut0);
final IgniteException err0 = new IgniteException("test error");
final AtomicBoolean chainedPassed = new AtomicBoolean();
IgniteFuture<Integer> chained = fut.chain(new C1<IgniteFuture<String>, Integer>() {
@Override
public Integer apply(IgniteFuture<String> fut) {
try {
fut.get();
fail();
return -1;
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
chainedPassed.set(true);
throw err;
}
}
});
final AtomicBoolean lsnrPassed = new AtomicBoolean();
IgniteInClosure<? super IgniteFuture<Integer>> lsnr1 = new CI1<IgniteFuture<Integer>>() {
@Override
public void apply(IgniteFuture<Integer> fut) {
try {
fut.get();
fail();
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
lsnrPassed.set(true);
}
}
};
chained.listen(lsnr1);
fut0.onDone(err0);
assertTrue(chainedPassed.get());
assertTrue(lsnrPassed.get());
try {
chained.get();
fail();
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
}
try {
fut.get();
fail();
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
}
}
{
GridFutureAdapter<String> fut0 = new GridFutureAdapter<>();
IgniteFutureImpl<String> fut = createFuture(fut0);
final IgniteCheckedException err0 = new IgniteCheckedException("test error");
final AtomicBoolean chainedPassed = new AtomicBoolean();
IgniteFuture<Integer> chained = fut.chain(new C1<IgniteFuture<String>, Integer>() {
@Override
public Integer apply(IgniteFuture<String> fut) {
try {
fut.get();
fail();
return -1;
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
chainedPassed.set(true);
throw err;
}
}
});
final AtomicBoolean lsnrPassed = new AtomicBoolean();
IgniteInClosure<? super IgniteFuture<Integer>> lsnr1 = new CI1<IgniteFuture<Integer>>() {
@Override
public void apply(IgniteFuture<Integer> fut) {
try {
fut.get();
fail();
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
lsnrPassed.set(true);
}
}
};
chained.listen(lsnr1);
fut0.onDone(err0);
assertTrue(chainedPassed.get());
assertTrue(lsnrPassed.get());
try {
chained.get();
fail();
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
}
try {
fut.get();
fail();
} catch (IgniteException | CacheException err) {
assertExpectedException(err, err0);
}
}
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteClientReconnectCacheQueriesFailoverTest method testReconnectCacheQueries.
/**
* @throws Exception If failed.
*/
public void testReconnectCacheQueries() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCache<Integer, Person> cache = client.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
SqlQuery<Integer, Person> sqlQry = new SqlQuery<>(Person.class, "where id > 1");
try {
assertEquals(9999, cache.query(sqlQry).getAll().size());
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
throw e;
else
log.info("Ignore error: " + e);
}
try {
SqlFieldsQuery fieldsQry = new SqlFieldsQuery("select avg(p.id) from Person p");
List<List<?>> res = cache.query(fieldsQry).getAll();
assertEquals(1, res.size());
Integer avg = (Integer) res.get(0).get(0);
assertEquals(5_000, avg.intValue());
} catch (CacheException e) {
if (e.getCause() instanceof IgniteClientDisconnectedException)
throw e;
else
log.info("Ignore error: " + e);
}
return null;
}
});
}
use of javax.cache.CacheException in project ignite by apache.
the class IgniteClientReconnectQueriesTest method testReconnectQueryInProgress.
/**
* @throws Exception If failed.
*/
public void testReconnectQueryInProgress() throws Exception {
Ignite cln = grid(serverCount());
assertTrue(cln.cluster().localNode().isClient());
final Ignite srv = clientRouter(cln);
final IgniteCache<Integer, Person> clnCache = cln.getOrCreateCache(QUERY_CACHE);
clnCache.put(1, new Person(1, "name1", "surname1"));
clnCache.put(2, new Person(2, "name2", "surname2"));
clnCache.put(3, new Person(3, "name3", "surname3"));
blockMessage(GridQueryNextPageResponse.class);
final SqlQuery<Integer, Person> qry = new SqlQuery<>(Person.class, "_key <> 0");
qry.setPageSize(1);
final QueryCursor<Cache.Entry<Integer, Person>> cur1 = clnCache.query(qry);
final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
cur1.getAll();
} catch (CacheException e) {
checkAndWait(e);
return true;
}
return false;
}
});
// Check that client waiting operation.
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return fut.get(200);
}
}, IgniteFutureTimeoutCheckedException.class, null);
assertNotDone(fut);
unblockMessage();
reconnectClientNode(cln, srv, null);
assertTrue((Boolean) fut.get(2, SECONDS));
QueryCursor<Cache.Entry<Integer, Person>> cur2 = clnCache.query(qry);
assertEquals(3, cur2.getAll().size());
}
Aggregations