Search in sources :

Example 81 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class GridCacheSetFailoverAbstractSelfTest method testNodeRestart.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("WhileLoopReplaceableByForEach")
public void testNodeRestart() throws Exception {
    IgniteSet<Integer> set = grid(0).set(SET_NAME, config(false));
    final int ITEMS = 10_000;
    Collection<Integer> items = new ArrayList<>(ITEMS);
    for (int i = 0; i < ITEMS; i++) items.add(i);
    set.addAll(items);
    assertEquals(ITEMS, set.size());
    AtomicBoolean stop = new AtomicBoolean();
    IgniteInternalFuture<?> killFut = startNodeKiller(stop);
    long stopTime = System.currentTimeMillis() + TEST_DURATION;
    try {
        ThreadLocalRandom rnd = ThreadLocalRandom.current();
        while (System.currentTimeMillis() < stopTime) {
            for (int i = 0; i < 10; i++) {
                try {
                    int size = set.size();
                    // TODO: IGNITE-584, check for equality when IGNITE-584 fixed.
                    assertTrue(size > 0);
                } catch (IgniteException ignore) {
                // No-op.
                }
                try {
                    Iterator<Integer> iter = set.iterator();
                    int cnt = 0;
                    while (iter.hasNext()) {
                        assertNotNull(iter.next());
                        cnt++;
                    }
                    // TODO: IGNITE-584, check for equality when IGNITE-584 fixed.
                    assertTrue(cnt > 0);
                } catch (IgniteException ignore) {
                // No-op.
                }
                int val = rnd.nextInt(ITEMS);
                assertTrue("Not contains: " + val, set.contains(val));
                val = ITEMS + rnd.nextInt(ITEMS);
                assertFalse("Contains: " + val, set.contains(val));
            }
            log.info("Remove set.");
            set.close();
            log.info("Create new set.");
            set = grid(0).set(SET_NAME, config(false));
            set.addAll(items);
        }
    } finally {
        stop.set(true);
    }
    killFut.get();
    set.close();
    if (false) {
        // TODO IGNITE-600: enable check when fixed.
        int cnt = 0;
        Set<IgniteUuid> setIds = new HashSet<>();
        for (int i = 0; i < gridCount(); i++) {
            GridCacheAdapter cache = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME);
            Iterator<GridCacheMapEntry> entries = cache.map().entries(cache.context().cacheId()).iterator();
            while (entries.hasNext()) {
                GridCacheEntryEx entry = entries.next();
                if (entry.hasValue()) {
                    cnt++;
                    if (entry.key() instanceof SetItemKey) {
                        SetItemKey setItem = (SetItemKey) entry.key();
                        if (setIds.add(setItem.setId()))
                            log.info("Unexpected set item [setId=" + setItem.setId() + ", grid: " + grid(i).name() + ", entry=" + entry + ']');
                    }
                }
            }
        }
        assertEquals("Found unexpected cache entries", 0, cnt);
    }
}
Also used : ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteException(org.apache.ignite.IgniteException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) SetItemKey(org.apache.ignite.internal.processors.datastructures.SetItemKey) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) HashSet(java.util.HashSet)

Example 82 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class IgniteAtomicLongApiAbstractSelfTest method testCreateRemove.

/**
 * @throws Exception If failed.
 */
public void testCreateRemove() throws Exception {
    info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
    Ignite ignite = grid(0);
    String atomicName1 = "FIRST";
    String atomicName2 = "SECOND";
    IgniteAtomicLong atomic1 = ignite.atomicLong(atomicName1, 0, true);
    IgniteAtomicLong atomic2 = ignite.atomicLong(atomicName2, 0, true);
    IgniteAtomicLong atomic3 = ignite.atomicLong(atomicName1, 0, true);
    assertNotNull(atomic1);
    assertNotNull(atomic2);
    assertNotNull(atomic3);
    assert atomic1.equals(atomic3);
    assert atomic3.equals(atomic1);
    assert !atomic3.equals(atomic2);
    atomic1.close();
    atomic2.close();
    atomic3.close();
    assertNull(ignite.atomicLong(atomicName1, 0, false));
    assertNull(ignite.atomicLong(atomicName2, 0, false));
    try {
        atomic1.get();
        fail();
    } catch (IllegalStateException | IgniteException e) {
        info("Caught expected exception: " + e.getMessage());
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteAtomicLong(org.apache.ignite.IgniteAtomicLong) Ignite(org.apache.ignite.Ignite)

Example 83 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class WalModeChangeAdvancedSelfTest method testClientReconnect.

/**
 * Test client re-connect.
 *
 * @throws Exception If failed.
 */
public void testClientReconnect() throws Exception {
    final Ignite srv = startGrid(config(SRV_1, false, false));
    Ignite cli = startGrid(config(CLI, true, false));
    cli.cluster().active(true);
    cli.getOrCreateCache(cacheConfig(PARTITIONED));
    final AtomicBoolean done = new AtomicBoolean();
    final CountDownLatch latch = new CountDownLatch(1);
    // Start load.
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            boolean state = false;
            while (!done.get()) {
                try {
                    if (state)
                        cli.cluster().enableWal(CACHE_NAME);
                    else
                        cli.cluster().disableWal(CACHE_NAME);
                } catch (IgniteException e) {
                    String msg = e.getMessage();
                    assert msg.startsWith("Client node disconnected") || msg.startsWith("Client node was disconnected") : e.getMessage();
                } finally {
                    state = !state;
                }
            }
            latch.countDown();
        }
    });
    t.setName("wal-load-" + cli.name());
    t.start();
    // Now perform multiple client reconnects.
    for (int i = 1; i <= 10; i++) {
        Thread.sleep(ThreadLocalRandom.current().nextLong(200, 1000));
        IgniteClientReconnectAbstractTest.reconnectClientNode(log, cli, srv, new Runnable() {

            @Override
            public void run() {
            // No-op.
            }
        });
        X.println(">>> Finished iteration: " + i);
    }
    done.set(true);
    latch.await();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 84 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class WalModeChangeAdvancedSelfTest method testCacheDestroy.

/**
 * Test client re-connect.
 *
 * @throws Exception If failed.
 */
public void testCacheDestroy() throws Exception {
    final Ignite srv = startGrid(config(SRV_1, false, false));
    Ignite cli = startGrid(config(CLI, true, false));
    cli.cluster().active(true);
    srv.createCache(cacheConfig(PARTITIONED));
    final AtomicBoolean done = new AtomicBoolean();
    final CountDownLatch latch = new CountDownLatch(1);
    // Start load.
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            boolean state = false;
            while (!done.get()) {
                try {
                    if (state)
                        cli.cluster().enableWal(CACHE_NAME);
                    else
                        cli.cluster().disableWal(CACHE_NAME);
                } catch (IgniteException e) {
                    String msg = e.getMessage();
                    assert msg.startsWith("Cache doesn't exist") || msg.startsWith("Failed to change WAL mode because some caches no longer exist") : e.getMessage();
                } finally {
                    state = !state;
                }
            }
            latch.countDown();
        }
    });
    t.setName("wal-load-" + cli.name());
    t.start();
    // Now perform multiple client reconnects.
    for (int i = 1; i <= 20; i++) {
        Thread.sleep(ThreadLocalRandom.current().nextLong(200, 1000));
        srv.destroyCache(CACHE_NAME);
        Thread.sleep(100);
        srv.createCache(cacheConfig(PARTITIONED));
        X.println(">>> Finished iteration: " + i);
    }
    done.set(true);
    latch.await();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 85 with IgniteException

use of org.apache.ignite.IgniteException in project ignite by apache.

the class GridActivationCacheAbstractTestSuit method transform.

/**
 * @param c Class to transform.
 * @return Transformed class.
 */
private static Class transform(Class c) {
    try {
        ClassPool pool = ClassPool.getDefault();
        pool.insertClassPath(new ClassClassPath(GridActivationCacheAbstractTestSuit.class));
        String path = c.getProtectionDomain().getCodeSource().getLocation().getPath();
        CtClass ct = pool.get(c.getName());
        String name = c.getName() + SUFFIX;
        CtClass pr = pool.get(GridActivateExtensionTest.class.getName());
        pr.setName(name);
        pr.setSuperclass(ct);
        pr.writeFile(path);
        return Class.forName(name);
    } catch (IOException e) {
        System.out.println("Io exception: " + e.getMessage());
        throw new IgniteException(e);
    } catch (CannotCompileException e) {
        System.out.println("Cannot compile exception: " + e.getMessage());
        throw new IgniteException(e);
    } catch (NotFoundException e) {
        System.out.println("Not found exception: " + e.getMessage());
        throw new IgniteException(e);
    } catch (ClassNotFoundException e) {
        System.out.println("Class not found exception: " + e.getMessage());
        throw new IgniteException(e);
    }
}
Also used : CtClass(javassist.CtClass) IgniteException(org.apache.ignite.IgniteException) ClassPool(javassist.ClassPool) NotFoundException(javassist.NotFoundException) IOException(java.io.IOException) CannotCompileException(javassist.CannotCompileException) ClassClassPath(javassist.ClassClassPath)

Aggregations

IgniteException (org.apache.ignite.IgniteException)498 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)160 Ignite (org.apache.ignite.Ignite)97 ClusterNode (org.apache.ignite.cluster.ClusterNode)54 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)45 CountDownLatch (java.util.concurrent.CountDownLatch)44 UUID (java.util.UUID)43 IOException (java.io.IOException)39 CacheException (javax.cache.CacheException)35 HashMap (java.util.HashMap)34 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)34 Transaction (org.apache.ignite.transactions.Transaction)34 List (java.util.List)24 CyclicBarrier (java.util.concurrent.CyclicBarrier)21 Map (java.util.Map)20 Collection (java.util.Collection)18 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)18 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)18 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)17