Search in sources :

Example 51 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class GridTaskExecutionContextSelfTest method testWithNoFailoverClosure.

/**
 * @throws Exception If failed.
 */
@Test
public void testWithNoFailoverClosure() throws Exception {
    final IgniteRunnable r = new GridAbsClosureX() {

        @Override
        public void applyx() {
            CNT.incrementAndGet();
            throw new ComputeExecutionRejectedException("Expected error.");
        }
    };
    final Ignite g = grid(0);
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            g.compute().withNoFailover().run(r);
            return null;
        }
    }, ComputeExecutionRejectedException.class, "Expected error.");
    assertEquals(1, CNT.get());
}
Also used : ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) Ignite(org.apache.ignite.Ignite) GridAbsClosureX(org.apache.ignite.internal.util.lang.GridAbsClosureX) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) ComputeExecutionRejectedException(org.apache.ignite.compute.ComputeExecutionRejectedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 52 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class IgniteMarshallerCacheSeparateDirectoryTest method run.

/**
 */
private void run(boolean ccfgOnClient, boolean ccfgOnServer, boolean indexedTypes, AccessMode putMode, AccessMode getMode) throws Exception {
    this.ccfgOnClient = ccfgOnClient;
    this.ccfgOnServer = ccfgOnServer;
    this.indexedTypes = indexedTypes;
    Ignite server = startGrid(SERVER);
    Ignite client = startGrid(CLIENT);
    if (putMode == AccessMode.CLOSURE) {
        client.compute().run(new IgniteRunnable() {

            @Override
            public void run() {
                Ignition.ignite(SERVER).cache(DEFAULT_CACHE_NAME).put(KEY, new TestClass());
            }
        });
    } else
        (putMode == AccessMode.SERVER ? server : client).cache(DEFAULT_CACHE_NAME).put(KEY, new TestClass());
    Object val;
    if (getMode == AccessMode.CLOSURE) {
        val = client.compute().call(new IgniteCallable<Object>() {

            @Override
            public Object call() throws Exception {
                return Ignition.ignite(SERVER).cache(DEFAULT_CACHE_NAME).get(KEY);
            }
        });
    } else
        val = (putMode == AccessMode.SERVER ? server : client).cache(DEFAULT_CACHE_NAME).get(KEY);
    assertNotNull(val);
    assertTrue(val.toString().contains("TestClass"));
}
Also used : IgniteCallable(org.apache.ignite.lang.IgniteCallable) Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 53 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class IgniteCacheReadThroughStoreCallTest method checkLoadCount.

/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void checkLoadCount(CacheConfiguration<Object, Object> ccfg) throws Exception {
    storeMap.clear();
    Ignite ignite0 = ignite(0);
    ignite0.createCache(ccfg);
    try {
        int key = 0;
        for (Ignite node : G.allGrids()) {
            log.info("Test for node: " + node.name());
            final IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
            for (int i = 0; i < 50; i++) {
                final int k = key++;
                checkReadThrough(cache, new IgniteRunnable() {

                    @Override
                    public void run() {
                        cache.invoke(k, new TestEntryProcessor());
                    }
                }, null, null, 1);
            }
            for (int i = 0; i < 50; i++) {
                final int k = key++;
                checkReadThrough(cache, new IgniteRunnable() {

                    @Override
                    public void run() {
                        cache.put(k, k);
                    }
                }, null, null, 0);
            }
            if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
                for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
                    for (TransactionIsolation isolation : values()) {
                        log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
                        for (int i = 0; i < 50; i++) {
                            final int k = key++;
                            checkReadThrough(cache, new IgniteRunnable() {

                                @Override
                                public void run() {
                                    cache.invoke(k, new TestEntryProcessor());
                                }
                            }, concurrency, isolation, 2);
                        }
                    }
                }
            }
        }
        ignite0.cache(ccfg.getName()).removeAll();
    } finally {
        ignite0.destroyCache(ccfg.getName());
    }
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 54 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class TcpCommunicationSpiDropNodesTest method testTwoNodesEachOther.

/**
 * Servers shouldn't fail each other if IGNITE_ENABLE_FORCIBLE_NODE_KILL=true.
 * @throws Exception If failed.
 */
@Test
public void testTwoNodesEachOther() throws Exception {
    pred = new IgniteBiPredicate<ClusterNode, ClusterNode>() {

        @Override
        public boolean apply(ClusterNode locNode, ClusterNode rmtNode) {
            return block && (locNode.order() == 2 || locNode.order() == 4) && (rmtNode.order() == 2 || rmtNode.order() == 4);
        }
    };
    startGrids(NODES_CNT);
    AtomicInteger evts = new AtomicInteger();
    grid(0).events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            evts.incrementAndGet();
            return true;
        }
    }, EVT_NODE_FAILED);
    // Wait for write timeout and closing idle connections.
    U.sleep(1000);
    block = true;
    final CyclicBarrier barrier = new CyclicBarrier(2);
    IgniteInternalFuture<Void> fut1 = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            barrier.await();
            grid(1).compute().withNoFailover().broadcast(new IgniteRunnable() {

                @Override
                public void run() {
                // No-op.
                }
            });
            return null;
        }
    });
    IgniteInternalFuture<Void> fut2 = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            barrier.await();
            grid(3).compute().withNoFailover().broadcast(new IgniteRunnable() {

                @Override
                public void run() {
                // No-op.
                }
            });
            return null;
        }
    });
    try {
        fut1.get();
        fail("Should fail with SpiException");
    } catch (IgniteCheckedException e) {
        assertTrue(e.getCause().getCause() instanceof IgniteSpiException);
    }
    try {
        fut2.get();
        fail("Should fail with SpiException");
    } catch (IgniteCheckedException e) {
        assertTrue(e.getCause().getCause() instanceof IgniteSpiException);
    }
    assertEquals(NODES_CNT, grid(0).cluster().nodes().size());
    assertEquals(0, evts.get());
    for (int j = 0; j < NODES_CNT; j++) {
        IgniteEx ignite;
        try {
            ignite = grid(j);
            log.info("Checking topology for grid(" + j + "): " + ignite.cluster().nodes());
            assertEquals(NODES_CNT, ignite.cluster().nodes().size());
        } catch (Exception e) {
            log.info("Checking topology for grid(" + j + "): no grid in topology.");
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) CyclicBarrier(java.util.concurrent.CyclicBarrier) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) Event(org.apache.ignite.events.Event) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 55 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class TcpCommunicationSpiDropNodesTest method testOneNode.

/**
 * Server node shouldn't be failed by other server node if IGNITE_ENABLE_FORCIBLE_NODE_KILL=true.
 *
 * @throws Exception If failed.
 */
@Test
public void testOneNode() throws Exception {
    pred = new IgniteBiPredicate<ClusterNode, ClusterNode>() {

        @Override
        public boolean apply(ClusterNode locNode, ClusterNode rmtNode) {
            return block && rmtNode.order() == 3;
        }
    };
    startGrids(NODES_CNT);
    AtomicInteger evts = new AtomicInteger();
    grid(0).events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            evts.incrementAndGet();
            return true;
        }
    }, EVT_NODE_FAILED);
    // Wait for write timeout and closing idle connections.
    U.sleep(1000);
    block = true;
    try {
        grid(0).compute().broadcast(new IgniteRunnable() {

            @Override
            public void run() {
            // No-op.
            }
        });
        fail("Should have exception here.");
    } catch (IgniteException e) {
        assertTrue(e.getCause() instanceof IgniteSpiException);
    }
    block = false;
    assertEquals(NODES_CNT, grid(0).cluster().nodes().size());
    assertEquals(0, evts.get());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)57 Test (org.junit.Test)30 Ignite (org.apache.ignite.Ignite)25 IgniteException (org.apache.ignite.IgniteException)19 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)19 IgniteEx (org.apache.ignite.internal.IgniteEx)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)11 UUID (java.util.UUID)10 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteFuture (org.apache.ignite.lang.IgniteFuture)6 IOException (java.io.IOException)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 List (java.util.List)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 Channel (java.nio.channels.Channel)3 Collection (java.util.Collection)3