mirror of
https://github.com/google/nomulus.git
synced 2025-08-03 00:12:11 +02:00
Switch from Guava Optionals to Java 8 Optionals
This was a surprisingly involved change. Some of the difficulties included java.util.Optional purposely not being Serializable (so I had to move a few Optionals in mapreduce classes to @Nullable) and having to add the Truth Java8 extension library for assertion support. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171863777
This commit is contained in:
parent
184b2b56ac
commit
c0f8da0c6e
581 changed files with 1325 additions and 932 deletions
|
@ -20,7 +20,6 @@ java_library(
|
|||
"//javatests/google/registry/testing",
|
||||
"//javatests/google/registry/testing/mapreduce",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"//third_party/java/truth",
|
||||
"@com_google_apis_google_api_services_bigquery",
|
||||
"@com_google_appengine_api_1_0_sdk//:testonly",
|
||||
"@com_google_appengine_api_stubs",
|
||||
|
@ -32,6 +31,8 @@ java_library(
|
|||
"@com_google_guava",
|
||||
"@com_google_http_client",
|
||||
"@com_google_re2j",
|
||||
"@com_google_truth",
|
||||
"@com_google_truth_extensions_truth_java8_extension",
|
||||
"@javax_servlet_api",
|
||||
"@joda_time",
|
||||
"@junit",
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.batch;
|
|||
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
|
||||
import static com.google.common.collect.MoreCollectors.onlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_DELETE;
|
||||
import static google.registry.flows.async.AsyncFlowEnqueuer.QUEUE_ASYNC_HOST_RENAME;
|
||||
import static google.registry.flows.async.AsyncFlowMetrics.OperationResult.STALE;
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.batch;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadByForeignKey;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.batch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING;
|
||||
import static google.registry.model.domain.Period.Unit.YEARS;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
|
@ -32,7 +33,6 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
|||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
@ -57,6 +57,7 @@ import google.registry.testing.InjectRule;
|
|||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
|
@ -89,7 +90,7 @@ public class ExpandRecurringBillingEventsActionTest
|
|||
action = new ExpandRecurringBillingEventsAction();
|
||||
action.mrRunner = makeDefaultRunner();
|
||||
action.clock = clock;
|
||||
action.cursorTimeParam = Optional.absent();
|
||||
action.cursorTimeParam = Optional.empty();
|
||||
createTld("tld");
|
||||
domain = persistActiveDomain("example.tld");
|
||||
historyEntry = persistResource(new HistoryEntry.Builder().setParent(domain).build());
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.batch;
|
|||
import static com.google.appengine.api.datastore.DatastoreServiceFactory.getDatastoreService;
|
||||
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
@ -45,13 +46,13 @@ import com.google.appengine.tools.pipeline.impl.model.JobInstanceRecord;
|
|||
import com.google.appengine.tools.pipeline.impl.model.JobRecord;
|
||||
import com.google.appengine.tools.pipeline.impl.model.ShardedValue;
|
||||
import com.google.appengine.tools.pipeline.impl.model.Slot;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -120,22 +121,22 @@ public class MapreduceEntityCleanupActionTest
|
|||
|
||||
private void setAnyJobAndDaysOld(int daysOld) {
|
||||
setJobIdJobNameAndDaysOld(
|
||||
Optional.<String>absent(), Optional.<String>absent(), Optional.<Integer>of(daysOld));
|
||||
Optional.<String>empty(), Optional.<String>empty(), Optional.<Integer>of(daysOld));
|
||||
}
|
||||
|
||||
private void setJobId(String jobId) {
|
||||
setJobIdJobNameAndDaysOld(
|
||||
Optional.of(jobId), Optional.<String>absent(), Optional.<Integer>absent());
|
||||
Optional.of(jobId), Optional.<String>empty(), Optional.<Integer>empty());
|
||||
}
|
||||
|
||||
private void setJobName(String jobName) {
|
||||
setJobIdJobNameAndDaysOld(
|
||||
Optional.<String>absent(), Optional.of(jobName), Optional.<Integer>absent());
|
||||
Optional.<String>empty(), Optional.of(jobName), Optional.<Integer>empty());
|
||||
}
|
||||
|
||||
private void setJobNameAndDaysOld(String jobName, int daysOld) {
|
||||
setJobIdJobNameAndDaysOld(
|
||||
Optional.<String>absent(), Optional.of(jobName), Optional.<Integer>of(daysOld));
|
||||
Optional.<String>empty(), Optional.of(jobName), Optional.<Integer>of(daysOld));
|
||||
}
|
||||
|
||||
private void setJobIdJobNameAndDaysOld(
|
||||
|
@ -144,9 +145,9 @@ public class MapreduceEntityCleanupActionTest
|
|||
action = new MapreduceEntityCleanupAction(
|
||||
jobId,
|
||||
jobName,
|
||||
Optional.<Integer>absent(), // numJobsToDelete
|
||||
Optional.<Integer>empty(), // numJobsToDelete
|
||||
daysOld,
|
||||
Optional.<Boolean>absent(), // force
|
||||
Optional.<Boolean>empty(), // force
|
||||
mapreduceEntityCleanupUtil,
|
||||
clock,
|
||||
DatastoreServiceFactory.getDatastoreService(),
|
||||
|
@ -269,7 +270,7 @@ public class MapreduceEntityCleanupActionTest
|
|||
createMapreduce("jobname");
|
||||
executeTasksUntilEmpty(QUEUE_NAME, clock);
|
||||
setJobIdJobNameAndDaysOld(
|
||||
Optional.<String>absent(), Optional.<String>absent(), Optional.<Integer>absent());
|
||||
Optional.<String>empty(), Optional.<String>empty(), Optional.<Integer>empty());
|
||||
|
||||
action.run();
|
||||
|
||||
|
@ -353,11 +354,11 @@ public class MapreduceEntityCleanupActionTest
|
|||
executeTasksUntilEmpty(QUEUE_NAME, clock);
|
||||
clock.setTo(DateTime.now(UTC));
|
||||
action = new MapreduceEntityCleanupAction(
|
||||
Optional.<String>absent(), // jobId
|
||||
Optional.<String>absent(), // jobName
|
||||
Optional.<String>empty(), // jobId
|
||||
Optional.<String>empty(), // jobName
|
||||
Optional.<Integer>of(1), // numJobsToDelete
|
||||
Optional.<Integer>of(0), // daysOld
|
||||
Optional.<Boolean>absent(), // force
|
||||
Optional.<Boolean>empty(), // force
|
||||
mapreduceEntityCleanupUtil,
|
||||
clock,
|
||||
DatastoreServiceFactory.getDatastoreService(),
|
||||
|
@ -432,10 +433,10 @@ public class MapreduceEntityCleanupActionTest
|
|||
clock.setTo(DateTime.now(UTC));
|
||||
action = new MapreduceEntityCleanupAction(
|
||||
Optional.of(jobId2), // jobId
|
||||
Optional.<String>absent(), // jobName
|
||||
Optional.<Integer>absent(), // numJobsToDelete
|
||||
Optional.<Integer>absent(), // daysOld
|
||||
Optional.<Boolean>absent(), // force
|
||||
Optional.<String>empty(), // jobName
|
||||
Optional.<Integer>empty(), // numJobsToDelete
|
||||
Optional.<Integer>empty(), // daysOld
|
||||
Optional.<Boolean>empty(), // force
|
||||
mapreduceEntityCleanupUtil,
|
||||
clock,
|
||||
DatastoreServiceFactory.getDatastoreService(),
|
||||
|
@ -477,9 +478,9 @@ public class MapreduceEntityCleanupActionTest
|
|||
clock.setTo(DateTime.now(UTC));
|
||||
action = new MapreduceEntityCleanupAction(
|
||||
Optional.of(jobId),
|
||||
Optional.<String>absent(), // jobName
|
||||
Optional.<Integer>absent(), // numJobsToDelete
|
||||
Optional.<Integer>absent(), // daysOld
|
||||
Optional.<String>empty(), // jobName
|
||||
Optional.<Integer>empty(), // numJobsToDelete
|
||||
Optional.<Integer>empty(), // daysOld
|
||||
Optional.of(true), // force
|
||||
mapreduceEntityCleanupUtil,
|
||||
clock,
|
||||
|
@ -501,7 +502,7 @@ public class MapreduceEntityCleanupActionTest
|
|||
@Test
|
||||
public void testJobIdAndJobName_fails() throws Exception {
|
||||
setJobIdJobNameAndDaysOld(
|
||||
Optional.of("jobid"), Optional.of("jobname"), Optional.<Integer>absent());
|
||||
Optional.of("jobid"), Optional.of("jobname"), Optional.<Integer>empty());
|
||||
|
||||
action.run();
|
||||
|
||||
|
@ -513,7 +514,7 @@ public class MapreduceEntityCleanupActionTest
|
|||
|
||||
@Test
|
||||
public void testJobIdAndDaysOld_fails() throws Exception {
|
||||
setJobIdJobNameAndDaysOld(Optional.of("jobid"), Optional.<String>absent(), Optional.of(0));
|
||||
setJobIdJobNameAndDaysOld(Optional.of("jobid"), Optional.<String>empty(), Optional.of(0));
|
||||
|
||||
action.run();
|
||||
|
||||
|
@ -528,10 +529,10 @@ public class MapreduceEntityCleanupActionTest
|
|||
public void testJobIdAndNumJobs_fails() throws Exception {
|
||||
action = new MapreduceEntityCleanupAction(
|
||||
Optional.of("jobid"),
|
||||
Optional.<String>absent(), // jobName
|
||||
Optional.<String>empty(), // jobName
|
||||
Optional.of(1), // numJobsToDelete
|
||||
Optional.<Integer>absent(), // daysOld
|
||||
Optional.<Boolean>absent(), // force
|
||||
Optional.<Integer>empty(), // daysOld
|
||||
Optional.<Boolean>empty(), // force
|
||||
mapreduceEntityCleanupUtil,
|
||||
clock,
|
||||
DatastoreServiceFactory.getDatastoreService(),
|
||||
|
@ -549,11 +550,11 @@ public class MapreduceEntityCleanupActionTest
|
|||
@Test
|
||||
public void testDeleteZeroJobs_throwsUsageError() throws Exception {
|
||||
new MapreduceEntityCleanupAction(
|
||||
Optional.<String>absent(), // jobId
|
||||
Optional.<String>absent(), // jobName
|
||||
Optional.<String>empty(), // jobId
|
||||
Optional.<String>empty(), // jobName
|
||||
Optional.<Integer>of(0), // numJobsToDelete
|
||||
Optional.<Integer>absent(), // daysOld
|
||||
Optional.<Boolean>absent(), // force
|
||||
Optional.<Integer>empty(), // daysOld
|
||||
Optional.<Boolean>empty(), // force
|
||||
mapreduceEntityCleanupUtil,
|
||||
clock,
|
||||
DatastoreServiceFactory.getDatastoreService(),
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.batch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistContactWithPendingTransfer;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package google.registry.batch;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.batch;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.deleteResource;
|
||||
import static google.registry.testing.DatastoreHelper.newContactResource;
|
||||
|
@ -37,7 +38,6 @@ import com.google.api.services.bigquery.Bigquery;
|
|||
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllRequest.Rows;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -57,6 +57,7 @@ import google.registry.testing.InjectRule;
|
|||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||
import google.registry.util.Retrier;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Before;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue