Search in sources :

Example 56 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class GridCacheNearEvictionSelfTest method testNearEnabledThreeNodes.

/**
 * @throws Exception If failed.
 */
@Test
public void testNearEnabledThreeNodes() throws Exception {
    gridCnt = 3;
    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++) {
            final GridCacheAdapter cache = internalCache(i);
            final GridCacheAdapter near = near(i);
            // Repeatedly check cache sizes because of concurrent cache updates.
            assertTrue(GridTestUtils.waitForCondition(new PA() {

                @Override
                public boolean apply() {
                    // Every node contains either near, backup, or primary.
                    return cnt == cache.size() + near.nearSize();
                }
            }, getTestTimeout()));
            int keySize = near(i).nearSize();
            assert keySize < cnt : "Key size is not less than count [cnt=" + cnt + ", size=" + keySize + ']';
        }
    } finally {
        stopAllGrids();
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 57 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class ClosureServiceClientsNodesTest method testClientClosure.

/**
 * @throws Exception If failed.
 */
@Test
public void testClientClosure() throws Exception {
    for (int i = 0; i < NODES_CNT; i++) {
        log.info("Iteration: " + i);
        Ignite ignite = grid(i);
        Collection<String> res = ignite.compute(ignite.cluster().forClients()).broadcast(new IgniteCallable<String>() {

            @IgniteInstanceResource
            Ignite ignite;

            @Override
            public String call() throws Exception {
                assertTrue(ignite.configuration().isClientMode());
                return ignite.name();
            }
        });
        assertEquals(1, res.size());
        assertEquals(getTestIgniteInstanceName(CLIENT_IDX), F.first(res));
    }
}
Also used : IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 58 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource 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 59 with IgniteInstanceResource

use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.

the class IgniteCacheLockPartitionOnAffinityRunTest method testReleasePartitionJobImplementMasterLeave.

/**
 * @throws Exception If failed.
 */
@Test
public void testReleasePartitionJobImplementMasterLeave() 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 RunnableWithMasterLeave() {

            @IgniteInstanceResource
            private Ignite ignite;

            @Override
            public void onMasterNodeLeft(ComputeTaskSession ses) throws IgniteException {
            // No-op.
            }

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

Aggregations

IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)59 Ignite (org.apache.ignite.Ignite)48 Test (org.junit.Test)40 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)28 IgniteException (org.apache.ignite.IgniteException)24 IgniteEx (org.apache.ignite.internal.IgniteEx)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 IgniteCache (org.apache.ignite.IgniteCache)15 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)11 List (java.util.List)9 UUID (java.util.UUID)9 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 IgniteLogger (org.apache.ignite.IgniteLogger)7 IgniteCallable (org.apache.ignite.lang.IgniteCallable)7 Callable (java.util.concurrent.Callable)6