Search in sources :

Example 56 with IgniteRunnable

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

Example 57 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class GridFactorySelfTest method testCurrentIgnite.

/**
 * @throws Exception If failed.
 */
@Test
public void testCurrentIgnite() throws Exception {
    final String LEFT = "LEFT";
    final String RIGHT = "RIGHT";
    try {
        Ignite iLEFT = startGrid(LEFT);
        Ignite iRIGHT = startGrid(RIGHT);
        waitForDiscovery(iLEFT, iRIGHT);
        iLEFT.compute(iLEFT.cluster().forRemotes()).run(new IgniteRunnable() {

            @Override
            public void run() {
                assert Ignition.localIgnite().name().equals(RIGHT);
            }
        });
        iRIGHT.compute(iRIGHT.cluster().forRemotes()).run(new IgniteRunnable() {

            @Override
            public void run() {
                assert Ignition.localIgnite().name().equals(LEFT);
            }
        });
    } finally {
        stopAllGrids();
    }
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)57 Test (org.junit.Test)30 Ignite (org.apache.ignite.Ignite)25 IgniteException (org.apache.ignite.IgniteException)19 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)19 IgniteEx (org.apache.ignite.internal.IgniteEx)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)11 UUID (java.util.UUID)10 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteFuture (org.apache.ignite.lang.IgniteFuture)6 IOException (java.io.IOException)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 List (java.util.List)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 Channel (java.nio.channels.Channel)3 Collection (java.util.Collection)3