Search in sources :

Example 11 with RequestLog

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

the class LogServiceImplTest method testGetLogsForRequestIds.

@Test
public void testGetLogsForRequestIds() throws Exception {
    int numRequested = LogService.DEFAULT_ITEMS_PER_FETCH;
    List<RequestLog> expectedData = getTestData(numRequested);
    List<String> requestIds = new ArrayList<>();
    LogReadRequest.Builder request = createLogReadRequest(null, null, null, null, requestIds).toBuilder();
    LogReadResponse response = createLogReadResponse(expectedData);
    ArrayList<String> queriedIds = new ArrayList<>();
    // List<ByteString> expectedIds = request.getRequestIdList();
    for (int i = 0; i < numRequested; i++) {
        String requestId = Integer.toString(i);
        queriedIds.add(requestId);
        // expectedIds.add(ByteString.copyFromUtf8(requestId));
        request.addRequestId(ByteString.copyFromUtf8(requestId));
    }
    setupExpectations(request.build(), response);
    LogQuery query = LogQuery.Builder.withRequestIds(queriedIds);
    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 : ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) LogReadResponse(com.google.apphosting.api.logservice.LogServicePb.LogReadResponse) Test(org.junit.Test)

Example 12 with RequestLog

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

the class LogServiceImplTest method testFetchWithOffset.

@Test
public void testFetchWithOffset() throws Exception {
    List<RequestLog> expectedData = getTestData(LogService.DEFAULT_ITEMS_PER_FETCH);
    LogReadRequest.Builder request = createLogReadRequest(null, null, null, null).toBuilder();
    LogOffset offset = LogOffset.newBuilder().setRequestId(ByteString.copyFrom(new byte[] { (byte) 0xfe, (byte) 0xff, (byte) 0xcd })).build();
    request.setOffset(offset);
    LogReadResponse response = createLogReadResponse(expectedData);
    setupExpectations(request.build(), response);
    LogQuery query = LogQuery.Builder.withDefaults();
    query.offset(base64().encode(offset.toByteArray()));
    new LogServiceImpl().fetch(query);
    // Test negative case.
    // Not parseable as Base64.
    query.offset("!");
    assertThrows(IllegalArgumentException.class, () -> new LogServiceImpl().fetch(query));
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog) LogReadRequest(com.google.apphosting.api.logservice.LogServicePb.LogReadRequest) LogOffset(com.google.apphosting.api.logservice.LogServicePb.LogOffset) LogReadResponse(com.google.apphosting.api.logservice.LogServicePb.LogReadResponse) Test(org.junit.Test)

Example 13 with RequestLog

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

the class LogServiceImplTest method getJustCombinedRequestFields.

public String getJustCombinedRequestFields(List<RequestLog> data) {
    StringBuilder combinedFields = new StringBuilder("[ ");
    for (RequestLog datum : data) {
        combinedFields.append(datum.getCombined()).append(" ");
    }
    combinedFields.append("]");
    return combinedFields.toString();
}
Also used : RequestLog(com.google.apphosting.api.logservice.LogServicePb.RequestLog)

Example 14 with RequestLog

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

the class LogServiceImplTest method testGetLogsForLast24Hours.

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

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

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