Search in sources :

Example 1 with TOPIC_CLASSLOAD

use of org.apache.ignite.internal.GridTopic.TOPIC_CLASSLOAD 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)

Aggregations

URL (java.net.URL)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 TOPIC_CLASSLOAD (org.apache.ignite.internal.GridTopic.TOPIC_CLASSLOAD)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 GridIoPolicy (org.apache.ignite.internal.managers.communication.GridIoPolicy)1 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 U (org.apache.ignite.internal.util.typedef.internal.U)1 GridTestExternalClassLoader (org.apache.ignite.testframework.GridTestExternalClassLoader)1 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)1 LogListener (org.apache.ignite.testframework.LogListener)1 GridTestProperties (org.apache.ignite.testframework.config.GridTestProperties)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1