Search in sources :

Example 11 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testAffinitySimpleNoCacheOnCoordinator2.

/**
 * @throws Exception If failed.
 */
public void testAffinitySimpleNoCacheOnCoordinator2() throws Exception {
    System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
    try {
        cacheC = new IgniteClosure<String, CacheConfiguration[]>() {

            @Override
            public CacheConfiguration[] apply(String igniteInstanceName) {
                if (igniteInstanceName.equals(getTestIgniteInstanceName(1)) || igniteInstanceName.equals(getTestIgniteInstanceName(2)))
                    return null;
                return new CacheConfiguration[] { cacheConfiguration() };
            }
        };
        cacheNodeFilter = new TestCacheNodeExcludingFilter(F.asList(getTestIgniteInstanceName(1), getTestIgniteInstanceName(2)));
        startServer(0, 1);
        startServer(1, 2);
        startServer(2, 3);
        startServer(3, 4);
        for (int i = 0; i < 4; i++) {
            TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi();
            // Prevent exchange finish while node0 or node1 is coordinator.
            spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite(0).name());
            spi.blockMessages(GridDhtPartitionsSingleMessage.class, ignite(1).name());
        }
        stopGrid(0);
        stopGrid(1);
        calculateAffinity(5);
        calculateAffinity(6);
        checkAffinity(2, topVer(6, 0), true);
        assertNull(((IgniteKernal) ignite(2)).context().cache().internalCache(CACHE_NAME1));
        assertNotNull(((IgniteKernal) ignite(3)).context().cache().internalCache(CACHE_NAME1));
        assertNotNull(ignite(2).cache(CACHE_NAME1));
        checkAffinity(2, topVer(6, 0), true);
        startServer(4, 7);
        checkAffinity(3, topVer(7, 0), false);
        checkAffinity(3, topVer(7, 1), true);
    } finally {
        System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi)

Example 12 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentCoordinatorLeave1.

/**
 * Wait for rebalance, coordinator leaves, 2 nodes.
 *
 * @throws Exception If failed.
 */
public void testDelayAssignmentCoordinatorLeave1() throws Exception {
    Ignite ignite0 = startServer(0, 1);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    blockSupplySend(spi, CACHE_NAME1);
    startServer(1, 2);
    stopNode(0, 3);
    checkAffinity(1, topVer(3, 0), true);
    checkNoExchange(1, topVer(3, 1));
    awaitPartitionMapExchange();
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 13 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentAffinityChanged2.

/**
 * Wait for rebalance, send affinity change message, but affinity already changed (new node joined).
 *
 * @throws Exception If failed.
 */
public void testDelayAssignmentAffinityChanged2() throws Exception {
    System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
    try {
        Ignite ignite0 = startServer(0, 1);
        TestTcpDiscoverySpi discoSpi0 = (TestTcpDiscoverySpi) ignite0.configuration().getDiscoverySpi();
        TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
        startClient(1, 2);
        checkAffinity(2, topVer(2, 0), true);
        startServer(2, 3);
        checkAffinity(3, topVer(3, 1), false);
        discoSpi0.blockCustomEvent();
        stopNode(2, 4);
        discoSpi0.waitCustomEvent();
        blockSupplySend(commSpi0, CACHE_NAME1);
        final IgniteInternalFuture<?> startedFuture = multithreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                startServer(3, 5);
                return null;
            }
        }, 1, "server-starter");
        Thread.sleep(2_000);
        discoSpi0.stopBlock();
        boolean started = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return startedFuture.isDone();
            }
        }, 10_000);
        if (!started)
            startedFuture.cancel();
        assertTrue(started);
        checkAffinity(3, topVer(5, 0), false);
        checkNoExchange(3, topVer(5, 1));
        commSpi0.stopBlock();
        checkAffinity(3, topVer(5, 1), true);
        long nodeJoinTopVer = grid(3).context().discovery().localJoinEvent().topologyVersion();
        assertEquals(5, nodeJoinTopVer);
        List<GridDhtPartitionsExchangeFuture> exFutures = grid(3).context().cache().context().exchange().exchangeFutures();
        for (GridDhtPartitionsExchangeFuture f : exFutures) {
            // Shouldn't contains staled futures.
            assertTrue(f.initialVersion().topologyVersion() >= nodeJoinTopVer);
        }
    } finally {
        System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
    }
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 14 with TestRecordingCommunicationSpi

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

the class CachePartitionStateTest method getConfiguration.

/**
 * {@inheritDoc}
 */
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    cfg.setClientMode(client);
    if (ccfg != null) {
        cfg.setCacheConfiguration(ccfg);
        ccfg = null;
    }
    return cfg;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 15 with TestRecordingCommunicationSpi

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

the class IgniteCacheClientMultiNodeUpdateTopologyLockTest method testPessimisticTx.

/**
 * @throws Exception If failed.
 */
public void testPessimisticTx() throws Exception {
    startGrids(3);
    client = true;
    Ignite clientNode = startGrid(3);
    client = false;
    IgniteCache<Integer, Integer> cache = clientNode.createCache(cacheConfiguration(0, FULL_SYNC));
    awaitPartitionMapExchange();
    Integer key1 = movingKeysAfterJoin(ignite(1), TEST_CACHE, 1).get(0);
    Integer key2 = movingKeysAfterJoin(ignite(2), TEST_CACHE, 1).get(0);
    log.info("Start tx [key1=" + key1 + ", key2=" + key2 + ']');
    IgniteInternalFuture<?> startFut;
    TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(ignite(2));
    final TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(clientNode);
    final UUID node0Id = ignite(0).cluster().localNode().id();
    final UUID node2Id = ignite(2).cluster().localNode().id();
    spi2.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (!node0Id.equals(node.id()))
                return false;
            return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsSingleMessage) msg).exchangeId() != null;
        }
    });
    clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(final ClusterNode node, final Message msg) {
            if (!node2Id.equals(node.id()))
                return false;
            if (msg instanceof GridNearTxFinishRequest) {
                log.info("Delay message [msg=" + msg + ']');
                GridTestUtils.runAsync(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(5000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        log.info("Send delayed message [msg=" + msg + ']');
                        clientSpi.stopBlock(true);
                    }
                });
                return true;
            }
            return false;
        }
    });
    try (Transaction tx = clientNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.put(key1, 1);
        startFut = GridTestUtils.runAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                startGrid(4);
                return null;
            }
        }, "start-thread");
        spi2.waitForRecorded();
        U.sleep(5);
        cache.put(key2, 2);
        log.info("Commit tx");
        tx.commit();
    }
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
    startFut.get();
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
    awaitPartitionMapExchange();
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) Callable(java.util.concurrent.Callable) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)

Aggregations

TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)61 Ignite (org.apache.ignite.Ignite)33 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)20 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)18 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)10 Message (org.apache.ignite.plugin.extensions.communication.Message)9 ArrayList (java.util.ArrayList)6 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)6 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)6 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)4 IgniteException (org.apache.ignite.IgniteException)3 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)3 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)3 CacheAffinityChangeMessage (org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage)3 Transaction (org.apache.ignite.transactions.Transaction)3 IOException (java.io.IOException)2