Search in sources :

Example 36 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class TcpRestUnmarshalVulnerabilityTest method testExploit.

/**
 * @param positive Positive.
 */
private void testExploit(boolean positive) throws Exception {
    try {
        startGrid();
        attack(marshal(new Exploit()).array());
        boolean res = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return SHARED.get();
            }
        }, 3000L);
        if (positive)
            assertTrue(res);
        else
            assertFalse(res);
    } finally {
        stopAllGrids();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 37 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class GridCacheAbstractLocalStoreSelfTest method testSwap.

/**
 * @throws Exception If failed.
 */
@Test
public void testSwap() throws Exception {
    Ignite ignite1 = startGrid(1);
    IgniteCache<Object, Object> cache = ignite1.cache(DEFAULT_CACHE_NAME);
    // Populate cache and check that local store has all value.
    for (int i = 0; i < KEYS; i++) cache.put(i, i);
    checkLocalStore(ignite1, LOCAL_STORE_1, DEFAULT_CACHE_NAME);
    // Push entry to swap.
    for (int i = 0; i < KEYS; i++) cache.localEvict(Lists.newArrayList(i));
    for (int i = 0; i < KEYS; i++) assertNull(cache.localPeek(i, CachePeekMode.ONHEAP));
    final AtomicInteger evtCnt = new AtomicInteger(0);
    if (getCacheMode() != REPLICATED) {
        ignite1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                evtCnt.incrementAndGet();
                return true;
            }
        }, EventType.EVT_CACHE_REBALANCE_PART_UNLOADED);
    }
    final Ignite ignite2 = startGrid(2);
    if (getCacheMode() != REPLICATED) {
        boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                // Partition count which must be transferred to 2'nd node.
                int parts = ignite2.affinity(DEFAULT_CACHE_NAME).allPartitions(ignite2.cluster().localNode()).length;
                return evtCnt.get() >= parts;
            }
        }, 5000);
        assertTrue(wait);
    }
    assertEquals(Ignition.allGrids().size(), 2);
    checkLocalStore(ignite1, LOCAL_STORE_1, DEFAULT_CACHE_NAME);
    checkLocalStore(ignite2, LOCAL_STORE_2, DEFAULT_CACHE_NAME);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 38 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class IgniteClientReconnectCacheTest method checkOperationInProgressFails.

/**
 * @param client Client.
 * @param ccfg Cache configuration.
 * @param msgToBlock Message to block.
 * @param c Cache operation closure.
 * @throws Exception If failed.
 */
private void checkOperationInProgressFails(final IgniteEx client, final CacheConfiguration<Object, Object> ccfg, Class<?> msgToBlock, final IgniteInClosure<IgniteCache<Object, Object>> c) throws Exception {
    Ignite srv = ignite(0);
    final UUID id = client.localNode().id();
    DiscoverySpi srvSpi = spi0(srv);
    final IgniteCache<Object, Object> cache = client.getOrCreateCache(ccfg);
    for (int i = 0; i < SRV_CNT; i++) {
        TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) grid(i).configuration().getCommunicationSpi();
        srvCommSpi.blockMessages(msgToBlock, client.localNode().id());
    }
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            IgniteClientDisconnectedException e0 = null;
            try {
                assertEquals(id, client.localNode().id());
                c.apply(cache);
                fail();
            } catch (IgniteClientDisconnectedException e) {
                log.info("Expected exception: " + e);
                e0 = e;
            } catch (CacheException e) {
                log.info("Expected exception: " + e);
                assertTrue("Unexpected cause: " + e.getCause(), e.getCause() instanceof IgniteClientDisconnectedException);
                e0 = (IgniteClientDisconnectedException) e.getCause();
            }
            assertNotNull(e0);
            assertNotNull(e0.reconnectFuture());
            e0.reconnectFuture().get();
            assertNotEquals(id, client.localNode().id());
            c.apply(cache);
            return null;
        }
    });
    Thread.sleep(1000);
    assertNotDone(fut);
    log.info("Fail client: " + client.localNode().id());
    srvSpi.failNode(client.localNode().id(), null);
    try {
        fut.get();
    } finally {
        for (int i = 0; i < SRV_CNT; i++) ((TestCommunicationSpi) grid(i).configuration().getCommunicationSpi()).stopBlock(false);
    }
    assertNotEquals(id, client.localNode().id());
    while (true) {
        try {
            cache.put(1, 1);
            break;
        } catch (Exception e) {
            MvccFeatureChecker.assertMvccWriteConflict(e);
        }
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return cache.get(1) != null;
        }
    }, 5000);
    assertEquals(1, cache.get(1));
}
Also used : CacheException(javax.cache.CacheException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) IgniteDiscoverySpi(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Example 39 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class IgniteClientReconnectDelayedSpiTest method testReconnectCacheDestroyedDelayedAffinityChange.

/**
 * Test checks correctness of stale {@link CacheAffinityChangeMessage} processing by client node as delayed
 * {@link GridDhtPartitionsSingleMessage} with exchId = null sends after client node reconnect happens.
 *
 * @throws Exception If failed.
 */
@Test
public void testReconnectCacheDestroyedDelayedAffinityChange() throws Exception {
    Ignite ignite = ignite(1);
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);
    spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite.name());
    spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() == null;
        }
    });
    final Ignite client = startClientGrid(getConfiguration());
    client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
    final Ignite srv = clientRouter(client);
    reconnectClientNode(client, srv, new Runnable() {

        @Override
        public void run() {
            srv.destroyCache(DEFAULT_CACHE_NAME);
            srv.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
        }
    });
    // Resend delayed GridDhtPartitionsSingleMessage.
    spi.waitForBlocked();
    spi.stopBlock();
    assertNotNull(client.cache(DEFAULT_CACHE_NAME));
    final GridDiscoveryManager srvDisco = ((IgniteEx) srv).context().discovery();
    assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return F.eq(true, srvDisco.cacheClientNode(client.cluster().localNode(), DEFAULT_CACHE_NAME));
        }
    }, 5000));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Example 40 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class IgniteClientReconnectCacheTest method reconnectMultinode.

/**
 * @param longHist If {@code true} generates many discovery events to overflow events history.
 * @throws Exception If failed.
 */
private void reconnectMultinode(boolean longHist) throws Exception {
    grid(0).createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
    final int CLIENTS = 5;
    List<Ignite> clients = new ArrayList<>();
    for (int i = 0; i < CLIENTS; i++) {
        Ignite client = startClientGrid(SRV_CNT + i);
        assertNotNull(client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)));
        clients.add(client);
    }
    if (longHist) {
        // Generate many discovery events to overflow discovery events history.
        final AtomicInteger nodeIdx = new AtomicInteger(SRV_CNT + CLIENTS);
        GridTestUtils.runMultiThreaded(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                int idx = nodeIdx.incrementAndGet();
                for (int i = 0; i < 25; i++) {
                    startClientGrid(idx);
                    stopGrid(idx);
                }
                return null;
            }
        }, 4, "restart-thread");
    }
    int nodes = SRV_CNT + CLIENTS;
    int srvNodes = SRV_CNT;
    for (int iter = 0; iter < 5; iter++) {
        log.info("Iteration: " + iter);
        reconnectClientNodes(log, clients, grid(0), null);
        final int expNodes = CLIENTS + srvNodes;
        for (final Ignite client : clients) {
            IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);
            assertNotNull(cache);
            cache.put(client.name(), 1);
            assertEquals(1, cache.get(client.name()));
            GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    ClusterGroup grp = client.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
                    return grp.nodes().size() == expNodes;
                }
            }, 5000);
            ClusterGroup grp = client.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
            assertEquals(expNodes, grp.nodes().size());
            grp = client.cluster().forClientNodes(DEFAULT_CACHE_NAME);
            assertEquals(CLIENTS, grp.nodes().size());
        }
        for (int i = 0; i < nodes; i++) {
            final Ignite ignite = grid(i);
            GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    ClusterGroup grp = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
                    return grp.nodes().size() == expNodes;
                }
            }, 5000);
            ClusterGroup grp = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
            assertEquals(CLIENTS + srvNodes, grp.nodes().size());
            grp = ignite.cluster().forClientNodes(DEFAULT_CACHE_NAME);
            assertEquals(CLIENTS, grp.nodes().size());
        }
        startGrid(nodes++);
        srvNodes++;
        startClientGrid(nodes++);
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheException(javax.cache.CacheException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ignite(org.apache.ignite.Ignite) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)229 Ignite (org.apache.ignite.Ignite)109 Test (org.junit.Test)102 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)65 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 ClusterNode (org.apache.ignite.cluster.ClusterNode)37 IgniteEx (org.apache.ignite.internal.IgniteEx)34 IgniteException (org.apache.ignite.IgniteException)31 ArrayList (java.util.ArrayList)29 CountDownLatch (java.util.concurrent.CountDownLatch)28 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)28 Transaction (org.apache.ignite.transactions.Transaction)25 Map (java.util.Map)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 IgniteCache (org.apache.ignite.IgniteCache)19 IgniteKernal (org.apache.ignite.internal.IgniteKernal)19 HashMap (java.util.HashMap)17 Duration (javax.cache.expiry.Duration)15 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)13 UUID (java.util.UUID)12