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);
}
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());
}
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);
}
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());
}
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);
}
});
}
Aggregations