Search in sources :

Example 16 with TestRecordingCommunicationSpi

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

the class CacheExchangeMessageDuplicatedStateTest method checkSingleMessages.

/**
     * @param crdIdx Coordinator node index.
     */
private void checkSingleMessages(int crdIdx) {
    int cnt = 0;
    for (Ignite ignite : Ignition.allGrids()) {
        if (getTestIgniteInstanceName(crdIdx).equals(ignite.name()) || ignite.configuration().isClientMode())
            continue;
        TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
        List<Object> msgs = commSpi0.recordedMessages(false);
        assertTrue(msgs.size() > 0);
        for (Object msg : msgs) {
            assertTrue("Unexpected messages: " + msg, msg instanceof GridDhtPartitionsSingleMessage);
            checkSingleMessage((GridDhtPartitionsSingleMessage) msg);
        }
        cnt++;
    }
    assertTrue(cnt > 0);
}
Also used : GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 17 with TestRecordingCommunicationSpi

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

the class CacheExchangeMessageDuplicatedStateTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    cfg.setClientMode(client);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    commSpi.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return (msg.getClass() == GridDhtPartitionsSingleMessage.class || msg.getClass() == GridDhtPartitionsFullMessage.class) && ((GridDhtPartitionsAbstractMessage) msg).exchangeId() != null;
        }
    });
    cfg.setCommunicationSpi(commSpi);
    List<CacheConfiguration> ccfgs = new ArrayList<>();
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE1);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF1_CACHE2);
        ccfg.setAffinity(new RendezvousAffinityFunction(false, 512));
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF3_CACHE1);
        ccfg.setBackups(3);
        RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, 64);
        ccfg.setAffinity(aff);
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE1);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setName(AFF4_FILTER_CACHE2);
        ccfg.setNodeFilter(new TestNodeFilter());
        ccfg.setAffinity(new RendezvousAffinityFunction());
        ccfgs.add(ccfg);
    }
    cfg.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) ArrayList(java.util.ArrayList) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 18 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentClientCacheStart.

/**
     * Wait for rebalance, client cache is started.
     *
     * @throws Exception If failed.
     */
public void testDelayAssignmentClientCacheStart() throws Exception {
    Ignite ignite0 = startServer(0, 1);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    blockSupplySend(spi, CACHE_NAME1);
    startServer(1, 2);
    startServer(2, 3);
    cacheC = new IgniteClosure<String, CacheConfiguration[]>() {

        @Override
        public CacheConfiguration[] apply(String nodeName) {
            return null;
        }
    };
    Ignite client = startClient(3, 4);
    checkAffinity(4, topVer(4, 0), false);
    assertNotNull(client.cache(CACHE_NAME1));
    checkAffinity(4, topVer(4, 1), false);
    spi.stopBlock();
    checkAffinity(4, topVer(4, 2), true);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 19 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentCacheDestroy.

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

Example 20 with TestRecordingCommunicationSpi

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

the class IgniteCacheNearLockValueSelfTest method testDhtVersion.

/**
     * @throws Exception If failed.
     */
public void testDhtVersion() throws Exception {
    CacheConfiguration<Object, Object> pCfg = new CacheConfiguration<>("partitioned");
    pCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    try (IgniteCache<Object, Object> cache = ignite(0).getOrCreateCache(pCfg, new NearCacheConfiguration<>())) {
        cache.put("key1", "val1");
        for (int i = 0; i < 3; i++) {
            try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
                cache.get("key1");
                tx.commit();
            }
            TestRecordingCommunicationSpi comm = (TestRecordingCommunicationSpi) ignite(0).configuration().getCommunicationSpi();
            Collection<GridNearLockRequest> reqs = (Collection) comm.recordedMessages(false);
            assertEquals(1, reqs.size());
            GridCacheAdapter<Object, Object> primary = ((IgniteKernal) grid(1)).internalCache("partitioned");
            GridCacheEntryEx dhtEntry = primary.peekEx(primary.context().toCacheKeyObject("key1"));
            assertNotNull(dhtEntry);
            GridNearLockRequest req = reqs.iterator().next();
            assertEquals(dhtEntry.version(), req.dhtVersion(0));
            // Check entry version in near cache after commit.
            GridCacheAdapter<Object, Object> near = ((IgniteKernal) grid(0)).internalCache("partitioned");
            GridNearCacheEntry nearEntry = (GridNearCacheEntry) near.peekEx(near.context().toCacheKeyObject("key1"));
            assertNotNull(nearEntry);
            assertEquals(dhtEntry.version(), nearEntry.dhtVersion());
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridNearLockRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockRequest) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridNearCacheEntry(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry) Transaction(org.apache.ignite.transactions.Transaction) Collection(java.util.Collection) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

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