use of javax.cache.CacheException 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 ConcurrentHashMap8<>();
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 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.currentThread().setName("restart-thread");
while (!stop.get()) {
U.sleep(random(KILL_DELAY.get1(), KILL_DELAY.get2()));
killAndRestart(stop);
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;
}
});
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 javax.cache.CacheException in project ignite by apache.
the class DataStreamerTimeoutTest method timeoutOnAddData.
/**
*
*/
private int timeoutOnAddData() throws Exception {
boolean thrown = false;
int processed = 0;
try {
Ignite ignite = startGrid(1);
try (IgniteDataStreamer ldr = ignite.dataStreamer(CACHE_NAME)) {
ldr.timeout(TIMEOUT);
ldr.receiver(new TestDataReceiver());
ldr.perNodeBufferSize(1);
ldr.perNodeParallelOperations(1);
((DataStreamerImpl) ldr).maxRemapCount(0);
try {
for (int i = 0; i < ENTRY_AMOUNT; i++) {
ldr.addData(i, i);
processed++;
}
} catch (IllegalStateException ignored) {
// No-op.
}
} catch (CacheException | IgniteDataStreamerTimeoutException ignored) {
thrown = true;
}
} finally {
stopAllGrids();
}
assertTrue(thrown);
return processed;
}
use of javax.cache.CacheException in project ignite by apache.
the class DataStreamerImplSelfTest method testNoDataNodesOnClose.
/**
* Test logging on {@code DataStreamer.addData()} method when cache have no data nodes
*
* @throws Exception If fail.
*/
public void testNoDataNodesOnClose() throws Exception {
boolean failed = false;
cnt = 0;
noNodesFilter = true;
try {
Ignite ignite = startGrid(1);
try (IgniteDataStreamer<Integer, String> streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
streamer.addData(1, "1");
} catch (CacheException ignored) {
failed = true;
}
} finally {
noNodesFilter = false;
assertTrue(failed);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class GridStartStopSelfTest method testStopWhileInUse.
/**
* @throws Exception If failed.
*/
public void testStopWhileInUse() throws Exception {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setConnectorConfiguration(null);
cfg.setIgniteInstanceName(getTestIgniteInstanceName(0));
CacheConfiguration cc = new CacheConfiguration(DEFAULT_CACHE_NAME);
cc.setAtomicityMode(TRANSACTIONAL);
cfg.setCacheConfiguration(cc);
final Ignite g0 = G.start(cfg);
cfg = new IgniteConfiguration();
cfg.setIgniteInstanceName(getTestIgniteInstanceName(1));
cc = new CacheConfiguration(DEFAULT_CACHE_NAME);
cc.setAtomicityMode(TRANSACTIONAL);
cfg.setCacheConfiguration(cc);
final CountDownLatch latch = new CountDownLatch(1);
Ignite g1 = G.start(cfg);
Thread stopper = new Thread(new Runnable() {
@Override
public void run() {
try {
try (Transaction ignored = g0.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
g0.cache(DEFAULT_CACHE_NAME).get(1);
latch.countDown();
Thread.sleep(500);
info("Before stop.");
G.stop(getTestIgniteInstanceName(1), true);
}
} catch (Exception e) {
error("Error.", e);
}
}
});
stopper.start();
assert latch.await(1, SECONDS);
info("Before remove.");
try {
g1.cache(DEFAULT_CACHE_NAME).remove(1);
} catch (CacheException ignore) {
// No-op.
}
}
use of javax.cache.CacheException in project ignite by apache.
the class GridCacheStopSelfTest method testStop.
/**
* @param startTx If {@code true} starts transactions.
* @throws Exception If failed.
*/
private void testStop(final boolean startTx) throws Exception {
for (int i = 0; i < 10; i++) {
startGrid(0);
final int PUT_THREADS = 50;
final CountDownLatch stopLatch = new CountDownLatch(1);
final CountDownLatch readyLatch = new CountDownLatch(PUT_THREADS);
final IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
assertEquals(atomic ? ATOMIC : TRANSACTIONAL, ccfg.getAtomicityMode());
assertEquals(replicated ? REPLICATED : PARTITIONED, ccfg.getCacheMode());
Collection<IgniteInternalFuture<?>> putFuts = new ArrayList<>();
for (int j = 0; j < PUT_THREADS; j++) {
final int key = j;
putFuts.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
if (startTx) {
TransactionConcurrency concurrency = key % 2 == 0 ? OPTIMISTIC : PESSIMISTIC;
try (Transaction tx = grid(0).transactions().txStart(concurrency, REPEATABLE_READ)) {
cache.put(key, key);
readyLatch.countDown();
stopLatch.await();
tx.commit();
}
} else {
readyLatch.countDown();
stopLatch.await();
cache.put(key, key);
}
} catch (CacheException | IgniteException | IllegalStateException e) {
log.info("Ignore error: " + e);
}
return null;
}
}, "cache-thread"));
}
readyLatch.await();
stopLatch.countDown();
stopGrid(0);
for (IgniteInternalFuture<?> fut : putFuts) fut.get();
try {
cache.put(1, 1);
} catch (IllegalStateException e) {
if (!e.getMessage().startsWith(EXPECTED_MSG))
e.printStackTrace();
assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().startsWith(EXPECTED_MSG));
}
}
}
Aggregations