mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Batch NORDN pull queue task deletions
They were failing because the maximum App Engine task batch size is 1,000, and we currently have more than 4,000 tasks in the pull queue. We keep re-uploading those to NORDN because we're unable to delete the tasks after successful upload, so the leases expire and they get processed again. Also renames TaskEnqueuer to TaskQueueUtils to reflect its newly expanded role. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=197060903
This commit is contained in:
parent
1248a7722b
commit
c989911526
21 changed files with 129 additions and 73 deletions
|
@ -28,7 +28,7 @@ import google.registry.request.Action;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public final class CommitLogCheckpointAction implements Runnable {
|
||||||
|
|
||||||
@Inject Clock clock;
|
@Inject Clock clock;
|
||||||
@Inject CommitLogCheckpointStrategy strategy;
|
@Inject CommitLogCheckpointStrategy strategy;
|
||||||
@Inject TaskEnqueuer taskEnqueuer;
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject CommitLogCheckpointAction() {}
|
@Inject CommitLogCheckpointAction() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,7 +76,7 @@ public final class CommitLogCheckpointAction implements Runnable {
|
||||||
.entities(
|
.entities(
|
||||||
checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime()));
|
checkpoint, CommitLogCheckpointRoot.create(checkpoint.getCheckpointTime()));
|
||||||
// Enqueue a diff task between previous and current checkpoints.
|
// Enqueue a diff task between previous and current checkpoints.
|
||||||
taskEnqueuer.enqueue(
|
taskQueueUtils.enqueue(
|
||||||
getQueue(QUEUE_NAME),
|
getQueue(QUEUE_NAME),
|
||||||
withUrl(ExportCommitLogDiffAction.PATH)
|
withUrl(ExportCommitLogDiffAction.PATH)
|
||||||
.param(LOWER_CHECKPOINT_TIME_PARAM, lastWrittenTime.toString())
|
.param(LOWER_CHECKPOINT_TIME_PARAM, lastWrittenTime.toString())
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.google.common.net.HostAndPort;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl;
|
import google.registry.config.RegistryConfigSettings.AppEngine.ToolsServiceUrl;
|
||||||
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -853,7 +854,7 @@ public final class RegistryConfig {
|
||||||
* <p>Note that this uses {@code @Named} instead of {@code @Config} so that it can be used from
|
* <p>Note that this uses {@code @Named} instead of {@code @Config} so that it can be used from
|
||||||
* the low-level util package, which cannot have a dependency on the config package.
|
* the low-level util package, which cannot have a dependency on the config package.
|
||||||
*
|
*
|
||||||
* @see google.registry.util.TaskEnqueuer
|
* @see TaskQueueUtils
|
||||||
*/
|
*/
|
||||||
@Provides
|
@Provides
|
||||||
@Named("transientFailureRetries")
|
@Named("transientFailureRetries")
|
||||||
|
|
|
@ -23,7 +23,7 @@ import google.registry.model.ofy.CommitLogBucket;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -40,7 +40,7 @@ public final class CommitLogFanoutAction implements Runnable {
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
@Inject TaskEnqueuer taskEnqueuer;
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject @Parameter("endpoint") String endpoint;
|
@Inject @Parameter("endpoint") String endpoint;
|
||||||
@Inject @Parameter("queue") String queue;
|
@Inject @Parameter("queue") String queue;
|
||||||
@Inject @Parameter("jitterSeconds") Optional<Integer> jitterSeconds;
|
@Inject @Parameter("jitterSeconds") Optional<Integer> jitterSeconds;
|
||||||
|
@ -55,7 +55,7 @@ public final class CommitLogFanoutAction implements Runnable {
|
||||||
.countdownMillis(jitterSeconds.isPresent()
|
.countdownMillis(jitterSeconds.isPresent()
|
||||||
? random.nextInt((int) SECONDS.toMillis(jitterSeconds.get()))
|
? random.nextInt((int) SECONDS.toMillis(jitterSeconds.get()))
|
||||||
: 0);
|
: 0);
|
||||||
taskEnqueuer.enqueue(taskQueue, taskOptions);
|
taskQueueUtils.enqueue(taskQueue, taskOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ import google.registry.request.RequestParameters;
|
||||||
import google.registry.request.Response;
|
import google.registry.request.Response;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -103,7 +103,7 @@ public final class TldFanoutAction implements Runnable {
|
||||||
|
|
||||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||||
|
|
||||||
@Inject TaskEnqueuer taskEnqueuer;
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject Response response;
|
@Inject Response response;
|
||||||
@Inject @Parameter(ENDPOINT_PARAM) String endpoint;
|
@Inject @Parameter(ENDPOINT_PARAM) String endpoint;
|
||||||
@Inject @Parameter(QUEUE_PARAM) String queue;
|
@Inject @Parameter(QUEUE_PARAM) String queue;
|
||||||
|
@ -144,7 +144,7 @@ public final class TldFanoutAction implements Runnable {
|
||||||
}
|
}
|
||||||
for (String tld : tlds) {
|
for (String tld : tlds) {
|
||||||
TaskOptions taskOptions = createTaskOptions(tld, flowThruParams);
|
TaskOptions taskOptions = createTaskOptions(tld, flowThruParams);
|
||||||
TaskHandle taskHandle = taskEnqueuer.enqueue(taskQueue, taskOptions);
|
TaskHandle taskHandle = taskQueueUtils.enqueue(taskQueue, taskOptions);
|
||||||
outputPayload.append(
|
outputPayload.append(
|
||||||
String.format(
|
String.format(
|
||||||
"- Task: '%s', tld: '%s', endpoint: '%s'\n",
|
"- Task: '%s', tld: '%s', endpoint: '%s'\n",
|
||||||
|
|
|
@ -47,7 +47,7 @@ import google.registry.request.RequestParameters;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -101,7 +101,7 @@ public final class ReadDnsQueueAction implements Runnable {
|
||||||
@Inject Clock clock;
|
@Inject Clock clock;
|
||||||
@Inject DnsQueue dnsQueue;
|
@Inject DnsQueue dnsQueue;
|
||||||
@Inject HashFunction hashFunction;
|
@Inject HashFunction hashFunction;
|
||||||
@Inject TaskEnqueuer taskEnqueuer;
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject ReadDnsQueueAction() {}
|
@Inject ReadDnsQueueAction() {}
|
||||||
|
|
||||||
/** Container for items we pull out of the DNS pull queue and process for fanout. */
|
/** Container for items we pull out of the DNS pull queue and process for fanout. */
|
||||||
|
@ -374,7 +374,7 @@ public final class ReadDnsQueueAction implements Runnable {
|
||||||
: PublishDnsUpdatesAction.PARAM_DOMAINS,
|
: PublishDnsUpdatesAction.PARAM_DOMAINS,
|
||||||
refreshItem.name());
|
refreshItem.name());
|
||||||
}
|
}
|
||||||
taskEnqueuer.enqueue(dnsPublishPushQueue, options);
|
taskQueueUtils.enqueue(dnsPublishPushQueue, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ import google.registry.request.HttpException.NotModifiedException;
|
||||||
import google.registry.request.Payload;
|
import google.registry.request.Payload;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -64,7 +64,7 @@ public class BigqueryPollJobAction implements Runnable {
|
||||||
static final Duration POLL_COUNTDOWN = Duration.standardSeconds(20);
|
static final Duration POLL_COUNTDOWN = Duration.standardSeconds(20);
|
||||||
|
|
||||||
@Inject Bigquery bigquery;
|
@Inject Bigquery bigquery;
|
||||||
@Inject TaskEnqueuer enqueuer;
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject @Header(CHAINED_TASK_QUEUE_HEADER) Lazy<String> chainedQueueName;
|
@Inject @Header(CHAINED_TASK_QUEUE_HEADER) Lazy<String> chainedQueueName;
|
||||||
@Inject @Header(PROJECT_ID_HEADER) String projectId;
|
@Inject @Header(PROJECT_ID_HEADER) String projectId;
|
||||||
@Inject @Header(JOB_ID_HEADER) String jobId;
|
@Inject @Header(JOB_ID_HEADER) String jobId;
|
||||||
|
@ -84,7 +84,7 @@ public class BigqueryPollJobAction implements Runnable {
|
||||||
} catch (ClassNotFoundException | IOException e) {
|
} catch (ClassNotFoundException | IOException e) {
|
||||||
throw new BadRequestException("Cannot deserialize task from payload", e);
|
throw new BadRequestException("Cannot deserialize task from payload", e);
|
||||||
}
|
}
|
||||||
String taskName = enqueuer.enqueue(getQueue(chainedQueueName.get()), task).getName();
|
String taskName = taskQueueUtils.enqueue(getQueue(chainedQueueName.get()), task).getName();
|
||||||
logger.infofmt(
|
logger.infofmt(
|
||||||
"Added chained task %s for %s to queue %s: %s",
|
"Added chained task %s for %s to queue %s: %s",
|
||||||
taskName,
|
taskName,
|
||||||
|
@ -127,16 +127,17 @@ public class BigqueryPollJobAction implements Runnable {
|
||||||
/** Helper class to enqueue a bigquery poll job. */
|
/** Helper class to enqueue a bigquery poll job. */
|
||||||
public static class BigqueryPollJobEnqueuer {
|
public static class BigqueryPollJobEnqueuer {
|
||||||
|
|
||||||
private final TaskEnqueuer enqueuer;
|
private final TaskQueueUtils taskQueueUtils;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BigqueryPollJobEnqueuer(TaskEnqueuer enqueuer) {
|
BigqueryPollJobEnqueuer(TaskQueueUtils taskQueueUtils) {
|
||||||
this.enqueuer = enqueuer;
|
this.taskQueueUtils = taskQueueUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enqueue a task to poll for the success or failure of the referenced BigQuery job. */
|
/** Enqueue a task to poll for the success or failure of the referenced BigQuery job. */
|
||||||
public TaskHandle enqueuePollTask(JobReference jobRef) {
|
public TaskHandle enqueuePollTask(JobReference jobRef) {
|
||||||
return enqueuer.enqueue(getQueue(QUEUE), createCommonPollTask(jobRef).method(Method.GET));
|
return taskQueueUtils.enqueue(
|
||||||
|
getQueue(QUEUE), createCommonPollTask(jobRef).method(Method.GET));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,7 +149,7 @@ public class BigqueryPollJobAction implements Runnable {
|
||||||
// Serialize the chainedTask into a byte array to put in the task payload.
|
// Serialize the chainedTask into a byte array to put in the task payload.
|
||||||
ByteArrayOutputStream taskBytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream taskBytes = new ByteArrayOutputStream();
|
||||||
new ObjectOutputStream(taskBytes).writeObject(chainedTask);
|
new ObjectOutputStream(taskBytes).writeObject(chainedTask);
|
||||||
return enqueuer.enqueue(
|
return taskQueueUtils.enqueue(
|
||||||
getQueue(QUEUE),
|
getQueue(QUEUE),
|
||||||
createCommonPollTask(jobRef)
|
createCommonPollTask(jobRef)
|
||||||
.method(Method.POST)
|
.method(Method.POST)
|
||||||
|
|
|
@ -34,7 +34,7 @@ import google.registry.request.Parameter;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.security.XsrfTokenManager;
|
import google.registry.security.XsrfTokenManager;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -147,8 +147,7 @@ public class LoadTestAction implements Runnable {
|
||||||
@Parameter("hostInfos")
|
@Parameter("hostInfos")
|
||||||
int hostInfosPerSecond;
|
int hostInfosPerSecond;
|
||||||
|
|
||||||
@Inject
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
TaskEnqueuer taskEnqueuer;
|
|
||||||
|
|
||||||
private final String xmlContactCreateTmpl;
|
private final String xmlContactCreateTmpl;
|
||||||
private final String xmlContactCreateFail;
|
private final String xmlContactCreateFail;
|
||||||
|
@ -344,7 +343,7 @@ public class LoadTestAction implements Runnable {
|
||||||
List<List<TaskOptions>> chunks = partition(tasks, maxTasksPerAdd());
|
List<List<TaskOptions>> chunks = partition(tasks, maxTasksPerAdd());
|
||||||
// Farm out tasks to multiple queues to work around queue qps quotas.
|
// Farm out tasks to multiple queues to work around queue qps quotas.
|
||||||
for (int i = 0; i < chunks.size(); i++) {
|
for (int i = 0; i < chunks.size(); i++) {
|
||||||
taskEnqueuer.enqueue(getQueue("load" + (i % NUM_QUEUES)), chunks.get(i));
|
taskQueueUtils.enqueue(getQueue("load" + (i % NUM_QUEUES)), chunks.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ import google.registry.request.RequestParameters;
|
||||||
import google.registry.request.lock.LockHandler;
|
import google.registry.request.lock.LockHandler;
|
||||||
import google.registry.tldconfig.idn.IdnTableEnum;
|
import google.registry.tldconfig.idn.IdnTableEnum;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import google.registry.xjc.rdeheader.XjcRdeHeader;
|
import google.registry.xjc.rdeheader.XjcRdeHeader;
|
||||||
import google.registry.xjc.rdeheader.XjcRdeHeaderElement;
|
import google.registry.xjc.rdeheader.XjcRdeHeaderElement;
|
||||||
import google.registry.xml.XmlException;
|
import google.registry.xml.XmlException;
|
||||||
|
@ -70,7 +70,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
||||||
|
|
||||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||||
|
|
||||||
private final TaskEnqueuer taskEnqueuer;
|
private final TaskQueueUtils taskQueueUtils;
|
||||||
private final LockHandler lockHandler;
|
private final LockHandler lockHandler;
|
||||||
private final int gcsBufferSize;
|
private final int gcsBufferSize;
|
||||||
private final String bucket;
|
private final String bucket;
|
||||||
|
@ -81,7 +81,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RdeStagingReducer(
|
RdeStagingReducer(
|
||||||
TaskEnqueuer taskEnqueuer,
|
TaskQueueUtils taskQueueUtils,
|
||||||
LockHandler lockHandler,
|
LockHandler lockHandler,
|
||||||
@Config("gcsBufferSize") int gcsBufferSize,
|
@Config("gcsBufferSize") int gcsBufferSize,
|
||||||
@Config("rdeBucket") String bucket,
|
@Config("rdeBucket") String bucket,
|
||||||
|
@ -89,7 +89,7 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
||||||
@Config("rdeStagingLockTimeout") Duration lockTimeout,
|
@Config("rdeStagingLockTimeout") Duration lockTimeout,
|
||||||
@KeyModule.Key("rdeStagingEncryptionKey") byte[] stagingKeyBytes,
|
@KeyModule.Key("rdeStagingEncryptionKey") byte[] stagingKeyBytes,
|
||||||
@Parameter(RdeModule.PARAM_LENIENT) boolean lenient) {
|
@Parameter(RdeModule.PARAM_LENIENT) boolean lenient) {
|
||||||
this.taskEnqueuer = taskEnqueuer;
|
this.taskQueueUtils = taskQueueUtils;
|
||||||
this.lockHandler = lockHandler;
|
this.lockHandler = lockHandler;
|
||||||
this.gcsBufferSize = gcsBufferSize;
|
this.gcsBufferSize = gcsBufferSize;
|
||||||
this.bucket = bucket;
|
this.bucket = bucket;
|
||||||
|
@ -248,11 +248,11 @@ public final class RdeStagingReducer extends Reducer<PendingDeposit, DepositFrag
|
||||||
"Rolled forward %s on %s cursor to %s", key.cursor(), tld, newPosition);
|
"Rolled forward %s on %s cursor to %s", key.cursor(), tld, newPosition);
|
||||||
RdeRevision.saveRevision(tld, watermark, mode, revision);
|
RdeRevision.saveRevision(tld, watermark, mode, revision);
|
||||||
if (mode == RdeMode.FULL) {
|
if (mode == RdeMode.FULL) {
|
||||||
taskEnqueuer.enqueue(
|
taskQueueUtils.enqueue(
|
||||||
getQueue("rde-upload"),
|
getQueue("rde-upload"),
|
||||||
withUrl(RdeUploadAction.PATH).param(RequestParameters.PARAM_TLD, tld));
|
withUrl(RdeUploadAction.PATH).param(RequestParameters.PARAM_TLD, tld));
|
||||||
} else {
|
} else {
|
||||||
taskEnqueuer.enqueue(
|
taskQueueUtils.enqueue(
|
||||||
getQueue("brda"),
|
getQueue("brda"),
|
||||||
withUrl(BrdaCopyAction.PATH)
|
withUrl(BrdaCopyAction.PATH)
|
||||||
.param(RequestParameters.PARAM_TLD, tld)
|
.param(RequestParameters.PARAM_TLD, tld)
|
||||||
|
|
|
@ -52,7 +52,7 @@ import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import google.registry.util.TeeOutputStream;
|
import google.registry.util.TeeOutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -108,7 +108,7 @@ public final class RdeUploadAction implements Runnable, EscrowTask {
|
||||||
@Inject RydePgpFileOutputStreamFactory pgpFileFactory;
|
@Inject RydePgpFileOutputStreamFactory pgpFileFactory;
|
||||||
@Inject RydePgpSigningOutputStreamFactory pgpSigningFactory;
|
@Inject RydePgpSigningOutputStreamFactory pgpSigningFactory;
|
||||||
@Inject RydeTarOutputStreamFactory tarFactory;
|
@Inject RydeTarOutputStreamFactory tarFactory;
|
||||||
@Inject TaskEnqueuer taskEnqueuer;
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject Retrier retrier;
|
@Inject Retrier retrier;
|
||||||
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
|
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
|
||||||
@Inject @Config("rdeBucket") String bucket;
|
@Inject @Config("rdeBucket") String bucket;
|
||||||
|
@ -125,7 +125,7 @@ public final class RdeUploadAction implements Runnable, EscrowTask {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
runner.lockRunAndRollForward(this, Registry.get(tld), timeout, CursorType.RDE_UPLOAD, interval);
|
runner.lockRunAndRollForward(this, Registry.get(tld), timeout, CursorType.RDE_UPLOAD, interval);
|
||||||
taskEnqueuer.enqueue(
|
taskQueueUtils.enqueue(
|
||||||
reportQueue,
|
reportQueue,
|
||||||
withUrl(RdeReportAction.PATH).param(RequestParameters.PARAM_TLD, tld));
|
withUrl(RdeReportAction.PATH).param(RequestParameters.PARAM_TLD, tld));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
import google.registry.model.domain.DomainResource;
|
import google.registry.model.domain.DomainResource;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.util.NonFinalForTesting;
|
import google.registry.util.NonFinalForTesting;
|
||||||
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -53,9 +54,6 @@ public class LordnTask {
|
||||||
+ "registration-datetime,application-datetime";
|
+ "registration-datetime,application-datetime";
|
||||||
private static final Duration LEASE_PERIOD = Duration.standardHours(1);
|
private static final Duration LEASE_PERIOD = Duration.standardHours(1);
|
||||||
|
|
||||||
/** This is the max allowable batch size. */
|
|
||||||
private static final long BATCH_SIZE = 1000;
|
|
||||||
|
|
||||||
@NonFinalForTesting
|
@NonFinalForTesting
|
||||||
private static Long backOffMillis = 2000L;
|
private static Long backOffMillis = 2000L;
|
||||||
|
|
||||||
|
@ -85,7 +83,7 @@ public class LordnTask {
|
||||||
List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder
|
List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder
|
||||||
.withTag(tld)
|
.withTag(tld)
|
||||||
.leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS)
|
.leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS)
|
||||||
.countLimit(BATCH_SIZE));
|
.countLimit(TaskQueueUtils.getBatchSize()));
|
||||||
allTasks.addAll(tasks);
|
allTasks.addAll(tasks);
|
||||||
if (tasks.isEmpty()) {
|
if (tasks.isEmpty()) {
|
||||||
return allTasks.build();
|
return allTasks.build();
|
||||||
|
|
|
@ -41,6 +41,7 @@ import google.registry.request.RequestParameters;
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.util.Clock;
|
import google.registry.util.Clock;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
|
import google.registry.util.TaskQueueUtils;
|
||||||
import google.registry.util.UrlFetchException;
|
import google.registry.util.UrlFetchException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -84,6 +85,7 @@ public final class NordnUploadAction implements Runnable {
|
||||||
@Inject @Config("tmchMarksdbUrl") String tmchMarksdbUrl;
|
@Inject @Config("tmchMarksdbUrl") String tmchMarksdbUrl;
|
||||||
@Inject @Parameter(LORDN_PHASE_PARAM) String phase;
|
@Inject @Parameter(LORDN_PHASE_PARAM) String phase;
|
||||||
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
|
@Inject @Parameter(RequestParameters.PARAM_TLD) String tld;
|
||||||
|
@Inject TaskQueueUtils taskQueueUtils;
|
||||||
@Inject NordnUploadAction() {}
|
@Inject NordnUploadAction() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +119,7 @@ public final class NordnUploadAction implements Runnable {
|
||||||
if (!tasks.isEmpty()) {
|
if (!tasks.isEmpty()) {
|
||||||
String csvData = convertTasksToCsv(tasks, now, columns);
|
String csvData = convertTasksToCsv(tasks, now, columns);
|
||||||
uploadCsvToLordn(String.format("/LORDN/%s/%s", tld, phase), csvData);
|
uploadCsvToLordn(String.format("/LORDN/%s/%s", tld, phase), csvData);
|
||||||
queue.deleteTask(tasks);
|
taskQueueUtils.deleteTasks(queue, tasks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -20,12 +20,14 @@ import com.google.appengine.api.taskqueue.Queue;
|
||||||
import com.google.appengine.api.taskqueue.TaskHandle;
|
import com.google.appengine.api.taskqueue.TaskHandle;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/** Utilities for dealing with App Engine task queues. */
|
/** Utilities for dealing with App Engine task queues. */
|
||||||
public class TaskEnqueuer implements Serializable {
|
public class TaskQueueUtils implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7893211200220508362L;
|
private static final long serialVersionUID = 7893211200220508362L;
|
||||||
|
|
||||||
|
@ -34,10 +36,23 @@ public class TaskEnqueuer implements Serializable {
|
||||||
private final Retrier retrier;
|
private final Retrier retrier;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TaskEnqueuer(Retrier retrier) {
|
public TaskQueueUtils(Retrier retrier) {
|
||||||
this.retrier = retrier;
|
this.retrier = retrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonFinalForTesting
|
||||||
|
@VisibleForTesting
|
||||||
|
static int BATCH_SIZE = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The batch size to use for App Engine task queue operations.
|
||||||
|
*
|
||||||
|
* <p>Note that 1,000 is currently the maximum allowable batch size in App Engine.
|
||||||
|
*/
|
||||||
|
public static int getBatchSize() {
|
||||||
|
return BATCH_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a task to a App Engine task queue in a reliable manner.
|
* Adds a task to a App Engine task queue in a reliable manner.
|
||||||
*
|
*
|
||||||
|
@ -73,4 +88,14 @@ public class TaskEnqueuer implements Serializable {
|
||||||
},
|
},
|
||||||
TransientFailureException.class);
|
TransientFailureException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Deletes the specified tasks from the queue in batches, with retrying. */
|
||||||
|
public void deleteTasks(Queue queue, List<TaskHandle> tasks) {
|
||||||
|
Lists.partition(tasks, BATCH_SIZE)
|
||||||
|
.stream()
|
||||||
|
.forEach(
|
||||||
|
batch ->
|
||||||
|
retrier.callWithRetry(
|
||||||
|
() -> queue.deleteTask(batch), TransientFailureException.class));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -60,7 +60,7 @@ public class CommitLogCheckpointActionTest {
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
task.clock = new FakeClock(now);
|
task.clock = new FakeClock(now);
|
||||||
task.strategy = strategy;
|
task.strategy = strategy;
|
||||||
task.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
|
task.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
||||||
when(strategy.computeCheckpoint())
|
when(strategy.computeCheckpoint())
|
||||||
.thenReturn(
|
.thenReturn(
|
||||||
CommitLogCheckpoint.create(
|
CommitLogCheckpoint.create(
|
||||||
|
|
|
@ -22,7 +22,7 @@ import google.registry.model.ofy.CommitLogBucket;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -54,7 +54,7 @@ public class CommitLogFanoutActionTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess() throws Exception {
|
public void testSuccess() throws Exception {
|
||||||
CommitLogFanoutAction action = new CommitLogFanoutAction();
|
CommitLogFanoutAction action = new CommitLogFanoutAction();
|
||||||
action.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
|
action.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
||||||
action.endpoint = ENDPOINT;
|
action.endpoint = ENDPOINT;
|
||||||
action.queue = QUEUE;
|
action.queue = QUEUE;
|
||||||
action.jitterSeconds = Optional.empty();
|
action.jitterSeconds = Optional.empty();
|
||||||
|
|
|
@ -35,7 +35,7 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -84,7 +84,7 @@ public class TldFanoutActionTest {
|
||||||
action.excludes = params.containsKey("exclude")
|
action.excludes = params.containsKey("exclude")
|
||||||
? ImmutableSet.copyOf(Splitter.on(',').split(params.get("exclude").get(0)))
|
? ImmutableSet.copyOf(Splitter.on(',').split(params.get("exclude").get(0)))
|
||||||
: ImmutableSet.of();
|
: ImmutableSet.of();
|
||||||
action.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
|
action.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
||||||
action.response = response;
|
action.response = response;
|
||||||
action.runInEmpty = params.containsKey("runInEmpty");
|
action.runInEmpty = params.containsKey("runInEmpty");
|
||||||
action.forEachRealTld = params.containsKey("forEachRealTld");
|
action.forEachRealTld = params.containsKey("forEachRealTld");
|
||||||
|
|
|
@ -47,7 +47,7 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
@ -122,7 +122,7 @@ public class ReadDnsQueueActionTest {
|
||||||
action.dnsQueue = dnsQueue;
|
action.dnsQueue = dnsQueue;
|
||||||
action.dnsPublishPushQueue = QueueFactory.getQueue(DNS_PUBLISH_PUSH_QUEUE_NAME);
|
action.dnsPublishPushQueue = QueueFactory.getQueue(DNS_PUBLISH_PUSH_QUEUE_NAME);
|
||||||
action.hashFunction = Hashing.murmur3_32();
|
action.hashFunction = Hashing.murmur3_32();
|
||||||
action.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
|
action.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
||||||
action.jitterSeconds = Optional.empty();
|
action.jitterSeconds = Optional.empty();
|
||||||
// Advance the time a little, to ensure that leaseTasks() returns all tasks.
|
// Advance the time a little, to ensure that leaseTasks() returns all tasks.
|
||||||
clock.advanceBy(Duration.standardHours(1));
|
clock.advanceBy(Duration.standardHours(1));
|
||||||
|
|
|
@ -44,7 +44,7 @@ import google.registry.testing.TaskQueueHelper;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.CapturingLogHandler;
|
import google.registry.util.CapturingLogHandler;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -71,8 +71,8 @@ public class BigqueryPollJobActionTest {
|
||||||
private static final String PROJECT_ID = "project_id";
|
private static final String PROJECT_ID = "project_id";
|
||||||
private static final String JOB_ID = "job_id";
|
private static final String JOB_ID = "job_id";
|
||||||
private static final String CHAINED_QUEUE_NAME = UpdateSnapshotViewAction.QUEUE;
|
private static final String CHAINED_QUEUE_NAME = UpdateSnapshotViewAction.QUEUE;
|
||||||
private static final TaskEnqueuer ENQUEUER =
|
private static final TaskQueueUtils TASK_QUEUE_UTILS =
|
||||||
new TaskEnqueuer(new Retrier(new FakeSleeper(new FakeClock()), 1));
|
new TaskQueueUtils(new Retrier(new FakeSleeper(new FakeClock()), 1));
|
||||||
|
|
||||||
private final Bigquery bigquery = mock(Bigquery.class);
|
private final Bigquery bigquery = mock(Bigquery.class);
|
||||||
private final Bigquery.Jobs bigqueryJobs = mock(Bigquery.Jobs.class);
|
private final Bigquery.Jobs bigqueryJobs = mock(Bigquery.Jobs.class);
|
||||||
|
@ -86,7 +86,7 @@ public class BigqueryPollJobActionTest {
|
||||||
action.bigquery = bigquery;
|
action.bigquery = bigquery;
|
||||||
when(bigquery.jobs()).thenReturn(bigqueryJobs);
|
when(bigquery.jobs()).thenReturn(bigqueryJobs);
|
||||||
when(bigqueryJobs.get(PROJECT_ID, JOB_ID)).thenReturn(bigqueryJobsGet);
|
when(bigqueryJobs.get(PROJECT_ID, JOB_ID)).thenReturn(bigqueryJobsGet);
|
||||||
action.enqueuer = ENQUEUER;
|
action.taskQueueUtils = TASK_QUEUE_UTILS;
|
||||||
action.projectId = PROJECT_ID;
|
action.projectId = PROJECT_ID;
|
||||||
action.jobId = JOB_ID;
|
action.jobId = JOB_ID;
|
||||||
action.chainedQueueName = () -> CHAINED_QUEUE_NAME;
|
action.chainedQueueName = () -> CHAINED_QUEUE_NAME;
|
||||||
|
@ -103,7 +103,7 @@ public class BigqueryPollJobActionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_enqueuePollTask() throws Exception {
|
public void testSuccess_enqueuePollTask() throws Exception {
|
||||||
new BigqueryPollJobEnqueuer(ENQUEUER).enqueuePollTask(
|
new BigqueryPollJobEnqueuer(TASK_QUEUE_UTILS).enqueuePollTask(
|
||||||
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID));
|
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID));
|
||||||
assertTasksEnqueued(BigqueryPollJobAction.QUEUE, newPollJobTaskMatcher("GET"));
|
assertTasksEnqueued(BigqueryPollJobAction.QUEUE, newPollJobTaskMatcher("GET"));
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class BigqueryPollJobActionTest {
|
||||||
.method(Method.POST)
|
.method(Method.POST)
|
||||||
.header("X-Testing", "foo")
|
.header("X-Testing", "foo")
|
||||||
.param("testing", "bar");
|
.param("testing", "bar");
|
||||||
new BigqueryPollJobEnqueuer(ENQUEUER).enqueuePollTask(
|
new BigqueryPollJobEnqueuer(TASK_QUEUE_UTILS).enqueuePollTask(
|
||||||
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID),
|
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID),
|
||||||
chainedTask,
|
chainedTask,
|
||||||
getQueue(CHAINED_QUEUE_NAME));
|
getQueue(CHAINED_QUEUE_NAME));
|
||||||
|
|
|
@ -64,7 +64,7 @@ import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import google.registry.tldconfig.idn.IdnTableEnum;
|
import google.registry.tldconfig.idn.IdnTableEnum;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.SystemSleeper;
|
import google.registry.util.SystemSleeper;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import google.registry.xjc.XjcXmlTransformer;
|
import google.registry.xjc.XjcXmlTransformer;
|
||||||
import google.registry.xjc.rde.XjcRdeContentType;
|
import google.registry.xjc.rde.XjcRdeContentType;
|
||||||
import google.registry.xjc.rde.XjcRdeDeposit;
|
import google.registry.xjc.rde.XjcRdeDeposit;
|
||||||
|
@ -132,7 +132,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
||||||
action.mrRunner = makeDefaultRunner();
|
action.mrRunner = makeDefaultRunner();
|
||||||
action.lenient = false;
|
action.lenient = false;
|
||||||
action.reducer = new RdeStagingReducer(
|
action.reducer = new RdeStagingReducer(
|
||||||
new TaskEnqueuer(new Retrier(new SystemSleeper(), 1)), // taskEnqueuer
|
new TaskQueueUtils(new Retrier(new SystemSleeper(), 1)), // taskQueueUtils
|
||||||
new FakeLockHandler(true),
|
new FakeLockHandler(true),
|
||||||
0, // gcsBufferSize
|
0, // gcsBufferSize
|
||||||
"rde-bucket", // bucket
|
"rde-bucket", // bucket
|
||||||
|
|
|
@ -72,7 +72,7 @@ import google.registry.testing.Lazies;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.testing.sftp.SftpServerRule;
|
import google.registry.testing.sftp.SftpServerRule;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskEnqueuer;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -208,7 +208,7 @@ public class RdeUploadActionTest {
|
||||||
action.stagingDecryptionKey = keyring.getRdeStagingDecryptionKey();
|
action.stagingDecryptionKey = keyring.getRdeStagingDecryptionKey();
|
||||||
action.reportQueue = QueueFactory.getQueue("rde-report");
|
action.reportQueue = QueueFactory.getQueue("rde-report");
|
||||||
action.runner = runner;
|
action.runner = runner;
|
||||||
action.taskEnqueuer = new TaskEnqueuer(new Retrier(null, 1));
|
action.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
||||||
action.retrier = new Retrier(new FakeSleeper(clock), 3);
|
action.retrier = new Retrier(new FakeSleeper(clock), 3);
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,12 @@ import google.registry.model.ofy.Ofy;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
|
import google.registry.testing.FakeSleeper;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.MockitoJUnitRule;
|
import google.registry.testing.MockitoJUnitRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
|
import google.registry.util.Retrier;
|
||||||
|
import google.registry.util.TaskQueueUtils;
|
||||||
import google.registry.util.UrlFetchException;
|
import google.registry.util.UrlFetchException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -109,6 +112,7 @@ public class NordnUploadActionTest {
|
||||||
action.fetchService = fetchService;
|
action.fetchService = fetchService;
|
||||||
action.lordnRequestInitializer = lordnRequestInitializer;
|
action.lordnRequestInitializer = lordnRequestInitializer;
|
||||||
action.phase = "claims";
|
action.phase = "claims";
|
||||||
|
action.taskQueueUtils = new TaskQueueUtils(new Retrier(new FakeSleeper(clock), 3));
|
||||||
action.tld = "tld";
|
action.tld = "tld";
|
||||||
action.tmchMarksdbUrl = "http://127.0.0.1";
|
action.tmchMarksdbUrl = "http://127.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -17,12 +17,14 @@ package google.registry.util;
|
||||||
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||||
|
import static google.registry.testing.TaskQueueHelper.getQueueInfo;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.appengine.api.taskqueue.Queue;
|
import com.google.appengine.api.taskqueue.Queue;
|
||||||
|
import com.google.appengine.api.taskqueue.QueueFactory;
|
||||||
import com.google.appengine.api.taskqueue.TaskHandle;
|
import com.google.appengine.api.taskqueue.TaskHandle;
|
||||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||||
|
@ -31,33 +33,39 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.FakeSleeper;
|
import google.registry.testing.FakeSleeper;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
/** Unit tests for {@link TaskEnqueuer}. */
|
/** Unit tests for {@link TaskQueueUtils}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public final class TaskEnqueuerTest {
|
public final class TaskQueueUtilsTest {
|
||||||
|
|
||||||
private static final int MAX_RETRIES = 3;
|
private static final int MAX_RETRIES = 3;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
public final AppEngineRule appEngine =
|
||||||
.withDatastore()
|
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||||
.build();
|
|
||||||
|
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
||||||
private final FakeSleeper sleeper = new FakeSleeper(clock);
|
private final FakeSleeper sleeper = new FakeSleeper(clock);
|
||||||
private final TaskEnqueuer taskEnqueuer =
|
private final TaskQueueUtils taskQueueUtils =
|
||||||
new TaskEnqueuer(new Retrier(sleeper, MAX_RETRIES));
|
new TaskQueueUtils(new Retrier(sleeper, MAX_RETRIES));
|
||||||
private final Queue queue = mock(Queue.class);
|
private final Queue queue = mock(Queue.class);
|
||||||
private final TaskOptions task = withUrl("url").taskName("name");
|
private final TaskOptions task = withUrl("url").taskName("name");
|
||||||
private final TaskHandle handle = new TaskHandle(task, "handle");
|
private final TaskHandle handle = new TaskHandle(task, "handle");
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
TaskQueueUtils.BATCH_SIZE = 2;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEnqueue_worksOnFirstTry_doesntSleep() throws Exception {
|
public void testEnqueue_worksOnFirstTry_doesntSleep() throws Exception {
|
||||||
when(queue.add(ImmutableList.of(task))).thenReturn(ImmutableList.of(handle));
|
when(queue.add(ImmutableList.of(task))).thenReturn(ImmutableList.of(handle));
|
||||||
assertThat(taskEnqueuer.enqueue(queue, task)).isSameAs(handle);
|
assertThat(taskQueueUtils.enqueue(queue, task)).isSameAs(handle);
|
||||||
verify(queue).add(ImmutableList.of(task));
|
verify(queue).add(ImmutableList.of(task));
|
||||||
assertThat(clock.nowUtc()).isEqualTo(DateTime.parse("2000-01-01TZ"));
|
assertThat(clock.nowUtc()).isEqualTo(DateTime.parse("2000-01-01TZ"));
|
||||||
}
|
}
|
||||||
|
@ -68,7 +76,7 @@ public final class TaskEnqueuerTest {
|
||||||
.thenThrow(new TransientFailureException(""))
|
.thenThrow(new TransientFailureException(""))
|
||||||
.thenThrow(new TransientFailureException(""))
|
.thenThrow(new TransientFailureException(""))
|
||||||
.thenReturn(ImmutableList.of(handle));
|
.thenReturn(ImmutableList.of(handle));
|
||||||
assertThat(taskEnqueuer.enqueue(queue, task)).isSameAs(handle);
|
assertThat(taskQueueUtils.enqueue(queue, task)).isSameAs(handle);
|
||||||
verify(queue, times(3)).add(ImmutableList.of(task));
|
verify(queue, times(3)).add(ImmutableList.of(task));
|
||||||
assertThat(clock.nowUtc()).isEqualTo(DateTime.parse("2000-01-01T00:00:00.6Z")); // 200 + 400ms
|
assertThat(clock.nowUtc()).isEqualTo(DateTime.parse("2000-01-01T00:00:00.6Z")); // 200 + 400ms
|
||||||
}
|
}
|
||||||
|
@ -80,7 +88,7 @@ public final class TaskEnqueuerTest {
|
||||||
ImmutableList<TaskHandle> handles =
|
ImmutableList<TaskHandle> handles =
|
||||||
ImmutableList.of(new TaskHandle(taskA, "a"), new TaskHandle(taskB, "b"));
|
ImmutableList.of(new TaskHandle(taskA, "a"), new TaskHandle(taskB, "b"));
|
||||||
when(queue.add(ImmutableList.of(taskA, taskB))).thenReturn(handles);
|
when(queue.add(ImmutableList.of(taskA, taskB))).thenReturn(handles);
|
||||||
assertThat(taskEnqueuer.enqueue(queue, ImmutableList.of(taskA, taskB))).isSameAs(handles);
|
assertThat(taskQueueUtils.enqueue(queue, ImmutableList.of(taskA, taskB))).isSameAs(handles);
|
||||||
assertThat(clock.nowUtc()).isEqualTo(DateTime.parse("2000-01-01TZ"));
|
assertThat(clock.nowUtc()).isEqualTo(DateTime.parse("2000-01-01TZ"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +100,7 @@ public final class TaskEnqueuerTest {
|
||||||
.thenThrow(new TransientFailureException("three"))
|
.thenThrow(new TransientFailureException("three"))
|
||||||
.thenThrow(new TransientFailureException("four"));
|
.thenThrow(new TransientFailureException("four"));
|
||||||
TransientFailureException thrown =
|
TransientFailureException thrown =
|
||||||
assertThrows(TransientFailureException.class, () -> taskEnqueuer.enqueue(queue, task));
|
assertThrows(TransientFailureException.class, () -> taskQueueUtils.enqueue(queue, task));
|
||||||
assertThat(thrown).hasMessageThat().contains("three");
|
assertThat(thrown).hasMessageThat().contains("three");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +109,27 @@ public final class TaskEnqueuerTest {
|
||||||
when(queue.add(ImmutableList.of(task))).thenThrow(new TransientFailureException(""));
|
when(queue.add(ImmutableList.of(task))).thenThrow(new TransientFailureException(""));
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
assertThrows(TransientFailureException.class, () -> taskEnqueuer.enqueue(queue, task));
|
assertThrows(TransientFailureException.class, () -> taskQueueUtils.enqueue(queue, task));
|
||||||
} finally {
|
} finally {
|
||||||
Thread.interrupted(); // Clear interrupt state so it doesn't pwn other tests.
|
Thread.interrupted(); // Clear interrupt state so it doesn't pwn other tests.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTasks_usesMultipleBatches() {
|
||||||
|
Queue defaultQ = QueueFactory.getQueue("default");
|
||||||
|
TaskOptions taskOptA = withUrl("/a").taskName("a");
|
||||||
|
TaskOptions taskOptB = withUrl("/b").taskName("b");
|
||||||
|
TaskOptions taskOptC = withUrl("/c").taskName("c");
|
||||||
|
taskQueueUtils.enqueue(defaultQ, ImmutableList.of(taskOptA, taskOptB, taskOptC));
|
||||||
|
assertThat(getQueueInfo("default").getTaskInfo()).hasSize(3);
|
||||||
|
|
||||||
|
taskQueueUtils.deleteTasks(
|
||||||
|
defaultQ,
|
||||||
|
ImmutableList.of(
|
||||||
|
new TaskHandle(taskOptA, "default"),
|
||||||
|
new TaskHandle(taskOptB, "default"),
|
||||||
|
new TaskHandle(taskOptC, "default")));
|
||||||
|
assertThat(getQueueInfo("default").getTaskInfo()).hasSize(0);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue