Search in sources :

Example 1 with RequestLog

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

the class LocalLogService method findLogInLogMapOrAddNewLog.

private synchronized RequestLog findLogInLogMapOrAddNewLog(String requestId) {
    if (requestId == null) {
        requestId = "null";
    }
    // assumed to be sorted by requestId.
    for (int i = 0; i < logs.size(); i++) {
        RequestLog possibleLog = logs.get(i);
        if (possibleLog.getRequestId().toStringUtf8().equals(requestId)) {
            return possibleLog;
        }
    }
    /* Items are sorted in descending order w.r.t. request id. Since request ids
     * are monotonically increasing, this means that the new request id we're
     * about to generate will have the largest value ever seen in the log list,
     * so put it at the beginning of the list. Lists also are not
     * thread-safe for adds and deletes, so synchronize access to it. */
    // Fill with required fields with dummy data that will be replaced later anyway.
    RequestLog.Builder log = RequestLog.newBuilder().setRequestId(ByteString.copyFromUtf8(requestId)).setFinished(false);
    LogOffset offset = LogOffset.newBuilder().setRequestId(ByteString.copyFromUtf8(requestId)).build();
    RequestLog built = log.setOffset(offset).buildPartial();
    logs.add(0, built);
    // If there are too many logs stored, remove the oldest (last) one.
    if (logs.size() > MAX_NUM_LOGS) {
        logs.remove(logs.size() - 1);
    }
    return built;
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogOffset(com.google.apphosting.api.logservice.LogServicePb.LogOffset)

Example 2 with RequestLog

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

the class LocalLogServiceTest method testGetAllLogs.

@Test
public void testGetAllLogs() throws Exception {
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    // Logs are stored reverse-chronologically
    List<Long> expectedLogStartTimes = new ArrayList<>();
    for (RequestLog record : Lists.reverse(allLogs)) {
        expectedLogStartTimes.add(record.getStartTime());
    }
    LogQuery query = LogQuery.Builder.withDefaults();
    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 3 with RequestLog

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

the class LocalLogServiceTest method testIncludeIncomplete.

@Test
public void testIncludeIncomplete() throws Exception {
    long completeLogStartTime = 10;
    List<RequestLog> completeLogs = getTestData(completeLogStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(completeLogs, completeLogsRequested);
    long incompleteLogStartTime = 40;
    List<RequestLog> incompleteLogs = getTestData(incompleteLogStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    boolean incompleteLogsRequested = false;
    writeTestData(incompleteLogs, incompleteLogsRequested);
    List<Long> allLogStartTimes = new ArrayList<>();
    for (RequestLog record : Lists.reverse(incompleteLogs)) {
        allLogStartTimes.add(record.getStartTime());
    }
    List<Long> completeLogStartTimes = new ArrayList<>();
    for (RequestLog record : Lists.reverse(completeLogs)) {
        allLogStartTimes.add(record.getStartTime());
        completeLogStartTimes.add(record.getStartTime());
    }
    LogQuery query = LogQuery.Builder.withIncludeIncomplete(true);
    List<Long> actualStartTimes = new ArrayList<>();
    for (RequestLogs record : logService.fetch(query)) {
        actualStartTimes.add(record.getStartTimeUsec());
    }
    String expected = joinLogStartTimes(allLogStartTimes);
    String actual = joinLogStartTimes(actualStartTimes);
    assertThat(actual).isEqualTo(expected);
    query.includeIncomplete(false);
    List<Long> actualCompleteStartTimes = new ArrayList<>();
    for (RequestLogs record : logService.fetch(query)) {
        actualCompleteStartTimes.add(record.getStartTimeUsec());
    }
    String expectedIncomplete = joinLogStartTimes(completeLogStartTimes);
    String actualIncomplete = joinLogStartTimes(actualCompleteStartTimes);
    assertThat(actualIncomplete).isEqualTo(expectedIncomplete);
}
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 4 with RequestLog

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

the class LocalLogServiceTest method testSetStartTime.

@Test
public void testSetStartTime() throws Exception {
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    long startTime = 4;
    // Logs are stored reverse-chronologically
    List<Long> expectedLogStartTimes = new ArrayList<>();
    for (RequestLog record : Lists.reverse(allLogs)) {
        if (record.getEndTime() >= startTime) {
            expectedLogStartTimes.add(record.getStartTime());
        }
    }
    LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime);
    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 5 with RequestLog

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

the class LocalLogServiceTest method testGetAllLogsWithSmallLimit.

@Test
public void testGetAllLogsWithSmallLimit() throws Exception {
    List<RequestLog> allLogs = getTestData(defaultStartTime, defaultVersion, defaultAppLogsDesired, completeLogsRequested);
    writeTestData(allLogs, completeLogsRequested);
    // Logs are stored reverse-chronologically
    List<Long> expectedLogStartTimes = new ArrayList<>();
    for (RequestLog record : Lists.reverse(allLogs)) {
        expectedLogStartTimes.add(record.getStartTime());
    }
    LogQuery query = LogQuery.Builder.withBatchSize(1);
    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)

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