Search in sources :

Example 56 with TestRecordingCommunicationSpi

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

the class IgniteTxCachePrimarySyncTest method singleKeyCommitFromPrimary.

/**
 * @param ignite Node executing cache operation.
 * @param ccfg Cache configuration.
 * @param c Cache update closure.
 * @throws Exception If failed.
 */
private void singleKeyCommitFromPrimary(Ignite ignite, final CacheConfiguration<Object, Object> ccfg, IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
    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);
    commSpi0.record(GridDhtTxFinishRequest.class);
    commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtTxFinishRequest;
        }
    });
    c.apply(key, cache);
    assertEquals(key, cache.localPeek(key));
    U.sleep(50);
    for (int i = 0; i < SRVS; i++) {
        Ignite node = ignite(i);
        if (node != ignite)
            assertNull(node.cache(DEFAULT_CACHE_NAME).localPeek(key));
    }
    commSpi0.stopBlock(true);
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
    List<Object> msgs = commSpi0.recordedMessages(true);
    assertEquals(ccfg.getBackups(), msgs.size());
    cache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    c.apply(key, cache);
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) Ignite(org.apache.ignite.Ignite)

Example 57 with TestRecordingCommunicationSpi

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

the class IgniteTxCachePrimarySyncTest method singleKeyCommit.

/**
 * @param client Node executing cache operation.
 * @param ccfg Cache configuration.
 * @param c Cache update closure.
 * @throws Exception If failed.
 */
private void singleKeyCommit(Ignite client, final CacheConfiguration<Object, Object> ccfg, 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);
    IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
    commSpiClient.record(GridNearTxFinishRequest.class);
    commSpi0.record(GridDhtTxFinishRequest.class);
    commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtTxFinishRequest;
        }
    });
    c.apply(key, clientCache);
    assertEquals(key, cache.localPeek(key));
    U.sleep(50);
    boolean nearCache = ((IgniteCacheProxy) clientCache).context().isNear();
    for (int i = 1; i < NODES; i++) {
        Ignite node = ignite(i);
        if (nearCache && node == client && !node.affinity(ccfg.getName()).isPrimaryOrBackup(node.cluster().localNode(), key))
            assertEquals("Invalid value for node: " + i, key, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
        else
            assertNull("Invalid value for node: " + i, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
    }
    commSpi0.stopBlock(true);
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
    List<Object> msgs = commSpiClient.recordedMessages(true);
    assertEquals(1, msgs.size());
    GridNearTxFinishRequest req = (GridNearTxFinishRequest) msgs.get(0);
    assertEquals(PRIMARY_SYNC, req.syncMode());
    msgs = commSpi0.recordedMessages(true);
    assertEquals(ccfg.getBackups(), msgs.size());
    clientCache.remove(key);
    waitKeyRemoved(ccfg.getName(), key);
    c.apply(key, clientCache);
    waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)

Example 58 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();
                final int grpId = groupIdForCache(ignite, ccfg.getName());
                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).groupId() == grpId;
                    }
                });
            }
            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 59 with TestRecordingCommunicationSpi

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

the class IgniteCacheReadFromBackupTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    cfg.setCommunicationSpi(commSpi);
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(ipFinder);
    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 60 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)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