mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +02:00
Refactor EppMetrics into the EppMetric value type
This change refactors EppMetrics from the mutable self-exporting thing that it was into a real value type EppMetric, and delegates exporting functionality to the BigQueryMetricsEnqueuer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132387660
This commit is contained in:
parent
b77ebd1df9
commit
42a39b0ddc
16 changed files with 484 additions and 234 deletions
|
@ -0,0 +1,111 @@
|
|||
// 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 google.registry.monitoring.whitebox;
|
||||
|
||||
import static google.registry.bigquery.BigqueryUtils.toBigqueryTimestamp;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.api.services.bigquery.model.TableFieldSchema;
|
||||
import com.google.appengine.api.modules.ModulesService;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.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.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/** Unit tests for {@link BigQueryMetricsEnqueuer}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BigQueryMetricsEnqueuerTest {
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withLocalModules()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
@Mock ModulesService modulesService;
|
||||
|
||||
private BigQueryMetricsEnqueuer enqueuer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
enqueuer = new BigQueryMetricsEnqueuer();
|
||||
enqueuer.modulesService = modulesService;
|
||||
when(modulesService.getVersionHostname(Matchers.anyString(), Matchers.anyString()))
|
||||
.thenReturn("1.backend.test.localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExport() throws Exception {
|
||||
TestMetric metric =
|
||||
TestMetric.create(
|
||||
DateTime.parse("1984-12-18TZ"), DateTime.parse("1984-12-18TZ").plusMillis(1));
|
||||
|
||||
enqueuer.export(metric, "laffo");
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
/** A stub implementation of {@link BigQueryMetric}. */
|
||||
@AutoValue
|
||||
abstract static class TestMetric implements BigQueryMetric {
|
||||
|
||||
static TestMetric create(DateTime startTimestamp, DateTime endTimestamp) {
|
||||
return new AutoValue_BigQueryMetricsEnqueuerTest_TestMetric(startTimestamp, endTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableId() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<TableFieldSchema> getSchemaFields() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, String> getBigQueryRowEncoding() {
|
||||
return ImmutableMap.of(
|
||||
"startTime", toBigqueryTimestamp(getStartTimestamp()),
|
||||
"endTime", toBigqueryTimestamp(getEndTimestamp()));
|
||||
}
|
||||
|
||||
abstract DateTime getStartTimestamp();
|
||||
|
||||
abstract DateTime getEndTimestamp();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue