Search in sources :

Example 6 with IgniteInstanceResource

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());
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteEx(org.apache.ignite.internal.IgniteEx) CollectionConfiguration(org.apache.ignite.configuration.CollectionConfiguration) IgniteException(org.apache.ignite.IgniteException)

Example 7 with IgniteInstanceResource

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();
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite)

Example 8 with IgniteInstanceResource

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);
    }
}
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 9 with IgniteInstanceResource

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);
}
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 10 with IgniteInstanceResource

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);
    }
}
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)

Aggregations

IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)44 Ignite (org.apache.ignite.Ignite)36 IgniteException (org.apache.ignite.IgniteException)17 IgniteCache (org.apache.ignite.IgniteCache)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 IgniteEx (org.apache.ignite.internal.IgniteEx)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)7 IgniteLogger (org.apache.ignite.IgniteLogger)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 LoggerResource (org.apache.ignite.resources.LoggerResource)6 Collection (java.util.Collection)5 Callable (java.util.concurrent.Callable)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Cache (javax.cache.Cache)4