From 89a06bc3bd6bfe504a06be4349d19c4ec144f103 Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Thu, 3 Oct 2019 11:29:02 +0200 Subject: [PATCH] Fix Glean SDK specific metrics API to be callable from Java This adds `@JvmOverloads` to the specific metrics API and the testing API. --- .../components/service/glean/private/BooleanMetricType.kt | 2 ++ .../components/service/glean/private/CounterMetricType.kt | 3 +++ .../components/service/glean/private/DatetimeMetricType.kt | 4 ++++ .../components/service/glean/private/EventMetricType.kt | 3 +++ .../service/glean/private/MemoryDistributionMetricType.kt | 2 ++ .../components/service/glean/private/StringListMetricType.kt | 2 ++ .../components/service/glean/private/StringMetricType.kt | 2 ++ .../components/service/glean/private/TimespanMetricType.kt | 2 ++ .../service/glean/private/TimingDistributionMetricType.kt | 2 ++ .../components/service/glean/private/UuidMetricType.kt | 2 ++ 10 files changed, 24 insertions(+) diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/BooleanMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/BooleanMetricType.kt index 3e4e44551a3..ab142ec1d2e 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/BooleanMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/BooleanMetricType.kt @@ -58,6 +58,7 @@ data class BooleanMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -76,6 +77,7 @@ data class BooleanMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/CounterMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/CounterMetricType.kt index 4a3eb316f28..1060e394f8e 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/CounterMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/CounterMetricType.kt @@ -34,6 +34,7 @@ data class CounterMetricType( * @param amount This is the amount to increment the counter by, defaulting to 1 if called * without parameters. */ + @JvmOverloads fun add(amount: Int = 1) { if (!shouldRecord(logger)) { return @@ -60,6 +61,7 @@ data class CounterMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -78,6 +80,7 @@ data class CounterMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): Int { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/DatetimeMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/DatetimeMetricType.kt index 4bdbc00f61b..5466a1dab27 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/DatetimeMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/DatetimeMetricType.kt @@ -34,6 +34,7 @@ data class DatetimeMetricType( * * @param value The [Date] value to set. If not provided, will record the current time. */ + @JvmOverloads fun set(value: Date = Date()) { if (!shouldRecord(logger)) { return @@ -85,6 +86,7 @@ data class DatetimeMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -104,6 +106,7 @@ data class DatetimeMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValueAsString(pingName: String = sendInPings.first()): String { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -126,6 +129,7 @@ data class DatetimeMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): Date { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/EventMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/EventMetricType.kt index 0536cff4a63..2ca40c96b47 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/EventMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/EventMetricType.kt @@ -47,6 +47,7 @@ data class EventMetricType>( * identifiers. This is used for events where additional richer context is needed. * The maximum length for values is defined by [MAX_LENGTH_EXTRA_KEY_VALUE] */ + @JvmOverloads fun record(extra: Map? = null) { if (!shouldRecord(logger)) { return @@ -96,6 +97,7 @@ data class EventMetricType>( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -117,6 +119,7 @@ data class EventMetricType>( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): List { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/MemoryDistributionMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/MemoryDistributionMetricType.kt index a80f4b55ee7..30b80a2321a 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/MemoryDistributionMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/MemoryDistributionMetricType.kt @@ -85,6 +85,7 @@ data class MemoryDistributionMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -103,6 +104,7 @@ data class MemoryDistributionMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): FunctionalHistogram { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringListMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringListMetricType.kt index 7557844639d..ae8f0e5ad7b 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringListMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringListMetricType.kt @@ -82,6 +82,7 @@ data class StringListMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -100,6 +101,7 @@ data class StringListMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): List { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringMetricType.kt index d044659666c..da3dd8fbb73 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/StringMetricType.kt @@ -60,6 +60,7 @@ data class StringMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -78,6 +79,7 @@ data class StringMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): String { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimespanMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimespanMetricType.kt index eaf99bc051c..502e51b88db 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimespanMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimespanMetricType.kt @@ -151,6 +151,7 @@ data class TimespanMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { return TimespansStorageEngine.getSnapshotWithTimeUnit(pingName, false)?.get(identifier) != null } @@ -165,6 +166,7 @@ data class TimespanMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): Long { return TimespansStorageEngine.getSnapshotWithTimeUnit(pingName, false)!![identifier]!!.second } diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimingDistributionMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimingDistributionMetricType.kt index 4f27be8a66c..c340c5c089a 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimingDistributionMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/TimingDistributionMetricType.kt @@ -128,6 +128,7 @@ data class TimingDistributionMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -146,6 +147,7 @@ data class TimingDistributionMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): FunctionalHistogram { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() diff --git a/components/service/glean/src/main/java/mozilla/components/service/glean/private/UuidMetricType.kt b/components/service/glean/src/main/java/mozilla/components/service/glean/private/UuidMetricType.kt index 0dfa14eaf25..1abb02495a6 100644 --- a/components/service/glean/src/main/java/mozilla/components/service/glean/private/UuidMetricType.kt +++ b/components/service/glean/src/main/java/mozilla/components/service/glean/private/UuidMetricType.kt @@ -78,6 +78,7 @@ data class UuidMetricType( * @return true if metric value exists, otherwise false */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testHasValue(pingName: String = sendInPings.first()): Boolean { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode() @@ -96,6 +97,7 @@ data class UuidMetricType( * @throws [NullPointerException] if no value is stored */ @VisibleForTesting(otherwise = VisibleForTesting.NONE) + @JvmOverloads fun testGetValue(pingName: String = sendInPings.first()): UUID { @Suppress("EXPERIMENTAL_API_USAGE") Dispatchers.API.assertInTestingMode()