use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheNearEvictionSelfTest method testNearEnabledThreeNodes.
/**
* @throws Exception If failed.
*/
@Test
public void testNearEnabledThreeNodes() throws Exception {
gridCnt = 3;
startGridsMultiThreaded(gridCnt);
try {
final int cnt = 100;
grid(0).compute().broadcast(new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public Object call() throws Exception {
IgniteCache<Integer, String> c = ignite.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < cnt; i++) c.put(i, Integer.toString(i));
return true;
}
});
for (int i = 0; i < gridCnt; i++) {
final GridCacheAdapter cache = internalCache(i);
final GridCacheAdapter near = near(i);
// Repeatedly check cache sizes because of concurrent cache updates.
assertTrue(GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
// Every node contains either near, backup, or primary.
return cnt == cache.size() + near.nearSize();
}
}, getTestTimeout()));
int keySize = near(i).nearSize();
assert keySize < cnt : "Key size is not less than count [cnt=" + cnt + ", size=" + keySize + ']';
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class ClosureServiceClientsNodesTest method testClientClosure.
/**
* @throws Exception If failed.
*/
@Test
public void testClientClosure() throws Exception {
for (int i = 0; i < NODES_CNT; i++) {
log.info("Iteration: " + i);
Ignite ignite = grid(i);
Collection<String> res = ignite.compute(ignite.cluster().forClients()).broadcast(new IgniteCallable<String>() {
@IgniteInstanceResource
Ignite ignite;
@Override
public String call() throws Exception {
assertTrue(ignite.configuration().isClientMode());
return ignite.name();
}
});
assertEquals(1, res.size());
assertEquals(getTestIgniteInstanceName(CLIENT_IDX), F.first(res));
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobMasterLeave.
/**
* @throws Exception If failed.
*/
@Test
public void testReleasePartitionJobMasterLeave() throws Exception {
final int orgId = primaryKey(grid(0).cache(Organization.class.getSimpleName()));
try {
grid(1).compute().affinityRunAsync(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteRunnable() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public void run() {
try {
checkPartitionsReservations((IgniteEx) ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
// No-op.
}
}
});
stopGrid(1, true);
Thread.sleep(3000);
awaitPartitionMapExchange();
checkPartitionsReservations(grid(0), orgId, 0);
} finally {
startGrid(1);
awaitPartitionMapExchange();
}
try {
grid(1).compute().affinityCallAsync(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public Object call() {
try {
checkPartitionsReservations((IgniteEx) ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
// No-op.
}
return null;
}
});
stopGrid(1, true);
Thread.sleep(3000);
awaitPartitionMapExchange();
checkPartitionsReservations(grid(0), orgId, 0);
} finally {
startGrid(1);
awaitPartitionMapExchange();
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobImplementMasterLeave.
/**
* @throws Exception If failed.
*/
@Test
public void testReleasePartitionJobImplementMasterLeave() throws Exception {
final int orgId = primaryKey(grid(0).cache(Organization.class.getSimpleName()));
try {
grid(1).compute().affinityRunAsync(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new RunnableWithMasterLeave() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public void onMasterNodeLeft(ComputeTaskSession ses) throws IgniteException {
// No-op.
}
@Override
public void run() {
try {
checkPartitionsReservations((IgniteEx) ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
// No-op.
}
}
});
stopGrid(1, true);
Thread.sleep(3000);
awaitPartitionMapExchange();
checkPartitionsReservations(grid(0), orgId, 0);
} finally {
startGrid(1);
awaitPartitionMapExchange();
}
}
Aggregations