Search in sources :

Example 16 with ListeningTestLogger

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

the class ClusterStateOnStartPropertyTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName).setClusterStateOnStart(state).setCacheConfiguration(new CacheConfiguration().setName(DEFAULT_CACHE_NAME)).setConsistentId(igniteInstanceName).setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(persistence)));
    if (autoActivation != null)
        cfg.setAutoActivationEnabled(autoActivation);
    if (activeOnStart != null)
        cfg.setActiveOnStart(activeOnStart);
    // Warn messages must be printed only if both options (old and new) are presented.
    if (autoActivation != null || activeOnStart != null) {
        ListeningTestLogger testLog = new ListeningTestLogger(false, log);
        LogListener lsnr = LogListener.matches(persistence ? "Property `autoActivation` will be ignored due to the property `clusterStateOnStart` is presented." : "Property `activeOnStart` will be ignored due to the property `clusterStateOnStart` is presented.").build();
        testLog.registerListener(lsnr);
        logListeners.put(igniteInstanceName, lsnr);
        cfg.setGridLogger(testLog);
    }
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 17 with ListeningTestLogger

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

the class GridCacheLongRunningTransactionDiagnosticsTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setConsistentId(igniteInstanceName);
    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    boolean isClient = "client".equals(igniteInstanceName);
    if (!isClient) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
        ccfg.setAtomicityMode(TRANSACTIONAL);
        ccfg.setBackups(2);
        ccfg.setWriteSynchronizationMode(FULL_SYNC);
        cfg.setCacheConfiguration(ccfg);
    }
    ListeningTestLogger testLog = new ListeningTestLogger(false, log);
    testLog.registerListener(dumpLsnr);
    cfg.setGridLogger(testLog);
    return cfg;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 18 with ListeningTestLogger

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

the class WarningOnBigQueryResultsBaseTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName).setCacheConfiguration(new CacheConfiguration().setName(CACHE0).setSqlSchema("TEST0").setQueryEntities(Collections.singleton(new QueryEntity(Long.class, Long.class).setTableName("test0").addQueryField("id", Long.class.getName(), null).addQueryField("val", Long.class.getName(), null).setKeyFieldName("id").setValueFieldName("val"))).setAffinity(new RendezvousAffinityFunction(false, 10)).setNodeFilter((IgnitePredicate<ClusterNode>) node -> node.attribute(TEST0_ATTR) != null && (boolean) node.attribute(TEST0_ATTR)), new CacheConfiguration().setName(CACHE1).setSqlSchema("TEST1").setQueryEntities(Collections.singleton(new QueryEntity(Long.class, Long.class).setTableName("test1").addQueryField("id", Long.class.getName(), null).addQueryField("val", Long.class.getName(), null).setKeyFieldName("id").setValueFieldName("val"))).setAffinity(new RendezvousAffinityFunction(false, 10)).setNodeFilter((IgnitePredicate<ClusterNode>) node -> node.attribute(TEST1_ATTR) != null && (boolean) node.attribute(TEST1_ATTR)));
    if (igniteInstanceName.startsWith("cli")) {
        cfg.setClientMode(true).setClientConnectorConfiguration(new ClientConnectorConfiguration().setPort(CLI_PORT));
    } else {
        cfg.setUserAttributes(Collections.singletonMap(getTestIgniteInstanceIndex(igniteInstanceName) < 2 ? TEST0_ATTR : TEST1_ATTR, true));
    }
    ListeningTestLogger testLog = new ListeningTestLogger(false, log);
    BigResultsLogListener lst = new BigResultsLogListener();
    testLog.registerListener(lst);
    logListeners.put(igniteInstanceName, lst);
    cfg.setGridLogger(new ListeningTestLogger(false, testLog));
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 19 with ListeningTestLogger

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

the class RebalanceStatisticsTest method testRebalanceStatistics.

/**
 * Test statistics of a rebalance.
 *
 * Steps:
 * 1)Creating and filling a cluster;
 * 2)Starting a new node with listening for logs and supply messages;
 * 3)Check that number of supply messages is equal to number of logs received +1;
 * 4)Find corresponding message in log for each supply message;
 * 5)Find log message after all of groups and to check its correctness.
 *
 * @throws Exception if any error occurs.
 */
@Test
public void testRebalanceStatistics() throws Exception {
    createCluster(3);
    ListeningTestLogger listeningTestLog = new ListeningTestLogger(log);
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(3)).setGridLogger(listeningTestLog);
    // Collect log messages with rebalance statistics.
    Collection<String> logMsgs = new ConcurrentLinkedQueue<>();
    listeningTestLog.registerListener(new CallbackExecutorLogListener("Completed( \\(final\\))? rebalanc(ing|e chain).*", logMsgs::add));
    Map<Ignite, Collection<T2<ClusterNode, Message>>> recordMsgs = new ConcurrentHashMap<>();
    G.allGrids().forEach(n -> TestRecordingCommunicationSpi.spi(n).record((node, msg) -> {
        if (GridDhtPartitionSupplyMessage.class.isInstance(msg))
            recordMsgs.computeIfAbsent(n, n1 -> new ConcurrentLinkedQueue<>()).add(new T2<>(node, msg));
        return false;
    }));
    IgniteEx node = startGrid(cfg);
    awaitPartitionMapExchange();
    // Collect supply messages only for new node.
    Map<Ignite, List<GridDhtPartitionSupplyMessage>> supplyMsgs = G.allGrids().stream().filter(n -> !n.equals(node)).collect(toMap(identity(), n -> recordMsgs.get(n).stream().filter(t2 -> t2.get1().id().equals(node.localNode().id())).map(IgniteBiTuple::get2).map(GridDhtPartitionSupplyMessage.class::cast).collect(toList())));
    // +1 because one message about end of rebalance for all groups.
    assertEquals(supplyMsgs.values().stream().mapToInt(List::size).sum() + 1, logMsgs.size());
    IgniteClosure2X<GridCacheEntryInfo, CacheObjectContext, Long> getSize = new IgniteClosure2X<GridCacheEntryInfo, CacheObjectContext, Long>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public Long applyx(GridCacheEntryInfo info, CacheObjectContext ctx) throws IgniteCheckedException {
            return (long) info.marshalledSize(ctx);
        }
    };
    for (Map.Entry<Ignite, List<GridDhtPartitionSupplyMessage>> supplyMsg : supplyMsgs.entrySet()) {
        List<String> supplierMsgs = logMsgs.stream().filter(s -> s.contains("supplier=" + supplyMsg.getKey().cluster().localNode().id())).collect(toList());
        List<GridDhtPartitionSupplyMessage> msgs = supplyMsg.getValue();
        assertEquals(msgs.size(), supplierMsgs.size());
        for (GridDhtPartitionSupplyMessage msg : msgs) {
            Map<Integer, CacheEntryInfoCollection> infos = U.field(msg, "infos");
            CacheGroupContext grpCtx = node.context().cache().cacheGroup(msg.groupId());
            long bytes = 0;
            for (CacheEntryInfoCollection c : infos.values()) {
                for (GridCacheEntryInfo i : c.infos()) bytes += getSize.apply(i, grpCtx.cacheObjectContext());
            }
            String[] checVals = { "grp=" + grpCtx.cacheOrGroupName(), "partitions=" + infos.size(), "entries=" + infos.values().stream().mapToInt(i -> i.infos().size()).sum(), "topVer=" + msg.topologyVersion(), "rebalanceId=" + U.field(msg, "rebalanceId"), "bytesRcvd=" + U.humanReadableByteCount(bytes), "fullPartitions=" + infos.size(), "fullEntries=" + infos.values().stream().mapToInt(i -> i.infos().size()).sum(), "fullBytesRcvd=" + U.humanReadableByteCount(bytes), "histPartitions=0", "histEntries=0", "histBytesRcvd=0" };
            assertTrue("msgs=" + supplierMsgs.toString() + ", checVals=" + asList(checVals).toString(), supplierMsgs.stream().anyMatch(s -> Stream.of(checVals).allMatch(s::contains)));
        }
    }
    String rebChainMsg = logMsgs.stream().filter(s -> s.startsWith("Completed rebalance chain")).findAny().get();
    long rebId = -1;
    int parts = 0;
    int entries = 0;
    long bytes = 0;
    for (List<GridDhtPartitionSupplyMessage> msgs : supplyMsgs.values()) {
        for (GridDhtPartitionSupplyMessage msg : msgs) {
            Map<Integer, CacheEntryInfoCollection> infos = U.field(msg, "infos");
            rebId = U.field(msg, "rebalanceId");
            parts += infos.size();
            entries += infos.values().stream().mapToInt(i -> i.infos().size()).sum();
            CacheObjectContext cacheObjCtx = node.context().cache().cacheGroup(msg.groupId()).cacheObjectContext();
            for (CacheEntryInfoCollection c : infos.values()) {
                for (GridCacheEntryInfo i : c.infos()) bytes += getSize.apply(i, cacheObjCtx);
            }
        }
    }
    String[] checVals = { "partitions=" + parts, "entries=" + entries, "rebalanceId=" + rebId, "bytesRcvd=" + U.humanReadableByteCount(bytes) };
    assertTrue(rebChainMsg, Stream.of(checVals).allMatch(rebChainMsg::contains));
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClosure2X(org.apache.ignite.internal.util.lang.IgniteClosure2X) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) G(org.apache.ignite.internal.util.typedef.G) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) T2(org.apache.ignite.internal.util.typedef.T2) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Function.identity(java.util.function.Function.identity) Message(org.apache.ignite.plugin.extensions.communication.Message) CallbackExecutorLogListener(org.apache.ignite.testframework.CallbackExecutorLogListener) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CacheMode(org.apache.ignite.cache.CacheMode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) Ignite(org.apache.ignite.Ignite) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) IgniteClosure2X(org.apache.ignite.internal.util.lang.IgniteClosure2X) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CallbackExecutorLogListener(org.apache.ignite.testframework.CallbackExecutorLogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) Collection(java.util.Collection) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 20 with ListeningTestLogger

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

the class GridCacheRebalancingUnmarshallingFailedSelfTest method runTest.

/**
 * @throws Exception e.
 */
private void runTest() throws Exception {
    customLog = new ListeningTestLogger(log);
    LogListener unmarshalErrorLogListener = LogListener.matches(UNMARSHALING_ERROR_PATTERN).atLeast(1).build();
    customLog.registerListener(unmarshalErrorLogListener);
    assert marshaller != null;
    readCnt.set(Integer.MAX_VALUE);
    startGrid(0);
    for (int i = 0; i < 100; i++) grid(0).cache(CACHE).put(new TestKey(String.valueOf(i)), i);
    readCnt.set(1);
    startGrid(1);
    readCnt.set(Integer.MAX_VALUE);
    for (int i = 0; i < 50; i++) assert grid(1).cache(CACHE).get(new TestKey(String.valueOf(i))) != null;
    stopGrid(0);
    for (int i = 50; i < 100; i++) assertNull(grid(1).cache(CACHE).get(new TestKey(String.valueOf(i))));
    assertTrue("Unmarshal log error message is not valid.", unmarshalErrorLogListener.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger)

Aggregations

ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)101 Test (org.junit.Test)51 LogListener (org.apache.ignite.testframework.LogListener)48 IgniteEx (org.apache.ignite.internal.IgniteEx)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)32 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)30 Ignite (org.apache.ignite.Ignite)21 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)21 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)17 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)14 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)9 List (java.util.List)8 Pattern (java.util.regex.Pattern)8 ClusterState (org.apache.ignite.cluster.ClusterState)7 GridQueryProcessor (org.apache.ignite.internal.processors.query.GridQueryProcessor)7 Collections (java.util.Collections)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6