use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class CacheFutureExceptionSelfTest method testGet.
/**
* @param nearCache If {@code true} creates near cache on client.
* @param cpyOnRead Cache copy on read flag.
* @throws Exception If failed.
*/
private void testGet(boolean nearCache, boolean cpyOnRead) throws Exception {
fail = false;
Ignite srv = grid(0);
Ignite client = grid(1);
final String cacheName = nearCache ? ("NEAR-CACHE-" + cpyOnRead) : ("CACHE-" + cpyOnRead);
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setCopyOnRead(cpyOnRead);
ccfg.setName(cacheName);
IgniteCache<Object, Object> cache = srv.createCache(ccfg);
cache.put("key", new NotSerializableClass());
IgniteCache<Object, Object> clientCache = nearCache ? client.createNearCache(cacheName, new NearCacheConfiguration<>()) : client.cache(cacheName);
fail = true;
final CountDownLatch futLatch = new CountDownLatch(1);
clientCache.getAsync("key").listen(new IgniteInClosure<IgniteFuture<Object>>() {
@Override
public void apply(IgniteFuture<Object> fut) {
assertTrue(fut.isDone());
try {
fut.get();
fail();
} catch (CacheException e) {
log.info("Expected error: " + e);
futLatch.countDown();
}
}
});
assertTrue(futLatch.await(5, SECONDS));
srv.destroyCache(cache.getName());
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class CacheGetEntryAbstractTest method testNear.
/**
* @throws Exception If failed.
*/
public void testNear() throws Exception {
CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
cfg.setWriteSynchronizationMode(FULL_SYNC);
cfg.setCacheMode(PARTITIONED);
cfg.setAtomicityMode(ATOMIC);
cfg.setName("near");
cfg.setNearConfiguration(new NearCacheConfiguration());
test(cfg);
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class CacheMetricsEntitiesCountTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
CacheConfiguration<?, ?> ccfg0 = new CacheConfiguration<>().setName(CACHE_PREFIX + 0).setCacheMode(CacheMode.LOCAL);
CacheConfiguration<?, ?> ccfg1 = new CacheConfiguration<>().setName(CACHE_PREFIX + 1).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setCacheMode(CacheMode.REPLICATED);
CacheConfiguration<?, ?> ccfg2 = new CacheConfiguration<>().setName(CACHE_PREFIX + 2).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setCacheMode(CacheMode.PARTITIONED).setBackups(1);
CacheConfiguration<?, ?> ccfg3 = new CacheConfiguration<>().setName(CACHE_PREFIX + 3).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setCacheMode(CacheMode.PARTITIONED).setBackups(1).setNearConfiguration(new NearCacheConfiguration<>());
cfg.setCacheConfiguration(ccfg0, ccfg1, ccfg2, ccfg3);
return cfg;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class CacheNearReaderUpdateTest method getUpdateMultithreaded.
/**
* @param ccfg Cache configuration.
* @param putNodes Nodes executing updates.
* @param getNodes Nodes executing gets.
* @param concurrency Transaction concurrency.
* @param isolation Transaction isolation.
* @throws Exception If failed.
*/
private void getUpdateMultithreaded(CacheConfiguration<Integer, Integer> ccfg, final List<Ignite> putNodes, final List<Ignite> getNodes, final TransactionConcurrency concurrency, final TransactionIsolation isolation) throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-627");
log.info("Execute updates [concurrency=" + concurrency + ", isolation=" + isolation + ']');
final Ignite ignite0 = ignite(0);
final String cacheName = ignite0.createCache(ccfg).getName();
try {
for (int i = 0; i < 5; i++) {
final Integer key = i;
final AtomicInteger putThreadIdx = new AtomicInteger();
final AtomicInteger getThreadIdx = new AtomicInteger();
final int PUT_THREADS = 20;
final int GET_THREAD = 20;
final CyclicBarrier barrier = new CyclicBarrier(PUT_THREADS + GET_THREAD);
final IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = putThreadIdx.getAndIncrement() % putNodes.size();
Ignite ignite = putNodes.get(idx);
IgniteCache<Integer, Integer> cache = ignite.cache(cacheName);
IgniteTransactions txs = ignite.transactions();
Thread.currentThread().setName("update-thread-" + ignite.name());
barrier.await();
for (int i = 0; i < 100; i++) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
if (concurrency != null) {
try (Transaction tx = txs.txStart(concurrency, isolation)) {
cache.put(key, rnd.nextInt());
tx.commit();
} catch (TransactionOptimisticException ignore) {
assertEquals(concurrency, OPTIMISTIC);
assertEquals(isolation, SERIALIZABLE);
}
} else
cache.put(key, rnd.nextInt());
}
return null;
}
}, PUT_THREADS, "update-thread");
IgniteInternalFuture<?> getFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = getThreadIdx.getAndIncrement() % getNodes.size();
Ignite ignite = getNodes.get(idx);
IgniteCache<Integer, Integer> cache;
if (ignite.configuration().isClientMode())
cache = ignite.createNearCache(cacheName, new NearCacheConfiguration<Integer, Integer>());
else
cache = ignite.cache(cacheName);
Thread.currentThread().setName("get-thread-" + ignite.name());
barrier.await();
while (!updateFut.isDone()) cache.get(key);
return null;
}
}, GET_THREAD, "get-thread");
updateFut.get();
getFut.get();
Integer val = (Integer) ignite0.cache(cacheName).get(key);
log.info("Iteration [iter=" + i + ", val=" + val + ']');
for (Ignite getNode : getNodes) {
IgniteCache<Integer, Integer> cache = getNode.cache(cacheName);
if (getNode.configuration().isClientMode() || cache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null)
assertNotNull(getNode.cache(cacheName).localPeek(key));
}
checkValue(key, val, cacheName);
for (int n = 0; n < SRVS + CLIENTS; n++) {
val = n;
ignite(n).cache(cacheName).put(key, val);
checkValue(key, val, cacheName);
}
}
} finally {
destroyCache(ignite0, cacheName);
}
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class IgniteDiagnosticMessagesTest method testRemoteTx.
/**
* @throws Exception If failed.
*/
public void testRemoteTx() throws Exception {
int timeout = 3500;
System.setProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, String.valueOf(timeout));
try {
testSpi = true;
startGrid(0);
GridStringLogger strLog = this.strLog = new GridStringLogger();
strLog.logLength(1024 * 100);
startGrid(1);
awaitPartitionMapExchange();
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setCacheMode(PARTITIONED);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setBackups(1);
ccfg.setNearConfiguration(new NearCacheConfiguration());
final Ignite node0 = ignite(0);
final Ignite node1 = ignite(1);
node0.createCache(ccfg);
UUID id0 = node0.cluster().localNode().id();
TestRecordingCommunicationSpi.spi(node0).blockMessages(GridDhtTxPrepareResponse.class, node1.name());
int txCnt = 4;
final List<Integer> keys = primaryKeys(node1.cache(DEFAULT_CACHE_NAME), txCnt, 0);
final AtomicInteger idx = new AtomicInteger();
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = node1.transactions().txStart()) {
Integer key = keys.get(idx.getAndIncrement());
cache.getAndPut(key, "new-" + key);
tx.commit();
}
return null;
}
}, txCnt, "tx");
U.sleep(timeout * 2);
assertFalse(fut.isDone());
TestRecordingCommunicationSpi.spi(node0).stopBlock();
fut.get();
String log = strLog.toString();
assertTrue(log.contains("Related transactions ["));
assertTrue(log.contains("General node info [id=" + id0));
} finally {
System.clearProperty(IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT);
}
}
Aggregations