Action to delete all cross-tld entities.

Plus refactoring of the KillAllXXXActions and tests to share
common code.

This essentially completes the KillAll []s. We can now reliably
clean out everything except for:
 * Lock - harmless to leave alone or delete from the gae console
 * GaeUserIdConverter - same
 * RdeRevision - filed [] to track, but harmless if not cleaned up
 * ForeignKeyHostIndex of renamed hosts - tracked in []
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120781975
This commit is contained in:
cgoldfeder 2016-04-25 22:09:58 -07:00 committed by Justine Tunney
parent ac2f17e10f
commit a41677aea1
9 changed files with 508 additions and 205 deletions

View file

@ -14,89 +14,44 @@
package com.google.domain.registry.tools.server;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.truth.Truth.assertThat;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
import static com.google.domain.registry.testing.DatastoreHelper.createTld;
import static com.google.domain.registry.testing.DatastoreHelper.newContactResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistResourceWithCommitLog;
import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME;
import static com.google.domain.registry.model.EntityClasses.CLASS_TO_KIND_FUNCTION;
import static java.util.Arrays.asList;
import com.google.appengine.api.datastore.Entity;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.domain.registry.mapreduce.MapreduceAction;
import com.google.domain.registry.mapreduce.MapreduceRunner;
import com.google.domain.registry.model.ImmutableObject;
import com.google.domain.registry.model.ofy.CommitLogBucket;
import com.google.domain.registry.model.ofy.CommitLogCheckpoint;
import com.google.domain.registry.model.ofy.CommitLogCheckpointRoot;
import com.google.domain.registry.model.ofy.CommitLogManifest;
import com.google.domain.registry.model.ofy.CommitLogMutation;
import com.google.domain.registry.testing.FakeResponse;
import com.google.domain.registry.testing.mapreduce.MapreduceTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import java.util.List;
/** Tests for {@link KillAllCommitLogsAction}.*/
@RunWith(JUnit4.class)
public class KillAllCommitLogsActionTest extends MapreduceTestCase<KillAllCommitLogsAction> {
public class KillAllCommitLogsActionTest extends KillAllActionTestCase<KillAllCommitLogsAction> {
static final List<Class<? extends ImmutableObject>> AFFECTED_TYPES = ImmutableList.of(
CommitLogBucket.class,
CommitLogCheckpoint.class,
CommitLogCheckpointRoot.class,
CommitLogMutation.class,
CommitLogManifest.class);
public KillAllCommitLogsActionTest() {
super(FluentIterable
.from(asList(
CommitLogBucket.class,
CommitLogCheckpoint.class,
CommitLogCheckpointRoot.class,
CommitLogMutation.class,
CommitLogManifest.class))
.transform(CLASS_TO_KIND_FUNCTION)
.toSet());
}
private void runMapreduce() throws Exception {
@Override
MapreduceAction createAction() {
action = new KillAllCommitLogsAction();
action.mrRunner = new MapreduceRunner(Optional.<Integer>absent(), Optional.<Integer>absent());
action.response = new FakeResponse();
action.run();
executeTasksUntilEmpty("mapreduce");
}
@Test
public void testKill() throws Exception {
int nextContactId = 5432;
for (String tld : asList("tld1", "tld2")) {
createTld(tld);
persistResourceWithCommitLog(
newContactResource(String.format("abc%d", nextContactId++)));
}
persistResource(CommitLogCheckpointRoot.create(START_OF_TIME.plusDays(1)));
persistResource(
CommitLogCheckpoint.create(
START_OF_TIME.plusDays(1),
ImmutableMap.of(1, START_OF_TIME.plusDays(2))));
for (Class<?> clazz : AFFECTED_TYPES) {
assertThat(ofy().load().type(clazz)).named("entities of type " + clazz).isNotEmpty();
}
ImmutableList<?> otherStuff = FluentIterable.from(ofy().load())
.filter(new Predicate<Object>() {
@Override
public boolean apply(Object obj) {
return !AFFECTED_TYPES.contains(obj.getClass());
}})
.toList();
assertThat(otherStuff).isNotEmpty();
runMapreduce();
for (Class<?> clazz : AFFECTED_TYPES) {
assertThat(ofy().load().type(clazz)).named("entities of type " + clazz).isEmpty();
}
// Filter out raw Entity objects created by the mapreduce.
assertThat(filter(ofy().load(), not(instanceOf(Entity.class))))
.containsExactlyElementsIn(otherStuff);
return action;
}
}