Search in sources :

Example 46 with Message

use of org.apache.ignite.plugin.extensions.communication.Message 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 47 with Message

use of org.apache.ignite.plugin.extensions.communication.Message 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 48 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class IgniteCacheAtomicProtocolTest method testPutMissedDhtRequest_UnstableTopology.

/**
     * @throws Exception If failed.
     */
public void testPutMissedDhtRequest_UnstableTopology() throws Exception {
    blockRebalance = true;
    ccfg = cacheConfiguration(1, FULL_SYNC);
    startServers(4);
    client = true;
    Ignite client = startGrid(4);
    IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE);
    testSpi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return msg instanceof GridDhtAtomicAbstractUpdateRequest;
        }
    });
    Integer key = primaryKey(ignite(0).cache(TEST_CACHE));
    log.info("Start put [key=" + key + ']');
    IgniteFuture<?> fut = nearCache.putAsync(key, key);
    U.sleep(500);
    assertFalse(fut.isDone());
    stopGrid(0);
    fut.get();
    checkData(F.asMap(key, key));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheMessage(org.apache.ignite.internal.processors.cache.GridCacheMessage) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) Ignite(org.apache.ignite.Ignite)

Aggregations

Message (org.apache.ignite.plugin.extensions.communication.Message)48 ClusterNode (org.apache.ignite.cluster.ClusterNode)25 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Ignite (org.apache.ignite.Ignite)10 UUID (java.util.UUID)9 IgniteException (org.apache.ignite.IgniteException)9 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)9 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)8 HashMap (java.util.HashMap)7 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)7 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Collection (java.util.Collection)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)4 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)4