use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testCheckReservePartitionException.
/**
* @throws Exception If failed.
*/
public void testCheckReservePartitionException() throws Exception {
int orgId = primaryKey(grid(1).cache(Organization.class.getSimpleName()));
try {
grid(0).compute().affinityRun(Arrays.asList(Organization.class.getSimpleName(), OTHER_CACHE_NAME), new Integer(orgId), new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
fail("Exception is expected");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Failed partition reservation. Partition is not primary on the node."));
}
try {
grid(0).compute().affinityCall(Arrays.asList(Organization.class.getSimpleName(), OTHER_CACHE_NAME), new Integer(orgId), new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
});
fail("Exception is expected");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Failed partition reservation. Partition is not primary on the node."));
}
}
use of org.apache.ignite.lang.IgniteRunnable 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.lang.IgniteRunnable 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.lang.IgniteRunnable 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);
}
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridProjectionLocalJobMultipleArgumentsSelfTest method testAffinityRun.
/**
* @throws Exception If failed.
*/
public void testAffinityRun() throws Exception {
for (int i : F.asList(1, 2, 3)) {
grid().compute().affinityRun(DEFAULT_CACHE_NAME, i, new IgniteRunnable() {
@Override
public void run() {
ids.add(this);
res.addAndGet(10);
}
});
}
assertEquals(30, res.get());
assertEquals(3, ids.size());
}
Aggregations