Search in sources :

Example 1 with LogListener

use of org.apache.ignite.testframework.LogListener 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 2 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class DiagnosticLogForPartitionStatesTest method doTest.

/**
 * @param cfgs Cache configurations.
 * @param msgExp {@code true} if warning message is expected.
 * @throws Exception If failed.
 */
private void doTest(List<CacheConfiguration<Integer, Integer>> cfgs, boolean msgExp) throws Exception {
    String name = (cfgs.size() == 1) ? cfgs.get(0).getName() : cfgs.get(0).getGroupName();
    LogListener lsnr = LogListener.matches(s -> s.startsWith(String.format(PARTITION_STATE_FAILED_MSG, name, ANY_MSG))).times(msgExp ? 1 : 0).build();
    log.registerListener(lsnr);
    IgniteEx node1 = startGrid(0);
    IgniteEx node2 = startGrid(1);
    node1.cluster().active(true);
    List<IgniteCache<Integer, Integer>> caches = cfgs.stream().map(cfg -> node1.getOrCreateCache(cfg)).collect(Collectors.toList());
    Map<String, Set<Integer>> clearKeys = new HashMap<>();
    for (IgniteCache<Integer, Integer> cache : caches) {
        String cacheName = cache.getName();
        Set<Integer> clr = new HashSet<>();
        for (int i = 0; i < 100; i++) {
            cache.put(i, i);
            if (node2.affinity(cacheName).isPrimary(node2.localNode(), i))
                clr.add(i);
        }
        clearKeys.put(cacheName, clr);
    }
    for (IgniteCache<Integer, Integer> c : caches) {
        node2.context().cache().cache(c.getName()).clearLocallyAll(clearKeys.get(c.getName()), true, true, true);
    }
    // Trigger partition map exchange and therefore trigger partitions validation.
    startGrid(2);
    awaitPartitionMapExchange();
    assertTrue(lsnr.check());
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) Arrays(java.util.Arrays) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) AccessedExpiryPolicy(javax.cache.expiry.AccessedExpiryPolicy) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) EternalExpiryPolicy(javax.cache.expiry.EternalExpiryPolicy) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Map(java.util.Map) After(org.junit.After) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Collections(java.util.Collections) Duration(javax.cache.expiry.Duration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PARTITION_STATE_FAILED_MSG(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.PARTITION_STATE_FAILED_MSG) Set(java.util.Set) HashSet(java.util.HashSet) LogListener(org.apache.ignite.testframework.LogListener) HashMap(java.util.HashMap) IgniteCache(org.apache.ignite.IgniteCache) HashSet(java.util.HashSet)

Example 3 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class ConsistentIdImplicitlyExplicitlyTest method testConsistentIdNotConfiguredWithPersistence.

/**
 * Consistent ID is not configurent neither in the {@link IgniteConfiguration} nor in the JVM property, and
 * persistent enabled.
 *
 * @throws Exception if failed.
 */
@Test
public void testConsistentIdNotConfiguredWithPersistence() throws Exception {
    persistenceEnabled = true;
    LogListener lsnr = expectLogEvent(WARN_MESSAGE, 1);
    Ignite ignite = startGrid(0);
    assertNull(ignite.configuration().getConsistentId());
    assertTrue(UUID_PATTERN.matcher(ignite.cluster().localNode().consistentId().toString()).find());
    assertTrue(lsnr.check());
    info("Consistent ID: " + ignite.cluster().localNode().consistentId());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class ConsistentIdImplicitlyExplicitlyTest method expectLogEvent.

/**
 * @param eventMsg Event message.
 * @param cnt Number of expected events.
 */
private LogListener expectLogEvent(String eventMsg, int cnt) {
    LogListener lsnr = LogListener.matches(s -> s.startsWith(eventMsg)).times(cnt).build();
    log.registerListener(lsnr);
    return lsnr;
}
Also used : LogListener(org.apache.ignite.testframework.LogListener)

Example 5 with LogListener

use of org.apache.ignite.testframework.LogListener in project ignite by apache.

the class ConsistentIdImplicitlyExplicitlyTest method testConsistentIdNotConfigured.

/**
 * Consistent ID is not configured neither in the {@link IgniteConfiguration} nor via the JVM property.
 *
 * @throws Exception if failed.
 */
@Test
public void testConsistentIdNotConfigured() throws Exception {
    LogListener lsnr = expectLogEvent(WARN_MESSAGE, 0);
    Ignite ignite = startGrid(0);
    assertNull(ignite.configuration().getConsistentId());
    assertTrue(ADDR_WITH_PORT_PATTERN.matcher(ignite.cluster().localNode().consistentId().toString()).find());
    assertTrue(lsnr.check());
    info("Consistent ID: " + ignite.cluster().localNode().consistentId());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

LogListener (org.apache.ignite.testframework.LogListener)144 Test (org.junit.Test)116 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)93 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)68 IgniteEx (org.apache.ignite.internal.IgniteEx)65 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)35 Ignite (org.apache.ignite.Ignite)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)31 IgniteCache (org.apache.ignite.IgniteCache)24 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)23 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)18 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)16 List (java.util.List)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 Pattern (java.util.regex.Pattern)15 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)13 UUID (java.util.UUID)12 Collections (java.util.Collections)11