use of org.apache.oozie.service.Services in project oozie by apache.
the class TestXLogUserFilterParam method testCombination.
// Test multiple combination
public void testCombination() throws Exception {
File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
Properties log4jProps = new Properties();
log4jProps.load(is);
log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
log4jProps.store(new FileOutputStream(log4jFile), "");
setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
new Services().init();
XLogFilter.reset();
Map<String, String[]> paramMap = new HashMap<String, String[]>();
String param = "start=14-02-20 02:06:25,499;end=14-02-27 02:06:47,550;debug;loglevel=ERROR|WARN;recent=3m";
paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
// Param date will be overwritten by user param
String out = doStreamLog(filter, new Date(), new Date());
assertEquals(out.split(System.getProperty("line.separator")).length, 1);
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Feb 27 02:03:47"));
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Feb 27 02:06:47"));
}
use of org.apache.oozie.service.Services in project oozie by apache.
the class TestXLogUserFilterParam method testStartEnd_startAbsolute.
// Test start and end date, both absolute
public void testStartEnd_startAbsolute() throws Exception {
File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
Properties log4jProps = new Properties();
log4jProps.load(is);
// prevent conflicts with other tests by changing the log file location
log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
log4jProps.store(new FileOutputStream(log4jFile), "");
setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
new Services().init();
Map<String, String[]> paramMap = new HashMap<String, String[]>();
String param = "start=14-03-20 02:06:25,499;end=4m;debug";
paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
// Param date will be overwritten by user param
String out = doStreamLog(filter, dt.parse("14-01-20 02:06:25,499"), dt.parse("14-02-20 02:06:25,499"));
assertEquals(out.split(System.getProperty("line.separator")).length, 1);
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Mar 20 02:06:25"));
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Mar 20 02:12:25"));
}
use of org.apache.oozie.service.Services in project oozie by apache.
the class TestXLogUserFilterParam method setLogFile.
public void setLogFile() throws Exception {
XLogFilter.reset();
File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
InputStream errorLogStream = cl.getResourceAsStream("userLogFilterTestlog.log");
Properties log4jProps = new Properties();
log4jProps.load(is);
// prevent conflicts with other tests by changing the log file location
log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
log4jProps.store(new FileOutputStream(log4jFile), "");
setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
new Services().init();
File logFile = new File(Services.get().get(XLogService.class).getOozieLogPath(), Services.get().get(XLogService.class).getOozieLogName());
IOUtils.copyStream(errorLogStream, new FileOutputStream(logFile));
}
use of org.apache.oozie.service.Services in project oozie by apache.
the class TestXLogUserFilterParam method testStartEnd_bothOffset.
// Test start and end date, both offset
public void testStartEnd_bothOffset() throws Exception {
File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
Properties log4jProps = new Properties();
log4jProps.load(is);
// prevent conflicts with other tests by changing the log file location
log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
log4jProps.store(new FileOutputStream(log4jFile), "");
setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
new Services().init();
Map<String, String[]> paramMap = new HashMap<String, String[]>();
String param = "start=3m;end=13m;debug";
paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
// Param date will be overwritten by user param
String out = doStreamLog(filter, dt.parse("14-02-20 02:06:25,499"), new Date());
assertEquals(out.split(System.getProperty("line.separator")).length, 1);
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Feb 20 02:07:25"));
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Feb 20 02:21:25"));
}
use of org.apache.oozie.service.Services in project oozie by apache.
the class TestXLogUserFilterParam method testStartEnd_bothabsoulte.
// Test start and end date, both absolute
public void testStartEnd_bothabsoulte() throws Exception {
File log4jFile = new File(getTestCaseConfDir(), "test-log4j.properties");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream is = cl.getResourceAsStream("test-no-dash-log4j.properties");
Properties log4jProps = new Properties();
log4jProps.load(is);
// prevent conflicts with other tests by changing the log file location
log4jProps.setProperty("log4j.appender.oozie.File", getTestCaseDir() + "/oozie.log");
log4jProps.store(new FileOutputStream(log4jFile), "");
setSystemProperty(XLogService.LOG4J_FILE, log4jFile.getName());
new Services().init();
Map<String, String[]> paramMap = new HashMap<String, String[]>();
String param = "start=14-03-20 02:06:25,499;end=14-03-20 02:10:25,499;debug";
paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
XLogFilter filter = new XLogFilter(new XLogUserFilterParam(paramMap));
// Param date will be overwritten by user param
String out = doStreamLog(filter, dt.parse("14-01-20 02:06:25,499"), dt.parse("14-02-20 02:06:25,499"));
assertEquals(out.split(System.getProperty("line.separator")).length, 1);
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Mar 20 02:06:25"));
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Mar 20 02:10:25"));
paramMap = new HashMap<String, String[]>();
param = "start=14-03-20 02:06:25;end=14-03-20 02:10:25;debug";
paramMap.put(RestConstants.LOG_FILTER_OPTION, new String[] { param });
filter = new XLogFilter(new XLogUserFilterParam(paramMap));
// Param date will be overwritten by user param
out = doStreamLog(filter, dt.parse("14-01-20 02:06:25,499"), dt.parse("14-02-20 02:06:25,499"));
assertEquals(out.split(System.getProperty("line.separator")).length, 1);
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log start time = Tue Mar 20 02:06:25"));
assertTrue(out.split(System.getProperty("line.separator"))[0].contains("Log end time = Tue Mar 20 02:10:25"));
}
Aggregations