Search in sources :

Example 16 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testBulkAddPullTasksToPushQueue.

@Test
public void testBulkAddPullTasksToPushQueue() throws Exception {
    for (TaskQueueAddRequest.Builder addRequest : bulkAddPullRequest.getAddRequestBuilderList()) {
        addRequest.setQueueName(ByteString.copyFromUtf8(entry.getName()));
    }
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddPullRequest.build());
    assertThat(response.getTaskResult(0).getResult().getNumber()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
    assertThat(response.getTaskResult(1).getResult().getNumber()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
    assertThat(response.getTaskResult(2).getResult().getNumber()).isEqualTo(ErrorCode.INVALID_QUEUE_MODE_VALUE);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) Test(org.junit.Test)

Example 17 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testBulkAdd.

@Test
public void testBulkAdd() throws Exception {
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddRequest.build());
    assertThat(response).isEqualTo(expectedBulkAddResponse.build());
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) Test(org.junit.Test)

Example 18 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testFetchQueueStats.

@Test
public void testFetchQueueStats() throws Exception {
    TaskQueueFetchQueueStatsRequest request = TaskQueueFetchQueueStatsRequest.newBuilder().addQueueName(ByteString.copyFromUtf8("default")).build();
    TaskQueueFetchQueueStatsResponse response = localService.fetchQueueStats(new Status(), request);
    assertThat(response.getQueueStatsCount()).isEqualTo(1);
    TaskQueueFetchQueueStatsResponse.QueueStats stats = response.getQueueStats(0);
    assertThat(stats.hasScannerInfo()).isTrue();
    TaskQueueScannerQueueInfo scannerInfo = stats.getScannerInfo();
    assertThat(scannerInfo.hasRequestsInFlight()).isTrue();
    assertThat(scannerInfo.hasEnforcedRate()).isTrue();
    assertThat((0 == stats.getNumTasks() && -1 == stats.getOldestEtaUsec()) || (0 < stats.getNumTasks() && 0 <= stats.getOldestEtaUsec())).isTrue();
    assertThat(scannerInfo.getEnforcedRate()).isAtLeast(0);
    assertThat(scannerInfo.getExecutedLastMinute()).isAtLeast(0);
    assertThat(scannerInfo.getRequestsInFlight()).isAtLeast(0);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueFetchQueueStatsResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse) TaskQueueScannerQueueInfo(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueScannerQueueInfo) TaskQueueFetchQueueStatsRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest) Test(org.junit.Test)

Example 19 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testBulkAddPullNoName.

@Test
public void testBulkAddPullNoName() throws Exception {
    addPullRequest1.clearTaskName();
    addPullRequest2.clearTaskName();
    addPullRequest3.clearTaskName();
    TaskQueueBulkAddResponse response = localService.bulkAdd(new Status(), bulkAddPullRequest.buildPartial());
    assertThat(response.getTaskResult(0).getChosenTaskName().toStringUtf8()).startsWith("task-");
    assertThat(response.getTaskResult(1).getChosenTaskName().toStringUtf8()).startsWith("task-");
    assertThat(response.getTaskResult(2).getChosenTaskName().toStringUtf8()).startsWith("task-");
    expectedTaskResult1.setChosenTaskName(response.getTaskResult(0).getChosenTaskName());
    expectedTaskResult2.setChosenTaskName(response.getTaskResult(1).getChosenTaskName());
    expectedTaskResult3.setChosenTaskName(response.getTaskResult(2).getChosenTaskName());
    assertThat(response).isEqualTo(expectedBulkAddResponse.build());
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) Test(org.junit.Test)

Example 20 with Status

use of com.google.appengine.tools.development.LocalRpcService.Status in project appengine-java-standard by GoogleCloudPlatform.

the class LocalBlobImageServlet method transformImage.

/**
 * Transforms the given image specified in the {@code ParseUrl} argument.
 *
 * Applies all the requested resize and crop operations to a valid image.
 *
 * @param request a valid {@code ParseUrl} instance
 *
 * @return the transformed image in an Image class
 * @throws ApiProxy.ApplicationException If the image cannot be opened,
 *    encoded, or if the transform is malformed
 */
protected Image transformImage(final ParsedUrl request) {
    return AccessController.doPrivileged(new PrivilegedAction<Image>() {

        @Override
        public Image run() {
            // Obtain the image bytes as a BufferedImage
            Status unusedStatus = new Status();
            ImageData imageData = ImageData.newBuilder().setBlobKey(request.getBlobKey()).setContent(ByteString.EMPTY).build();
            String originalMimeType = imagesService.getMimeType(imageData);
            BufferedImage img = imagesService.openImage(imageData, unusedStatus);
            // Apply the transform
            if (request.hasOptions()) {
                // Crop
                if (request.getCrop()) {
                    Transform.Builder cropXform = null;
                    float width = img.getWidth();
                    float height = img.getHeight();
                    if (width > height) {
                        cropXform = Transform.newBuilder();
                        float delta = (width - height) / (width * 2.0f);
                        cropXform.setCropLeftX(delta);
                        cropXform.setCropRightX(1.0f - delta);
                    } else if (width < height) {
                        cropXform = Transform.newBuilder();
                        float delta = (height - width) / (height * 2.0f);
                        float topDelta = Math.max(0.0f, delta - 0.25f);
                        float bottomDelta = 1.0f - (2.0f * delta) + topDelta;
                        cropXform.setCropTopY(topDelta);
                        cropXform.setCropBottomY(bottomDelta);
                    }
                    if (cropXform != null) {
                        img = imagesService.processTransform(img, cropXform.build(), unusedStatus);
                    }
                }
                // Resize
                Transform resizeXform = Transform.newBuilder().setWidth(request.getResize()).setHeight(request.getResize()).build();
                img = imagesService.processTransform(img, resizeXform, unusedStatus);
            } else if (img.getWidth() > DEFAULT_SERVING_SIZE || img.getHeight() > DEFAULT_SERVING_SIZE) {
                // Resize down to default serving size.
                Transform resizeXform = Transform.newBuilder().setWidth(DEFAULT_SERVING_SIZE).setHeight(DEFAULT_SERVING_SIZE).build();
                img = imagesService.processTransform(img, resizeXform, unusedStatus);
            }
            MIME_TYPE outputMimeType = MIME_TYPE.JPEG;
            String outputMimeTypeString = "image/jpeg";
            if (transcodeToPng.contains(originalMimeType)) {
                outputMimeType = MIME_TYPE.PNG;
                outputMimeTypeString = "image/png";
            }
            return new Image(imagesService.saveImage(img, outputMimeType, unusedStatus), outputMimeTypeString);
        }
    });
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) ImageData(com.google.appengine.api.images.ImagesServicePb.ImageData) ByteString(com.google.protobuf.ByteString) BufferedImage(java.awt.image.BufferedImage) Transform(com.google.appengine.api.images.ImagesServicePb.Transform) BufferedImage(java.awt.image.BufferedImage) MIME_TYPE(com.google.appengine.api.images.ImagesServicePb.OutputSettings.MIME_TYPE)

Aggregations

Status (com.google.appengine.tools.development.LocalRpcService.Status)34 Test (org.junit.Test)31 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)18 TaskQueueQueryAndOwnTasksRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksRequest)5 ApiProxy (com.google.apphosting.api.ApiProxy)5 ByteString (com.google.protobuf.ByteString)5 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)4 TaskQueueModifyTaskLeaseRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueModifyTaskLeaseRequest)4 TaskQueueQueryAndOwnTasksResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse)4 Clock (com.google.appengine.tools.development.Clock)4 QueueXml (com.google.apphosting.utils.config.QueueXml)4 TaskQueueDeleteRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueDeleteRequest)3 TaskQueueDeleteResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueDeleteResponse)3 TaskQueueAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse)2 TaskQueueBulkAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImageData (com.google.appengine.api.images.ImagesServicePb.ImageData)1 MIME_TYPE (com.google.appengine.api.images.ImagesServicePb.OutputSettings.MIME_TYPE)1 Transform (com.google.appengine.api.images.ImagesServicePb.Transform)1 TaskQueueFetchQueueStatsRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest)1