Search in sources :

Example 16 with IgniteEx

use of org.apache.ignite.internal.IgniteEx 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 17 with IgniteEx

use of org.apache.ignite.internal.IgniteEx 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 18 with IgniteEx

use of org.apache.ignite.internal.IgniteEx 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 19 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class IgniteCacheConfigVariationsFullApiTest method testRemoveAfterClear.

/**
     * @throws Exception If failed.
     */
public void testRemoveAfterClear() throws Exception {
    IgniteEx ignite = grid(0);
    boolean affNode = ignite.context().cache().internalCache(cacheName()).context().affinityNode();
    if (!affNode) {
        if (gridCount() < 2)
            return;
        ignite = grid(1);
    }
    IgniteCache<Integer, Integer> cache = ignite.cache(cacheName());
    int key = 0;
    Collection<Integer> keys = new ArrayList<>();
    for (int k = 0; k < 2; k++) {
        while (!ignite.affinity(cacheName()).isPrimary(ignite.localNode(), key)) key++;
        keys.add(key);
        key++;
    }
    info("Keys: " + keys);
    for (Integer k : keys) cache.put(k, k);
    cache.clear();
    for (int g = 0; g < gridCount(); g++) {
        Ignite grid0 = grid(g);
        grid0.cache(cacheName()).removeAll();
        assertTrue(grid0.cache(cacheName()).localSize() == 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) Ignite(org.apache.ignite.Ignite)

Example 20 with IgniteEx

use of org.apache.ignite.internal.IgniteEx in project ignite by apache.

the class MemoryPolicyInitializationTest method testCustomConfigNoDefault.

/**
     * Verifies that expected memory policies are allocated when used provides MemoryPolicyConfiguration
     * with non-default custom MemoryPolicy.
     */
public void testCustomConfigNoDefault() throws Exception {
    prepareCustomNoDefaultConfig();
    IgniteEx ignite = startGrid(0);
    Collection<MemoryPolicy> allMemPlcs = ignite.context().cache().context().database().memoryPolicies();
    assertTrue(allMemPlcs.size() == 3);
    verifyDefaultAndSystemMemoryPolicies(allMemPlcs);
    assertTrue("Custom non-default memory policy is not presented", isMemoryPolicyPresented(allMemPlcs, CUSTOM_NON_DEFAULT_MEM_PLC_NAME));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)198 Ignite (org.apache.ignite.Ignite)42 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)40 IgniteException (org.apache.ignite.IgniteException)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)32 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)26 Transaction (org.apache.ignite.transactions.Transaction)25 HashMap (java.util.HashMap)18 CacheException (javax.cache.CacheException)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 ArrayList (java.util.ArrayList)16 LinkedHashMap (java.util.LinkedHashMap)16 IgniteCache (org.apache.ignite.IgniteCache)16 CountDownLatch (java.util.concurrent.CountDownLatch)14 IgniteKernal (org.apache.ignite.internal.IgniteKernal)14 UUID (java.util.UUID)13 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)12 IOException (java.io.IOException)11 Map (java.util.Map)11