use of org.apache.log4j.Layout in project hadoop by apache.
the class TestJobMonitorAndPrint method testJobMonitorAndPrint.
@Test
public void testJobMonitorAndPrint() throws Exception {
JobStatus jobStatus_1 = new JobStatus(new JobID("job_000", 1), 1f, 0.1f, 0.1f, 0f, State.RUNNING, JobPriority.HIGH, "tmp-user", "tmp-jobname", "tmp-queue", "tmp-jobfile", "tmp-url", true);
JobStatus jobStatus_2 = new JobStatus(new JobID("job_000", 1), 1f, 1f, 1f, 1f, State.SUCCEEDED, JobPriority.HIGH, "tmp-user", "tmp-jobname", "tmp-queue", "tmp-jobfile", "tmp-url", true);
doAnswer(new Answer<TaskCompletionEvent[]>() {
@Override
public TaskCompletionEvent[] answer(InvocationOnMock invocation) throws Throwable {
return new TaskCompletionEvent[0];
}
}).when(job).getTaskCompletionEvents(anyInt(), anyInt());
doReturn(new TaskReport[5]).when(job).getTaskReports(isA(TaskType.class));
when(clientProtocol.getJobStatus(any(JobID.class))).thenReturn(jobStatus_1, jobStatus_2);
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("stdout").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setThreshold(Level.ALL);
Logger qlogger = Logger.getLogger(Job.class);
qlogger.addAppender(appender);
job.monitorAndPrintJob();
qlogger.removeAppender(appender);
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean foundHundred = false;
boolean foundComplete = false;
boolean foundUber = false;
String uberModeMatch = "uber mode : true";
String progressMatch = "map 100% reduce 100%";
String completionMatch = "completed successfully";
while ((line = r.readLine()) != null) {
if (line.contains(uberModeMatch)) {
foundUber = true;
}
foundHundred = line.contains(progressMatch);
if (foundHundred)
break;
}
line = r.readLine();
foundComplete = line.contains(completionMatch);
assertTrue(foundUber);
assertTrue(foundHundred);
assertTrue(foundComplete);
System.out.println("The output of job.toString() is : \n" + job.toString());
assertTrue(job.toString().contains("Number of maps: 5\n"));
assertTrue(job.toString().contains("Number of reduces: 5\n"));
}
use of org.apache.log4j.Layout in project hadoop by apache.
the class TestTaskLogAppender method testTaskLogAppender.
/**
* test TaskLogAppender
*/
@SuppressWarnings("deprecation")
@Test(timeout = 5000)
public void testTaskLogAppender() {
TaskLogAppender appender = new TaskLogAppender();
System.setProperty(TaskLogAppender.TASKID_PROPERTY, "attempt_01_02_m03_04_001");
System.setProperty(TaskLogAppender.LOGSIZE_PROPERTY, "1003");
appender.activateOptions();
assertEquals(appender.getTaskId(), "attempt_01_02_m03_04_001");
assertEquals(appender.getTotalLogFileSize(), 1000);
assertEquals(appender.getIsCleanup(), false);
// test writer
Writer writer = new StringWriter();
appender.setWriter(writer);
Layout layout = new PatternLayout("%-5p [%t]: %m%n");
appender.setLayout(layout);
Category logger = Logger.getLogger(getClass().getName());
LoggingEvent event = new LoggingEvent("fqnOfCategoryClass", logger, Priority.INFO, "message", new Throwable());
appender.append(event);
appender.flush();
appender.close();
assertTrue(writer.toString().length() > 0);
// test cleanup should not changed
appender = new TaskLogAppender();
appender.setIsCleanup(true);
appender.activateOptions();
assertEquals(appender.getIsCleanup(), true);
}
use of org.apache.log4j.Layout in project zookeeper by apache.
the class QuorumPeerMainTest method testBadPeerAddressInQuorum.
/**
* Verify handling of bad quorum address
*/
@Test
public void testBadPeerAddressInQuorum() throws Exception {
ClientBase.setupTestEnv();
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setThreshold(Level.WARN);
Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
qlogger.addAppender(appender);
try {
final int CLIENT_PORT_QP1 = PortAssignment.unique();
final int CLIENT_PORT_QP2 = PortAssignment.unique();
String quorumCfgSection = "server.1=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2;
MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
q1.start();
boolean isup = ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, 30000);
Assert.assertFalse("Server never came up", isup);
q1.shutdown();
Assert.assertTrue("waiting for server 1 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, ClientBase.CONNECTION_TIMEOUT));
} finally {
qlogger.removeAppender(appender);
}
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
boolean found = false;
Pattern p = Pattern.compile(".*Cannot open channel to .* at election address .*");
while ((line = r.readLine()) != null) {
found = p.matcher(line).matches();
if (found) {
break;
}
}
Assert.assertTrue("complains about host", found);
}
use of org.apache.log4j.Layout in project zookeeper by apache.
the class ReadOnlyModeTest method testSeekForRwServer.
/**
* Ensures that client seeks for r/w servers while it's connected to r/o
* server.
*/
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {
// setup the logger to capture all logs
Layout layout = Logger.getRootLogger().getAppender("CONSOLE").getLayout();
ByteArrayOutputStream os = new ByteArrayOutputStream();
WriterAppender appender = new WriterAppender(layout, os);
appender.setImmediateFlush(true);
appender.setThreshold(Level.INFO);
Logger zlogger = Logger.getLogger("org.apache.zookeeper");
zlogger.addAppender(appender);
try {
qu.shutdown(2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(qu.getConnString(), CONNECTION_TIMEOUT, watcher, true);
watcher.waitForConnected(CONNECTION_TIMEOUT);
// if we don't suspend a peer it will rejoin a quorum
qu.getPeer(1).peer.suspend();
// start two servers to form a quorum; client should detect this and
// connect to one of them
watcher.reset();
qu.start(2);
qu.start(3);
ClientBase.waitForServerUp(qu.getConnString(), 2000);
watcher.waitForConnected(CONNECTION_TIMEOUT);
zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// resume poor fellow
qu.getPeer(1).peer.resume();
} finally {
zlogger.removeAppender(appender);
}
os.close();
LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
String line;
Pattern p = Pattern.compile(".*Majority server found.*");
boolean found = false;
while ((line = r.readLine()) != null) {
if (p.matcher(line).matches()) {
found = true;
break;
}
}
Assert.assertTrue("Majority server wasn't found while connected to r/o server", found);
}
use of org.apache.log4j.Layout in project symmetric-ds by JumpMind.
the class AbstractCommandLauncher method configureLogging.
protected void configureLogging(CommandLine line) throws MalformedURLException {
/* Optionally remove existing handlers attached to j.u.l root logger */
SLF4JBridgeHandler.removeHandlersForRootLogger();
/*
* Add SLF4JBridgeHandler to j.u.l's root logger, should be done once
* during the initialization phase of your application
*/
SLF4JBridgeHandler.install();
URL log4jUrl = new URL(System.getProperty("log4j.configuration", "file:" + AppUtils.getSymHome() + "/conf/log4j-blank.xml"));
File log4jFile = new File(new File(log4jUrl.getFile()).getParent(), "log4j.xml");
if (line.hasOption(OPTION_DEBUG)) {
log4jFile = new File(log4jFile.getParent(), "log4j-debug.xml");
}
if (log4jFile.exists()) {
DOMConfigurator.configure(log4jFile.getAbsolutePath());
}
if (line.hasOption(OPTION_VERBOSE_CONSOLE)) {
Appender consoleAppender = org.apache.log4j.Logger.getRootLogger().getAppender("CONSOLE");
if (consoleAppender != null) {
Layout layout = consoleAppender.getLayout();
if (layout instanceof PatternLayout) {
((PatternLayout) layout).setConversionPattern("%d %-5p [%c{2}] [%t] %m%n");
}
}
}
if (line.hasOption(OPTION_NO_LOG_CONSOLE)) {
org.apache.log4j.Logger.getRootLogger().removeAppender("CONSOLE");
}
if (line.hasOption(OPTION_NO_LOG_FILE)) {
org.apache.log4j.Logger.getRootLogger().removeAppender("ROLLING");
} else {
Appender appender = org.apache.log4j.Logger.getRootLogger().getAppender("ROLLING");
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
if (line.hasOption(OPTION_PROPERTIES_FILE)) {
File file = new File(line.getOptionValue(OPTION_PROPERTIES_FILE));
String name = file.getName();
int index = name.lastIndexOf(".");
if (index > 0) {
name = name.substring(0, index);
}
fileAppender.setFile(fileAppender.getFile().replace("symmetric.log", name + ".log"));
fileAppender.activateOptions();
}
System.err.println(String.format("Log output will be written to %s", fileAppender.getFile()));
}
}
}
Aggregations