Search in sources :

Example 11 with IgniteRunnable

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."));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 12 with IgniteRunnable

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 13 with IgniteRunnable

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 14 with IgniteRunnable

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);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 15 with IgniteRunnable

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());
}
Also used : IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Aggregations

IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)45 Ignite (org.apache.ignite.Ignite)21 IgniteException (org.apache.ignite.IgniteException)11 IgniteEx (org.apache.ignite.internal.IgniteEx)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 UUID (java.util.UUID)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 IgniteCompute (org.apache.ignite.IgniteCompute)4 TaskEvent (org.apache.ignite.events.TaskEvent)4 IgniteFuture (org.apache.ignite.lang.IgniteFuture)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 Event (org.apache.ignite.events.Event)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Collection (java.util.Collection)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2