use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method lock.
/**
* @param nearCfg Near cache configuration.
* @throws Exception If failed.
*/
private void lock(NearCacheConfiguration nearCfg) throws Exception {
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setRebalanceMode(SYNC);
ccfg.setNearConfiguration(nearCfg);
final IgniteEx ignite0 = startGrid(0);
final IgniteEx ignite1 = startGrid(1);
awaitPartitionMapExchange();
client = true;
final Ignite ignite2 = startGrid(2);
assertTrue(ignite2.configuration().isClientMode());
final List<Integer> keys = new ArrayList<>();
for (int i = 0; i < 100; i++) keys.add(i);
TestCommunicationSpi spi = (TestCommunicationSpi) ignite2.configuration().getCommunicationSpi();
spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id());
spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id());
final IgniteCache<Integer, Integer> cache = ignite2.cache(DEFAULT_CACHE_NAME);
final CountDownLatch lockedLatch = new CountDownLatch(1);
final CountDownLatch unlockLatch = new CountDownLatch(1);
IgniteInternalFuture<Lock> lockFut = GridTestUtils.runAsync(new Callable<Lock>() {
@Override
public Lock call() throws Exception {
Thread.currentThread().setName("put-thread");
Lock lock = cache.lockAll(keys);
lock.lock();
log.info("Locked");
lockedLatch.countDown();
unlockLatch.await();
lock.unlock();
return lock;
}
});
client = false;
startGrid(3);
log.info("Stop block.");
assertEquals(1, lockedLatch.getCount());
spi.stopBlock();
assertTrue(lockedLatch.await(3000, TimeUnit.MILLISECONDS));
IgniteCache<Integer, Integer> cache0 = ignite0.cache(DEFAULT_CACHE_NAME);
for (Integer key : keys) {
Lock lock = cache0.lock(key);
assertFalse(lock.tryLock());
}
unlockLatch.countDown();
lockFut.get();
awaitPartitionMapExchange();
boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (int i = 0; i < 4; i++) {
if (!unlocked(ignite(i)))
return false;
}
return true;
}
private boolean unlocked(Ignite ignite) {
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
for (Integer key : keys) {
if (cache.isLocalLocked(key, false)) {
log.info("Key is locked [key=" + key + ", node=" + ignite.name() + ']');
return false;
}
}
return true;
}
}, 10_000);
assertTrue(wait);
for (Integer key : keys) {
Lock lock = cache0.lock(key);
assertTrue("Failed to lock: " + key, lock.tryLock());
lock.unlock();
}
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class IgniteDynamicClientCacheStartSelfTest method testReplicatedWithNearCacheClient.
/**
* @throws Exception If failed.
*/
public void testReplicatedWithNearCacheClient() throws Exception {
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setNearConfiguration(new NearCacheConfiguration());
ccfg.setCacheMode(REPLICATED);
final String cacheName = DEFAULT_CACHE_NAME;
Ignite ignite0 = startGrid(0);
checkCache(ignite0, cacheName, true, false);
client = true;
final Ignite ignite1 = startGrid(1);
checkCache(ignite1, cacheName, false, true);
ccfg.setNearConfiguration(null);
Ignite ignite2 = startGrid(2);
checkCache(ignite2, cacheName, false, false);
ccfg = null;
Ignite ignite3 = startGrid(3);
checkNoCache(ignite3, cacheName);
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class IgniteNearClientCacheCloseTest method cacheConfiguration.
/**
* @param atomicityMode Cache atomicity mode.
* @param nearCache {@code True} to enable near cache.
* @return Cache configuration.
*/
private CacheConfiguration cacheConfiguration(CacheAtomicityMode atomicityMode, boolean nearCache) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
if (nearCache)
ccfg.setNearConfiguration(new NearCacheConfiguration());
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setAtomicityMode(atomicityMode);
ccfg.setBackups(1);
return ccfg;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class IgniteTxReentryAbstractSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
discoSpi.setIpFinder(IP_FINDER);
cfg.setCommunicationSpi(new CountingCommunicationSpi());
cfg.setDiscoverySpi(discoSpi);
CacheConfiguration cacheCfg = defaultCacheConfiguration();
cacheCfg.setCacheMode(cacheMode());
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cacheCfg.setAtomicityMode(TRANSACTIONAL);
if (nearEnabled())
cacheCfg.setNearConfiguration(new NearCacheConfiguration());
cfg.setCacheConfiguration(cacheCfg);
return cfg;
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheMultithreadedFailoverAbstractTest method configuration.
/**
* Node configuration.
*
* @param idx Node index.
* @return Node configuration.
* @throws Exception If failed.
*/
private IgniteConfiguration configuration(int idx) throws Exception {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(CACHE_NAME);
ccfg.setCacheMode(cacheMode());
ccfg.setAtomicityMode(atomicityMode());
ccfg.setRebalanceMode(SYNC);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setEvictionPolicy(null);
if (cacheMode() == PARTITIONED)
ccfg.setBackups(backups());
if (atomicityMode() != ATOMIC && cacheMode() == PARTITIONED) {
ccfg.setNearConfiguration(new NearCacheConfiguration());
}
IgniteConfiguration cfg = getConfiguration(nodeName(idx));
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
discoSpi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discoSpi);
cfg.setLocalHost("127.0.0.1");
cfg.setCacheConfiguration(ccfg);
cfg.setConnectorConfiguration(null);
return cfg;
}
Aggregations