Skip to content

Commit

Permalink
Add xxxKeyValue() variants with KeyValue to ObservationContextAssert (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Aug 21, 2023
1 parent c959eb3 commit a2ad7e1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ public SELF hasLowCardinalityKeyValue(String key, String value) {
return (SELF) this;
}

/**
* Return whether it has the given low cardinality key value.
* @param keyValue key value
* @return whether it has the given low cardinality key value
* @since 1.12.0
*/
public SELF hasLowCardinalityKeyValue(KeyValue keyValue) {
return hasLowCardinalityKeyValue(keyValue.getKey(), keyValue.getValue());
}

public SELF doesNotHaveLowCardinalityKeyValueWithKey(String key) {
isNotNull();
if (this.actual.getLowCardinalityKeyValues().stream().anyMatch(tag -> tag.getKey().equals(key))) {
Expand All @@ -278,6 +288,16 @@ public SELF doesNotHaveLowCardinalityKeyValue(String key, String value) {
return (SELF) this;
}

/**
* Return whether it does not have the given low cardinality key value.
* @param keyValue key value
* @return whether it does not have the given low cardinality key value
* @since 1.12.0
*/
public SELF doesNotHaveLowCardinalityKeyValue(KeyValue keyValue) {
return doesNotHaveLowCardinalityKeyValue(keyValue.getKey(), keyValue.getValue());
}

public SELF hasHighCardinalityKeyValueWithKey(String key) {
isNotNull();
if (this.actual.getHighCardinalityKeyValues().stream().noneMatch(tag -> tag.getKey().equals(key))) {
Expand Down Expand Up @@ -305,6 +325,16 @@ public SELF hasHighCardinalityKeyValue(String key, String value) {
return (SELF) this;
}

/**
* Return whether it has the given high cardinality key value.
* @param keyValue key value
* @return whether it has the given high cardinality key value
* @since 1.12.0
*/
public SELF hasHighCardinalityKeyValue(KeyValue keyValue) {
return hasHighCardinalityKeyValue(keyValue.getKey(), keyValue.getValue());
}

public SELF doesNotHaveHighCardinalityKeyValueWithKey(String key) {
isNotNull();
if (this.actual.getHighCardinalityKeyValues().stream().anyMatch(tag -> tag.getKey().equals(key))) {
Expand All @@ -330,6 +360,16 @@ public SELF doesNotHaveHighCardinalityKeyValue(String key, String value) {
return (SELF) this;
}

/**
* Return whether it does not have the given high cardinality key value.
* @param keyValue key value
* @return whether it does not have the given high cardinality key value
* @since 1.12.0
*/
public SELF doesNotHaveHighCardinalityKeyValue(KeyValue keyValue) {
return doesNotHaveHighCardinalityKeyValue(keyValue.getKey(), keyValue.getValue());
}

public SELF hasMapEntry(Object key, Object value) {
isNotNull();
Object mapValue = this.actual.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.micrometer.observation.tck;

import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
Expand Down Expand Up @@ -237,7 +238,8 @@ void should_not_throw_exception_when_low_cardinality_key_value_exists() {
Observation observation = Observation.start("foo", context, registry);
observation.lowCardinalityKeyValue("foo", "bar");

thenNoException().isThrownBy(() -> assertThat(context).hasLowCardinalityKeyValue("foo", "bar"));
thenNoException().isThrownBy(() -> assertThat(context).hasLowCardinalityKeyValue("foo", "bar")
.hasLowCardinalityKeyValue(KeyValue.of("foo", "bar")));
}

@Test
Expand All @@ -256,7 +258,8 @@ void should_not_throw_exception_when_high_cardinality_key_value_exists() {
Observation observation = Observation.start("foo", context, registry);
observation.highCardinalityKeyValue("foo", "bar");

thenNoException().isThrownBy(() -> assertThat(context).hasHighCardinalityKeyValue("foo", "bar"));
thenNoException().isThrownBy(() -> assertThat(context).hasHighCardinalityKeyValue("foo", "bar")
.hasHighCardinalityKeyValue(KeyValue.of("foo", "bar")));
}

@Test
Expand All @@ -272,7 +275,8 @@ void should_throw_exception_when_high_cardinality_key_value_missing() {

@Test
void should_not_throw_exception_when_high_cardinality_key_value_present() {
thenNoException().isThrownBy(() -> assertThat(context).doesNotHaveHighCardinalityKeyValue("foo", "bar"));
thenNoException().isThrownBy(() -> assertThat(context).doesNotHaveHighCardinalityKeyValue("foo", "bar")
.doesNotHaveHighCardinalityKeyValue(KeyValue.of("foo", "bar")));
}

@Test
Expand All @@ -299,7 +303,8 @@ void should_not_throw_exception_when_high_cardinality_key_value_present_with_oth

@Test
void should_not_throw_exception_when_low_cardinality_key_value_missing() {
thenNoException().isThrownBy(() -> assertThat(context).doesNotHaveLowCardinalityKeyValue("foo", "bar"));
thenNoException().isThrownBy(() -> assertThat(context).doesNotHaveLowCardinalityKeyValue("foo", "bar")
.doesNotHaveLowCardinalityKeyValue(KeyValue.of("foo", "bar")));
}

@Test
Expand Down

0 comments on commit a2ad7e1

Please sign in to comment.