Search in sources :

Example 11 with IgniteEx

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

the class GridServiceProcessorStopSelfTest method testStopDuringHangedDeployment.

/**
     * @throws Exception If failed.
     */
public void testStopDuringHangedDeployment() throws Exception {
    final CountDownLatch depLatch = new CountDownLatch(1);
    final CountDownLatch finishLatch = new CountDownLatch(1);
    final IgniteEx node0 = startGrid(0);
    final IgniteEx node1 = startGrid(1);
    final IgniteEx node2 = startGrid(2);
    final IgniteCache<Object, Object> cache = node2.getOrCreateCache(new CacheConfiguration<Object, Object>("def").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
    node0.services().deployNodeSingleton("myService", new TestServiceImpl());
    // Guarantee lock owner will never left topology unexpectedly.
    final Integer lockKey = keyForNode(node2.affinity("def"), new AtomicInteger(1), node2.cluster().localNode());
    // Lock to hold topology version undone.
    final Lock lock = cache.lock(lockKey);
    // Try to change topology once service has deployed.
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            depLatch.await();
            node1.close();
            return null;
        }
    }, "top-change-thread");
    // Stop node on unstable topology.
    GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            depLatch.await();
            Thread.sleep(1000);
            node0.close();
            finishLatch.countDown();
            return null;
        }
    }, "stopping-node-thread");
    assertNotNull(node0.services().service("myService"));
    // Freeze topology changing
    lock.lock();
    depLatch.countDown();
    boolean wait = finishLatch.await(15, TimeUnit.SECONDS);
    if (!wait)
        U.dumpThreads(log);
    assertTrue("Deploy future isn't completed", wait);
    fut.get();
    Ignition.stopAll(true);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) Lock(java.util.concurrent.locks.Lock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 12 with IgniteEx

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

the class IgniteServiceProxyTimeoutInitializedTest method testUnavailableService.

/**
     * Checks that we limit retries to get not available service by timeout.
     *
     * @throws Exception If fail.
     */
@SuppressWarnings({ "Convert2Lambda", "ThrowableResultOfMethodCallIgnored" })
public void testUnavailableService() throws Exception {
    srvc = new TestWaitServiceImpl();
    latch1 = new CountDownLatch(1);
    latch2 = new CountDownLatch(1);
    try {
        GridTestUtils.runAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                startGrid(0);
                return null;
            }
        });
        assert latch1.await(1, TimeUnit.MINUTES);
        final IgniteEx ignite1 = startGrid(1);
        final TestService testSrvc = ignite1.services().serviceProxy("testService", TestService.class, false, 500);
        GridTestUtils.assertThrows(null, new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                testSrvc.test();
                return null;
            }
        }, IgniteException.class, null);
    } finally {
        latch2.countDown();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteException(org.apache.ignite.IgniteException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 13 with IgniteEx

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

the class IgniteServiceProxyTimeoutInitializedTest method testServiceException.

/**
     * Checks that service not hangs if timeout set. Here we get hang with marshalling exception.
     *
     * @throws Exception If fail.
     */
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "Convert2Lambda" })
public void testServiceException() throws Exception {
    srvc = new HangServiceImpl();
    // Start service grid.
    startGrid(0);
    final IgniteEx ignite1 = startGrid(1);
    final HangService testSrvc = ignite1.services().serviceProxy("testService", HangService.class, false, 1_000);
    GridTestUtils.assertThrows(null, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            testSrvc.hang();
            return null;
        }
    }, ComputeTaskTimeoutException.class, null);
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteException(org.apache.ignite.IgniteException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 14 with IgniteEx

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

the class IgniteCacheLockPartitionOnAffinityRunTest method testSingleCache.

/**
     * @throws Exception If failed.
     */
public void testSingleCache() throws Exception {
    final PersonsCountGetter personsCntGetter = new PersonsCountGetter() {

        @Override
        public int getPersonsCount(IgniteEx ignite, IgniteLogger log, int orgId) throws Exception {
            return getPersonsCountSingleCache(ignite, log, orgId);
        }
    };
    // Run restart threads: start re-balancing.
    beginNodesRestart();
    IgniteInternalFuture<Long> affFut = null;
    try {
        final AtomicInteger threadNum = new AtomicInteger(0);
        affFut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

            @Override
            public void run() {
                if (threadNum.getAndIncrement() % 2 == 0) {
                    while (System.currentTimeMillis() < endTime) {
                        for (final int orgId : orgIds) {
                            if (System.currentTimeMillis() >= endTime)
                                break;
                            grid(0).compute().affinityRun(Person.class.getSimpleName(), new Person(0, orgId).createKey(), new TestAffinityRun(personsCntGetter, orgId));
                        }
                    }
                } else {
                    while (System.currentTimeMillis() < endTime) {
                        for (final int orgId : orgIds) {
                            if (System.currentTimeMillis() >= endTime)
                                break;
                            int personsCnt = grid(0).compute().affinityCall(Person.class.getSimpleName(), new Person(0, orgId).createKey(), new TestAffinityCall(personsCntGetter, orgId));
                            assertEquals(PERS_AT_ORG_CNT, personsCnt);
                        }
                    }
                }
            }
        }, AFFINITY_THREADS_CNT, "affinity-run");
    } finally {
        if (affFut != null)
            affFut.get();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 15 with IgniteEx

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

the class IgniteCacheLockPartitionOnAffinityRunTest method testMultipleCaches.

/**
     * @throws Exception If failed.
     */
public void testMultipleCaches() throws Exception {
    final PersonsCountGetter personsCntGetter = new PersonsCountGetter() {

        @Override
        public int getPersonsCount(IgniteEx ignite, IgniteLogger log, int orgId) throws Exception {
            return getPersonsCountMultipleCache(ignite, log, orgId);
        }
    };
    // Run restart threads: start re-balancing.
    beginNodesRestart();
    IgniteInternalFuture<Long> affFut = null;
    try {
        final AtomicInteger threadNum = new AtomicInteger(0);
        affFut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

            @Override
            public void run() {
                if (threadNum.getAndIncrement() % 2 == 0) {
                    while (System.currentTimeMillis() < endTime) {
                        for (final int orgId : orgIds) {
                            if (System.currentTimeMillis() >= endTime)
                                break;
                            grid(0).compute().affinityRun(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new TestAffinityRun(personsCntGetter, orgId));
                        }
                    }
                } else {
                    while (System.currentTimeMillis() < endTime) {
                        for (final int orgId : orgIds) {
                            if (System.currentTimeMillis() >= endTime)
                                break;
                            int personsCnt = grid(0).compute().affinityCall(Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new TestAffinityCall(personsCntGetter, orgId));
                            assertEquals(PERS_AT_ORG_CNT, personsCnt);
                        }
                    }
                }
            }
        }, AFFINITY_THREADS_CNT, "affinity-run");
    } finally {
        if (affFut != null)
            affFut.get();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteLogger(org.apache.ignite.IgniteLogger)

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