Search in sources :

Example 1 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class SysLogReaderTest method testLogCountSysParser.

/**
 * Test if reader could recognize the correct count of system logs
 */
@Test
public void testLogCountSysParser() throws Exception {
    System.out.println("starting testLogCountSysParser");
    LogStatusInfo status = new LogStatusInfo();
    final int WARN = 5;
    // four kinds of different patterns in file
    String filePath = "src/main/data/testReaderData/testSyslogParser.log";
    long logCount = 47;
    LogReader reader = null;
    LogRequest req = new LogRequest.Builder().logLevel(WARN).build();
    reader = new LogReader(filePath, req, status, null);
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            assertEquals("Log count should match", logCount, reader.getLogCount());
            break;
        }
    }
    System.out.println("done testLogCountSysParser");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Test(org.junit.Test)

Example 2 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class SysLogReaderTest method testLogStatusInfo.

/**
 * Test if reader could record correct status information
 */
@Test
public void testLogStatusInfo() throws Exception {
    System.out.println("starting testLogStatusInfo");
    LogStatusInfo status = new LogStatusInfo();
    String filePath = "src/main/data/testReaderData/testStatus.log";
    long logCount = 42;
    LogReader reader = null;
    LogRequest req = new LogRequest.Builder().build();
    reader = new LogReader(filePath, req, status, null);
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            assertEquals("Log count should match", logCount, reader.getLogCount());
            break;
        }
    }
    BufferedReader br = new BufferedReader(new FileReader("src/main/data/testReaderData/testStatusResult.log"));
    String line = br.readLine();
    int index = 0;
    while (line != null) {
        assertTrue("status's size is not correct!", status.getStatus().size() > index);
        assertEquals("status's contect is not correct!", line, status.getStatus().get(index));
        index++;
        line = br.readLine();
    }
    assertEquals("status's size is not correct!", status.getStatus().size(), index);
    br.close();
    System.out.println("done testLogStatusInfo");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 3 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader 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()));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Example 4 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class LogReaderPerfTest method testPerformance.

@Test
public void testPerformance() throws Exception {
    LogStatusInfo status = new LogStatusInfo();
    String filePath = PATH;
    File file = new File(filePath);
    double fileSize = (double) file.length() / (1024L * 1024L);
    LogRequest req = new LogRequest.Builder().build();
    // empty service list
    LogReader reader = new LogReader(filePath, req, status, null);
    long startTime = System.nanoTime();
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            break;
        }
    }
    double elapsedTime = (double) (System.nanoTime() - startTime) / 1000000000.0;
    double speed = fileSize / elapsedTime;
    System.out.println("Performance for LogReader");
    System.out.println("Total read " + fileSize + " MB;" + " Used " + elapsedTime + " sec; Average " + speed + " MB/sec.");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) File(java.io.File) Test(org.junit.Test)

Example 5 with LogReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogReader in project coprhd-controller by CoprHD.

the class LogReaderTest method testMultipleLinesInfoNoFilterSVCParser.

/**
 * Test if readMessage() can read multiple lines INFO service log from file and parse it correctly
 * Test log whose first line's message field is null.
 */
@Test
public void testMultipleLinesInfoNoFilterSVCParser() throws Exception {
    LogStatusInfo status = new LogStatusInfo();
    LogRequest req = new LogRequest.Builder().build();
    LogReader reader = new LogReader(multipleLineINFOLogPath, req, status, null);
    LogMessage l = reader.readNextLogMessage();
    Calendar calendar = Calendar.getInstance();
    // month starts from 0;
    calendar.set(2014, 0, 16, 18, 58, 24);
    calendar.set(Calendar.MILLISECOND, 25);
    Date date = calendar.getTime();
    long time = date.getTime();
    assertEquals("Time is wrong", l.getTime(), time);
    assertTrue("Thread name is wrong", Arrays.equals(LogUtil.stringToBytes("pool-10-thread-1"), l.getThreadName()));
    assertEquals("Log level is wrong", new String(l.getLevel()), "INFO");
    assertTrue("File name is wrong", Arrays.equals(LogUtil.stringToBytes("ProcessMonitor"), l.getFileName()));
    assertTrue("Line number is wrong", Arrays.equals(l.getLineNumber(), LogUtil.stringToBytes("34")));
    assertTrue("Log message content is wrong", Arrays.equals(LogUtil.stringToBytes("" + '\n' + "Memory Usage Metrics " + '\n' + "Total  Memory: 379MB; " + '\n' + "Available Free Memory: 146MB; " + '\n' + "Available Maximum Memory : 910MB; " + '\n' + "Used Memory: 233MB; " + '\n' + "Max used Memory : 366MB at 2014-01-01 23:03:24.025 UTC; "), l.getLogContent()));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LogReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogReader)10 LogRequest (com.emc.vipr.model.sys.logging.LogRequest)10 Test (org.junit.Test)10 LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)7 LogStatusInfo (com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo)7 Calendar (java.util.Calendar)5 Date (java.util.Date)5 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 File (java.io.File)1