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);
}
}
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;
}
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);
}
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);
}
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();
}
Aggregations