Add response information to TldFanoutAction

TldFanoutAction now returns an HTTP response detailing the actions it's taking.
The format is as follows:

OK: Launched the following 3 tasks in queue the-queue
- Task: task-a6ad250b-a9d8-427d-bbf7-eb736e6f4dcb, tld: com, endpoint: /the/servlet/com
- Task: task-cf6c4bb4-0542-411e-ae4d-723beec09e9c, tld: net, endpoint: /the/servlet/net
- Task: task-57899661-fc3f-4049-a265-d6604051406e, tld: org, endpoint: /the/servlet/org

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=152264954
This commit is contained in:
larryruili 2017-04-05 09:12:01 -07:00 committed by Ben McIlwain
parent 87a9d27299
commit 69cf0d4b55
3 changed files with 50 additions and 7 deletions

View file

@ -16,12 +16,15 @@ package google.registry.cron;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Lists.transform;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static java.util.Arrays.asList;
import com.google.appengine.api.taskqueue.dev.QueueStateInfo.TaskStateInfo;
import com.google.appengine.tools.development.testing.LocalTaskQueueTestConfig;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
@ -32,9 +35,11 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldType;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeResponse;
import google.registry.testing.TaskQueueHelper.TaskMatcher;
import google.registry.util.Retrier;
import google.registry.util.TaskEnqueuer;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -47,6 +52,7 @@ public class TldFanoutActionTest {
private static final String ENDPOINT = "/the/servlet";
private static final String QUEUE = "the-queue";
private final FakeResponse response = new FakeResponse();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@ -74,7 +80,7 @@ public class TldFanoutActionTest {
return params.build();
}
private static void run(ImmutableListMultimap<String, String> params) throws Exception {
private void run(ImmutableListMultimap<String, String> params) throws Exception {
TldFanoutAction action = new TldFanoutAction();
action.params = params;
action.endpoint = getLast(params.get("endpoint"));
@ -83,6 +89,7 @@ public class TldFanoutActionTest {
? ImmutableSet.copyOf(Splitter.on(',').split(params.get("exclude").get(0)))
: ImmutableSet.<String>of();
action.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
action.response = response;
action.runInEmpty = params.containsKey("runInEmpty");
action.forEachRealTld = params.containsKey("forEachRealTld");
action.forEachTestTld = params.containsKey("forEachTestTld");
@ -208,4 +215,23 @@ public class TldFanoutActionTest {
assertTasksEnqueued(QUEUE,
new TaskMatcher().url("/the/servlet").param("newkey", "newval"));
}
@Test
public void testSuccess_returnHttpResponse() throws Exception {
run(getParamsMap("forEachRealTld", "", "endpoint", "/the/servlet/:tld"));
List<TaskStateInfo> taskList =
LocalTaskQueueTestConfig.getLocalTaskQueue().getQueueStateInfo().get(QUEUE).getTaskInfo();
assertThat(taskList).hasSize(3);
String expectedResponse = String.format(
"OK: Launched the following 3 tasks in queue the-queue\n"
+ "- Task: %s, tld: com, endpoint: /the/servlet/com\n"
+ "- Task: %s, tld: net, endpoint: /the/servlet/net\n"
+ "- Task: %s, tld: org, endpoint: /the/servlet/org\n",
taskList.get(0).getTaskName(),
taskList.get(1).getTaskName(),
taskList.get(2).getTaskName());
assertThat(response.getPayload()).isEqualTo(expectedResponse);
}
}