use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheQueueApiSelfAbstractTest method testAffinityCall.
/**
* @throws Exception If failed.
*/
public void testAffinityCall() throws Exception {
final CollectionConfiguration colCfg = collectionConfiguration();
colCfg.setCollocated(false);
colCfg.setCacheMode(CacheMode.PARTITIONED);
try (final IgniteQueue<Integer> queue1 = grid(0).queue("Queue1", 0, colCfg)) {
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
queue1.affinityCall(new IgniteCallable<Object>() {
@Override
public Object call() {
return null;
}
});
return null;
}
}, IgniteException.class, "Failed to execute affinityCall() for non-collocated queue: " + queue1.name() + ". This operation is supported only for collocated queues.");
}
colCfg.setCollocated(true);
try (final IgniteQueue<Integer> queue2 = grid(0).queue("Queue2", 0, colCfg)) {
queue2.add(100);
Integer res = queue2.affinityCall(new IgniteCallable<Integer>() {
@IgniteInstanceResource
private IgniteEx ignite;
@Override
public Integer call() {
assertTrue(ignite.cachex("datastructures_0").affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Queue2"));
return queue2.take();
}
});
assertEquals(100, res.intValue());
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridCacheNearEvictionSelfTest method testNearEnabledTwoNodes.
/** @throws Exception If failed. */
public void testNearEnabledTwoNodes() throws Exception {
gridCnt = 2;
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++) {
assertEquals(cnt, internalCache(i).size());
assertEquals(0, near(i).nearSize());
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobThrowsError.
/**
* @throws Exception If failed.
*/
public void testReleasePartitionJobThrowsError() throws Exception {
final int orgId = primaryKey(grid(1).cache(Organization.class.getSimpleName()));
try {
grid(0).compute().affinityRun(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteRunnable() {
@IgniteInstanceResource
IgniteEx ignite;
@Override
public void run() {
try {
checkPartitionsReservations(ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
throw new Error("Test job throws error");
}
});
fail("Error must be thrown");
} catch (Throwable ignored) {
checkPartitionsReservations(grid(1), orgId, 0);
}
try {
grid(0).compute().affinityCall(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteCallable<Object>() {
@IgniteInstanceResource
IgniteEx ignite;
@Override
public Object call() {
try {
checkPartitionsReservations(ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
throw new Error("Test job throws error");
}
});
fail("Error must be thrown");
} catch (Throwable ignored) {
checkPartitionsReservations(grid(1), orgId, 0);
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobCompletesNormally.
/**
* @throws Exception If failed.
*/
public void testReleasePartitionJobCompletesNormally() throws Exception {
final int orgId = primaryKey(grid(1).cache(Organization.class.getSimpleName()));
grid(0).compute().affinityRun(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteRunnable() {
@IgniteInstanceResource
IgniteEx ignite;
@Override
public void run() {
try {
checkPartitionsReservations(ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
}
});
checkPartitionsReservations(grid(1), orgId, 0);
grid(0).compute().affinityCall(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteCallable<Object>() {
@IgniteInstanceResource
IgniteEx ignite;
@Override
public Object call() {
try {
checkPartitionsReservations(ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
return null;
}
});
checkPartitionsReservations(grid(1), orgId, 0);
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobThrowsException.
/**
* @throws Exception If failed.
*/
public void testReleasePartitionJobThrowsException() throws Exception {
final int orgId = primaryKey(grid(1).cache(Organization.class.getSimpleName()));
try {
grid(0).compute().affinityRun(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteRunnable() {
@IgniteInstanceResource
IgniteEx ignite;
@Override
public void run() {
try {
checkPartitionsReservations(ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
throw new RuntimeException("Test job throws exception");
}
});
fail("Exception must be thrown");
} catch (Exception ignored) {
checkPartitionsReservations(grid(1), orgId, 0);
}
try {
grid(0).compute().affinityCall(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new IgniteCallable<Object>() {
@IgniteInstanceResource
IgniteEx ignite;
@Override
public Object call() {
try {
checkPartitionsReservations(ignite, orgId, 1);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
throw new RuntimeException("Test job throws exception");
}
});
fail("Exception must be thrown");
} catch (Exception ignored) {
checkPartitionsReservations(grid(1), orgId, 0);
}
}
Aggregations