Search in sources :

Example 6 with LogReadRequest

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

the class LogServiceImplTest method testGetLogsForTwoDaysAgo.

@Test
public void testGetLogsForTwoDaysAgo() throws Exception {
    List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
    Long endTime = getTimeForNDaysAgo(1, null);
    Long startTime = getTimeForNDaysAgo(1, endTime);
    Integer batchSize = null;
    LogReadRequest request = createLogReadRequest(startTime, endTime, batchSize, null);
    LogReadResponse response = createLogReadResponse(expectedData);
    setupExpectations(request, response);
    LogQuery query = LogQuery.Builder.withStartTimeUsec(startTime).endTimeUsec(endTime);
    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) Test(org.junit.Test)

Example 7 with LogReadRequest

use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest 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 8 with LogReadRequest

use of com.google.apphosting.api.logservice.LogServicePb.LogReadRequest 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)

Example 9 with LogReadRequest

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

the class LogServiceImplTest method createLogReadRequest.

public LogReadRequest createLogReadRequest(Long startTime, Long endTime, Integer batchSize, List<Version> versions, List<String> requestIds) {
    LogReadRequest.Builder request = LogReadRequest.newBuilder().setAppId(APPLICATION_ID);
    if (startTime != null) {
        request.setStartTime(startTime);
    }
    if (endTime != null) {
        request.setEndTime(endTime);
    }
    if (batchSize != null) {
        batchSize = 20;
    }
    if (versions != null) {
        for (Version version : versions) {
            LogModuleVersion.Builder requestModuleVersion = request.addModuleVersionBuilder();
            if (!version.getModuleId().equals("default")) {
                requestModuleVersion.setModuleId(version.getModuleId());
            }
            requestModuleVersion.setVersionId(version.getVersionId());
        }
    } else {
        request.addModuleVersionBuilder().setVersionId(LogServiceImplTest.MAJOR_VERSION_ID);
    }
    if (requestIds != null) {
        for (String requestId : requestIds) {
            request.addRequestId(ByteString.copyFromUtf8(requestId));
        }
    }
    if (batchSize == null) {
        batchSize = LogService.DEFAULT_ITEMS_PER_FETCH;
    }
    return request.setCount(batchSize).setIncludeIncomplete(false).setIncludeAppLogs(false).build();
}
Also used : LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) Version(com.google.appengine.api.log.LogQuery.Version) LogModuleVersion(com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion) ByteString(com.google.protobuf.ByteString) LogModuleVersion(com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion)

Aggregations

LogReadRequest (com.google.apphosting.api.logservice.LogServicePb.LogReadRequest)9 Test (org.junit.Test)7 ByteString (com.google.protobuf.ByteString)5 LogReadResponse (com.google.apphosting.api.logservice.LogServicePb.LogReadResponse)4 RequestLog (com.google.apphosting.api.logservice.LogServicePb.RequestLog)4 ArrayList (java.util.ArrayList)4 ApiProxy (com.google.apphosting.api.ApiProxy)3 Version (com.google.appengine.api.log.LogQuery.Version)1 LogModuleVersion (com.google.apphosting.api.logservice.LogServicePb.LogModuleVersion)1 LogOffset (com.google.apphosting.api.logservice.LogServicePb.LogOffset)1 BigInteger (java.math.BigInteger)1