Search in sources :

Example 26 with RequestLog

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

the class LocalLogServiceTest method testSetEndTime.

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

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

the class LogServiceImplTest method getAllLogsForAppVersions.

private void getAllLogsForAppVersions(LogQuery query, List<Version> moduleVersions) throws Exception {
    List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
    Long startTime = null;
    Long endTime = null;
    Integer batchSize = null;
    LogReadRequest request = createLogReadRequest(startTime, endTime, batchSize, moduleVersions);
    LogReadResponse response = createLogReadResponse(expectedData);
    setupExpectations(request, response);
    List<RequestLogs> actualData = new ArrayList<>();
    for (RequestLogs record : new LogServiceImpl().fetch(query)) {
        actualData.add(record);
    }
    String expectedLogs = getJustCombinedRequestFields(expectedData);
    String actualLogs = getJustCombinedFields(actualData);
    assertThat(actualLogs).isEqualTo(expectedLogs);
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) LogReadResponse(com.google.apphosting.api.logservice.LogServicePb.LogReadResponse)

Example 28 with RequestLog

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

the class LogServiceImplTest method testGetLogsForTwoDaysAgoMillis.

@Test
public void testGetLogsForTwoDaysAgoMillis() throws Exception {
    List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
    // Use millisecond-aligned microsecond timestamps.
    Long endTimeUsec = getTimeForNDaysAgo(1, null) / 1000 * 1000;
    Long startTimeUsec = getTimeForNDaysAgo(1, endTimeUsec) / 1000 * 1000;
    Long endTimeMillis = endTimeUsec / 1000;
    Long startTimeMillis = startTimeUsec / 1000;
    Integer batchSize = null;
    LogReadRequest request = createLogReadRequest(startTimeMillis * 1000, endTimeMillis * 1000, batchSize, null);
    LogReadResponse response = createLogReadResponse(expectedData);
    setupExpectations(request, response);
    LogQuery query = LogQuery.Builder.withStartTimeMillis(startTimeMillis).endTimeMillis(endTimeMillis);
    List<RequestLogs> actualData = new ArrayList<>();
    for (RequestLogs record : new LogServiceImpl().fetch(query)) {
        actualData.add(record);
    }
    String expectedLogs = getJustCombinedRequestFields(expectedData);
    String actualLogs = getJustCombinedFields(actualData);
    assertThat(actualLogs).isEqualTo(expectedLogs);
    // Test the Usec/Millis variants.
    assertThat(startTimeUsec).isEqualTo(query.getStartTimeUsec());
    assertThat(endTimeUsec).isEqualTo(query.getEndTimeUsec());
    assertThat(startTimeMillis).isEqualTo(query.getStartTimeMillis());
    assertThat(endTimeMillis).isEqualTo(query.getEndTimeMillis());
    query = LogQuery.Builder.withEndTimeMillis(endTimeMillis).startTimeMillis(startTimeMillis);
    assertThat(startTimeUsec).isEqualTo(query.getStartTimeUsec());
    assertThat(endTimeUsec).isEqualTo(query.getEndTimeUsec());
    assertThat(startTimeMillis).isEqualTo(query.getStartTimeMillis());
    assertThat(endTimeMillis).isEqualTo(query.getEndTimeMillis());
    query = LogQuery.Builder.withDefaults();
    assertThat(query.getStartTimeUsec()).isNull();
    assertThat(query.getEndTimeUsec()).isNull();
    assertThat(query.getStartTimeMillis()).isNull();
    assertThat(query.getEndTimeMillis()).isNull();
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) LogReadResponse(com.google.apphosting.api.logservice.LogServicePb.LogReadResponse) 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