mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-11 00:12:04 -06:00
nosqlbench-1935 Allow for +increment format in cycles and recycles intervals
This commit is contained in:
parent
dead305986
commit
149adc8b8a
@ -22,7 +22,12 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
|
|
||||||
public record CyclesSpec(long first_inclusive, long last_exclusive, String firstSpec, String lastSpec) {
|
public record CyclesSpec(
|
||||||
|
long first_inclusive,
|
||||||
|
long last_exclusive,
|
||||||
|
String firstSpec,
|
||||||
|
String lastSpec
|
||||||
|
) {
|
||||||
private final static Logger logger = LogManager.getLogger(CyclesSpec.class);
|
private final static Logger logger = LogManager.getLogger(CyclesSpec.class);
|
||||||
public CyclesSpec {
|
public CyclesSpec {
|
||||||
if (first_inclusive>last_exclusive) {
|
if (first_inclusive>last_exclusive) {
|
||||||
@ -32,16 +37,24 @@ public record CyclesSpec(long first_inclusive, long last_exclusive, String first
|
|||||||
|
|
||||||
public static CyclesSpec parse(String spec) {
|
public static CyclesSpec parse(String spec) {
|
||||||
int rangeAt = spec.indexOf("..");
|
int rangeAt = spec.indexOf("..");
|
||||||
String beginningInclusive = "0";
|
String beginningSpec = "0";
|
||||||
String endingExclusive = spec;
|
String endingSpec = spec;
|
||||||
if (0 < rangeAt) {
|
if (0 < rangeAt) {
|
||||||
beginningInclusive = spec.substring(0, rangeAt);
|
beginningSpec = spec.substring(0, rangeAt);
|
||||||
endingExclusive = spec.substring(rangeAt+2);
|
endingSpec = spec.substring(rangeAt+2);
|
||||||
|
}
|
||||||
|
long first = Unit.longCountFor(beginningSpec).orElseThrow(() -> new RuntimeException("Unable to parse start cycles from " + spec));
|
||||||
|
long last=first;
|
||||||
|
if (endingSpec.startsWith("+")) {
|
||||||
|
long added=Unit.longCountFor(endingSpec.substring(1)).orElseThrow(() -> new RuntimeException(
|
||||||
|
"Unable to parse incremental cycle interval. Use one of these forms: 100 or 0..100 or 0..+100"
|
||||||
|
));
|
||||||
|
last = first+added;
|
||||||
|
} else {
|
||||||
|
last = Unit.longCountFor(endingSpec).orElseThrow(() -> new RuntimeException("Unable to parse start cycles from " + spec));
|
||||||
}
|
}
|
||||||
long first = Unit.longCountFor(beginningInclusive).orElseThrow(() -> new RuntimeException("Unable to parse start cycles from " + spec));
|
|
||||||
long last = Unit.longCountFor(endingExclusive).orElseThrow(() -> new RuntimeException("Unable to parse start cycles from " + spec));
|
|
||||||
|
|
||||||
return new CyclesSpec(first, last, beginningInclusive, endingExclusive);
|
return new CyclesSpec(first, last, beginningSpec, endingSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String summary() {
|
public String summary() {
|
||||||
@ -74,4 +87,30 @@ public record CyclesSpec(long first_inclusive, long last_exclusive, String first
|
|||||||
public long cycle_count() {
|
public long cycle_count() {
|
||||||
return last_exclusive -first_inclusive;
|
return last_exclusive -first_inclusive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (!(o instanceof CyclesSpec that))
|
||||||
|
return false;
|
||||||
|
if (last_exclusive!=that.last_exclusive)
|
||||||
|
return false;
|
||||||
|
if (first_inclusive!=that.first_inclusive)
|
||||||
|
return false;
|
||||||
|
if (!firstSpec.equals(that.firstSpec))
|
||||||
|
return false;
|
||||||
|
if (!lastSpec.equals(that.lastSpec))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = Long.hashCode(first_inclusive);
|
||||||
|
result = 31 * result + Long.hashCode(last_exclusive);
|
||||||
|
result = 31 * result + firstSpec.hashCode();
|
||||||
|
result = 31 * result + lastSpec.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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.nb.api.engine.activityimpl;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class CyclesSpecTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSingleNumberSpec() {
|
||||||
|
assertThat(CyclesSpec.parse("100")).isEqualTo(
|
||||||
|
new CyclesSpec(0,100,"0","100")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntervalSpec() {
|
||||||
|
assertThat(CyclesSpec.parse("3..13")).isEqualTo(
|
||||||
|
new CyclesSpec(3,13,"3","13")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnitsSupport() {
|
||||||
|
assertThat(CyclesSpec.parse("5M")).isEqualTo(
|
||||||
|
new CyclesSpec(0,5_000_000L,"0","5M")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIncrementalSupport() {
|
||||||
|
assertThat(CyclesSpec.parse("5M..+100")).isEqualTo(
|
||||||
|
new CyclesSpec(5_000_000L,5_000_100L,"5M","+100")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIncrementalUnitsSupport() {
|
||||||
|
assertThat(CyclesSpec.parse("5M..+1M")).isEqualTo(
|
||||||
|
new CyclesSpec(5_000_000L,6_000_000L,"5M","+1M")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user