use of javax.cache.CacheException in project ignite by apache.
the class GridH2IndexBase method toSearchRowMessage.
/**
* @param row Search row.
* @return Row message.
*/
private GridH2RowMessage toSearchRowMessage(SearchRow row) {
if (row == null)
return null;
List<GridH2ValueMessage> vals = new ArrayList<>(indexColumns.length);
for (IndexColumn idxCol : indexColumns) {
Value val = row.getValue(idxCol.column.getColumnId());
if (val == null)
break;
try {
vals.add(GridH2ValueMessageFactory.toMessage(val));
} catch (IgniteCheckedException e) {
throw new CacheException(e);
}
}
GridH2RowMessage res = new GridH2RowMessage();
res.values(vals);
return res;
}
use of javax.cache.CacheException in project ignite by apache.
the class GridH2IndexBase method toSearchRow.
/**
* @param msg Row message.
* @return Search row.
*/
private SearchRow toSearchRow(GridH2RowMessage msg) {
if (msg == null)
return null;
GridKernalContext ctx = kernalContext();
Value[] vals = new Value[getTable().getColumns().length];
assert vals.length > 0;
List<GridH2ValueMessage> msgVals = msg.values();
for (int i = 0; i < indexColumns.length; i++) {
if (i >= msgVals.size())
continue;
try {
vals[indexColumns[i].column.getColumnId()] = msgVals.get(i).value(ctx);
} catch (IgniteCheckedException e) {
throw new CacheException(e);
}
}
return database.createRow(vals, MEMORY_CALCULATE);
}
use of javax.cache.CacheException in project ignite by apache.
the class CacheGetInsideLockChangingTopologyTest method testMultithreaded.
/**
* @throws Exception If failed.
*/
public void testMultithreaded() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-2204");
final AtomicBoolean finished = new AtomicBoolean();
final int NEW_NODE = SRVS + CLIENTS;
final AtomicInteger stopIdx = new AtomicInteger();
IgniteInternalFuture<?> restartFut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int idx = stopIdx.getAndIncrement();
int node = NEW_NODE + idx;
while (!finished.get()) {
log.info("Start node: " + node);
startGrid(node);
U.sleep(300);
log.info("Stop node: " + node);
stopGrid(node);
}
return null;
}
}, 2, "stop-thread");
try {
final long stopTime = System.currentTimeMillis() + 60_000;
final AtomicInteger idx = new AtomicInteger();
final int KEYS = 100_000;
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
int node = idx.getAndIncrement() % (SRVS + CLIENTS);
Ignite ignite = ignite(node);
IgniteCache<Integer, Integer> txCache1 = ignite.cache(TX_CACHE1);
IgniteCache<Integer, Integer> txCache2 = ignite.cache(TX_CACHE2);
IgniteCache<Integer, Integer> atomicCache = ignite.cache(ATOMIC_CACHE);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (U.currentTimeMillis() < stopTime) {
Integer lockKey = rnd.nextInt(KEYS, KEYS + 1000);
Lock lock = txCache1.lock(lockKey);
try {
lock.lock();
try {
executeGet(txCache1);
executeGet(txCache2);
executeGet(atomicCache);
} finally {
lock.unlock();
}
try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
txCache1.put(lockKey, lockKey);
executeGet(txCache1);
executeGet(txCache2);
executeGet(atomicCache);
tx.commit();
}
} catch (IgniteException | CacheException e) {
log.info("Error: " + e);
}
}
return null;
}
private void executeGet(IgniteCache<Integer, Integer> cache) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < 100; i++) cache.get(rnd.nextInt(KEYS));
Set<Integer> keys = new HashSet<>();
for (int i = 0; i < 100; i++) {
keys.add(rnd.nextInt(KEYS));
if (keys.size() == 20) {
cache.getAll(keys);
keys.clear();
}
}
cache.getAll(keys);
}
}, 10, "test-thread");
finished.set(true);
restartFut.get();
} finally {
finished.set(true);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class CacheAsyncOperationsTest method async2.
/**
*
* @param cache Cache.
*/
private void async2(IgniteCache<Integer, Integer> cache) {
cache.put(1, 1);
latch = new CountDownLatch(1);
IgniteFuture<?> fut1 = cache.putAsync(0, 0);
IgniteFuture<?> fut2 = cache.putAsync(0, 0);
IgniteFuture<?> fut3 = cache.getAndPutAsync(1, 2);
IgniteFuture<?> fut4 = cache.putAsync(0, 0);
assertFalse(fut1.isDone());
assertFalse(fut2.isDone());
assertFalse(fut3.isDone());
assertFalse(fut4.isDone());
latch.countDown();
try {
fut1.get();
fail();
} catch (CacheException e) {
log.info("Expected error: " + e);
}
try {
fut2.get();
fail();
} catch (CacheException e) {
log.info("Expected error: " + e);
}
assertEquals(1, fut3.get());
try {
fut4.get();
fail();
} catch (CacheException e) {
log.info("Expected error: " + e);
}
assertNull(cache.get(0));
assertEquals((Integer) 2, cache.get(1));
}
use of javax.cache.CacheException in project ignite by apache.
the class GridCachePartitionedTopologyChangeSelfTest method testExplicitLocks.
/**
* @throws Exception If failed.
*/
public void testExplicitLocks() throws Exception {
try {
startGridsMultiThreaded(2);
IgniteKernal[] nodes = new IgniteKernal[] { (IgniteKernal) grid(0), (IgniteKernal) grid(1) };
Collection<IgniteInternalFuture> futs = new ArrayList<>();
final CountDownLatch startLatch = new CountDownLatch(1);
for (final IgniteKernal node : nodes) {
List<Integer> parts = partitions(node, PARTITION_PRIMARY);
Map<Integer, Integer> keyMap = keysFor(node, parts);
for (final Integer key : keyMap.values()) {
futs.add(multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
Lock lock = node.cache(DEFAULT_CACHE_NAME).lock(key);
lock.lock();
try {
info(">>> Acquired explicit lock for key: " + key);
startLatch.await();
info(">>> Acquiring explicit lock for key: " + key * 10);
Lock lock10 = node.cache(DEFAULT_CACHE_NAME).lock(key * 10);
lock10.lock();
try {
info(">>> Releasing locks [key1=" + key + ", key2=" + key * 10 + ']');
} finally {
lock10.unlock();
}
} finally {
lock.unlock();
}
} catch (CacheException e) {
info(">>> Failed to perform lock [key=" + key + ", e=" + e + ']');
} catch (InterruptedException ignored) {
info(">>> Interrupted while waiting for start latch.");
Thread.currentThread().interrupt();
}
}
}, 1));
}
}
IgniteInternalFuture<?> startFut = multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
startGrid(2);
info(">>> Started grid2.");
} catch (Exception e) {
info(">>> Failed to start grid: " + e);
}
}
}, 1);
U.sleep(5000);
assertFalse(startFut.isDone());
info(">>> Waiting for all locks to be released.");
startLatch.countDown();
for (IgniteInternalFuture fut : futs) fut.get(1000);
startFut.get();
} finally {
stopAllGrids();
}
}
Aggregations