mirror of
https://github.com/google/nomulus.git
synced 2025-06-28 07:13:34 +02:00
Refector metrics truth subject
The concrete implementation of a Metric is not of importance when asserting on the values it contains. Therefore this CL removes Metric<T> as a type parameter of AbstractMetricSubject. As a result the two implementations of the abstract subject can be used on any Metric<Long> and Metric<Distribution>, respectively. Also migrate to Subject.Factory from deprecated SubjectFactory. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171012012
This commit is contained in:
parent
a9ecccf672
commit
9d8e48cf24
7 changed files with 60 additions and 74 deletions
|
@ -21,7 +21,7 @@ import com.google.common.base.Joiner;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.google.common.truth.FailureStrategy;
|
||||
import com.google.common.truth.FailureMetadata;
|
||||
import com.google.common.truth.Subject;
|
||||
import google.registry.monitoring.metrics.Metric;
|
||||
import google.registry.monitoring.metrics.MetricPoint;
|
||||
|
@ -34,12 +34,11 @@ import javax.annotation.Nullable;
|
|||
*
|
||||
* <p>For use with the Google <a href="https://google.github.io/truth/">Truth</a> framework.
|
||||
*/
|
||||
abstract class AbstractMetricSubject<
|
||||
T, M extends Metric<T>, S extends AbstractMetricSubject<T, M, S>>
|
||||
extends Subject<S, M> {
|
||||
abstract class AbstractMetricSubject<T, S extends AbstractMetricSubject<T, S>>
|
||||
extends Subject<S, Metric<T>> {
|
||||
|
||||
/** And chainer to allow fluent assertions. */
|
||||
public static class And<S extends AbstractMetricSubject<?, ?, S>> {
|
||||
public static class And<S extends AbstractMetricSubject<?, S>> {
|
||||
|
||||
private final S subject;
|
||||
|
||||
|
@ -57,7 +56,8 @@ abstract class AbstractMetricSubject<
|
|||
return new And<>((S) this);
|
||||
}
|
||||
|
||||
/** List of label value tuples about which an assertion has been made so far.
|
||||
/**
|
||||
* List of label value tuples about which an assertion has been made so far.
|
||||
*
|
||||
* <p>Used to track what tuples have been seen, in order to support hasNoOtherValues() assertions.
|
||||
*/
|
||||
|
@ -77,8 +77,8 @@ abstract class AbstractMetricSubject<
|
|||
}
|
||||
};
|
||||
|
||||
protected AbstractMetricSubject(FailureStrategy strategy, M actual) {
|
||||
super(strategy, checkNotNull(actual));
|
||||
protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
|
||||
super(metadata, checkNotNull(actual));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,9 +148,7 @@ abstract class AbstractMetricSubject<
|
|||
return andChainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the metric does not have a (non-default) value for the specified label values.
|
||||
*/
|
||||
/** Asserts that the metric does not have a (non-default) value for the specified label values. */
|
||||
protected And<S> doesNotHaveAnyValueForLabels(String... labels) {
|
||||
MetricPoint<T> metricPoint = findMetricPointForLabels(ImmutableList.copyOf(labels));
|
||||
if (metricPoint != null) {
|
||||
|
@ -197,6 +195,15 @@ abstract class AbstractMetricSubject<
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of a metric point value, for use in error messages.
|
||||
*
|
||||
* <p>Subclass can override this method if the string needs extra processing.
|
||||
*/
|
||||
protected String getMessageRepresentation(T value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the metric point has a non-default value.
|
||||
*
|
||||
|
@ -204,7 +211,4 @@ abstract class AbstractMetricSubject<
|
|||
* return true if the value is not zero, and so on.
|
||||
*/
|
||||
protected abstract boolean hasDefaultValue(MetricPoint<T> metricPoint);
|
||||
|
||||
/** Returns a string representation of a metric point value, for use in error messages. */
|
||||
protected abstract String getMessageRepresentation(T value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue