Search in sources :

Example 46 with IgniteBiPredicate

use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.

the class IgniteClientCheckClusterGroupLocalIdAfterReconnect method testClusterGroupLocalIdAfterClientReconnect.

/**
 * Test checks that local id in cluster group was change and client
 * will be able to send the message to itself after reconnect.
 */
@Test
public void testClusterGroupLocalIdAfterClientReconnect() throws Exception {
    Ignite server = startGrid(0);
    Ignite client = startClientGrid(1);
    UUID clientId = client.cluster().node().id();
    ClusterGroup cg1 = client.cluster().forLocal();
    assertNotNull("Local client ID is different with local ClusterGroup node id. ", cg1.node(clientId));
    // check sending messages is possible while connected
    IgniteMessaging messaging = client.message(client.cluster().forLocal());
    CountDownLatch topicSignal = new CountDownLatch(2);
    messaging.localListen("topic", (IgniteBiPredicate<UUID, Object>) (uuid, n) -> {
        topicSignal.countDown();
        return true;
    });
    // countDown latch = 1
    messaging.send("topic", new External());
    CountDownLatch discSignal = new CountDownLatch(1);
    client.events().localListen((IgnitePredicate<DiscoveryEvent>) evt -> {
        discSignal.countDown();
        return true;
    }, EventType.EVT_CLIENT_NODE_DISCONNECTED);
    server.close();
    assertTrue("client did not disconnect", discSignal.await(LATCH_TIMEOUT, TimeUnit.SECONDS));
    startGrid(0);
    // wait for client reconnect
    IgniteFuture future = client.cluster().clientReconnectFuture();
    assertNotNull(future);
    // throws if times out
    future.get(20_000);
    ClusterGroup cg2 = client.cluster().forLocal();
    UUID newClientId = client.cluster().localNode().id();
    assertNotNull("Local client ID wasn't changed for local ClusterGroup.", cg2.node(newClientId));
    awaitPartitionMapExchange();
    // check sending messages is possible after reconnecting
    // countDown latch = 0
    messaging = client.message(client.cluster().forLocal());
    messaging.send("topic", new External());
    assertTrue("Message wasn't received", topicSignal.await(LATCH_TIMEOUT, TimeUnit.SECONDS));
}
Also used : IgniteMessaging(org.apache.ignite.IgniteMessaging) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Externalizable(java.io.Externalizable) EventType(org.apache.ignite.events.EventType) ObjectOutput(java.io.ObjectOutput) IOException(java.io.IOException) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) After(org.junit.After) ObjectInput(java.io.ObjectInput) IgniteMessaging(org.apache.ignite.IgniteMessaging) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 47 with IgniteBiPredicate

use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.

the class TxPartitionCounterStateAbstractTest method createBackupMessagePredicate.

/**
 * @param wrappedBackupSpi Wrapped backup spi.
 * @param futMap Future map.
 * @param cb Callback.
 */
private IgniteBiPredicate<ClusterNode, Message> createBackupMessagePredicate(TestRecordingCommunicationSpi wrappedBackupSpi, Map<IgniteUuid, GridCacheVersion> futMap, TxCallback cb) {
    return (node, msg) -> {
        if (msg instanceof GridDhtTxPrepareResponse) {
            IgniteEx from = fromNode(wrappedBackupSpi);
            IgniteEx to = IgnitionEx.gridxx(node.id());
            GridDhtTxPrepareResponse resp = (GridDhtTxPrepareResponse) msg;
            GridCacheVersion ver = futMap.get(resp.futureId());
            if (ver == null)
                // Message from parallel partition.
                return false;
            IgniteInternalTx backupTx = findTx(from, ver, false);
            return cb.afterBackupPrepare(to, from, backupTx, ver.asIgniteUuid(), createSendFuture(wrappedBackupSpi, msg));
        } else if (msg instanceof GridDhtTxFinishResponse) {
            IgniteEx from = fromNode(wrappedBackupSpi);
            IgniteEx to = IgnitionEx.gridxx(node.id());
            GridDhtTxFinishResponse resp = (GridDhtTxFinishResponse) msg;
            GridCacheVersion ver = futMap.get(resp.futureId());
            if (ver == null)
                // Message from parallel partition.
                return false;
            // Version is null if message is a response to checkCommittedRequest.
            return cb.afterBackupFinish(to, from, ver.asIgniteUuid(), createSendFuture(wrappedBackupSpi, msg));
        }
        return false;
    };
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgnitionEx(org.apache.ignite.internal.IgnitionEx) TestRecordingCommunicationSpi.spi(org.apache.ignite.internal.TestRecordingCommunicationSpi.spi) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridNearTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridNearTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) GridDhtTxFinishRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest) CyclicBarrier(java.util.concurrent.CyclicBarrier) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) LOG_ONLY(org.apache.ignite.configuration.WALMode.LOG_ONLY) IgniteWalRebalanceTest(org.apache.ignite.internal.processors.cache.persistence.db.wal.IgniteWalRebalanceTest) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) Message(org.apache.ignite.plugin.extensions.communication.Message) Queue(java.util.Queue) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridTestUtils.runMultiThreadedAsync(org.apache.ignite.testframework.GridTestUtils.runMultiThreadedAsync) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IntStream(java.util.stream.IntStream) GridDhtTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareRequest) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) Collectors.toCollection(java.util.stream.Collectors.toCollection) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareResponse) IgniteClosure(org.apache.ignite.lang.IgniteClosure) DAYS(java.util.concurrent.TimeUnit.DAYS) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridNearTxPrepareRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareRequest) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) GridNearTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishResponse) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Ignite(org.apache.ignite.Ignite) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) T3(org.apache.ignite.internal.util.typedef.T3) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) T2(org.apache.ignite.internal.util.typedef.T2) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheTxRecoveryRequest(org.apache.ignite.internal.processors.cache.distributed.GridCacheTxRecoveryRequest) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Collections(java.util.Collections) GridDhtTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishResponse) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtTxFinishResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishResponse) GridDhtTxPrepareResponse(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareResponse)

Example 48 with IgniteBiPredicate

use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.

the class TxRollbackOnIncorrectParamsTest method testRollbackInsideLocalListenerAfterRemoteFilter.

/**
 */
@Test
public void testRollbackInsideLocalListenerAfterRemoteFilter() throws Exception {
    Ignite ignite = startGrid(0);
    Ignite remote = startGrid(1);
    IgniteCache cacheLocal = ignite.getOrCreateCache(defaultCacheConfiguration());
    IgniteCache cacheRemote = remote.getOrCreateCache(defaultCacheConfiguration());
    AtomicBoolean rollbackFailed = new AtomicBoolean();
    AtomicBoolean alreadyRolledBack = new AtomicBoolean();
    ignite.events().remoteListen((IgniteBiPredicate<UUID, Event>) (uuid, e) -> {
        assert e instanceof TransactionStateChangedEvent;
        TransactionStateChangedEvent evt = (TransactionStateChangedEvent) e;
        Transaction tx = evt.tx();
        try {
            tx.setRollbackOnly();
        } catch (IgniteException ignored) {
            alreadyRolledBack.set(rollbackFailed.getAndSet(true));
        }
        return true;
    }, (IgnitePredicate<Event>) e -> {
        assert e instanceof TransactionStateChangedEvent;
        return true;
    }, EVT_TX_STARTED);
    assertFalse(rollbackFailed.get());
    assertFalse(alreadyRolledBack.get());
    try (Transaction tx = ignite.transactions().txStart()) {
        cacheLocal.put(1, 1);
        tx.commit();
        fail("Should fail prior this line.");
    } catch (CacheException ex) {
        if (MvccFeatureChecker.forcedMvcc())
            assertTrue(ex.toString(), ex.getCause() instanceof TransactionAlreadyCompletedException);
        else
            assertTrue(ex.toString(), ex.getCause() instanceof TransactionRollbackException);
    }
    assertFalse(rollbackFailed.get());
    assertFalse(alreadyRolledBack.get());
    try (Transaction tx = remote.transactions().txStart()) {
        cacheRemote.put(1, 2);
        tx.commit();
    }
    assertTrue(GridTestUtils.waitForCondition(rollbackFailed::get, 5_000));
    assertFalse(alreadyRolledBack.get());
}
Also used : TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) Transaction(org.apache.ignite.transactions.Transaction) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransactionAlreadyCompletedException(org.apache.ignite.transactions.TransactionAlreadyCompletedException) Test(org.junit.Test) EVT_TX_STARTED(org.apache.ignite.events.EventType.EVT_TX_STARTED) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) TransactionStateChangedEvent(org.apache.ignite.events.TransactionStateChangedEvent) CacheException(javax.cache.CacheException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.apache.ignite.transactions.Transaction) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) IgniteCache(org.apache.ignite.IgniteCache) Event(org.apache.ignite.events.Event) TransactionStateChangedEvent(org.apache.ignite.events.TransactionStateChangedEvent) Ignite(org.apache.ignite.Ignite) TransactionAlreadyCompletedException(org.apache.ignite.transactions.TransactionAlreadyCompletedException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) UUID(java.util.UUID) TransactionStateChangedEvent(org.apache.ignite.events.TransactionStateChangedEvent) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 49 with IgniteBiPredicate

use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.

the class CacheLateAffinityAssignmentTest method testNoForceKeysRequests.

/**
 * @throws Exception If failed.
 */
@Test
public void testNoForceKeysRequests() throws Exception {
    cacheC = new IgniteClosure<String, CacheConfiguration[]>() {

        @Override
        public CacheConfiguration[] apply(String s) {
            return null;
        }
    };
    final AtomicBoolean fail = new AtomicBoolean();
    spiC = new IgniteClosure<String, TestRecordingCommunicationSpi>() {

        @Override
        public TestRecordingCommunicationSpi apply(String s) {
            TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
            spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

                @Override
                public boolean apply(ClusterNode node, Message msg) {
                    if (msg instanceof GridDhtForceKeysRequest || msg instanceof GridDhtForceKeysResponse) {
                        fail.set(true);
                        U.dumpStack(log, "Unexpected message: " + msg);
                    }
                    return false;
                }
            });
            return spi;
        }
    };
    final int SRVS = 3;
    for (int i = 0; i < SRVS; i++) startGrid(i);
    startClientGrid(SRVS);
    final List<CacheConfiguration> ccfgs = new ArrayList<>();
    ccfgs.add(cacheConfiguration("tc1", TRANSACTIONAL, 0));
    ccfgs.add(cacheConfiguration("tc2", TRANSACTIONAL, 1));
    ccfgs.add(cacheConfiguration("tc3", TRANSACTIONAL, 2));
    for (CacheConfiguration ccfg : ccfgs) ignite(0).createCache(ccfg);
    final int NODES = SRVS + 1;
    final AtomicInteger nodeIdx = new AtomicInteger();
    final long stopTime = System.currentTimeMillis() + 60_000;
    IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            int idx = nodeIdx.getAndIncrement();
            Ignite node = grid(idx);
            List<IgniteCache<Object, Object>> caches = new ArrayList<>();
            for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
            while (!fail.get() && System.currentTimeMillis() < stopTime) {
                for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
            }
            return null;
        }
    }, NODES, "update-thread");
    IgniteInternalFuture<?> srvRestartFut = GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            while (!fail.get() && System.currentTimeMillis() < stopTime) {
                Ignite node = startGrid(NODES);
                List<IgniteCache<Object, Object>> caches = new ArrayList<>();
                for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
                for (int i = 0; i < 2; i++) {
                    for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
                }
                U.sleep(500);
                stopGrid(NODES);
                U.sleep(500);
            }
            return null;
        }
    }, "srv-restart");
    srvRestartFut.get();
    updateFut.get();
    assertFalse("Unexpected messages.", fail.get());
}
Also used : GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) GridDhtPartitionsAbstractMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsAbstractMessage) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) ArrayList(java.util.ArrayList) GridDhtForceKeysRequest(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest) Ignite(org.apache.ignite.Ignite) List(java.util.List) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgniteCache(org.apache.ignite.IgniteCache) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with IgniteBiPredicate

use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.

the class GridP2PContinuousDeploymentClientDisconnectTest method testMessageRemoteListen.

/**
 * Test starts 1 server node and 1 client node. Class-loading request for the {@link #P2P_TEST_OBJ_RSRC_NAME}
 * resource blocks on the client node. The client node tries to deploy remote message listener for
 * the cache {@link #DEFAULT_CACHE_NAME}.
 * Expected that exception with 'Failed to unmarshal deployable object.' error message will be thrown and
 * the server node wouldn't be failed.
 *
 * @throws Exception If failed.
 */
@Test
public void testMessageRemoteListen() throws Exception {
    Class<IgniteBiPredicate<UUID, String>> rmtLsnrCls = (Class<IgniteBiPredicate<UUID, String>>) getExternalClassLoader().loadClass(MSG_REMOTE_LSNR_CLS_NAME);
    LogListener lsnr = LogListener.matches("Failed to unmarshal deployable object.").build();
    testLog.registerListener(lsnr);
    assertThrowsWithCause(() -> grid(1).message().remoteListen("test", rmtLsnrCls.newInstance()), IgniteException.class);
    assertTrue(lsnr.check());
    // Check that the failure handler was not called.
    assertFalse(failure.get());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)57 Ignite (org.apache.ignite.Ignite)36 UUID (java.util.UUID)28 IgniteCache (org.apache.ignite.IgniteCache)22 Test (org.junit.Test)22 List (java.util.List)21 Collection (java.util.Collection)18 Map (java.util.Map)18 HashMap (java.util.HashMap)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 ClusterNode (org.apache.ignite.cluster.ClusterNode)17 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)17 ArrayList (java.util.ArrayList)16 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)16 ScanQuery (org.apache.ignite.cache.query.ScanQuery)15 IgniteEx (org.apache.ignite.internal.IgniteEx)15 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 IgniteException (org.apache.ignite.IgniteException)13 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)13