Search in sources :

Example 6 with TestRecordingCommunicationSpi

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

the class IgniteCacheSingleGetMessageTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setClientMode(client);
    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 7 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 8 with TestRecordingCommunicationSpi

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

the class IgniteCacheClientMultiNodeUpdateTopologyLockTest method testPessimisticTx.

/**
     * @throws Exception If failed.
     */
public void testPessimisticTx() throws Exception {
    startGrids(3);
    client = true;
    Ignite clientNode = startGrid(3);
    client = false;
    IgniteCache<Integer, Integer> cache = clientNode.createCache(cacheConfiguration(0, FULL_SYNC));
    awaitPartitionMapExchange();
    Integer key1 = movingKeysAfterJoin(ignite(1), TEST_CACHE, 1).get(0);
    Integer key2 = movingKeysAfterJoin(ignite(2), TEST_CACHE, 1).get(0);
    log.info("Start tx [key1=" + key1 + ", key2=" + key2 + ']');
    IgniteInternalFuture<?> startFut;
    TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(ignite(2));
    final TestRecordingCommunicationSpi clientSpi = TestRecordingCommunicationSpi.spi(clientNode);
    final UUID node0Id = ignite(0).cluster().localNode().id();
    final UUID node2Id = ignite(2).cluster().localNode().id();
    spi2.record(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            if (!node0Id.equals(node.id()))
                return false;
            return (msg instanceof GridDhtPartitionsSingleMessage) && ((GridDhtPartitionsSingleMessage) msg).exchangeId() != null;
        }
    });
    clientSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(final ClusterNode node, final Message msg) {
            if (!node2Id.equals(node.id()))
                return false;
            if (msg instanceof GridNearTxFinishRequest) {
                log.info("Delay message [msg=" + msg + ']');
                GridTestUtils.runAsync(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(5000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        log.info("Send delayed message [msg=" + msg + ']');
                        clientSpi.stopBlock(true);
                    }
                });
                return true;
            }
            return false;
        }
    });
    try (Transaction tx = clientNode.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.put(key1, 1);
        startFut = GridTestUtils.runAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                startGrid(4);
                return null;
            }
        }, "start-thread");
        spi2.waitForRecorded();
        U.sleep(5);
        cache.put(key2, 2);
        log.info("Commit tx");
        tx.commit();
    }
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
    startFut.get();
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
    awaitPartitionMapExchange();
    assertEquals((Integer) 1, cache.get(key1));
    assertEquals((Integer) 2, cache.get(key2));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) Callable(java.util.concurrent.Callable) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest)

Example 9 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentClientJoin.

/**
     * Wait for rebalance, client node joins.
     *
     * @throws Exception If failed.
     */
public void testDelayAssignmentClientJoin() throws Exception {
    Ignite ignite0 = startServer(0, 1);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    blockSupplySend(spi, CACHE_NAME1);
    startServer(1, 2);
    startClient(2, 3);
    checkAffinity(3, topVer(3, 0), false);
    spi.stopBlock();
    checkAffinity(3, topVer(3, 1), true);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

Example 10 with TestRecordingCommunicationSpi

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

the class CacheLateAffinityAssignmentTest method testDelayAssignmentCoordinatorLeave1.

/**
     * Wait for rebalance, coordinator leaves, 2 nodes.
     *
     * @throws Exception If failed.
     */
public void testDelayAssignmentCoordinatorLeave1() throws Exception {
    Ignite ignite0 = startServer(0, 1);
    TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite0.configuration().getCommunicationSpi();
    blockSupplySend(spi, CACHE_NAME1);
    startServer(1, 2);
    stopNode(0, 3);
    checkAffinity(1, topVer(3, 0), true);
    checkNoExchange(1, topVer(3, 1));
    awaitPartitionMapExchange();
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite)

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