Search in sources :

Example 61 with TestRecordingCommunicationSpi

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

the class CacheClientsConcurrentStartTest method doTest.

/**
 * @throws Exception If failed.
 */
private void doTest() throws Exception {
    final AtomicBoolean failed = new AtomicBoolean();
    startGrids(SRV_CNT);
    for (int i = 0; i < SRV_CNT; i++) {
        ((TestRecordingCommunicationSpi) ignite(i).configuration().getCommunicationSpi()).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

            @Override
            public boolean apply(ClusterNode node, Message msg) {
                if (msg instanceof GridDhtPartitionsFullMessage) {
                    try {
                        U.sleep(ThreadLocalRandom.current().nextLong(500) + 100);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                return false;
            }
        });
    }
    List<IgniteInternalFuture<?>> futs = new ArrayList<>();
    for (int i = 0; i < CLIENTS_CNT; i++) {
        final int idx = i;
        IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

            @Override
            public void run() {
                Random rnd = new Random();
                try {
                    Ignite ignite = startGrid(SRV_CNT + idx);
                    assertTrue(ignite.configuration().isClientMode());
                    for (int i = 0; i < CACHES / 2; i++) {
                        String cacheName = "cache-" + rnd.nextInt(CACHES);
                        IgniteCache<Object, Object> cache = getCache(ignite, cacheName);
                        cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
                        IgniteAtomicSequence seq = ignite.atomicSequence("seq-" + rnd.nextInt(20), 0, true);
                        seq.getAndIncrement();
                    }
                    while (!stopped) {
                        IgniteCache<Object, Object> cache = getCache(ignite, "cache-" + rnd.nextInt(CACHES));
                        int val = Math.abs(rnd.nextInt(100));
                        if (val >= 0 && val < 40)
                            cache.containsKey(ignite.cluster().localNode().id());
                        else if (val >= 40 && val < 80)
                            cache.get(ignite.cluster().localNode().id());
                        else
                            cache.put(ignite.cluster().localNode().id(), UUID.randomUUID());
                        Thread.sleep(10);
                    }
                } catch (Exception e) {
                    log.error("Unexpected error: " + e, e);
                    failed.set(true);
                }
            }
        }, 1, "client-thread");
        futs.add(fut);
    }
    Thread.sleep(10_000);
    stopped = true;
    for (IgniteInternalFuture<?> fut : futs) fut.get();
    assertFalse(failed.get());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) 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) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite)

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