Search in sources :

Example 21 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class ServiceReassignmentFunctionSelfTest method mockServiceProcessor.

/**
 * Mocks IgniteServiceProcessor to test method {@link IgniteServiceProcessor#reassign(IgniteUuid,
 * ServiceConfiguration, AffinityTopologyVersion, TreeMap)} AffinityTopologyVersion, Map)} )}.
 */
private IgniteServiceProcessor mockServiceProcessor() {
    GridTestKernalContext spyCtx = spy(new GridTestKernalContext(new GridTestLog4jLogger()));
    GridEventStorageManager mockEvt = mock(GridEventStorageManager.class);
    GridIoManager mockIo = mock(GridIoManager.class);
    GridSystemViewManager sysViewMgr = mock(GridSystemViewManager.class);
    when(spyCtx.event()).thenReturn(mockEvt);
    when(spyCtx.io()).thenReturn(mockIo);
    when(spyCtx.systemView()).thenReturn(sysViewMgr);
    GridDiscoveryManager mockDisco = mock(GridDiscoveryManager.class);
    when(mockDisco.nodes(any(AffinityTopologyVersion.class))).thenReturn(new ArrayList<>(nodes));
    spyCtx.add(mockDisco);
    return new IgniteServiceProcessor(spyCtx);
}
Also used : GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 22 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class GridCacheMessageSelfTest method doSend.

/**
 * @throws Exception If failed.
 */
private void doSend() throws Exception {
    GridIoManager mgr0 = grid(0).context().io();
    GridIoManager mgr1 = grid(1).context().io();
    String topic = "test-topic";
    final CountDownLatch latch = new CountDownLatch(SAMPLE_CNT);
    mgr1.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            try {
                latch.countDown();
                Collection<TestMessage1> messages = ((TestMessage) msg).entries();
                assertEquals(10, messages.size());
                int cnt = 0;
                for (TestMessage1 msg1 : messages) {
                    assertTrue(msg1.body().contains(TEST_BODY));
                    int i = Integer.parseInt(msg1.body().substring(TEST_BODY.length() + 1));
                    assertEquals(cnt, i);
                    TestMessage2 msg2 = (TestMessage2) msg1.message();
                    assertEquals(TEST_BODY + "_" + i + "_2", msg2.body());
                    assertEquals(grid(0).localNode().id(), msg2.nodeId());
                    assertEquals(i, msg2.id());
                    GridTestMessage msg3 = (GridTestMessage) msg2.message();
                    assertEquals(cnt, msg3.getMsgId());
                    assertEquals(grid(1).localNode().id(), msg3.getSourceNodeId());
                    cnt++;
                }
            } catch (Exception e) {
                fail("Exception " + e.getMessage());
            }
        }
    });
    TestMessage msg = new TestMessage();
    for (int i = 0; i < 10; i++) {
        TestMessage2 mes1 = new TestMessage2();
        mes1.init(new GridTestMessage(grid(1).localNode().id(), i, 0), grid(0).localNode().id(), i, TEST_BODY + "_" + i + "_2");
        TestMessage1 mes2 = new TestMessage1();
        mes2.init(mes1, TEST_BODY + "_" + i);
        msg.add(mes2);
    }
    mgr0.sendToCustomTopic(grid(1).localNode(), topic, msg, GridIoPolicy.PUBLIC_POOL);
    assert latch.await(3, SECONDS);
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) Collection(java.util.Collection) GridDirectCollection(org.apache.ignite.internal.GridDirectCollection) UUID(java.util.UUID)

Aggregations

GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 UUID (java.util.UUID)8 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)7 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)7 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Event (org.apache.ignite.events.Event)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 LongAdder (java.util.concurrent.atomic.LongAdder)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 GridEventStorageManager (org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager)3 RuntimeMXBean (java.lang.management.RuntimeMXBean)2 DecimalFormat (java.text.DecimalFormat)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2