Search in sources :

Example 21 with RequestLog

use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.

the class LocalLogServiceTest method testGetByRequestId.

@Test
public void testGetByRequestId() throws Exception {
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    String expectedId = allLogs.get(1).getRequestId().toStringUtf8();
    List<String> requestIds = new ArrayList<>();
    requestIds.add(expectedId);
    LogQuery query = LogQuery.Builder.withRequestIds(requestIds);
    List<String> actualRequestIds = new ArrayList<>();
    for (RequestLogs record : logService.fetch(query)) {
        actualRequestIds.add(record.getRequestId());
    }
    assertThat(actualRequestIds.size()).isEqualTo(1);
    assertThat(actualRequestIds.get(0)).isEqualTo(expectedId);
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Example 22 with RequestLog

use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.

the class LocalLogServiceTest method testSetStartAndEndTime.

@Test
public void testSetStartAndEndTime() throws Exception {
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    long startTime = 4;
    long endTime = 7;
    // Logs are stored reverse-chronologically
    List<Long> expectedLogStartTimes = new ArrayList<>();
    for (RequestLog record : Lists.reverse(allLogs)) {
        if ((record.getEndTime() >= startTime) && (record.getEndTime() < endTime)) {
            expectedLogStartTimes.add(record.getStartTime());
        }
    }
    LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime).endTimeUsec(endTime);
    List<Long> actualLogStartTimes = new ArrayList<>();
    for (RequestLogs record : logService.fetch(query)) {
        actualLogStartTimes.add(record.getStartTimeUsec());
    }
    String expected = joinLogStartTimes(expectedLogStartTimes);
    String actual = joinLogStartTimes(actualLogStartTimes);
    assertThat(actual).isEqualTo(expected);
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Example 23 with RequestLog

use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.

the class LocalLogServiceTest method testGetOneLog.

@Test
public void testGetOneLog() throws Exception {
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    Long expectedFirstLogStartTime = allLogs.get(0).getStartTime();
    LogQuery query = LogQuery.Builder.withBatchSize(1);
    Long actualFirstLogStartTime = (long) -1;
    for (RequestLogs record : logService.fetch(query)) {
        actualFirstLogStartTime = record.getStartTimeUsec();
    }
    assertThat(actualFirstLogStartTime).isEqualTo(expectedFirstLogStartTime);
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogQuery(com.google.appengine.api.log.LogQuery) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Example 24 with RequestLog

use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.

the class LocalLogServiceTest method testMinLogLevelFiltering.

@Test
public void testMinLogLevelFiltering() throws Exception {
    boolean appLogsDesired = true;
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, appLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    List<Integer> allAppLogLevels = new ArrayList<>();
    for (RequestLog record : Lists.reverse(allLogs)) {
        for (LogLine line : record.getLineList()) {
            allAppLogLevels.add(line.getLevel());
        }
    }
    // Test filtering for all legitimate log level values
    for (LogLevel minLogLevel : LogLevel.values()) {
        int minLogLevelInt = minLogLevel.ordinal();
        List<Integer> expectedAppLogLevels = new ArrayList<>();
        for (Integer thisLevel : allAppLogLevels) {
            if (thisLevel >= minLogLevelInt) {
                expectedAppLogLevels.add(thisLevel);
            }
        }
        LogQuery query = LogQuery.Builder.withIncludeAppLogs(appLogsDesired).minLogLevel(minLogLevel);
        List<Integer> actualAppLogLevels = new ArrayList<>();
        for (RequestLogs record : logService.fetch(query)) {
            for (AppLogLine line : record.getAppLogLines()) {
                actualAppLogLevels.add(line.getLogLevel().ordinal());
            }
        }
        String expectedLevels = joinAppLogLevels(expectedAppLogLevels);
        String actualLevels = joinAppLogLevels(actualAppLogLevels);
        assertThat(actualLevels).isEqualTo(expectedLevels);
    }
}
Also used : ArrayList(java.util.ArrayList) LogLine(com.google.apphosting.api.logservice.LogServicePb.LogLine) AppLogLine(com.google.appengine.api.log.AppLogLine) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) LogLevel(com.google.appengine.api.log.LogService.LogLevel) BigInteger(java.math.BigInteger) RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogQuery(com.google.appengine.api.log.LogQuery) AppLogLine(com.google.appengine.api.log.AppLogLine) Test(org.junit.Test)

Example 25 with RequestLog

use of com.google.apphosting.api.logservice.LogServicePb.RequestLog in project appengine-java-standard by GoogleCloudPlatform.

the class LocalLogServiceTest method testIncludeAppLogs.

@Test
public void testIncludeAppLogs() throws Exception {
    boolean appLogsDesired = true;
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, appLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    // Try a test where we want app logs
    List<Integer> expectedLogLevels = new ArrayList<>();
    for (RequestLog item : Lists.reverse(allLogs)) {
        for (LogLine line : item.getLineList()) {
            expectedLogLevels.add(line.getLevel());
        }
    }
    LogQuery query = LogQuery.Builder.withIncludeAppLogs(appLogsDesired);
    List<Integer> actualLogLevels = new ArrayList<>();
    for (RequestLogs record : logService.fetch(query)) {
        for (AppLogLine line : record.getAppLogLines()) {
            actualLogLevels.add(line.getLogLevel().ordinal());
        }
    }
    String expectedLevels = joinAppLogLevels(expectedLogLevels);
    String actualLevels = joinAppLogLevels(actualLogLevels);
    assertThat(actualLevels).isEqualTo(expectedLevels);
    // Now try a test where we don't want app logs
    query.includeAppLogs(false);
    List<Integer> actualLogLevelsForExcludedQuery = new ArrayList<>();
    for (RequestLogs record : logService.fetch(query)) {
        for (AppLogLine line : record.getAppLogLines()) {
            actualLogLevelsForExcludedQuery.add(line.getLogLevel().ordinal());
        }
    }
    assertThat(actualLogLevelsForExcludedQuery.size()).isEqualTo(0);
}
Also used : BigInteger(java.math.BigInteger) RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) ArrayList(java.util.ArrayList) LogQuery(com.google.appengine.api.log.LogQuery) AppLogLine(com.google.appengine.api.log.AppLogLine) LogLine(com.google.apphosting.api.logservice.LogServicePb.LogLine) AppLogLine(com.google.appengine.api.log.AppLogLine) ByteString(com.google.protobuf.ByteString) RequestLogs(com.google.appengine.api.log.RequestLogs) Test(org.junit.Test)

Aggregations

RequestLog (com.google.apphosting.api.logservice.LogServicePb.RequestLog)28 ByteString (com.google.protobuf.ByteString)20 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)19 LogQuery (com.google.appengine.api.log.LogQuery)13 RequestLogs (com.google.appengine.api.log.RequestLogs)13 LogReadResponse (com.google.apphosting.api.logservice.LogServicePb.LogReadResponse)8 LogReadRequest (com.google.apphosting.api.logservice.LogServicePb.LogReadRequest)7 LogLine (com.google.apphosting.api.logservice.LogServicePb.LogLine)6 AppLogLine (com.google.appengine.api.log.AppLogLine)4 LogOffset (com.google.apphosting.api.logservice.LogServicePb.LogOffset)4 BigInteger (java.math.BigInteger)3 LogLevel (com.google.appengine.api.log.LogService.LogLevel)2 ApiProxy (com.google.apphosting.api.ApiProxy)1 LogModuleVersion (com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion)1 Level (java.util.logging.Level)1