Search in sources :

Example 11 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridP2PSameClassLoaderSelfTest method processTest.

/**
     * Test.
     * @throws Exception if error occur
     */
@SuppressWarnings({ "unchecked" })
private void processTest() throws Exception {
    try {
        final Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        Ignite ignite3 = startGrid(3);
        assert GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return ignite1.cluster().nodes().size() == 3;
            }
        }, 20000L);
        Class task1 = CLASS_LOADER.loadClass(TEST_TASK1_NAME);
        Class task2 = CLASS_LOADER.loadClass(TEST_TASK2_NAME);
        // Execute task1 and task2 from node1 on node2 and make sure that they reuse same class loader on node2.
        Integer res1 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        Integer res2 = (Integer) ignite1.compute().execute(task2, ignite2.cluster().localNode().id());
        // Class loaders are same
        assert res1.equals(res2);
        Integer res3 = (Integer) ignite3.compute().execute(task1, ignite2.cluster().localNode().id());
        Integer res4 = (Integer) ignite3.compute().execute(task2, ignite2.cluster().localNode().id());
        assert res3.equals(res4);
    } finally {
        stopGrid(1);
        stopGrid(2);
        stopGrid(3);
    }
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) Ignite(org.apache.ignite.Ignite)

Example 12 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridListenActorSelfTest method testRespondToRemote.

/**
     * Testing {@link org.apache.ignite.messaging.MessagingListenActor#respond(UUID, Object)} method.
     *
     * @throws Exception If failed.
     */
public void testRespondToRemote() throws Exception {
    startGrid(1);
    try {
        final ClusterNode rmt = grid(1).localNode();
        grid().message().localListen(null, new MessagingListenActor<String>() {

            @Override
            protected void receive(UUID nodeId, String rcvMsg) throws IgniteException {
                System.out.println("Local node received message: '" + rcvMsg + "'");
                respond(rmt.id(), "RESPONSE");
            }
        });
        final AtomicInteger cnt = new AtomicInteger();
        // Response listener
        grid(1).message().localListen(null, new MessagingListenActor<String>() {

            @Override
            public void receive(UUID nodeId, String rcvMsg) {
                if ("RESPONSE".equals(rcvMsg)) {
                    System.out.println("Remote node received message: '" + rcvMsg + "'");
                    cnt.incrementAndGet();
                }
            }
        });
        grid().message().send(null, "REQUEST");
        assert GridTestUtils.waitForCondition(new PA() {

            @Override
            public boolean apply() {
                return cnt.intValue() == 1;
            }
        }, getTestTimeout());
    } finally {
        stopGrid(1);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) PA(org.apache.ignite.internal.util.typedef.PA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) UUID(java.util.UUID)

Example 13 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class IgniteDbPutGetAbstractTest method checkEmpty.

private void checkEmpty(final GridCacheAdapter internalCache, final Object key) throws Exception {
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return internalCache.peekEx(key) == null;
        }
    }, 5000);
    assertNull(internalCache.peekEx(key));
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA)

Example 14 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridMessagingSelfTest method testAsyncOld.

/**
     * @throws Exception If failed.
     */
public void testAsyncOld() throws Exception {
    final AtomicInteger msgCnt = new AtomicInteger();
    TestTcpDiscoverySpi discoSpi = (TestTcpDiscoverySpi) ignite2.configuration().getDiscoverySpi();
    assertFalse(ignite2.message().isAsync());
    final IgniteMessaging msg = ignite2.message().withAsync();
    assertTrue(msg.isAsync());
    assertFalse(ignite2.message().isAsync());
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    discoSpi.blockCustomEvent();
    final String topic = "topic";
    UUID id = msg.remoteListen(topic, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt.incrementAndGet();
            return true;
        }
    });
    Assert.assertNull(id);
    IgniteFuture<UUID> starFut = msg.future();
    Assert.assertNotNull(starFut);
    U.sleep(500);
    Assert.assertFalse(starFut.isDone());
    discoSpi.stopBlock();
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    id = starFut.get();
    Assert.assertNotNull(id);
    Assert.assertTrue(starFut.isDone());
    discoSpi.blockCustomEvent();
    message(ignite1.cluster().forRemotes()).send(topic, "msg1");
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return msgCnt.get() > 0;
        }
    }, 5000);
    assertEquals(1, msgCnt.get());
    msg.stopRemoteListen(id);
    IgniteFuture<?> stopFut = msg.future();
    Assert.assertNotNull(stopFut);
    GridTestUtils.assertThrows(log, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            msg.future();
            return null;
        }
    }, IllegalStateException.class, null);
    U.sleep(500);
    Assert.assertFalse(stopFut.isDone());
    discoSpi.stopBlock();
    stopFut.get();
    Assert.assertTrue(stopFut.isDone());
    message(ignite1.cluster().forRemotes()).send(topic, "msg2");
    U.sleep(1000);
    assertEquals(1, msgCnt.get());
}
Also used : IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) PA(org.apache.ignite.internal.util.typedef.PA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteMessaging(org.apache.ignite.IgniteMessaging) UUID(java.util.UUID)

Example 15 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridMessagingSelfTest method testStopRemoteListen.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("TooBroadScope")
public void testStopRemoteListen() throws Exception {
    final AtomicInteger msgCnt1 = new AtomicInteger();
    final AtomicInteger msgCnt2 = new AtomicInteger();
    final AtomicInteger msgCnt3 = new AtomicInteger();
    final String topic1 = null;
    final String topic2 = "top2";
    final String topic3 = "top3";
    UUID id1 = ignite2.message().remoteListen(topic1, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener1 received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt1.incrementAndGet();
            return true;
        }
    });
    UUID id2 = ignite2.message().remoteListen(topic2, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener2 received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt2.incrementAndGet();
            return true;
        }
    });
    UUID id3 = ignite2.message().remoteListen(topic3, new P2<UUID, Object>() {

        @Override
        public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() + " Listener3 received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');
            msgCnt3.incrementAndGet();
            return true;
        }
    });
    message(ignite1.cluster().forRemotes()).send(topic1, "msg1-1");
    message(ignite1.cluster().forRemotes()).send(topic2, "msg1-2");
    message(ignite1.cluster().forRemotes()).send(topic3, "msg1-3");
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return msgCnt1.get() > 0 && msgCnt2.get() > 0 && msgCnt3.get() > 0;
        }
    }, 5000);
    assertEquals(1, msgCnt1.get());
    assertEquals(1, msgCnt2.get());
    assertEquals(1, msgCnt3.get());
    ignite2.message().stopRemoteListen(id2);
    message(ignite1.cluster().forRemotes()).send(topic1, "msg2-1");
    message(ignite1.cluster().forRemotes()).send(topic2, "msg2-2");
    message(ignite1.cluster().forRemotes()).send(topic3, "msg2-3");
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return msgCnt1.get() > 1 && msgCnt3.get() > 1;
        }
    }, 5000);
    assertEquals(2, msgCnt1.get());
    assertEquals(1, msgCnt2.get());
    assertEquals(2, msgCnt3.get());
    // Try remove one more time.
    ignite2.message().stopRemoteListen(id2);
    ignite2.message().stopRemoteListen(id1);
    ignite2.message().stopRemoteListen(id3);
    message(ignite1.cluster().forRemotes()).send(topic1, "msg3-1");
    message(ignite1.cluster().forRemotes()).send(topic2, "msg3-2");
    message(ignite1.cluster().forRemotes()).send(topic3, "msg3-3");
    U.sleep(1000);
    assertEquals(2, msgCnt1.get());
    assertEquals(1, msgCnt2.get());
    assertEquals(2, msgCnt3.get());
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UUID(java.util.UUID)

Aggregations

PA (org.apache.ignite.internal.util.typedef.PA)48 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 Ignite (org.apache.ignite.Ignite)17 ArrayList (java.util.ArrayList)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 UUID (java.util.UUID)9 CacheEntryEvent (javax.cache.event.CacheEntryEvent)9 IgniteException (org.apache.ignite.IgniteException)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Transaction (org.apache.ignite.transactions.Transaction)4