mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 10:16:07 +02:00
Change EppMetric.Builder to use @AutoValue.Builder
Getting rid of builder boilerplate makes my heart sing. Since we can no longer @Inject the Builder() constructor, this change adds a provider in WhiteboxModule that calls a special builderForRequest() factory method, which gets passed a request ID and Clock and preserves the existing EppMetric magic that sets the start and end time for you. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132714432
This commit is contained in:
parent
ceb5c2117e
commit
2537e95de5
10 changed files with 108 additions and 107 deletions
|
@ -36,21 +36,22 @@ public class EppMetricTest {
|
|||
@Test
|
||||
public void testGetBigQueryRowEncoding_encodesCorrectly() throws Exception {
|
||||
EppMetric metric =
|
||||
new EppMetric.Builder(new DateTime(1337))
|
||||
.setEppTarget("target")
|
||||
.setPrivilegeLevel("level")
|
||||
EppMetric.builder()
|
||||
.setRequestId("request-id-1")
|
||||
.setStartTimestamp(new DateTime(1337))
|
||||
.setEndTimestamp(new DateTime(1338))
|
||||
.setCommandName("command")
|
||||
.setClientId("client")
|
||||
.setPrivilegeLevel("level")
|
||||
.setEppTarget("target")
|
||||
.setStatus(Code.CommandUseError)
|
||||
.incrementAttempts()
|
||||
.build(new DateTime(1338));
|
||||
.build();
|
||||
|
||||
// The request_id is randomly generated and hard to mock without a lot of supporting code
|
||||
// so we just use the tested metric's request_id verbatim.
|
||||
assertThat(metric.getBigQueryRowEncoding())
|
||||
.containsExactlyEntriesIn(
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
.put("requestId", metric.getRequestId())
|
||||
.put("requestId", "request-id-1")
|
||||
.put("startTime", "1.337000")
|
||||
.put("endTime", "1.338000")
|
||||
.put("commandName", "command")
|
||||
|
@ -65,14 +66,17 @@ public class EppMetricTest {
|
|||
@Test
|
||||
public void testGetBigQueryRowEncoding_hasAllSchemaFields() throws Exception {
|
||||
EppMetric metric =
|
||||
new EppMetric.Builder(new DateTime(1337))
|
||||
.setEppTarget("target")
|
||||
.setPrivilegeLevel("level")
|
||||
EppMetric.builder()
|
||||
.setRequestId("request-id-1")
|
||||
.setStartTimestamp(new DateTime(1337))
|
||||
.setEndTimestamp(new DateTime(1338))
|
||||
.setCommandName("command")
|
||||
.setClientId("client")
|
||||
.setPrivilegeLevel("level")
|
||||
.setEppTarget("target")
|
||||
.setStatus(Code.CommandUseError)
|
||||
.incrementAttempts()
|
||||
.build(new DateTime(1338));
|
||||
.build();
|
||||
ImmutableSet.Builder<String> schemaFieldNames = new ImmutableSet.Builder<>();
|
||||
for (TableFieldSchema schemaField : metric.getSchemaFields()) {
|
||||
schemaFieldNames.add(schemaField.getName());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue