Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xxxKeyValue() variants with KeyValue to ObservationContextAssert #4038

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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