mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
fixes for passing basic tests
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
package io.nosqlbench.engine.api.activityimpl.input;
|
||||
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.activityimpl.CyclesSpec;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBFunctionGauge;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver;
|
||||
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.CycleSegment;
|
||||
import io.nosqlbench.engine.api.activityapi.input.Input;
|
||||
@@ -44,7 +44,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* after the max value. They simply expose it to callers. It is up to the
|
||||
* caller to check the value to determine when the input is deemed "used up."</p>
|
||||
*/
|
||||
public class AtomicInput implements Input, ActivityDefObserver, Gauge<Long>, NBLabeledElement {
|
||||
public class AtomicInput extends NBBaseComponent implements Input, ActivityDefObserver, Gauge<Long> {
|
||||
private final static Logger logger = LogManager.getLogger(AtomicInput.class);
|
||||
|
||||
private final AtomicLong cycle_value = new AtomicLong(0L);
|
||||
@@ -57,20 +57,19 @@ public class AtomicInput implements Input, ActivityDefObserver, Gauge<Long>, NBL
|
||||
private final long startedAt = System.currentTimeMillis();
|
||||
|
||||
private final ActivityDef activityDef;
|
||||
private final NBLabeledElement parent;
|
||||
|
||||
public AtomicInput(NBLabeledElement parent, ActivityDef activityDef) {
|
||||
this.parent = parent;
|
||||
public AtomicInput(NBComponent parent, ActivityDef activityDef) {
|
||||
super(parent);
|
||||
this.activityDef = activityDef;
|
||||
onActivityDefUpdate(activityDef);
|
||||
ActivityMetrics.gauge(this, "input_cycles_first", new NBFunctionGauge(this, () -> (double)this.cycles_min.get()));
|
||||
ActivityMetrics.gauge(this, "input_cycles_last", new NBFunctionGauge(this, () -> (double)this.cycles_max.get()));
|
||||
ActivityMetrics.gauge(this, "input_cycle", new NBFunctionGauge(this, () -> (double)this.cycle_value.get()));
|
||||
ActivityMetrics.gauge(this, "input_cycles_total", new NBFunctionGauge(this, this::getTotalCycles));
|
||||
ActivityMetrics.gauge(this, "input_recycles_first", new NBFunctionGauge(this, () -> (double)this.recycles_min.get()));
|
||||
ActivityMetrics.gauge(this, "input_recycles_last", new NBFunctionGauge(this, () -> (double)this.recycles_max.get()));
|
||||
ActivityMetrics.gauge(this, "input_recycle", new NBFunctionGauge(this, () -> (double) this.recycle_value.get()));
|
||||
ActivityMetrics.gauge(this, "input_recycles_total", new NBFunctionGauge(this, this::getTotalRecycles));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, () -> (double) this.cycles_min.get(), "input_cycles_first"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, () -> (double) this.cycles_max.get(), "input_cycles_last"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, () -> (double) this.cycle_value.get(), "input_cycle"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, this::getTotalCycles, "input_cycles_total"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, () -> (double) this.recycles_min.get(), "input_recycles_first"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, () -> (double) this.recycles_max.get(), "input_recycles_last"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, () -> (double) this.recycle_value.get(), "input_recycle"));
|
||||
ActivityMetrics.gauge(new NBFunctionGauge(this, this::getTotalRecycles, "input_recycles_total"));
|
||||
}
|
||||
|
||||
private double getTotalRecycles() {
|
||||
@@ -90,7 +89,7 @@ public class AtomicInput implements Input, ActivityDefObserver, Gauge<Long>, NBL
|
||||
recycle_value.getAndIncrement();
|
||||
if (recycle_value.get() >= recycles_max.get()) {
|
||||
logger.trace(() -> "Exhausted input for " + activityDef.getAlias() + " at " + currentStrideStart + ", recycle " +
|
||||
"count " + recycle_value.get());
|
||||
"count " + recycle_value.get());
|
||||
return null;
|
||||
} else {
|
||||
cycle_value.set(cycles_min.get());
|
||||
@@ -107,11 +106,11 @@ public class AtomicInput implements Input, ActivityDefObserver, Gauge<Long>, NBL
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AtomicInput{" +
|
||||
"cycleValue=" + cycle_value +
|
||||
", min=" + cycles_min +
|
||||
", max=" + cycles_max +
|
||||
", activity=" + activityDef.getAlias() +
|
||||
'}';
|
||||
"cycleValue=" + cycle_value +
|
||||
", min=" + cycles_min +
|
||||
", max=" + cycles_max +
|
||||
", activity=" + activityDef.getAlias() +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,16 +120,16 @@ public class AtomicInput implements Input, ActivityDefObserver, Gauge<Long>, NBL
|
||||
|
||||
cycles_max.set(cyclesSpec.last_exclusive());
|
||||
if (cycles_min.get() != cyclesSpec.first_inclusive()) {
|
||||
logger.info(() -> "resetting cycle value to new start: cycle[" + cycles_min.get() + "->" + cyclesSpec.first_inclusive()+"] " +
|
||||
" start["+cycle_value.get()+"->"+ cycles_min.get()+"]");
|
||||
logger.info(() -> "resetting cycle value to new start: cycle[" + cycles_min.get() + "->" + cyclesSpec.first_inclusive() + "] " +
|
||||
" start[" + cycle_value.get() + "->" + cycles_min.get() + "]");
|
||||
cycles_min.set(cyclesSpec.first_inclusive());
|
||||
cycle_value.set(cycles_min.get());
|
||||
}
|
||||
|
||||
recycles_max.set(recyclesSpec.last_exclusive());
|
||||
if (recycles_min.get() != recyclesSpec.first_inclusive()) {
|
||||
logger.info(() -> "resetting recycle value to new start: recycle[" + recycles_min.get() + "->" + recyclesSpec.first_inclusive()+"] " +
|
||||
" start["+recycle_value.get()+"->"+ recycles_min.get()+"]");
|
||||
logger.info(() -> "resetting recycle value to new start: recycle[" + recycles_min.get() + "->" + recyclesSpec.first_inclusive() + "] " +
|
||||
" start[" + recycle_value.get() + "->" + recycles_min.get() + "]");
|
||||
recycles_min.set(recyclesSpec.first_inclusive());
|
||||
recycle_value.set(recyclesSpec.first_inclusive());
|
||||
}
|
||||
@@ -145,11 +144,6 @@ public class AtomicInput implements Input, ActivityDefObserver, Gauge<Long>, NBL
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBLabels getLabels() {
|
||||
return parent.getLabels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return this.cycle_value.get();
|
||||
|
||||
@@ -152,13 +152,13 @@ public class StandardActivity<R extends Op, S> extends SimpleActivity implements
|
||||
throw new OpConfigError("Error mapping workload template to operations: " + e.getMessage(), null, e);
|
||||
}
|
||||
|
||||
this.pendingOpsGauge = ActivityMetrics.register(
|
||||
new NBFunctionGauge(this, () -> this.getProgressMeter().getSummary().pending(), "ops_pending")
|
||||
this.pendingOpsGauge = ActivityMetrics.gauge(
|
||||
new NBFunctionGauge(this,() -> this.getProgressMeter().getSummary().pending(), "ops_pending")
|
||||
);
|
||||
this.activeOpsGauge = ActivityMetrics.register(
|
||||
this.activeOpsGauge = ActivityMetrics.gauge(
|
||||
new NBFunctionGauge(this, () -> this.getProgressMeter().getSummary().current(),"ops_active")
|
||||
);
|
||||
this.completeOpsGauge = ActivityMetrics.register(
|
||||
this.completeOpsGauge = ActivityMetrics.gauge(
|
||||
new NBFunctionGauge(this, () -> this.getProgressMeter().getSummary().complete(),"ops_complete"));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityimpl.input;
|
||||
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.CycleSegment;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -25,16 +26,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class AtomicInputTest {
|
||||
|
||||
private final static NBComponent root = new TestComponent("testing","atomicinput");
|
||||
@Test
|
||||
public void testThatNoCyclesAndNoRecyclesMeansZero() {
|
||||
AtomicInput input = new AtomicInput(NBLabeledElement.EMPTY, ActivityDef.parseActivityDef("alias=foo;cycles=0;recycles=0"));
|
||||
AtomicInput input = new AtomicInput(root, ActivityDef.parseActivityDef("alias=foo;cycles=0;recycles=0"));
|
||||
CycleSegment inputSegment = input.getInputSegment(1);
|
||||
assertThat(inputSegment).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatNoCyclesAndDefaultRecyclesMeans1xCycles() {
|
||||
AtomicInput input = new AtomicInput(NBLabeledElement.EMPTY, ActivityDef.parseActivityDef("alias=foo;cycles=10"));
|
||||
AtomicInput input = new AtomicInput(root, ActivityDef.parseActivityDef("alias=foo;cycles=10"));
|
||||
CycleSegment inputSegment =null;
|
||||
|
||||
inputSegment= input.getInputSegment(10);
|
||||
@@ -51,7 +53,7 @@ public class AtomicInputTest {
|
||||
int intendedRecycles=4;
|
||||
int stride=10;
|
||||
|
||||
AtomicInput input = new AtomicInput(NBLabeledElement.EMPTY, ActivityDef.parseActivityDef("alias=foo;cycles="+intendedCycles+";recycles="+intendedRecycles));
|
||||
AtomicInput input = new AtomicInput(root, ActivityDef.parseActivityDef("alias=foo;cycles="+intendedCycles+";recycles="+intendedRecycles));
|
||||
CycleSegment segment =null;
|
||||
for (int nextRecycle = 0; nextRecycle < intendedRecycles; nextRecycle++) {
|
||||
for (int nextCycle = 0; nextCycle < intendedCycles; nextCycle+=stride) {
|
||||
@@ -66,7 +68,7 @@ public class AtomicInputTest {
|
||||
|
||||
@Test
|
||||
public void testThatCycleAndRecycleOffsetsWork() {
|
||||
AtomicInput input = new AtomicInput(NBLabeledElement.EMPTY, ActivityDef.parseActivityDef("alias=foo;cycles=310..330;recycles=37..39"));
|
||||
AtomicInput input = new AtomicInput(root, ActivityDef.parseActivityDef("alias=foo;cycles=310..330;recycles=37..39"));
|
||||
CycleSegment segment = null;
|
||||
int stride=10;
|
||||
segment = input.getInputSegment(stride);
|
||||
@@ -88,7 +90,7 @@ public class AtomicInputTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyIntervalShouldNotProvideValues() {
|
||||
AtomicInput i = new AtomicInput(NBLabeledElement.EMPTY,ActivityDef.parseActivityDef("alias=foo;cycles=23..23"));
|
||||
AtomicInput i = new AtomicInput(root,ActivityDef.parseActivityDef("alias=foo;cycles=23..23"));
|
||||
CycleSegment inputSegment = i.getInputSegment(1);
|
||||
assertThat(inputSegment).isNull();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user