Search in sources :

Example 6 with GridMessageListener

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

the class DeploymentRequestOfUnknownClassProcessingTest method testResponseReceivingOnDeploymentRequestOfUnknownClass.

/**
 * @throws Exception If failed.
 */
@Test
public void testResponseReceivingOnDeploymentRequestOfUnknownClass() throws Exception {
    IgniteEx locNode = grid(0);
    IgniteEx remNode = grid(1);
    // Register deployment on remote node for attemt to load class on request receiving
    GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) });
    Class task = ldr.loadClass("org.apache.ignite.tests.p2p.P2PTestTaskExternalPath1");
    GridDeployment locDep = remNode.context().deploy().deploy(task, task.getClassLoader());
    final GridFutureAdapter<Void> testResultFut = new GridFutureAdapter<>();
    final LogListener remNodeLogLsnr = LogListener.matches(s -> s.matches("Failed to resolve class.*?" + UNKNOWN_CLASS_NAME + ".*")).build();
    remNodeLog.registerListener(remNodeLogLsnr);
    locNode.context().io().addMessageListener(TEST_TOPIC_NAME, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            try {
                assertTrue(msg instanceof GridDeploymentResponse);
                GridDeploymentResponse resp = (GridDeploymentResponse) msg;
                assertFalse("Unexpected response result, success=" + resp.success(), resp.success());
                String errMsg = resp.errorMessage();
                assertNotNull("Response should contain an error message.", errMsg);
                assertTrue("Response contains unexpected error message, errorMessage=" + errMsg, errMsg.matches("Requested resource not found \\(ignoring locally\\).*?" + UNKNOWN_CLASS_NAME + ".*"));
                testResultFut.onDone();
            } catch (Error e) {
                testResultFut.onDone(e);
            }
        }
    });
    GridDeploymentRequest req = new GridDeploymentRequest(TEST_TOPIC_NAME, locDep.classLoaderId(), UNKNOWN_CLASS_NAME, false);
    req.responseTopicBytes(U.marshal(locNode.context(), req.responseTopic()));
    locNode.context().io().sendToGridTopic(remNode.localNode(), TOPIC_CLASSLOAD, req, GridIoPolicy.P2P_POOL);
    // Сhecks that the expected response has been received.
    testResultFut.get(5_000, TimeUnit.MILLISECONDS);
    // Checks that error has been logged on remote node.
    assertTrue(remNodeLogLsnr.check());
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridTestProperties(org.apache.ignite.testframework.config.GridTestProperties) URL(java.net.URL) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) UUID(java.util.UUID) TOPIC_CLASSLOAD(org.apache.ignite.internal.GridTopic.TOPIC_CLASSLOAD) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) TimeUnit(java.util.concurrent.TimeUnit) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridIoPolicy(org.apache.ignite.internal.managers.communication.GridIoPolicy) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) LogListener(org.apache.ignite.testframework.LogListener) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) URL(java.net.URL) IgniteEx(org.apache.ignite.internal.IgniteEx) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with GridMessageListener

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

the class IgniteMarshallerCacheClientRequestsMappingOnMissTest method replaceWithStoppingMappingRequestListener.

/**
 */
private void replaceWithStoppingMappingRequestListener(GridIoManager ioMgr, final int nodeIdToStop, final CountDownLatch latch) {
    ioMgr.removeMessageListener(GridTopic.TOPIC_MAPPING_MARSH);
    ioMgr.addMessageListener(GridTopic.TOPIC_MAPPING_MARSH, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    mappingReqsCounter.incrementAndGet();
                    latch.countDown();
                    stopGrid(nodeIdToStop, true);
                }
            }).start();
        }
    });
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) UUID(java.util.UUID)

Example 8 with GridMessageListener

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

the class IgniteMarshallerCacheClientRequestsMappingOnMissTest method replaceWithCountingMappingRequestListener.

/**
 */
private void replaceWithCountingMappingRequestListener(GridIoManager ioMgr) {
    GridMessageListener[] lsnrs = U.field(ioMgr, "sysLsnrs");
    final GridMessageListener delegate = lsnrs[GridTopic.TOPIC_MAPPING_MARSH.ordinal()];
    GridMessageListener wrapper = new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            mappingReqsCounter.incrementAndGet();
            delegate.onMessage(nodeId, msg, plc);
        }
    };
    lsnrs[GridTopic.TOPIC_MAPPING_MARSH.ordinal()] = wrapper;
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) UUID(java.util.UUID)

Example 9 with GridMessageListener

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

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method replaceWithStoppingMappingRequestListener.

/**
 */
private void replaceWithStoppingMappingRequestListener(GridIoManager ioMgr, final int nodeIdToStop) {
    ioMgr.removeMessageListener(GridTopic.TOPIC_METADATA_REQ);
    ioMgr.addMessageListener(GridTopic.TOPIC_METADATA_REQ, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    metadataReqsCounter.incrementAndGet();
                    stopGrid(nodeIdToStop, true);
                }
            }).start();
        }
    });
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) BinaryObject(org.apache.ignite.binary.BinaryObject) UUID(java.util.UUID)

Example 10 with GridMessageListener

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

the class GridCacheBinaryObjectMetadataExchangeMultinodeTest method replaceWithCountingMappingRequestListener.

/**
 */
private void replaceWithCountingMappingRequestListener(GridIoManager ioMgr) {
    GridMessageListener[] lsnrs = U.field(ioMgr, "sysLsnrs");
    final GridMessageListener delegate = lsnrs[GridTopic.TOPIC_METADATA_REQ.ordinal()];
    GridMessageListener wrapper = new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            metadataReqsCounter.incrementAndGet();
            delegate.onMessage(nodeId, msg, plc);
        }
    };
    lsnrs[GridTopic.TOPIC_METADATA_REQ.ordinal()] = wrapper;
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) BinaryObject(org.apache.ignite.binary.BinaryObject) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)30 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)12 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)11 Event (org.apache.ignite.events.Event)11 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)11 GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)7 Test (org.junit.Test)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Collection (java.util.Collection)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 IgniteKernal (org.apache.ignite.internal.IgniteKernal)4 Message (org.apache.ignite.plugin.extensions.communication.Message)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IgniteException (org.apache.ignite.IgniteException)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3