Search in sources :

Example 1 with GridTestLog4jLogger

use of org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger in project ignite by apache.

the class GridHashMapLoadTest method testMapEntry.

/**
     * @throws Exception If failed.
     */
public void testMapEntry() throws Exception {
    Map<Integer, GridCacheMapEntry> map = new HashMap<>(5 * 1024 * 1024);
    int i = 0;
    GridCacheTestContext<Integer, Integer> ctx = new GridCacheTestContext<>(new GridTestKernalContext(new GridTestLog4jLogger()));
    while (true) {
        Integer key = i++;
        map.put(key, new GridCacheMapEntry(ctx, ctx.toCacheKeyObject(key)) {

            @Override
            public boolean tmLock(IgniteInternalTx tx, long timeout, @Nullable GridCacheVersion serOrder, GridCacheVersion serReadVer, boolean read) {
                return false;
            }

            @Override
            protected void checkThreadChain(GridCacheMvccCandidate owner) {
            // No-op.
            }

            @Override
            public void txUnlock(IgniteInternalTx tx) {
            // No-op.
            }

            @Override
            public boolean removeLock(GridCacheVersion ver) {
                return false;
            }
        });
        if (i % 100000 == 0)
            info("Inserted objects: " + i / 2);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 2 with GridTestLog4jLogger

use of org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger in project ignite by apache.

the class GridRandomCommandLineLoader method getConfiguration.

/**
     * Initializes configurations.
     *
     * @param springCfgPath Configuration file path.
     * @param logCfgPath Log file name.
     * @return List of configurations.
     * @throws IgniteCheckedException If an error occurs.
     */
@SuppressWarnings("unchecked")
private static IgniteConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) throws IgniteCheckedException {
    assert springCfgPath != null;
    File path = GridTestUtils.resolveIgnitePath(springCfgPath);
    if (path == null)
        throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
    if (!path.isFile())
        throw new IgniteCheckedException("Provided file path is not a file: " + path);
    // Add no-op logger to remove no-appender warning.
    Appender app = new NullAppender();
    Logger.getRootLogger().addAppender(app);
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
    } catch (BeansException | MalformedURLException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
    // Remove previously added no-op logger.
    Logger.getRootLogger().removeAppender(app);
    if (cfgMap.size() != 1)
        throw new IgniteCheckedException("Spring configuration file should contain exactly 1 grid configuration: " + path);
    IgniteConfiguration cfg = (IgniteConfiguration) F.first(cfgMap.values());
    assert cfg != null;
    if (logCfgPath != null)
        cfg.setGridLogger(new GridTestLog4jLogger(U.resolveIgniteUrl(logCfgPath)));
    return cfg;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NullAppender(org.apache.log4j.varia.NullAppender) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 3 with GridTestLog4jLogger

use of org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger in project ignite by apache.

the class GridCacheAbstractLoadTest method initLogger.

/**
     * Initializes logger.
     *
     * @param log Log file name.
     * @return Logger.
     * @throws IgniteCheckedException If file initialization failed.
     */
protected IgniteLogger initLogger(String log) throws IgniteCheckedException {
    Logger impl = Logger.getRootLogger();
    impl.removeAllAppenders();
    String fileName = U.getIgniteHome() + "/work/log/" + log;
    // Configure output that should go to System.out
    RollingFileAppender fileApp;
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    try {
        fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
        fileApp.setMaxBackupIndex(0);
        fileApp.setAppend(false);
        // fileApp.rollOver();
        fileApp.activateOptions();
    } catch (IOException e) {
        throw new IgniteCheckedException("Unable to initialize file appender.", e);
    }
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    fileApp.addFilter(lvlFilter);
    impl.addAppender(fileApp);
    // Configure output that should go to System.out
    ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    lvlFilter.setLevelMax(Level.INFO);
    conApp.addFilter(lvlFilter);
    conApp.activateOptions();
    impl.addAppender(conApp);
    // Configure output that should go to System.err
    conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
    conApp.setThreshold(Level.WARN);
    conApp.activateOptions();
    impl.addAppender(conApp);
    impl.setLevel(Level.INFO);
    return new GridTestLog4jLogger(false);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter) IOException(java.io.IOException) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.log4j.Logger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 4 with GridTestLog4jLogger

use of org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger in project ignite by apache.

the class GridSingleExecutionTest method initLogger.

/**
     * Initializes logger.
     *
     * @param log Log file name.
     * @return Logger.
     * @throws IgniteCheckedException If file initialization failed.
     */
private static IgniteLogger initLogger(String log) throws IgniteCheckedException {
    Logger impl = Logger.getRootLogger();
    impl.removeAllAppenders();
    String fileName = U.getIgniteHome() + "/work/log/" + log;
    // Configure output that should go to System.out
    RollingFileAppender fileApp;
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    try {
        fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
        fileApp.setMaxBackupIndex(0);
        fileApp.rollOver();
    } catch (IOException e) {
        throw new IgniteCheckedException("Unable to initialize file appender.", e);
    }
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    fileApp.addFilter(lvlFilter);
    impl.addAppender(fileApp);
    // Configure output that should go to System.out
    ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.INFO);
    lvlFilter.setLevelMax(Level.INFO);
    conApp.addFilter(lvlFilter);
    impl.addAppender(conApp);
    // Configure output that should go to System.err
    conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
    conApp.setThreshold(Level.WARN);
    impl.addAppender(conApp);
    impl.setLevel(Level.INFO);
    Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG);
    return new GridTestLog4jLogger(false);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter) IOException(java.io.IOException) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.log4j.Logger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 5 with GridTestLog4jLogger

use of org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger in project ignite by apache.

the class GridNioBenchmarkTest method run.

/**
     * Runs the benchmark.
     *
     * @throws UnknownHostException If can't connect to given hist,
     * @throws IgniteCheckedException If NIO server initialisation failed.
     */
@SuppressWarnings("ConstantConditions")
public void run() throws UnknownHostException, IgniteCheckedException {
    GridNioServerListener<ByteBuffer> lsnr = new GridNioServerListenerAdapter<ByteBuffer>() {

        @Override
        public void onConnected(GridNioSession ses) {
            X.print("New connection accepted.");
        }

        @Override
        public void onDisconnected(GridNioSession ses, @Nullable Exception e) {
        // No-op.
        }

        @Override
        public void onMessage(GridNioSession ses, ByteBuffer msg) {
            ByteBuffer buf = ByteBuffer.allocate(msg.remaining()).put(msg);
            buf.position(0);
            ses.send(buf);
        }

        @Override
        public void onSessionWriteTimeout(GridNioSession ses) {
            X.error("Session write timeout. Closing.");
        }

        @Override
        public void onSessionIdleTimeout(GridNioSession ses) {
            X.error("Session idle timeout. Closing.");
        }
    };
    IgniteLogger log = new GridTestLog4jLogger(U.resolveIgniteUrl("config/ignite-log4j.xml"));
    GridNioServer.<ByteBuffer>builder().address(InetAddress.getByName("localhost")).port(port).listener(lsnr).logger(log).selectorCount(selectorCnt).igniteInstanceName("").tcpNoDelay(false).directBuffer(false).byteOrder(ByteOrder.nativeOrder()).socketSendBufferSize(0).socketReceiveBufferSize(0).sendQueueLimit(0).build().start();
}
Also used : GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridNioServerListenerAdapter(org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter) IgniteLogger(org.apache.ignite.IgniteLogger) ByteBuffer(java.nio.ByteBuffer) Nullable(org.jetbrains.annotations.Nullable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UnknownHostException(java.net.UnknownHostException) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Aggregations

GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 IOException (java.io.IOException)2 ConsoleAppender (org.apache.log4j.ConsoleAppender)2 Logger (org.apache.log4j.Logger)2 PatternLayout (org.apache.log4j.PatternLayout)2 RollingFileAppender (org.apache.log4j.RollingFileAppender)2 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 GridCacheMapEntry (org.apache.ignite.internal.processors.cache.GridCacheMapEntry)1 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)1 IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)1