Search in sources :

Example 46 with TestRecordingCommunicationSpi

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

the class IgniteClusterActivateDeactivateTest method clientReconnectClusterDeactivated.

/**
 * @param transition If {@code true} client reconnects while cluster state transition is in progress.
 * @throws Exception If failed.
 */
private void clientReconnectClusterDeactivated(final boolean transition) throws Exception {
    testReconnectSpi = true;
    testSpi = transition;
    final int SRVS = 3;
    final int CLIENTS = 3;
    startWithCaches1(SRVS, CLIENTS);
    final Ignite srv = ignite(0);
    IgniteEx client = grid(SRVS);
    if (persistenceEnabled())
        ignite(0).cluster().active(true);
    checkCache(client, CU.UTILITY_CACHE_NAME, true);
    checkCaches1(SRVS + CLIENTS);
    // Wait for late affinity assignment to finish.
    grid(0).context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(SRVS + CLIENTS, 1)).get();
    final AffinityTopologyVersion STATE_CHANGE_TOP_VER = new AffinityTopologyVersion(SRVS + CLIENTS + 1, 1);
    final TestRecordingCommunicationSpi spi1 = transition ? TestRecordingCommunicationSpi.spi(ignite(1)) : null;
    final AtomicReference<IgniteInternalFuture> stateFut = new AtomicReference<>();
    IgniteClientReconnectAbstractTest.reconnectClientNode(log, client, srv, () -> {
        if (transition) {
            blockExchangeSingleMessage(spi1, STATE_CHANGE_TOP_VER);
            stateFut.set(GridTestUtils.runAsync(() -> srv.cluster().active(false), "deactivate"));
            try {
                U.sleep(500);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else
            srv.cluster().active(false);
    });
    if (transition) {
        assertFalse(stateFut.get().isDone());
        // Public API method would block forever because we blocked the exchange message.
        assertFalse(client.context().state().publicApiActiveState(false));
        spi1.waitForBlocked();
        spi1.stopBlock();
        stateFut.get().get();
    }
    checkNoCaches(SRVS + CLIENTS);
    ignite(0).cluster().active(true);
    checkCache(client, CU.UTILITY_CACHE_NAME, true);
    assertTrue(client.cluster().active());
    checkCaches1(SRVS + CLIENTS);
    checkCache(client, CACHE_NAME_PREFIX + 0, true);
    this.client = false;
    startGrid(SRVS + CLIENTS);
    this.client = true;
    startGrid(SRVS + CLIENTS + 1);
    checkCaches1(SRVS + CLIENTS + 2);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 47 with TestRecordingCommunicationSpi

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

the class IgniteClusterActivateDeactivateTest method clientReconnectClusterActivated.

/**
 * @param transition If {@code true} client reconnects while cluster state transition is in progress.
 * @throws Exception If failed.
 */
private void clientReconnectClusterActivated(final boolean transition) throws Exception {
    testReconnectSpi = true;
    testSpi = transition;
    active = false;
    final int SRVS = 3;
    final int CLIENTS = 3;
    startWithCaches1(SRVS, CLIENTS);
    final Ignite srv = ignite(0);
    IgniteEx client = grid(SRVS);
    checkNoCaches(SRVS + CLIENTS);
    final AffinityTopologyVersion STATE_CHANGE_TOP_VER = new AffinityTopologyVersion(SRVS + CLIENTS + 1, 1);
    final TestRecordingCommunicationSpi spi1 = transition ? TestRecordingCommunicationSpi.spi(ignite(1)) : null;
    final AtomicReference<IgniteInternalFuture> stateFut = new AtomicReference<>();
    IgniteClientReconnectAbstractTest.reconnectClientNode(log, client, srv, () -> {
        if (transition) {
            blockExchangeSingleMessage(spi1, STATE_CHANGE_TOP_VER);
            stateFut.set(GridTestUtils.runAsync(() -> srv.cluster().active(true), "activate"));
            try {
                U.sleep(500);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else
            srv.cluster().active(true);
    });
    if (transition) {
        assertFalse(stateFut.get().isDone());
        assertTrue(client.context().state().clusterState().transition());
        spi1.waitForBlocked();
        spi1.stopBlock();
        stateFut.get().get();
    }
    checkCache(client, CU.UTILITY_CACHE_NAME, true);
    checkCaches1(SRVS + CLIENTS);
    checkCache(client, CACHE_NAME_PREFIX + 0, true);
    this.client = false;
    startGrid(SRVS + CLIENTS);
    this.client = true;
    startGrid(SRVS + CLIENTS + 1);
    checkCaches1(SRVS + CLIENTS + 2);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 48 with TestRecordingCommunicationSpi

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

the class IgniteClusterActivateDeactivateTest method joinWhileActivate1.

/**
 * @param startClient If {@code true} joins client node, otherwise server.
 * @param withNewCache If {@code true} joining node has new cache in configuration.
 * @throws Exception If failed.
 */
private void joinWhileActivate1(final boolean startClient, final boolean withNewCache) throws Exception {
    IgniteInternalFuture<?> activeFut = startNodesAndBlockStatusChange(2, 0, 0, false);
    IgniteInternalFuture<?> startFut = GridTestUtils.runAsync((Callable<Void>) () -> {
        client = startClient;
        ccfgs = withNewCache ? cacheConfigurations2() : cacheConfigurations1();
        startGrid(2);
        return null;
    });
    TestRecordingCommunicationSpi spi1 = TestRecordingCommunicationSpi.spi(ignite(1));
    spi1.stopBlock();
    activeFut.get();
    startFut.get();
    for (int c = 0; c < 2; c++) checkCache(ignite(2), CACHE_NAME_PREFIX + c, true);
    if (withNewCache) {
        for (int i = 0; i < 3; i++) {
            for (int c = 0; c < 4; c++) checkCache(ignite(i), CACHE_NAME_PREFIX + c, true);
        }
    }
    awaitPartitionMapExchange();
    checkCaches(3, withNewCache ? 4 : 2);
    client = false;
    startGrid(3);
    checkCaches(4, withNewCache ? 4 : 2);
    client = true;
    startGrid(4);
    checkCaches(5, withNewCache ? 4 : 2);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi)

Example 49 with TestRecordingCommunicationSpi

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

the class IgniteOnePhaseCommitInvokeTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    cfg.setCommunicationSpi(commSpi);
    cfg.setClientMode(client);
    CacheConfiguration ccfg = new CacheConfiguration();
    ccfg.setName(CACHE_NAME);
    ccfg.setAtomicityMode(TRANSACTIONAL);
    ccfg.setBackups(1);
    ccfg.setRebalanceMode(ASYNC);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 50 with TestRecordingCommunicationSpi

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

the class IgniteOnePhaseCommitNearReadersTest method getConfiguration.

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

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