mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 17:01:51 +02:00
mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package rename. The repository is now in a broken state because the code itself hasn't been updated. However this should ensure that git correctly preserves history for each file.
This commit is contained in:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
45
javatests/google/registry/monitoring/whitebox/BUILD
Normal file
45
javatests/google/registry/monitoring/whitebox/BUILD
Normal file
|
@ -0,0 +1,45 @@
|
|||
package(
|
||||
default_visibility = ["//java/com/google/domain/registry:registry_project"],
|
||||
)
|
||||
|
||||
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
|
||||
|
||||
|
||||
java_library(
|
||||
name = "whitebox",
|
||||
srcs = glob(["*.java"]),
|
||||
deps = [
|
||||
"//apiserving/discoverydata/bigquery:bigqueryv2",
|
||||
"//java/com/google/api/client/http",
|
||||
"//java/com/google/api/client/json",
|
||||
"//java/com/google/api/client/util",
|
||||
"//java/com/google/common/base",
|
||||
"//java/com/google/common/collect",
|
||||
"//java/com/google/common/net",
|
||||
"//java/com/google/common/testing",
|
||||
"//java/com/google/domain/registry/bigquery",
|
||||
"//java/com/google/domain/registry/config",
|
||||
"//java/com/google/domain/registry/mapreduce",
|
||||
"//java/com/google/domain/registry/model",
|
||||
"//java/com/google/domain/registry/monitoring/whitebox",
|
||||
"//java/com/google/domain/registry/util",
|
||||
"//javatests/com/google/domain/registry/testing",
|
||||
"//javatests/com/google/domain/registry/testing/mapreduce",
|
||||
"//third_party/java/appengine:appengine-api-testonly",
|
||||
"//third_party/java/appengine:appengine-stubs",
|
||||
"//third_party/java/appengine:appengine-testing",
|
||||
"//third_party/java/joda_money",
|
||||
"//third_party/java/joda_time",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/mockito",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
)
|
||||
|
||||
GenTestRules(
|
||||
name = "GeneratedTestRules",
|
||||
test_files = glob(["*Test.java"]),
|
||||
deps = [":whitebox"],
|
||||
)
|
|
@ -0,0 +1,130 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.monitoring.whitebox;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.api.client.http.HttpRequestInitializer;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.services.bigquery.Bigquery;
|
||||
import com.google.api.services.bigquery.Bigquery.Tabledata;
|
||||
import com.google.api.services.bigquery.Bigquery.Tabledata.InsertAll;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
|
||||
import com.google.api.services.bigquery.model.TableDataInsertAllResponse.InsertErrors;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.domain.registry.bigquery.BigqueryFactory;
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/** Unit tests for {@link MetricsExportAction}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MetricsExportActionTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
@Mock
|
||||
BigqueryFactory bigqueryFactory;
|
||||
|
||||
@Mock
|
||||
Bigquery bigquery;
|
||||
|
||||
@Mock
|
||||
Tabledata tabledata;
|
||||
|
||||
@Mock
|
||||
InsertAll insertAll;
|
||||
|
||||
private TableDataInsertAllResponse response = new TableDataInsertAllResponse();
|
||||
private long currentTimeMillis = 1000000000000L;
|
||||
|
||||
private ImmutableListMultimap<String, String> parameters =
|
||||
new ImmutableListMultimap.Builder<String, String>()
|
||||
.put("startTime", String.valueOf(MILLISECONDS.toSeconds(currentTimeMillis - 100)))
|
||||
.put("endTime", String.valueOf(MILLISECONDS.toSeconds(currentTimeMillis)))
|
||||
.put("jobname", "test job")
|
||||
.put("status", "success")
|
||||
.put("tld", "test")
|
||||
.build();
|
||||
|
||||
MetricsExportAction action;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
when(bigqueryFactory.create(anyString(), anyString(), anyString())).thenReturn(bigquery);
|
||||
when(bigqueryFactory.create(
|
||||
anyString(),
|
||||
Matchers.any(HttpTransport.class),
|
||||
Matchers.any(JsonFactory.class),
|
||||
Matchers.any(HttpRequestInitializer.class)))
|
||||
.thenReturn(bigquery);
|
||||
|
||||
when(bigquery.tabledata()).thenReturn(tabledata);
|
||||
when(tabledata.insertAll(
|
||||
anyString(),
|
||||
anyString(),
|
||||
anyString(),
|
||||
Matchers.any(TableDataInsertAllRequest.class))).thenReturn(insertAll);
|
||||
action = new MetricsExportAction();
|
||||
action.bigqueryFactory = bigqueryFactory;
|
||||
action.insertId = "insert id";
|
||||
action.parameters = parameters;
|
||||
action.projectId = "project id";
|
||||
action.tableId = "eppMetrics";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_nullErrors() throws Exception {
|
||||
when(insertAll.execute()).thenReturn(response);
|
||||
response.setInsertErrors(null);
|
||||
action.run();
|
||||
verify(insertAll).execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_emptyErrors() throws Exception {
|
||||
when(insertAll.execute()).thenReturn(response);
|
||||
response.setInsertErrors(ImmutableList.<InsertErrors>of());
|
||||
action.run();
|
||||
verify(insertAll).execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_errors() throws Exception {
|
||||
when(insertAll.execute()).thenReturn(response);
|
||||
response.setInsertErrors(ImmutableList.of(new InsertErrors()));
|
||||
action.run();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.monitoring.whitebox;
|
||||
|
||||
import static com.google.domain.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
import com.google.domain.registry.testing.FakeClock;
|
||||
import com.google.domain.registry.testing.InjectRule;
|
||||
import com.google.domain.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/** Unit tests for {@link Metrics}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MetricsTest {
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withLocalModules()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("1984-12-18TZ"));
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
inject.setStaticField(Metrics.class, "clock", clock);
|
||||
inject.setStaticField(Metrics.class, "idGenerator", Suppliers.ofInstance("laffo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExport() throws Exception {
|
||||
class TestMetric extends Metrics {}
|
||||
Metrics metrics = new TestMetric();
|
||||
clock.advanceOneMilli();
|
||||
metrics.setTableId("test");
|
||||
metrics.export();
|
||||
assertTasksEnqueued("bigquery-streaming-metrics",
|
||||
new TaskMatcher()
|
||||
.url("/_dr/task/metrics")
|
||||
.header("Host", "1.backend.test.localhost")
|
||||
.param("tableId", "test")
|
||||
.param("startTime", "472176000.000000")
|
||||
.param("endTime", "472176000.001000")
|
||||
.param("insertId", "laffo"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.monitoring.whitebox;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.createTld;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.deleteResource;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.newDomainResource;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.persistDeletedContact;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.persistDomainAsDeleted;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.persistResource;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.api.client.util.Data;
|
||||
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;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.bigquery.BigqueryFactory;
|
||||
import com.google.domain.registry.config.RegistryEnvironment;
|
||||
import com.google.domain.registry.mapreduce.MapreduceRunner;
|
||||
import com.google.domain.registry.model.contact.ContactResource;
|
||||
import com.google.domain.registry.model.domain.DomainResource;
|
||||
import com.google.domain.registry.model.domain.ReferenceUnion;
|
||||
import com.google.domain.registry.model.host.HostResource;
|
||||
import com.google.domain.registry.model.index.EppResourceIndex;
|
||||
import com.google.domain.registry.model.index.ForeignKeyIndex;
|
||||
import com.google.domain.registry.model.index.ForeignKeyIndex.ForeignKeyContactIndex;
|
||||
import com.google.domain.registry.model.index.ForeignKeyIndex.ForeignKeyDomainIndex;
|
||||
import com.google.domain.registry.testing.FakeClock;
|
||||
import com.google.domain.registry.testing.FakeResponse;
|
||||
import com.google.domain.registry.testing.FakeSleeper;
|
||||
import com.google.domain.registry.testing.InjectRule;
|
||||
import com.google.domain.registry.testing.mapreduce.MapreduceTestCase;
|
||||
import com.google.domain.registry.util.Retrier;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.Ref;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/** Unit tests for {@link VerifyEntityIntegrityAction}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VerifyEntityIntegrityActionTest
|
||||
extends MapreduceTestCase<VerifyEntityIntegrityAction> {
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private VerifyEntityIntegrityStreamer integrity;
|
||||
private ArgumentCaptor<TableDataInsertAllRequest> rowsCaptor;
|
||||
private final DateTime now = DateTime.parse("2012-01-02T03:04:05Z");
|
||||
|
||||
@Mock
|
||||
private Bigquery bigquery;
|
||||
|
||||
@Mock
|
||||
private Bigquery.Tabledata bigqueryTableData;
|
||||
|
||||
@Mock
|
||||
private Bigquery.Tabledata.InsertAll bigqueryInsertAll;
|
||||
|
||||
@Mock
|
||||
private BigqueryFactory bigqueryFactory;
|
||||
|
||||
@Mock
|
||||
private VerifyEntityIntegrityStreamerFactory streamerFactory;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
createTld("tld");
|
||||
|
||||
action = new VerifyEntityIntegrityAction();
|
||||
action.mrRunner = new MapreduceRunner(Optional.of(2), Optional.of(2));
|
||||
action.response = new FakeResponse();
|
||||
WhiteboxComponent component = mock(WhiteboxComponent.class);
|
||||
inject.setStaticField(VerifyEntityIntegrityAction.class, "component", component);
|
||||
integrity =
|
||||
new VerifyEntityIntegrityStreamer(
|
||||
bigqueryFactory,
|
||||
RegistryEnvironment.UNITTEST,
|
||||
new Retrier(new FakeSleeper(new FakeClock()), 1),
|
||||
Suppliers.ofInstance("rowid"),
|
||||
now);
|
||||
when(bigqueryFactory.create(anyString(), anyString(), anyString())).thenReturn(bigquery);
|
||||
when(component.verifyEntityIntegrityStreamerFactory()).thenReturn(streamerFactory);
|
||||
when(streamerFactory.create(any(DateTime.class))).thenReturn(integrity);
|
||||
when(bigquery.tabledata()).thenReturn(bigqueryTableData);
|
||||
rowsCaptor = ArgumentCaptor.forClass(TableDataInsertAllRequest.class);
|
||||
when(bigqueryTableData.insertAll(anyString(), anyString(), anyString(), rowsCaptor.capture()))
|
||||
.thenReturn(bigqueryInsertAll);
|
||||
when(bigqueryInsertAll.execute()).thenReturn(new TableDataInsertAllResponse());
|
||||
|
||||
}
|
||||
|
||||
private void runMapreduce() throws Exception {
|
||||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_singleDomain_noBadInvariants() throws Exception {
|
||||
persistActiveDomain("ninetails.tld");
|
||||
runMapreduce();
|
||||
verifyZeroInteractions(bigquery);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_lotsOfData_noBadInvariants() throws Exception {
|
||||
createTld("march");
|
||||
ContactResource contact = persistActiveContact("longbottom");
|
||||
persistResource(newDomainResource("ninetails.tld", contact));
|
||||
persistResource(newDomainResource("tentails.tld", contact));
|
||||
persistDomainAsDeleted(newDomainResource("long.march", contact), now.minusMonths(4));
|
||||
persistResource(
|
||||
newDomainResource("long.march", contact)
|
||||
.asBuilder()
|
||||
.setCreationTimeForTest(now.minusMonths(3))
|
||||
.build());
|
||||
persistDeletedContact("ricketycricket", now.minusDays(3));
|
||||
persistDeletedContact("ricketycricket", now.minusDays(2));
|
||||
persistDeletedContact("ricketycricket", now.minusDays(1));
|
||||
persistActiveContact("ricketycricket");
|
||||
persistActiveHost("ns9001.example.net");
|
||||
runMapreduce();
|
||||
verifyZeroInteractions(bigquery);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_missingFki() throws Exception {
|
||||
persistActiveDomain("ninetails.tld");
|
||||
ForeignKeyIndex<DomainResource> fki =
|
||||
ForeignKeyIndex.load(DomainResource.class, "ninetails.tld", DateTime.now(DateTimeZone.UTC));
|
||||
deleteResource(fki);
|
||||
runMapreduce();
|
||||
assertIntegrityErrors(IntegrityError.create(
|
||||
"ninetails.tld", "DomainBase", "Missing foreign key index for EppResource"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_missingEppResourceIndex() throws Exception {
|
||||
Key<ContactResource> cooperKey = Key.create(persistActiveContact("cooper"));
|
||||
deleteResource(EppResourceIndex.create(cooperKey));
|
||||
runMapreduce();
|
||||
assertIntegrityErrors(IntegrityError.create(
|
||||
Data.NULL_STRING, cooperKey.toString(), "Missing EPP resource index for EPP resource"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_referencesToHostsThatDontExist() throws Exception {
|
||||
Key<HostResource> missingHost1 = Key.create(HostResource.class, "DEADBEEF-ROID");
|
||||
Key<HostResource> missingHost2 = Key.create(HostResource.class, "123ABC-ROID");
|
||||
Key<HostResource> missingHost3 = Key.create(HostResource.class, "FADDACA-ROID");
|
||||
DomainResource domain =
|
||||
persistResource(
|
||||
newDomainResource("blah.tld")
|
||||
.asBuilder()
|
||||
.setNameservers(
|
||||
ImmutableSet.of(
|
||||
ReferenceUnion.create(Ref.create(missingHost1)),
|
||||
ReferenceUnion.create(Ref.create(missingHost2)),
|
||||
ReferenceUnion.create(Ref.create(missingHost3))))
|
||||
.build());
|
||||
String source = Key.create(domain).toString();
|
||||
runMapreduce();
|
||||
assertIntegrityErrors(
|
||||
IntegrityError.create(source, missingHost1.toString(), "Target entity does not exist"),
|
||||
IntegrityError.create(source, missingHost2.toString(), "Target entity does not exist"),
|
||||
IntegrityError.create(source, missingHost3.toString(), "Target entity does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_overlappingActivePeriods() throws Exception {
|
||||
ContactResource contact123 = persistActiveContact("contact123");
|
||||
// These two have overlapping active periods because they will have both been created at
|
||||
// START_OF_TIME.
|
||||
DomainResource domain1 =
|
||||
persistDomainAsDeleted(newDomainResource("penny.tld", contact123), now.minusYears(2));
|
||||
DomainResource domain2 = persistActiveDomain("penny.tld");
|
||||
runMapreduce();
|
||||
assertIntegrityErrors(
|
||||
IntegrityError.create(
|
||||
ForeignKeyDomainIndex.createKey(domain2).toString(),
|
||||
Key.create(domain1).toString(),
|
||||
"Found inactive resource deleted more recently than when active resource was created"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_multipleActiveContactsWithSameContactId() throws Exception {
|
||||
ContactResource contact1 = persistActiveContact("dupeid");
|
||||
ContactResource contact2 = persistActiveContact("dupeid");
|
||||
runMapreduce();
|
||||
assertIntegrityErrors(
|
||||
IntegrityError.create(
|
||||
Key.create(ForeignKeyContactIndex.class, "dupeid").toString(),
|
||||
Key.create(contact1).toString(),
|
||||
"Multiple active EppResources with same foreign key"),
|
||||
IntegrityError.create(
|
||||
Key.create(ForeignKeyContactIndex.class, "dupeid").toString(),
|
||||
Key.create(contact2).toString(),
|
||||
"Multiple active EppResources with same foreign key"));
|
||||
}
|
||||
|
||||
/** Encapsulates the data representing a single integrity error. */
|
||||
private static class IntegrityError {
|
||||
String source;
|
||||
String target;
|
||||
String message;
|
||||
|
||||
static IntegrityError create(String source, String target, String message) {
|
||||
IntegrityError instance = new IntegrityError();
|
||||
instance.source = source;
|
||||
instance.target = target;
|
||||
instance.message = message;
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map representing the JSON blob corresponding to the BigQuery output for this
|
||||
* integrity violation at the given scan time.
|
||||
*/
|
||||
Map<String, Object> toMap(DateTime scanTime) {
|
||||
return new ImmutableMap.Builder<String, Object>()
|
||||
.put("scanTime", new com.google.api.client.util.DateTime(scanTime.toDate()))
|
||||
.put("source", source)
|
||||
.put("target", target)
|
||||
.put("message", message)
|
||||
.build();
|
||||
}
|
||||
|
||||
private IntegrityError() {}
|
||||
}
|
||||
|
||||
/** Asserts that the given integrity errors, and no others, were logged to BigQuery. */
|
||||
private void assertIntegrityErrors(IntegrityError... errors) {
|
||||
ImmutableList.Builder<Rows> expected = new ImmutableList.Builder<>();
|
||||
for (IntegrityError error : errors) {
|
||||
expected.add(new Rows().setInsertId("rowid").setJson(error.toMap(now)));
|
||||
}
|
||||
ImmutableList.Builder<Rows> allRows = new ImmutableList.Builder<>();
|
||||
for (TableDataInsertAllRequest req : rowsCaptor.getAllValues()) {
|
||||
allRows.addAll(req.getRows());
|
||||
}
|
||||
assertThat(allRows.build()).containsExactlyElementsIn(expected.build());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue