use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogReaderTest method testReadRegularLogNoFilterSvcParser.
/**
* Test if readMessage() can read regular service log from file and parse it correctly
*/
@Test
public void testReadRegularLogNoFilterSvcParser() throws Exception {
LogStatusInfo status = new LogStatusInfo();
LogRequest req = new LogRequest.Builder().build();
LogReader reader = new LogReader(regularSvcLogPath, req, status, null);
LogMessage l = reader.readNextLogMessage();
Calendar calendar = Calendar.getInstance();
// month starts from 0;
calendar.set(2014, 0, 16, 17, 7, 57);
calendar.set(Calendar.MILLISECOND, 561);
Date date = calendar.getTime();
long time = date.getTime();
assertEquals("Time is wrong", l.getTime(), time);
assertTrue("Thread name is wrong", Arrays.equals(LogUtil.stringToBytes("LogLevelResetter"), l.getThreadName()));
assertEquals("Log level is wrong", new String(l.getLevel()), "INFO");
assertTrue("File name is wrong", Arrays.equals(LogUtil.stringToBytes("LoggingMBean"), l.getFileName()));
assertTrue("Line number is wrong", Arrays.equals(l.getLineNumber(), LogUtil.stringToBytes("322")));
assertTrue("Log message contact is wrong", Arrays.equals(LogUtil.stringToBytes("Starting log level config reset, lastResetTime = 0"), l.getLogContent()));
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogRequestTest method testMarshalUnMarshal.
@Test
public void testMarshalUnMarshal() throws Exception {
System.out.println("Entering testMarshlUnMarshal()");
LogRequest req = new LogRequest();
List<String> baseNames = new ArrayList<String>();
List<String> nodeIds = new ArrayList<String>();
baseNames.add("apisvc");
nodeIds.add("standalone");
req.setBaseNames(baseNames);
req.setMaxCount(10);
req.setNodeIds(nodeIds);
File file = new File(PATH + File.separator + "file.xml");
JAXBContext jc = JAXBContext.newInstance(LogRequest.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(req, file);
Unmarshaller jaxbUnmarshaller = jc.createUnmarshaller();
LogRequest reqNew = (LogRequest) jaxbUnmarshaller.unmarshal(file);
assertTrue("The object after marshal and unMarshal should be the same with " + "the origianl one", req.toString().equals(reqNew.toString()));
System.out.println("Done testMarshlUnMarshal() ");
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogStreamMergerTest method testMergeSortCorrectness.
/**
* Test if merge process can result correct content
*/
@Test
@Ignore
public void testMergeSortCorrectness() throws Exception {
List<String> svcs = new ArrayList<String>() {
{
add("controllersvc");
add("coordinatorsvc");
}
};
LogRequest req = new LogRequest.Builder().baseNames(svcs).build();
LogStreamMerger merger = new LogStreamMerger(req, propertiesLoader);
long prevTime = -1;
while (true) {
LogMessage log = merger.readNextMergedLogMessage();
if (log == null) {
break;
}
long time = log.getTime();
assertTrue("Output of StreamMerger should be sorted.", prevTime <= time);
prevTime = time;
}
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogStreamTest method testGetFilePathTimeFilter.
/**
* Test if LogStream can find all files need to read correctly with time
* range filter
* This test can only be tested on root@10.10.191.121
*/
@Test
@Ignore
public void testGetFilePathTimeFilter() {
String svcName = "controllersvc";
List<File> files = new ArrayList<File>();
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140110-231105.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140114-151216.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140112-175108.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140116-031010.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140109-101159.gz"));
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 0, 10, 0, 0);
Date startTimeFilter = calendar.getTime();
calendar.set(2014, 0, 14, 16, 38);
Date endTimeFilter = calendar.getTime();
LogRequest req = new LogRequest.Builder().startTime(startTimeFilter).endTime(endTimeFilter).build();
LogFileStream stream = new LogFileStream(svcName, files, req, null);
List<String> paths = stream.getLogPaths();
List<String> result = new ArrayList<String>();
result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140110-231105.gz");
result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140112-175108.gz");
result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140114-151216.gz");
result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140116-031010.gz");
int i = 0;
assertTrue("Time range and svc filters are not correct", paths.size() == result.size());
for (String str : paths) {
assertEquals("Time range and svc filters are not correct", str, result.get(i));
i++;
}
}
use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.
the class LogStreamTest method testMultipleFilesTimeRangeFilter.
/**
* Test if logs read from files are in time range specified in LogRequest
* This test can only be tested on root@10.10.191.121
*/
@Test
@Ignore
public void testMultipleFilesTimeRangeFilter() throws Exception {
List<File> files = new ArrayList<File>();
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140110-231105.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140114-151216.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140112-175108.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140116-031010.gz"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log"));
files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140109-101159.gz"));
Calendar calendar = Calendar.getInstance();
calendar.set(2013, 10, 20, 16, 38);
Date startTime = calendar.getTime();
long startTimeLong = startTime.getTime();
calendar.set(2014, 0, 16, 16, 38);
Date endTime = calendar.getTime();
long endTimeLong = endTime.getTime();
LogRequest req = new LogRequest.Builder().startTime(startTime).endTime(endTime).build();
LogStatusInfo status = new LogStatusInfo();
LogFileStream stream = new LogFileStream("", files, req, status);
while (true) {
LogMessage log = stream.readNextLogMessage();
if (log == null) {
break;
}
long time = log.getTime();
assertTrue("Lines read from LogStream should in time range(multiple files)", time >= startTimeLong && time <= endTimeLong);
}
}
Aggregations