mirror of
https://github.com/google/nomulus.git
synced 2025-07-12 05:58:13 +02:00
Move GCP proxy code to the old [] proxy's location
1. Moved code for the GCP proxy to where the [] proxy code used to live. 3. Corrected reference to the GCP proxy location. 4. Misc changes to make ErrorProne and various tools happy. +diekmann to LGTM terraform whitelist change. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=213630560
This commit is contained in:
parent
961e5cc7c7
commit
3fc7271145
102 changed files with 296 additions and 11 deletions
173
javatests/google/registry/proxy/metric/BackendMetricsTest.java
Normal file
173
javatests/google/registry/proxy/metric/BackendMetricsTest.java
Normal file
|
@ -0,0 +1,173 @@
|
|||
// Copyright 2017 The Nomulus 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.proxy.metric;
|
||||
|
||||
import static com.google.monitoring.metrics.contrib.DistributionMetricSubject.assertThat;
|
||||
import static com.google.monitoring.metrics.contrib.LongMetricSubject.assertThat;
|
||||
import static google.registry.proxy.TestUtils.makeHttpPostRequest;
|
||||
import static google.registry.proxy.TestUtils.makeHttpResponse;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link BackendMetrics}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class BackendMetricsTest {
|
||||
|
||||
private final String host = "host.tld";
|
||||
private final String certHash = "blah12345";
|
||||
private final String protocol = "frontend protocol";
|
||||
|
||||
private final BackendMetrics metrics = new BackendMetrics();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
metrics.resetMetric();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest() {
|
||||
String content = "some content";
|
||||
FullHttpRequest request = makeHttpPostRequest(content, host, "/");
|
||||
metrics.requestSent(protocol, certHash, request.content().readableBytes());
|
||||
|
||||
assertThat(BackendMetrics.requestsCounter)
|
||||
.hasValueForLabels(1, protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.requestBytes)
|
||||
.hasDataSetForLabels(ImmutableSet.of(content.length()), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responsesCounter).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responseBytes).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.latencyMs).hasNoOtherValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipleRequests() {
|
||||
String content1 = "some content";
|
||||
String content2 = "some other content";
|
||||
FullHttpRequest request1 = makeHttpPostRequest(content1, host, "/");
|
||||
FullHttpRequest request2 = makeHttpPostRequest(content2, host, "/");
|
||||
metrics.requestSent(protocol, certHash, request1.content().readableBytes());
|
||||
metrics.requestSent(protocol, certHash, request2.content().readableBytes());
|
||||
|
||||
assertThat(BackendMetrics.requestsCounter)
|
||||
.hasValueForLabels(2, protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.requestBytes)
|
||||
.hasDataSetForLabels(
|
||||
ImmutableSet.of(content1.length(), content2.length()), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responsesCounter).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responseBytes).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.latencyMs).hasNoOtherValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneResponse() {
|
||||
String content = "some response";
|
||||
FullHttpResponse response = makeHttpResponse(content, HttpResponseStatus.OK);
|
||||
metrics.responseReceived(protocol, certHash, response, 5);
|
||||
|
||||
assertThat(BackendMetrics.requestsCounter).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.requestBytes).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responsesCounter)
|
||||
.hasValueForLabels(1, protocol, certHash, "200 OK")
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responseBytes)
|
||||
.hasDataSetForLabels(ImmutableSet.of(content.length()), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.latencyMs)
|
||||
.hasDataSetForLabels(ImmutableSet.of(5), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipleResponses() {
|
||||
String content1 = "some response";
|
||||
String content2 = "other response";
|
||||
String content3 = "a very bad response";
|
||||
FullHttpResponse response1 = makeHttpResponse(content1, HttpResponseStatus.OK);
|
||||
FullHttpResponse response2 = makeHttpResponse(content2, HttpResponseStatus.OK);
|
||||
FullHttpResponse response3 = makeHttpResponse(content3, HttpResponseStatus.BAD_REQUEST);
|
||||
metrics.responseReceived(protocol, certHash, response1, 5);
|
||||
metrics.responseReceived(protocol, certHash, response2, 8);
|
||||
metrics.responseReceived(protocol, certHash, response3, 2);
|
||||
|
||||
assertThat(BackendMetrics.requestsCounter).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.requestBytes).hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responsesCounter)
|
||||
.hasValueForLabels(2, protocol, certHash, "200 OK")
|
||||
.and()
|
||||
.hasValueForLabels(1, protocol, certHash, "400 Bad Request")
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responseBytes)
|
||||
.hasDataSetForLabels(
|
||||
ImmutableSet.of(content1.length(), content2.length(), content3.length()),
|
||||
protocol,
|
||||
certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.latencyMs)
|
||||
.hasDataSetForLabels(ImmutableSet.of(5, 8, 2), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest_oneResponse() {
|
||||
String requestContent = "some request";
|
||||
String responseContent = "the only response";
|
||||
FullHttpRequest request = makeHttpPostRequest(requestContent, host, "/");
|
||||
FullHttpResponse response = makeHttpResponse(responseContent, HttpResponseStatus.OK);
|
||||
metrics.requestSent(protocol, certHash, request.content().readableBytes());
|
||||
metrics.responseReceived(protocol, certHash, response, 10);
|
||||
|
||||
assertThat(BackendMetrics.requestsCounter)
|
||||
.hasValueForLabels(1, protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responsesCounter)
|
||||
.hasValueForLabels(1, protocol, certHash, "200 OK")
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.requestBytes)
|
||||
.hasDataSetForLabels(ImmutableSet.of(requestContent.length()), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.responseBytes)
|
||||
.hasDataSetForLabels(ImmutableSet.of(responseContent.length()), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
assertThat(BackendMetrics.latencyMs)
|
||||
.hasDataSetForLabels(ImmutableSet.of(10), protocol, certHash)
|
||||
.and()
|
||||
.hasNoOtherValues();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue