mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 17:56:08 +02:00
Swap all uses of Lock to LockHandler
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=167661348
This commit is contained in:
parent
57bcd6b1eb
commit
c3861f6e95
10 changed files with 50 additions and 21 deletions
|
@ -30,8 +30,11 @@ import google.registry.dns.writer.DnsWriter;
|
|||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.request.HttpException.ServiceUnavailableException;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import google.registry.testing.InjectRule;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
|
@ -54,7 +57,11 @@ public class PublishDnsUpdatesActionTest {
|
|||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
|
||||
private final FakeLockHandler lockHandler = new FakeLockHandler(true);
|
||||
private final DnsWriter dnsWriter = mock(DnsWriter.class);
|
||||
private final DnsMetrics dnsMetrics = mock(DnsMetrics.class);
|
||||
private PublishDnsUpdatesAction action;
|
||||
|
@ -82,6 +89,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
action.dnsWriter = "mock";
|
||||
action.dnsWriterProxy = new DnsWriterProxy(ImmutableMap.of("mock", dnsWriter));
|
||||
action.dnsMetrics = dnsMetrics;
|
||||
action.lockHandler = lockHandler;
|
||||
return action;
|
||||
}
|
||||
|
||||
|
@ -148,4 +156,14 @@ public class PublishDnsUpdatesActionTest {
|
|||
verify(dnsMetrics, times(3)).incrementPublishHostRequests("xn--q9jyb4c", Status.REJECTED);
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLockIsntAvailable() throws Exception {
|
||||
thrown.expect(ServiceUnavailableException.class, "Lock failure");
|
||||
action = createAction("xn--q9jyb4c");
|
||||
action.domains = ImmutableSet.of("example.com", "example2.com");
|
||||
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
||||
action.lockHandler = new FakeLockHandler(false);
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ java_library(
|
|||
"//java/google/registry/monitoring/whitebox",
|
||||
"//java/google/registry/pricing",
|
||||
"//java/google/registry/request",
|
||||
"//java/google/registry/request/lock",
|
||||
"//java/google/registry/tmch",
|
||||
"//java/google/registry/util",
|
||||
"//java/google/registry/xml",
|
||||
|
|
|
@ -30,7 +30,9 @@ import google.registry.flows.domain.DomainFlowTmchUtils;
|
|||
import google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer;
|
||||
import google.registry.monitoring.whitebox.EppMetric;
|
||||
import google.registry.request.RequestScope;
|
||||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import google.registry.testing.FakeSleeper;
|
||||
import google.registry.tmch.TmchCertificateAuthority;
|
||||
import google.registry.tmch.TmchXmlSignature;
|
||||
|
@ -58,6 +60,7 @@ interface EppTestComponent {
|
|||
private DomainFlowTmchUtils domainFlowTmchUtils;
|
||||
private EppMetric.Builder metricBuilder;
|
||||
private FakeClock clock;
|
||||
private FakeLockHandler lockHandler;
|
||||
private ModulesService modulesService;
|
||||
private Sleeper sleeper;
|
||||
|
||||
|
@ -85,6 +88,7 @@ interface EppTestComponent {
|
|||
instance.metricBuilder = eppMetricBuilder;
|
||||
instance.modulesService = mock(ModulesService.class);
|
||||
instance.metricsEnqueuer = mock(BigQueryMetricsEnqueuer.class);
|
||||
instance.lockHandler = new FakeLockHandler(true);
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -98,6 +102,11 @@ interface EppTestComponent {
|
|||
return clock;
|
||||
}
|
||||
|
||||
@Provides
|
||||
LockHandler provideLockHandler() {
|
||||
return lockHandler;
|
||||
}
|
||||
|
||||
@Provides
|
||||
CustomLogicFactory provideCustomLogicFactory() {
|
||||
return new TestCustomLogicFactory();
|
||||
|
|
|
@ -26,14 +26,13 @@ import static org.mockito.Mockito.verify;
|
|||
import google.registry.model.common.Cursor;
|
||||
import google.registry.model.common.Cursor.CursorType;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.server.Lock;
|
||||
import google.registry.rde.EscrowTaskRunner.EscrowTask;
|
||||
import google.registry.request.HttpException.NoContentException;
|
||||
import google.registry.request.HttpException.ServiceUnavailableException;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import java.util.concurrent.Callable;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Before;
|
||||
|
@ -68,6 +67,7 @@ public class EscrowTaskRunnerTest {
|
|||
runner = new EscrowTaskRunner();
|
||||
runner.clock = clock;
|
||||
runner.tld = "lol";
|
||||
runner.lockHandler = new FakeLockHandler(true);
|
||||
DateTimeZone.setDefault(DateTimeZone.forID("America/New_York")); // Make sure UTC stuff works.
|
||||
}
|
||||
|
||||
|
@ -112,16 +112,8 @@ public class EscrowTaskRunnerTest {
|
|||
persistResource(
|
||||
Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry));
|
||||
thrown.expect(ServiceUnavailableException.class, "Lock in use: " + lockName);
|
||||
Lock.executeWithLocks(
|
||||
new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
runner.lockRunAndRollForward(
|
||||
task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1));
|
||||
return null;
|
||||
}},
|
||||
"lol",
|
||||
standardSeconds(30),
|
||||
lockName);
|
||||
runner.lockHandler = new FakeLockHandler(false);
|
||||
runner.lockRunAndRollForward(
|
||||
task, registry, standardSeconds(30), CursorType.RDE_STAGING, standardDays(1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import google.registry.request.RequestParameters;
|
|||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeKeyringModule;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||
|
@ -137,6 +138,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
action.lenient = false;
|
||||
action.reducer = new RdeStagingReducer(
|
||||
new TaskEnqueuer(new Retrier(new SystemSleeper(), 1)), // taskEnqueuer
|
||||
new FakeLockHandler(true),
|
||||
0, // gcsBufferSize
|
||||
"rde-bucket", // bucket
|
||||
31337, // ghostrydeBufferSize
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue