diff --git a/java/google/registry/monitoring/metrics/contrib/AbstractMetricSubject.java b/java/google/registry/monitoring/metrics/contrib/AbstractMetricSubject.java
index e6a893e40..562c0bdae 100644
--- a/java/google/registry/monitoring/metrics/contrib/AbstractMetricSubject.java
+++ b/java/google/registry/monitoring/metrics/contrib/AbstractMetricSubject.java
@@ -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;
*
*
For use with the Google Truth framework.
*/
-abstract class AbstractMetricSubject<
- T, M extends Metric, S extends AbstractMetricSubject>
- extends Subject {
+abstract class AbstractMetricSubject>
+ extends Subject> {
/** And chainer to allow fluent assertions. */
- public static class And> {
+ public static class And> {
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.
*
* 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 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 doesNotHaveAnyValueForLabels(String... labels) {
MetricPoint 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.
+ *
+ * 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 metricPoint);
-
- /** Returns a string representation of a metric point value, for use in error messages. */
- protected abstract String getMessageRepresentation(T value);
}
diff --git a/java/google/registry/monitoring/metrics/contrib/EventMetricSubject.java b/java/google/registry/monitoring/metrics/contrib/DistributionMetricSubject.java
similarity index 71%
rename from java/google/registry/monitoring/metrics/contrib/EventMetricSubject.java
rename to java/google/registry/monitoring/metrics/contrib/DistributionMetricSubject.java
index 937ac09e6..69c86bfb1 100644
--- a/java/google/registry/monitoring/metrics/contrib/EventMetricSubject.java
+++ b/java/google/registry/monitoring/metrics/contrib/DistributionMetricSubject.java
@@ -18,24 +18,24 @@ import static com.google.common.truth.Truth.assertAbout;
import com.google.common.collect.BoundType;
import com.google.common.collect.Range;
-import com.google.common.truth.FailureStrategy;
-import com.google.common.truth.SubjectFactory;
+import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.Subject;
import google.registry.monitoring.metrics.Distribution;
-import google.registry.monitoring.metrics.EventMetric;
+import google.registry.monitoring.metrics.Metric;
import google.registry.monitoring.metrics.MetricPoint;
import java.util.Map;
import javax.annotation.Nullable;
/**
- * Truth subject for the {@link EventMetric} class.
+ * Truth subject for the {@link Metric} class.
*
* For use with the Google Truth framework. Usage:
*
- *
assertThat(myEventMetric)
+ * assertThat(myDistributionMetric)
* .hasAnyValueForLabels("label1", "label2", "label3")
* .and()
* .hasNoOtherValues();
- * assertThat(myEventMetric)
+ * assertThat(myDistributionMetric)
* .doesNotHaveAnyValueForLabels("label1", "label2");
*
*
@@ -44,28 +44,23 @@ import javax.annotation.Nullable;
* it's difficult to write assertions about expected metric data when any number of empty
* distributions can also be present, so they are screened out for convenience.
*/
-public final class EventMetricSubject
- extends AbstractMetricSubject {
+public final class DistributionMetricSubject
+ extends AbstractMetricSubject {
- /** {@link SubjectFactory} for assertions about {@link EventMetric} objects. */
- private static final SubjectFactory
+ /** {@link Subject.Factory} for assertions about {@link Metric} objects. */
+ private static final Subject.Factory>
SUBJECT_FACTORY =
- new SubjectFactory() {
- // The Truth extensibility documentation indicates that the target should be nullable.
- @Override
- public EventMetricSubject getSubject(
- FailureStrategy failureStrategy, @Nullable EventMetric target) {
- return new EventMetricSubject(failureStrategy, target);
- }
- };
+ // The Truth extensibility documentation indicates that the target should be nullable.
+ (FailureMetadata failureMetadata, @Nullable Metric target) ->
+ new DistributionMetricSubject(failureMetadata, target);
- /** Static assertThat({@link EventMetric}) shortcut method. */
- public static EventMetricSubject assertThat(@Nullable EventMetric metric) {
+ /** Static assertThat({@link Metric}) shortcut method. */
+ public static DistributionMetricSubject assertThat(@Nullable Metric metric) {
return assertAbout(SUBJECT_FACTORY).that(metric);
}
- private EventMetricSubject(FailureStrategy strategy, EventMetric actual) {
- super(strategy, actual);
+ private DistributionMetricSubject(FailureMetadata metadata, Metric actual) {
+ super(metadata, actual);
}
/**
diff --git a/java/google/registry/monitoring/metrics/contrib/IncrementableMetricSubject.java b/java/google/registry/monitoring/metrics/contrib/LongMetricSubject.java
similarity index 56%
rename from java/google/registry/monitoring/metrics/contrib/IncrementableMetricSubject.java
rename to java/google/registry/monitoring/metrics/contrib/LongMetricSubject.java
index aed68d27d..148ffad13 100644
--- a/java/google/registry/monitoring/metrics/contrib/IncrementableMetricSubject.java
+++ b/java/google/registry/monitoring/metrics/contrib/LongMetricSubject.java
@@ -16,24 +16,24 @@ package google.registry.monitoring.metrics.contrib;
import static com.google.common.truth.Truth.assertAbout;
-import com.google.common.truth.FailureStrategy;
-import com.google.common.truth.SubjectFactory;
-import google.registry.monitoring.metrics.IncrementableMetric;
+import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.Subject;
+import google.registry.monitoring.metrics.Metric;
import google.registry.monitoring.metrics.MetricPoint;
import javax.annotation.Nullable;
/**
- * Truth subject for the {@link IncrementableMetric} class.
+ * Truth subject for the {@link Metric} class.
*
* For use with the Google Truth framework. Usage:
*
- *
assertThat(myIncrementableMetric)
+ * assertThat(myLongMetric)
* .hasValueForLabels(5, "label1", "label2", "label3")
* .and()
* .hasAnyValueForLabels("label1", "label2", "label4")
* .and()
* .hasNoOtherValues();
- * assertThat(myIncrementableMetric)
+ * assertThat(myLongMetric)
* .doesNotHaveAnyValueForLabels("label1", "label2");
*
*
@@ -42,35 +42,28 @@ import javax.annotation.Nullable;
* after they are reset. But it's difficult to write assertions about expected metric data when any
* number of zero values can also be present, so they are screened out for convenience.
*/
-public final class IncrementableMetricSubject
- extends AbstractMetricSubject {
+public final class LongMetricSubject extends AbstractMetricSubject {
- /** {@link SubjectFactory} for assertions about {@link IncrementableMetric} objects. */
- private static final SubjectFactory
- SUBJECT_FACTORY =
- new SubjectFactory() {
- // The Truth extensibility documentation indicates that the target should be nullable.
- @Override
- public IncrementableMetricSubject getSubject(
- FailureStrategy failureStrategy, @Nullable IncrementableMetric target) {
- return new IncrementableMetricSubject(failureStrategy, target);
- }
- };
+ /** {@link Subject.Factory} for assertions about {@link Metric} objects. */
+ private static final Subject.Factory> SUBJECT_FACTORY =
+ // The Truth extensibility documentation indicates that the target should be nullable.
+ (FailureMetadata failureMetadata, @Nullable Metric target) ->
+ new LongMetricSubject(failureMetadata, target);
- /** Static assertThat({@link IncrementableMetric}) shortcut method. */
- public static IncrementableMetricSubject assertThat(@Nullable IncrementableMetric metric) {
+ /** Static assertThat({@link Metric}) shortcut method. */
+ public static LongMetricSubject assertThat(@Nullable Metric metric) {
return assertAbout(SUBJECT_FACTORY).that(metric);
}
- private IncrementableMetricSubject(FailureStrategy strategy, IncrementableMetric actual) {
- super(strategy, actual);
+ private LongMetricSubject(FailureMetadata metadata, Metric actual) {
+ super(metadata, actual);
}
/**
* Asserts that the metric has a given value for the specified label values. This is a convenience
* method that takes a long instead of a Long, for ease of use.
*/
- public And hasValueForLabels(long value, String... labels) {
+ public And hasValueForLabels(long value, String... labels) {
return hasValueForLabels(Long.valueOf(value), labels);
}
@@ -82,10 +75,4 @@ public final class IncrementableMetricSubject
protected boolean hasDefaultValue(MetricPoint metricPoint) {
return metricPoint.value() == 0L;
}
-
- /** Returns an appropriate string representation of a metric value for use in error messages. */
- @Override
- protected String getMessageRepresentation(Long value) {
- return String.valueOf(value);
- }
}
diff --git a/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java b/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java
index da5a39749..8762f256d 100644
--- a/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java
+++ b/javatests/google/registry/model/registry/label/PremiumListUtilsTest.java
@@ -27,8 +27,8 @@ import static google.registry.model.registry.label.PremiumListUtils.deletePremiu
import static google.registry.model.registry.label.PremiumListUtils.doesPremiumListExist;
import static google.registry.model.registry.label.PremiumListUtils.getPremiumPrice;
import static google.registry.model.registry.label.PremiumListUtils.savePremiumListAndEntries;
-import static google.registry.monitoring.metrics.contrib.EventMetricSubject.assertThat;
-import static google.registry.monitoring.metrics.contrib.IncrementableMetricSubject.assertThat;
+import static google.registry.monitoring.metrics.contrib.DistributionMetricSubject.assertThat;
+import static google.registry.monitoring.metrics.contrib.LongMetricSubject.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadPremiumListEntries;
import static google.registry.testing.DatastoreHelper.persistPremiumList;
diff --git a/javatests/google/registry/model/registry/label/ReservedListTest.java b/javatests/google/registry/model/registry/label/ReservedListTest.java
index c32eb9255..493cc2be4 100644
--- a/javatests/google/registry/model/registry/label/ReservedListTest.java
+++ b/javatests/google/registry/model/registry/label/ReservedListTest.java
@@ -28,8 +28,8 @@ import static google.registry.model.registry.label.ReservationType.RESERVED_FOR_
import static google.registry.model.registry.label.ReservedList.getAllowedNameservers;
import static google.registry.model.registry.label.ReservedList.getReservationTypes;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
-import static google.registry.monitoring.metrics.contrib.EventMetricSubject.assertThat;
-import static google.registry.monitoring.metrics.contrib.IncrementableMetricSubject.assertThat;
+import static google.registry.monitoring.metrics.contrib.DistributionMetricSubject.assertThat;
+import static google.registry.monitoring.metrics.contrib.LongMetricSubject.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource;
diff --git a/javatests/google/registry/monitoring/metrics/contrib/EventMetricSubjectTest.java b/javatests/google/registry/monitoring/metrics/contrib/DistributionMetricSubjectTest.java
similarity index 96%
rename from javatests/google/registry/monitoring/metrics/contrib/EventMetricSubjectTest.java
rename to javatests/google/registry/monitoring/metrics/contrib/DistributionMetricSubjectTest.java
index 4460c5b61..15be8d8e9 100644
--- a/javatests/google/registry/monitoring/metrics/contrib/EventMetricSubjectTest.java
+++ b/javatests/google/registry/monitoring/metrics/contrib/DistributionMetricSubjectTest.java
@@ -15,7 +15,7 @@
package google.registry.monitoring.metrics.contrib;
import static com.google.common.truth.Truth.assertThat;
-import static google.registry.monitoring.metrics.contrib.EventMetricSubject.assertThat;
+import static google.registry.monitoring.metrics.contrib.DistributionMetricSubject.assertThat;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableSet;
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
-public class EventMetricSubjectTest {
+public class DistributionMetricSubjectTest {
private static final ImmutableSet LABEL_DESCRIPTORS =
ImmutableSet.of(
diff --git a/javatests/google/registry/monitoring/metrics/contrib/IncrementableMetricSubjectTest.java b/javatests/google/registry/monitoring/metrics/contrib/LongMetricSubjectTest.java
similarity index 96%
rename from javatests/google/registry/monitoring/metrics/contrib/IncrementableMetricSubjectTest.java
rename to javatests/google/registry/monitoring/metrics/contrib/LongMetricSubjectTest.java
index 1098575a1..daaece1e0 100644
--- a/javatests/google/registry/monitoring/metrics/contrib/IncrementableMetricSubjectTest.java
+++ b/javatests/google/registry/monitoring/metrics/contrib/LongMetricSubjectTest.java
@@ -15,7 +15,7 @@
package google.registry.monitoring.metrics.contrib;
import static com.google.common.truth.Truth.assertThat;
-import static google.registry.monitoring.metrics.contrib.IncrementableMetricSubject.assertThat;
+import static google.registry.monitoring.metrics.contrib.LongMetricSubject.assertThat;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableSet;
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
-public class IncrementableMetricSubjectTest {
+public class LongMetricSubjectTest {
private static final ImmutableSet LABEL_DESCRIPTORS =
ImmutableSet.of(