Search in sources :

Example 31 with TestRecordingCommunicationSpi

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

the class IgniteClusterActivateDeactivateTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    if (testReconnectSpi) {
        TcpDiscoverySpi spi = new IgniteClientReconnectAbstractTest.TestTcpDiscoverySpi();
        cfg.setDiscoverySpi(spi);
        spi.setJoinTimeout(2 * 60_000);
    }
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
    cfg.setConsistentId(igniteInstanceName);
    cfg.setClientMode(client);
    cfg.setActiveOnStart(active);
    if (ccfgs != null) {
        cfg.setCacheConfiguration(ccfgs);
        ccfgs = null;
    }
    DataStorageConfiguration memCfg = new DataStorageConfiguration();
    memCfg.setPageSize(4 * 1024);
    memCfg.setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(300 * 1024 * 1024).setPersistenceEnabled(persistenceEnabled()));
    memCfg.setDataRegionConfigurations(new DataRegionConfiguration().setMaxSize(300 * 1024 * 1024).setName(NO_PERSISTENCE_REGION).setPersistenceEnabled(false));
    if (persistenceEnabled())
        memCfg.setWalMode(WALMode.LOG_ONLY);
    cfg.setDataStorageConfiguration(memCfg);
    if (testSpi) {
        TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
        if (testSpiRecord != null)
            spi.record(testSpiRecord);
        cfg.setCommunicationSpi(spi);
    }
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 32 with TestRecordingCommunicationSpi

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

the class IgniteCacheSingleGetMessageTest method checkSingleGetMessage.

/**
 * @param cache Cache.
 * @param key Key.
 * @param backup {@code True} if given key is backup key.
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
private void checkSingleGetMessage(IgniteCache<Integer, Integer> cache, Integer key, boolean backup) throws Exception {
    CacheConfiguration<Integer, Integer> ccfg = cache.getConfiguration(CacheConfiguration.class);
    Ignite node = cache.unwrap(Ignite.class);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) node.configuration().getCommunicationSpi();
    spi.record(GridNearSingleGetRequest.class);
    Ignite primary = primaryNode(key, cache.getName());
    assertNotSame(node, primary);
    TestRecordingCommunicationSpi primarySpi = (TestRecordingCommunicationSpi) primary.configuration().getCommunicationSpi();
    primarySpi.record(GridNearSingleGetResponse.class);
    assertNull(cache.get(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    assertFalse(cache.containsKey(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    cache.put(key, 1);
    assertNotNull(cache.get(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    assertTrue(cache.containsKey(key));
    if (backup)
        checkNoMessages(spi, primarySpi);
    else
        checkMessages(spi, primarySpi);
    if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
        cache.remove(key);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertNull(cache.get(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertFalse(cache.containsKey(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
        cache.put(key, 1);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertNotNull(cache.get(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
        try (Transaction tx = node.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) {
            assertTrue(cache.containsKey(key));
            tx.commit();
        }
        if (backup)
            checkNoMessages(spi, primarySpi);
        else
            checkMessages(spi, primarySpi);
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite)

Example 33 with TestRecordingCommunicationSpi

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

the class IgniteTxCachePrimarySyncTest method checkOnePhaseMessages.

/**
 * @param client Node executing cache operation.
 * @param ccfg Cache configuration.
 * @param c Cache update closure.
 * @throws Exception If failed.
 */
private void checkOnePhaseMessages(Ignite client, final CacheConfiguration<Object, Object> ccfg, final IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
    Ignite ignite = ignite(0);
    assertNotSame(ignite, client);
    TestRecordingCommunicationSpi commSpiClient = (TestRecordingCommunicationSpi) client.configuration().getCommunicationSpi();
    TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
    IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
    final Integer key = primaryKey(cache);
    cache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    final IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
    commSpi0.record(GridNearTxFinishResponse.class, GridNearTxPrepareResponse.class);
    commSpiClient.record(GridNearTxPrepareRequest.class, GridNearTxFinishRequest.class);
    c.apply(key, clientCache);
    List<Object> srvMsgs = commSpi0.recordedMessages(true);
    assertEquals("Unexpected messages: " + srvMsgs, 1, srvMsgs.size());
    assertTrue("Unexpected message: " + srvMsgs.get(0), srvMsgs.get(0) instanceof GridNearTxPrepareResponse);
    List<Object> clientMsgs = commSpiClient.recordedMessages(true);
    assertEquals("Unexpected messages: " + clientMsgs, 1, clientMsgs.size());
    assertTrue("Unexpected message: " + clientMsgs.get(0), clientMsgs.get(0) instanceof GridNearTxPrepareRequest);
    GridNearTxPrepareRequest req = (GridNearTxPrepareRequest) clientMsgs.get(0);
    assertTrue(req.onePhaseCommit());
    for (Ignite ignite0 : G.allGrids()) assertEquals(key, ignite0.cache(cache.getName()).get(key));
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridNearTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareResponse) Ignite(org.apache.ignite.Ignite) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest)

Example 34 with TestRecordingCommunicationSpi

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

the class IgniteTxCachePrimarySyncTest method checkWaitPrimaryResponse.

/**
 * @param client Node executing cache operation.
 * @param ccfg Cache configuration.
 * @param c Cache update closure.
 * @throws Exception If failed.
 */
private void checkWaitPrimaryResponse(Ignite client, final CacheConfiguration<Object, Object> ccfg, final IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
    Ignite ignite = ignite(0);
    assertNotSame(ignite, client);
    TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
    IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
    final Integer key = primaryKey(cache);
    cache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    final IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
    commSpi0.blockMessages(GridNearTxFinishResponse.class, client.name());
    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            c.apply(key, clientCache);
            return null;
        }
    }, "tx-thread");
    U.sleep(100);
    assertFalse(fut.isDone());
    commSpi0.stopBlock(true);
    fut.get();
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) CacheWriterException(javax.cache.integration.CacheWriterException) CacheLoaderException(javax.cache.integration.CacheLoaderException)

Example 35 with TestRecordingCommunicationSpi

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

the class CacheExchangeMessageDuplicatedStateTest method checkFullMessages.

/**
 * @param crdIdx Coordinator node index.
 */
private void checkFullMessages(int crdIdx) {
    TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite(crdIdx).configuration().getCommunicationSpi();
    List<Object> msgs = commSpi0.recordedMessages(false);
    assertTrue(!msgs.isEmpty());
    for (Object msg : msgs) {
        assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsFullMessage);
        checkFullMessage((GridDhtPartitionsFullMessage) msg);
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)

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