Search in sources :

Example 21 with TestRecordingCommunicationSpi

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

the class GridCacheDhtPreloadMessageCountTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
    assert preloadMode != null;
    CacheConfiguration cc = defaultCacheConfiguration();
    cc.setCacheMode(PARTITIONED);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(preloadMode);
    cc.setAffinity(new RendezvousAffinityFunction(false, 521));
    cc.setBackups(1);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    c.setFailureDetectionTimeout(Integer.MAX_VALUE);
    c.setDiscoverySpi(disco);
    c.setCacheConfiguration(cc);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    commSpi.record(GridDhtPartitionsSingleMessage.class);
    c.setCommunicationSpi(commSpi);
    return c;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 22 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 23 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheStart.

/**
     * Wait for rebalance, cache is started.
     *
     * @throws Exception If failed.
     */
public void testDelayAssignmentCacheStart() throws Exception {
    Ignite ignite0 = startServer(0, 1);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    blockSupplySend(spi, CACHE_NAME1);
    startServer(1, 2);
    startServer(2, 3);
    checkAffinity(3, topVer(3, 0), false);
    CacheConfiguration ccfg = cacheConfiguration();
    ccfg.setName(CACHE_NAME2);
    ignite0.createCache(ccfg);
    calculateAffinity(3);
    checkAffinity(3, topVer(3, 1), false);
    spi.stopBlock();
    checkAffinity(3, topVer(3, 2), true);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 24 with TestRecordingCommunicationSpi

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

the class IgniteCacheReadFromBackupTest method testGetFromPrimaryPreloadInProgress.

/**
     * @throws Exception If failed.
     */
public void testGetFromPrimaryPreloadInProgress() throws Exception {
    for (final CacheConfiguration<Object, Object> ccfg : cacheConfigurations()) {
        boolean near = (ccfg.getNearConfiguration() != null);
        log.info("Test cache [mode=" + ccfg.getCacheMode() + ", atomicity=" + ccfg.getAtomicityMode() + ", backups=" + ccfg.getBackups() + ", near=" + near + "]");
        ignite(0).createCache(ccfg);
        awaitPartitionMapExchange();
        try {
            Map<Ignite, Integer> backupKeys = new HashMap<>();
            Map<Ignite, Integer> nearKeys = new HashMap<>();
            for (int i = 0; i < NODES; i++) {
                Ignite ignite = ignite(i);
                IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
                backupKeys.put(ignite, backupKey(cache));
                if (ccfg.getCacheMode() == PARTITIONED)
                    nearKeys.put(ignite, nearKey(cache));
                TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
                spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

                    @Override
                    public boolean apply(ClusterNode node, Message msg) {
                        if (!msg.getClass().equals(GridDhtPartitionSupplyMessage.class))
                            return false;
                        return ((GridDhtPartitionSupplyMessage) msg).cacheId() == CU.cacheId(ccfg.getName());
                    }
                });
            }
            try (Ignite newNode = startGrid(NODES)) {
                IgniteCache<Integer, Integer> cache = newNode.cache(ccfg.getName());
                TestRecordingCommunicationSpi newNodeSpi = recordGetRequests(newNode, near);
                Integer key = backupKey(cache);
                assertNull(cache.get(key));
                List<Object> msgs = newNodeSpi.recordedMessages(false);
                assertEquals(1, msgs.size());
                for (int i = 0; i < NODES; i++) {
                    Ignite ignite = ignite(i);
                    log.info("Check node: " + ignite.name());
                    checkLocalRead(ignite, ccfg, backupKeys.get(ignite), nearKeys.get(ignite));
                }
                for (int i = 0; i < NODES; i++) {
                    Ignite ignite = ignite(i);
                    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
                    spi.stopBlock(true);
                }
                awaitPartitionMapExchange();
                checkLocalRead(NODES + 1, ccfg);
            }
        } finally {
            ignite(0).destroyCache(ccfg.getName());
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 25 with TestRecordingCommunicationSpi

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

the class IgniteCacheReadFromBackupTest method checkLocalRead.

/**
     * @param ignite Node.
     * @param ccfg Cache configuration.
     * @param backupKey Backup key.
     * @param nearKey Near key.
     * @throws Exception If failed.
     */
private void checkLocalRead(Ignite ignite, CacheConfiguration<Object, Object> ccfg, Integer backupKey, Integer nearKey) throws Exception {
    IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
    TestRecordingCommunicationSpi spi = recordGetRequests(ignite, ccfg.getNearConfiguration() != null);
    List<Object> msgs;
    if (nearKey != null) {
        assertNull(cache.get(nearKey));
        msgs = spi.recordedMessages(false);
        assertEquals(1, msgs.size());
    }
    assertNull(cache.get(backupKey));
    msgs = spi.recordedMessages(false);
    assertTrue(msgs.isEmpty());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi)

Aggregations

TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)41 Ignite (org.apache.ignite.Ignite)25 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)11 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)10 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 Message (org.apache.ignite.plugin.extensions.communication.Message)7 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)5 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)4 ArrayList (java.util.ArrayList)3 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)3 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)3 Transaction (org.apache.ignite.transactions.Transaction)3 List (java.util.List)2 CacheLoaderException (javax.cache.integration.CacheLoaderException)2 CacheWriterException (javax.cache.integration.CacheWriterException)2 IgniteException (org.apache.ignite.IgniteException)2 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)2 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)2 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)2