Search in sources :

Example 76 with IgniteInternalFuture

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

the class CacheExchangeMergeTest method concurrentStart.

/**
 * @param withClients If {@code true} also starts client nodes.
 * @throws Exception If failed.
 */
private void concurrentStart(final boolean withClients) throws Exception {
    for (int i = 0; i < 5; i++) {
        log.info("Iteration: " + i);
        startGrid(0);
        final AtomicInteger idx = new AtomicInteger(1);
        IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                if (withClients)
                    client.set(ThreadLocalRandom.current().nextBoolean());
                int nodeIdx = idx.getAndIncrement();
                Ignite node = startGrid(nodeIdx);
                checkNodeCaches(node, nodeIdx * 1000, 1000);
                return null;
            }
        }, 10, "start-node");
        fut.get();
        checkCaches();
        startGrid(1000);
        checkCaches();
        stopAllGrids();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 77 with IgniteInternalFuture

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

the class CacheExchangeMergeTest method startCacheOnJoinAndJoinMerge1.

/**
 * @param nodes Number of nodes to start.
 * @param withClients If {@code true} starts both servers and clients.
 * @throws Exception If failed.
 */
private void startCacheOnJoinAndJoinMerge1(int nodes, boolean withClients) throws Exception {
    cfgCache = false;
    final IgniteEx srv0 = startGrid(0);
    mergeExchangeWaitVersion(srv0, nodes + 1);
    if (withClients) {
        clientC = new IgniteClosure<String, Boolean>() {

            @Override
            public Boolean apply(String nodeName) {
                return getTestIgniteInstanceIndex(nodeName) % 2 == 0;
            }
        };
    }
    cfgCache = true;
    IgniteInternalFuture fut = startGridsAsync(srv0, 1, nodes);
    fut.get();
    checkCaches();
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 78 with IgniteInternalFuture

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

the class CacheExchangeMergeTest method testStartCacheOnJoinAndCoordinatorFailed2.

/**
 * @throws Exception If failed.
 */
public void testStartCacheOnJoinAndCoordinatorFailed2() throws Exception {
    cfgCache = false;
    final Ignite srv0 = startGrid(0);
    mergeExchangeWaitVersion(srv0, 3);
    cfgCache = true;
    IgniteInternalFuture fut = startGridsAsync(srv0, 1, 2);
    stopGrid(0);
    fut.get();
    checkCaches();
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 79 with IgniteInternalFuture

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

the class CacheExchangeMergeTest method testMergeStartStopRandomClientsServers.

/**
 * @throws Exception If failed.
 */
public void testMergeStartStopRandomClientsServers() throws Exception {
    for (int iter = 0; iter < 3; iter++) {
        log.info("Iteration: " + iter);
        final int srvs = 5;
        final int clients = 5;
        Ignite srv0 = startGrids(srvs);
        for (int i = 0; i < clients; i++) {
            client.set(true);
            startGrid(srvs + i);
        }
        final int threads = 8;
        final int initNodes = srvs + clients;
        mergeExchangeWaitVersion(srv0, initNodes + threads);
        final AtomicInteger idx = new AtomicInteger(initNodes);
        final ConcurrentHashSet<Integer> stopNodes = new ConcurrentHashSet<>();
        IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                if (rnd.nextBoolean()) {
                    Integer stopIdx;
                    for (; ; ) {
                        stopIdx = rnd.nextInt(initNodes - 1) + 1;
                        if (stopNodes.add(stopIdx))
                            break;
                    }
                    log.info("Stop node: " + stopIdx);
                    stopGrid(getTestIgniteInstanceName(stopIdx), true, false);
                } else {
                    int nodeIdx = idx.incrementAndGet();
                    if (rnd.nextInt(5) == 0) {
                        log.info("Start client: " + nodeIdx);
                        client.set(true);
                    } else
                        log.info("Start server: " + nodeIdx);
                    startGrid(nodeIdx);
                }
                return null;
            }
        }, threads, "test-thread");
        fut.get();
        checkCaches();
        stopAllGrids();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashSet(org.eclipse.jetty.util.ConcurrentHashSet) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Example 80 with IgniteInternalFuture

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

the class CacheAbstractRestartSelfTest method testRestart.

/**
 * @throws Exception If failed.
 */
public void testRestart() throws Exception {
    final int clientGrid = gridCount() - 1;
    assertTrue(ignite(clientGrid).configuration().isClientMode());
    final IgniteEx grid = grid(clientGrid);
    final IgniteCache cache = jcache(clientGrid);
    updateCache(grid, cache);
    final AtomicBoolean stop = new AtomicBoolean();
    ArrayList<IgniteInternalFuture> updaterFuts = new ArrayList<>();
    for (int i = 0; i < updatersNumber(); i++) {
        final int threadIdx = i;
        IgniteInternalFuture<?> updateFut = GridTestUtils.runAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Thread.currentThread().setName("update-thread-" + threadIdx);
                assertTrue(cacheCheckedLatch.await(30_000, TimeUnit.MILLISECONDS));
                int iter = 0;
                while (!stop.get()) {
                    log.info("Start update: " + iter);
                    rwl.readLock().lock();
                    try {
                        updateCache(grid, cache);
                    } finally {
                        rwl.readLock().unlock();
                    }
                    log.info("End update: " + iter++);
                }
                log.info("Update iterations: " + iter);
                return null;
            }
        });
        updaterFuts.add(updateFut);
    }
    IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Thread.currentThread().setName("restart-thread");
            ThreadLocalRandom rnd = ThreadLocalRandom.current();
            while (!stop.get()) {
                assertTrue(cacheCheckedLatch.await(30_000, TimeUnit.MILLISECONDS));
                int node = rnd.nextInt(0, gridCount() - 1);
                log.info("Stop node: " + node);
                stopGrid(node);
                U.sleep(restartSleep());
                log.info("Start node: " + node);
                startGrid(node);
                cacheCheckedLatch = new CountDownLatch(1);
                U.sleep(restartDelay());
                awaitPartitionMapExchange();
            }
            return null;
        }
    });
    long endTime = System.currentTimeMillis() + getTestDuration();
    try {
        int iter = 0;
        while (System.currentTimeMillis() < endTime && !isAnyDone(updaterFuts) && !restartFut.isDone()) {
            try {
                log.info("Start of cache checking: " + iter);
                rwl.writeLock().lock();
                try {
                    checkCache(grid, cache);
                } finally {
                    rwl.writeLock().unlock();
                }
                log.info("End of cache checking: " + iter++);
            } finally {
                cacheCheckedLatch.countDown();
            }
        }
        log.info("Checking iteration: " + iter);
    } finally {
        cacheCheckedLatch.countDown();
        stop.set(true);
    }
    for (IgniteInternalFuture fut : updaterFuts) fut.get();
    restartFut.get();
    checkCache(grid, cache);
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)245 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)71 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)46 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 IgniteException (org.apache.ignite.IgniteException)33 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)29 UUID (java.util.UUID)28 IgniteCache (org.apache.ignite.IgniteCache)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)28 Callable (java.util.concurrent.Callable)27 HashMap (java.util.HashMap)25 Map (java.util.Map)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 CacheException (javax.cache.CacheException)16 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)16 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)16