use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheNearOnlyMultiNodeFullApiSelfTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
cnt = new AtomicInteger();
super.beforeTestsStarted();
for (int i = 0; i < gridCount(); i++) {
if (ignite(i).configuration().isClientMode()) {
if (clientHasNearCache())
ignite(i).getOrCreateCache(defaultCacheConfiguration(), new NearCacheConfiguration<>());
else
ignite(i).getOrCreateCache(DEFAULT_CACHE_NAME);
break;
}
}
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheNearOnlyTopologySelfTest method checkStartupNearNode.
/**
* @throws Exception If failed.
*/
private void checkStartupNearNode(int nearNodeIdx, int totalNodeCnt) throws Exception {
try {
cache = true;
for (int i = 0; i < totalNodeCnt; i++) {
cilent = nearNodeIdx == i;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheNearOnlyTopologySelfTest method testKeyMappingOnComputeNode.
/**
* @throws Exception If failed.
*/
public void testKeyMappingOnComputeNode() throws Exception {
try {
cache = true;
for (int i = 0; i < 4; i++) {
cilent = i == 0;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
cache = false;
cilent = true;
Ignite compute = startGrid(4);
for (int i = 0; i < 100; i++) {
ClusterNode node = compute.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(i);
assertFalse("For key: " + i, node.id().equals(compute.cluster().localNode().id()));
assertFalse("For key: " + i, node.id().equals(grid(0).localNode().id()));
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheNearOnlyTopologySelfTest method testKeyMapping.
/**
* @throws Exception If failed.
*/
public void testKeyMapping() throws Exception {
try {
cache = true;
for (int i = 0; i < 4; i++) {
cilent = i == 0;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
for (int i = 0; i < 100; i++) assertFalse("For key: " + i, grid(0).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(0).localNode(), i));
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.configuration.NearCacheConfiguration in project ignite by apache.
the class GridCacheNearOnlyTopologySelfTest method testNodeLeave.
/**
* @throws Exception If failed.
*/
public void testNodeLeave() throws Exception {
try {
cache = true;
for (int i = 0; i < 2; i++) {
cilent = i == 0;
Ignite ignite = startGrid(i);
if (cilent)
ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration());
}
for (int i = 0; i < 10; i++) grid(1).cache(DEFAULT_CACHE_NAME).put(i, i);
final Ignite igniteNearOnly = grid(0);
final IgniteCache<Object, Object> nearOnly = igniteNearOnly.cache(DEFAULT_CACHE_NAME);
// Populate near cache.
for (int i = 0; i < 10; i++) {
assertEquals(i, nearOnly.get(i));
assertEquals(i, nearOnly.localPeek(i, CachePeekMode.ONHEAP));
}
// Stop the only dht node.
stopGrid(1);
for (int i = 0; i < 10; i++) {
assertNull(nearOnly.localPeek(i, CachePeekMode.ONHEAP));
final int key = i;
GridTestUtils.assertThrowsWithCause(new Callable<Object>() {
@Override
public Object call() throws Exception {
return nearOnly.get(key);
}
}, ClusterTopologyCheckedException.class);
}
// Test optimistic transaction.
GridTestUtils.assertThrowsWithCause(new Callable<Object>() {
@Override
public Object call() throws Exception {
try (Transaction tx = igniteNearOnly.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
nearOnly.put("key", "val");
tx.commit();
}
return null;
}
}, ClusterTopologyCheckedException.class);
// Test pessimistic transaction.
GridTestUtils.assertThrowsWithCause(new Callable<Object>() {
@Override
public Object call() throws Exception {
try (Transaction tx = igniteNearOnly.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
nearOnly.put("key", "val");
tx.commit();
}
return null;
}
}, ClusterTopologyCheckedException.class);
} finally {
stopAllGrids();
}
}
Aggregations