Remove internal public validateLabelPairs, move to the class that uses it (#2215)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
69208f8f79
commit
be9c31ecad
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
package io.opentelemetry.api.internal;
|
||||
|
||||
import java.util.Objects;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/** General internal utility methods. */
|
||||
|
|
@ -26,23 +25,4 @@ public final class Utils {
|
|||
throw new IllegalArgumentException(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the array of Strings is 1) even in length, and 2) they can be formed into valid
|
||||
* pairs where the first item in the pair is not null.
|
||||
*
|
||||
* <p>TODO: write unit tests for this method.
|
||||
*
|
||||
* @param keyValuePairs The String[] to validate for correctness.
|
||||
* @throws IllegalArgumentException if any of the preconditions are violated.
|
||||
*/
|
||||
public static void validateLabelPairs(String[] keyValuePairs) {
|
||||
checkArgument(
|
||||
keyValuePairs.length % 2 == 0,
|
||||
"You must provide an even number of key/value pair arguments.");
|
||||
for (int i = 0; i < keyValuePairs.length; i += 2) {
|
||||
String key = keyValuePairs[i];
|
||||
Objects.requireNonNull(key, "You cannot provide null keys for label creation.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ final class DefaultMeter implements Meter {
|
|||
|
||||
@Override
|
||||
public BatchRecorder newBatchRecorder(String... keyValuePairs) {
|
||||
Utils.validateLabelPairs(keyValuePairs);
|
||||
validateLabelPairs(keyValuePairs);
|
||||
return NoopBatchRecorder.INSTANCE;
|
||||
}
|
||||
|
||||
|
|
@ -676,4 +676,21 @@ final class DefaultMeter implements Meter {
|
|||
|
||||
protected abstract B getThis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the array of Strings is 1) even in length, and 2) they can be formed into valid
|
||||
* pairs where the first item in the pair is not null.
|
||||
*
|
||||
* @param keyValuePairs The String[] to validate for correctness.
|
||||
* @throws IllegalArgumentException if any of the preconditions are violated.
|
||||
*/
|
||||
private static void validateLabelPairs(String[] keyValuePairs) {
|
||||
Utils.checkArgument(
|
||||
keyValuePairs.length % 2 == 0,
|
||||
"You must provide an even number of key/value pair arguments.");
|
||||
for (int i = 0; i < keyValuePairs.length; i += 2) {
|
||||
String key = keyValuePairs[i];
|
||||
Objects.requireNonNull(key, "You cannot provide null keys for label creation.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,16 @@ class BatchRecorderTest {
|
|||
private static final Meter meter = Meter.getDefault();
|
||||
|
||||
@Test
|
||||
void testNewBatchRecorder_badLabelSet() {
|
||||
void testNewBatchRecorder_WrongNumberOfLabels() {
|
||||
assertThrows(IllegalArgumentException.class, () -> meter.newBatchRecorder("key"), "key/value");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNewBatchRecorder_NullLabelKey() {
|
||||
assertThrows(
|
||||
NullPointerException.class, () -> meter.newBatchRecorder(null, "value"), "null keys");
|
||||
}
|
||||
|
||||
@Test
|
||||
void preventNull_MeasureLong() {
|
||||
assertThrows(
|
||||
|
|
|
|||
Loading…
Reference in New Issue