mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
yet even more merge fixes
This commit is contained in:
parent
a9fe6fb07e
commit
9b39e2abc3
@ -17,11 +17,9 @@
|
||||
package io.nosqlbench.adapters.api.util;
|
||||
|
||||
import io.nosqlbench.api.engine.util.Tagged;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -107,6 +105,12 @@ public class TagFilter {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public <T extends NBLabeledElement> List<T> filterLabeled(Collection<T> labeled) {
|
||||
return labeled.stream()
|
||||
.filter(l -> this.matches(l.getLabels().asMap()).matched())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public <T extends Tagged> List<String> filterLog(List<T> tagged) {
|
||||
return tagged.stream()
|
||||
.map(this::matchesTaggedResult)
|
||||
@ -156,6 +160,11 @@ public class TagFilter {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Implement Me!
|
||||
// public TagFilter(Map<String,String> filterSpec) {
|
||||
//
|
||||
// }
|
||||
|
||||
private static String unquote(String filterSpec) {
|
||||
for (String s : new String[]{"'", "\""}) {
|
||||
if (filterSpec.indexOf(s) == 0 && filterSpec.indexOf(s, 1) == filterSpec.length() - 1) {
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.api.engine.metrics.instruments;
|
||||
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
|
||||
public class NBBaseMetric implements NBMetric {
|
||||
private final NBLabels labels;
|
||||
|
||||
public NBBaseMetric(String... labels) {
|
||||
this.labels = NBLabels.forKV((Object[]) labels);
|
||||
}
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return this.labels;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.api.engine.metrics.instruments;
|
||||
|
||||
import com.codahale.metrics.Metric;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
|
||||
public interface NBMetric extends Metric, NBLabeledElement {
|
||||
}
|
@ -17,9 +17,10 @@
|
||||
package io.nosqlbench.api.engine.metrics.instruments;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
|
||||
public class NBMetricCounter extends Counter implements NBLabeledMetric {
|
||||
public class NBMetricCounter extends Counter implements NBMetric {
|
||||
|
||||
private final NBLabels labels;
|
||||
|
||||
|
@ -18,6 +18,6 @@ package io.nosqlbench.api.engine.metrics.instruments;
|
||||
|
||||
import com.codahale.metrics.Gauge;
|
||||
|
||||
public interface NBMetricGauge<T> extends Gauge<T>, NBLabeledMetric {
|
||||
public interface NBMetricGauge<T> extends Gauge<T>, NBMetric {
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package io.nosqlbench.api.engine.metrics.instruments;
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
|
||||
public class NBMetricGaugeWrapper<T> implements NBMetricGauge<T> {
|
||||
public class NBMetricGaugeWrapper<T> implements NBMetricGauge<T>, NBMetric {
|
||||
|
||||
private final Gauge<? extends T> gauge;
|
||||
private final NBLabels labels;
|
||||
|
@ -24,7 +24,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
||||
public class NBMetricHistogram extends Histogram implements DeltaSnapshotter, HdrDeltaHistogramAttachment, HistogramAttachment, NBLabeledMetric {
|
||||
public class NBMetricHistogram extends Histogram implements DeltaSnapshotter, HdrDeltaHistogramAttachment, HistogramAttachment, NBMetric {
|
||||
|
||||
private final DeltaHdrHistogramReservoir hdrDeltaReservoir;
|
||||
private final NBLabels labels;
|
||||
|
@ -19,7 +19,7 @@ package io.nosqlbench.api.engine.metrics.instruments;
|
||||
import com.codahale.metrics.Meter;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
|
||||
public class NBMetricMeter extends Meter implements NBLabeledMetric {
|
||||
public class NBMetricMeter extends Meter implements NBMetric {
|
||||
|
||||
private final NBLabels labels;
|
||||
|
||||
|
@ -25,7 +25,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NBMetricTimer extends Timer implements DeltaSnapshotter, HdrDeltaHistogramAttachment, TimerAttachment, NBLabeledMetric {
|
||||
public class NBMetricTimer extends Timer implements DeltaSnapshotter, HdrDeltaHistogramAttachment, TimerAttachment, NBMetric {
|
||||
private final DeltaHdrHistogramReservoir deltaHdrHistogramReservoir;
|
||||
private long cacheExpiry;
|
||||
private List<Timer> mirrors;
|
||||
|
@ -123,9 +123,11 @@ public class MapLabels implements NBLabels {
|
||||
@Override
|
||||
public String linearizeAsMetrics() {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
this.labels.forEach((k,v) -> {
|
||||
sb.append(k).append(":\"").append(v).append("\",");
|
||||
});
|
||||
ArrayList<String> keys = new ArrayList<>(this.labels.keySet());
|
||||
Collections.sort(keys);
|
||||
for (String key : keys) {
|
||||
sb.append(key).append("=\"").append(labels.get(key)).append("\",");
|
||||
}
|
||||
sb.setLength(sb.length()-",".length());
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
|
@ -170,10 +170,10 @@ public interface NBLabels {
|
||||
*/
|
||||
Map<String, String> asMap();
|
||||
|
||||
String linearizeAsMetrics();
|
||||
|
||||
/**
|
||||
* @return a new set of labels which includes only those which are not using per-instance semantics.
|
||||
* Return a String representation of the metric's labels as you would see it in an openmetrics filter,
|
||||
* like <PRE>{@code {__name__="metric_family_name",k="20"}}</PRE>
|
||||
* @return a String
|
||||
*/
|
||||
|
||||
String linearizeAsMetrics();
|
||||
}
|
||||
|
@ -16,11 +16,15 @@
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class NBBaseComponent implements NBComponent {
|
||||
public class NBBaseComponent extends NBBaseComponentMetrics implements NBComponent {
|
||||
private final NBComponent parent;
|
||||
private final List<NBComponent> children = new ArrayList<>();
|
||||
private final NBLabels labels;
|
||||
@ -57,4 +61,25 @@ public class NBBaseComponent implements NBComponent {
|
||||
return (this.parent==null) ? labels : this.parent.getLabels().and(labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBMetric lookupMetricInTree(String name) {
|
||||
Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(this);
|
||||
while (tree.hasNext()) {
|
||||
NBComponent c = tree.next();
|
||||
NBMetric metric = c.lookupMetric(name);
|
||||
if (metric!=null) return metric;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NBMetric> findMetricsInTree(String pattern) {
|
||||
Iterator<NBComponent> tree = NBComponentTraversal.traverseBreadth(this);
|
||||
List<NBMetric> found = new ArrayList<>();
|
||||
while (tree.hasNext()) {
|
||||
NBComponent c = tree.next();
|
||||
found.addAll(c.findMetrics(pattern));
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.adapters.api.util.TagFilter;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class NBBaseComponentMetrics implements NBComponentMetrics {
|
||||
private final Lock lock = new ReentrantLock(false);
|
||||
private final Map<String, NBMetric> metrics = new HashMap<>();
|
||||
@Override
|
||||
public String addMetric(NBMetric metric) {
|
||||
try {
|
||||
lock.lock();
|
||||
String openMetricsName = metric.getLabels().linearizeAsMetrics();
|
||||
if (metrics.containsKey(openMetricsName)) {
|
||||
throw new RuntimeException("Can't add the same metric by label set to the same live component:" + openMetricsName);
|
||||
}
|
||||
metrics.put(openMetricsName,metric);
|
||||
return metric.getLabels().linearizeAsMetrics();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public NBMetric lookupMetric(String name) {
|
||||
return metrics.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NBMetric> findMetrics(String pattern) {
|
||||
TagFilter filter = new TagFilter(pattern);
|
||||
return filter.filterLabeled(metrics.values());
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ import java.util.List;
|
||||
*
|
||||
* This interface will start as a tagging interface, but will eventually include aspects of above by extension.
|
||||
*/
|
||||
public interface NBComponent extends NBLabeledElement {
|
||||
public interface NBComponent extends NBLabeledElement, NBComponentMetrics, NBMetricsQuery {
|
||||
|
||||
NBComponent getParent();
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface NBComponentMetrics {
|
||||
String addMetric(NBMetric metric);
|
||||
|
||||
/**
|
||||
* If you have the serialized open metrics name of a metric, you can ask for it
|
||||
* this way and get a direct result.
|
||||
* @param name The name of a metric in {@code {a:"b",...}} form
|
||||
* @return the metric or null if it dosen't exist
|
||||
*/
|
||||
NBMetric lookupMetric(String name);
|
||||
|
||||
default Optional<NBMetric> lookupMetricOptionally(String name) {
|
||||
return Optional.ofNullable(lookupMetric(name));
|
||||
}
|
||||
|
||||
List<NBMetric> findMetrics(String pattern);
|
||||
|
||||
default NBMetric findOneMetric(String pattern) {
|
||||
List<NBMetric> found = findMetrics(pattern);
|
||||
if (found.size()!=1) {
|
||||
throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1");
|
||||
}
|
||||
return found.get(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface NBMetricsQuery {
|
||||
/**
|
||||
* If you have the serialized open metrics name of a metric, you can ask for it
|
||||
* this way and get a direct result.
|
||||
* @param name The name of a metric in {@code {a:"b",...}} form
|
||||
* @return the metric or null if it dosen't exist
|
||||
*/
|
||||
NBMetric lookupMetricInTree(String name);
|
||||
|
||||
default Optional<NBMetric> lookupMetricOptionallyInTree(String name) {
|
||||
return Optional.ofNullable(lookupMetricInTree(name));
|
||||
}
|
||||
|
||||
List<NBMetric> findMetricsInTree(String pattern);
|
||||
|
||||
default NBMetric findOneMetricInTree(String pattern) {
|
||||
List<NBMetric> found = findMetricsInTree(pattern);
|
||||
if (found.size()!=1) {
|
||||
throw new RuntimeException("Found " + found.size() + " metrics with pattern '" + pattern + "', expected exactly 1");
|
||||
}
|
||||
return found.get(0);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* <P>The component types in this package create a basic structural and lifecycle
|
||||
* pattern that NoSQLBench runtimes should build upon. This allows leverage of
|
||||
* the base component types to achieve:
|
||||
* <UL>
|
||||
* <LI>consistent runtime behavior between modules</LI>
|
||||
* <LI>modular composition of runtime modules in different configurations</LI>
|
||||
* <LI>a uniform configuration interface across all components</LI>
|
||||
* <LI>exposition of foundational runtime structure to users</LI>
|
||||
* <LI>consistent layering of components and their lifetimes at different runtime scopes</LI>
|
||||
* <LI>a naming and metadata based view which allows for components to be managed in a tangible way</LI>
|
||||
* <LI>a consistent manifest and registry interface for attached elements, like metrics</LI>
|
||||
* </UL>
|
||||
* </P>
|
||||
* <hr/>
|
||||
*
|
||||
* <H2>Components Defined</H2>
|
||||
* <P>There can be different layers or types of components, but there is only one component hierarchy in each
|
||||
* NoSQLBench process. Basically the Session is a component. The Scenario is a component. Each activity within a
|
||||
* scenario is a component. Whether something is meaningful as a component depends on whether the management facilities
|
||||
* provided by the component API make using, interacting with, or understanding that element better for users. However
|
||||
* there is a limit to how fine-grained the component hierarchy should be allowed to get. This is because maintaining
|
||||
* the component structure at runtime incurs a cost, and most feature of the component types are related to assemblage
|
||||
* of fixtures in the runtime which are configured and initialized before steady state processing begins. For example,
|
||||
* it makes sense to wire an activity as component, but not an operation, since an operation is ephemeral and
|
||||
* short-lived. Apart from these trade-offs, make a layer a component layer if it makes sense for the user and/or the
|
||||
* developer, as consolidating the logic into the component layer is beneficial to both.</P>
|
||||
*
|
||||
* <H2>Adoption Strategy</H2>
|
||||
* <P>Consolidating existing logic to use the component types will be an incremental process. The base contract type
|
||||
* {@link io.nosqlbench.components.NBComponent} establishes the contract for any conforming types. As contract facets
|
||||
* are added to this type, common logic can be implemented on the base implementation types where possible, allowing
|
||||
* for the elision of duplicitous code from prior functionality.</P>
|
||||
* <p>
|
||||
* <p>
|
||||
* <hr/>
|
||||
*
|
||||
* <H2>Component System Design</H2>
|
||||
* <P><strong>All</strong> key types in the NBComponent system must have names starting with <em>NBComponent</em>.</P>
|
||||
*
|
||||
* <P>Components are structured hierarchically. All components exist within the scope of their parent, with the only
|
||||
* exception being the root component, which has no parent. Components always know their parent from construction time.
|
||||
* After a component is constructed, it is informed of children components being added and removed via
|
||||
* {@link io.nosqlbench.components.NBComponent#attach} and {@link io.nosqlbench.components.NBComponent#detach}
|
||||
* methods.</P>
|
||||
*
|
||||
* <P>Component logic should interact with other components using the component interfaces and types. No contextual
|
||||
* typing or casting should be allowed within the component layer methods. Components only understand components by
|
||||
* design, and breaking this abstraction is counter-productive at best.</P>
|
||||
*
|
||||
* <P>Utility classes which understand how to interact with components should be used where possible when the
|
||||
* capabilities they provide are well-themed and cohesive. A Corollary to this is that each interface added to the core
|
||||
* component type should be solely informational about the structure and properties of the component hierarchy when
|
||||
* possible. This will help organize usage patterns around themed utilities and keep the surface area of the core types
|
||||
* to a minimum.</p>
|
||||
*
|
||||
* TODO: labeling consistency
|
||||
*/
|
||||
package io.nosqlbench.components;
|
@ -168,4 +168,18 @@ public class TagFilterTest {
|
||||
TagFilter tf2 = new TagFilter("any(car:truck,block:moon)");
|
||||
assertThat(tf2.matches(itemtags).matched()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoneCondition() {
|
||||
Map<String, String> itemtags = Map.of("block", "main", "truck", "car");
|
||||
TagFilter tf = new TagFilter("");
|
||||
assertThat(tf.matches(itemtags).matched()).isTrue();
|
||||
TagFilter tf4 = new TagFilter("none(unseen)");
|
||||
assertThat(tf4.matches(itemtags).matched()).isTrue();
|
||||
TagFilter tf2 = new TagFilter("none(truck)");
|
||||
assertThat(tf2.matches(itemtags).matched()).isFalse();
|
||||
TagFilter tf3 = new TagFilter("none(truck:car)");
|
||||
assertThat(tf3.matches(itemtags).matched()).isFalse();
|
||||
}
|
||||
|
||||
}
|
@ -16,7 +16,6 @@
|
||||
|
||||
package io.nosqlbench.api.labels;
|
||||
|
||||
import io.nosqlbench.api.labels.MapLabels;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
@ -38,6 +37,4 @@ public class MapLabelsTest {
|
||||
public void testInvalidCharacters() {
|
||||
assertThatThrownBy(() -> new MapLabels(Map.of("a-b","c-d"))).isOfAnyClassIn(RuntimeException.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBBaseMetric;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class NBBaseComponentMetricsTest {
|
||||
|
||||
@Test
|
||||
void testBasicAddAndLookup() {
|
||||
NBBaseComponentMetrics cm = new NBBaseComponentMetrics();
|
||||
NBMetric m1 = new NBBaseMetric("k","20");
|
||||
String m1Handle = cm.addMetric(m1);
|
||||
NBMetric m2 = new NBBaseMetric("k","27","l","62");
|
||||
String m2Handle = cm.addMetric(m2);
|
||||
|
||||
assertThat(cm.lookupMetric(m1Handle)).isEqualTo(m1);
|
||||
assertThat(cm.lookupMetric(m2Handle)).isEqualTo(m2);
|
||||
}
|
||||
@Test
|
||||
void find() {
|
||||
NBBaseComponentMetrics cm = new NBBaseComponentMetrics();
|
||||
NBMetric m1 = new NBBaseMetric("k","20");
|
||||
String m1Handle = cm.addMetric(m1);
|
||||
NBMetric m2 = new NBBaseMetric("k","27","l","62");
|
||||
String m2Handle = cm.addMetric(m2);
|
||||
|
||||
assertThat(cm.findMetrics("k=27")).isEqualTo(List.of(m2));
|
||||
assertThat(cm.findMetrics("k=20")).isNotEqualTo(List.of(m2));
|
||||
}
|
||||
}
|
@ -19,8 +19,6 @@ package io.nosqlbench.components;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class NBComponentLifecycleTest {
|
||||
|
||||
@Test
|
||||
@ -36,7 +34,7 @@ class NBComponentLifecycleTest {
|
||||
System.out.println("node2 active");
|
||||
}
|
||||
|
||||
System.out.print("node1 inactive");
|
||||
System.out.print("all inactive");
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,19 +19,27 @@ package io.nosqlbench.components;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class NBComponentViewsTest {
|
||||
@Test
|
||||
public void testBasicTreeView() {
|
||||
var root = new TestComponent("a", "b")
|
||||
.attach(new TestComponent("c", "d")
|
||||
var root1 = new TestComponent("a", "b");
|
||||
var cd = new TestComponent(root1, "c", "d");
|
||||
var UV = new TestComponent(cd, "U", "V");
|
||||
var YZ = new TestComponent(cd, "Y", "Z");
|
||||
var ef = new TestComponent(root1, "e", "f");
|
||||
|
||||
var root2 = new TestComponent("a", "b");
|
||||
|
||||
root2.attach(new TestComponent(root2, "c", "d")
|
||||
.attach(new TestComponent("U", "V"))
|
||||
.attach(new TestComponent("Y", "Z")))
|
||||
.attach(new TestComponent("e", "f"));
|
||||
System.out.println(NBComponentViews.treeView(root));
|
||||
|
||||
System.out.println(NBComponentViews.treeView(root, c -> String.valueOf(c.hashCode())));
|
||||
System.out.println("root1:\n" + NBComponentViews.treeView(root1));
|
||||
System.out.println("root1:\n" + NBComponentViews.treeView(root1, c -> String.valueOf(c.hashCode())));
|
||||
|
||||
System.out.println("root2:\n" + NBComponentViews.treeView(root2));
|
||||
System.out.println("root2:\n" + NBComponentViews.treeView(root2, c -> String.valueOf(c.hashCode())));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.nosqlbench.components;
|
||||
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBBaseMetric;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetric;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class NBMetricsQueryTest {
|
||||
private final static TestComponent root = new TestComponent("root","root","type","rootelement");
|
||||
private final static TestComponent root_c2 = new TestComponent(root,"c2","c2");
|
||||
private final static TestComponent root_c3 = new TestComponent(root,"c3","c3");
|
||||
private final static NBMetric m1 = new NBBaseMetric("m1","m1");
|
||||
private final String m1Handle = root.addMetric(m1);
|
||||
private final static NBMetric m2 = new NBBaseMetric("m2","m2");
|
||||
private final String m2Handle = root_c2.addMetric(m2);
|
||||
private final static NBMetric m3 = new NBBaseMetric("m3","m3");
|
||||
private final String m3Handle = root_c3.addMetric(m3);
|
||||
|
||||
@Test
|
||||
public void testFindInTree() {
|
||||
NBMetric expectedM3 = root.findOneMetricInTree("m3:m3");
|
||||
assertThat(expectedM3).isEqualTo(m3);
|
||||
assertThatThrownBy(() -> root.findOneMetricInTree("m3:m4")).isOfAnyClassIn(RuntimeException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindOneInTree() {
|
||||
List<NBMetric> metricsInTree = root.findMetricsInTree("");
|
||||
assertThat(metricsInTree).containsExactly(m1, m2, m3);
|
||||
List<NBMetric> m3Only = root.findMetricsInTree("m3:m3");
|
||||
assertThat(m3Only).containsExactly(m3);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user