Merge pull request #1069 from nosqlbench/nosqlbench-1068-examplefixups

changes needed to make examples robust
This commit is contained in:
Jonathan Shook 2023-02-07 19:26:40 -06:00 committed by GitHub
commit ef830f0101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 47 additions and 23 deletions

View File

@ -80,6 +80,7 @@ public class StandardActivity<R extends Op, S> extends SimpleActivity implements
for (OpTemplate ot : opTemplates) { for (OpTemplate ot : opTemplates) {
ParsedOp incompleteOpDef = new ParsedOp(ot, NBConfiguration.empty(), List.of()); ParsedOp incompleteOpDef = new ParsedOp(ot, NBConfiguration.empty(), List.of());
String driverName = incompleteOpDef.takeOptionalStaticValue("driver", String.class) String driverName = incompleteOpDef.takeOptionalStaticValue("driver", String.class)
.or(() -> incompleteOpDef.takeOptionalStaticValue("type",String.class))
.or(() -> activityDef.getParams().getOptionalString("driver")) .or(() -> activityDef.getParams().getOptionalString("driver"))
.orElseThrow(() -> new OpConfigError("Unable to identify driver name for op template:\n" + ot)); .orElseThrow(() -> new OpConfigError("Unable to identify driver name for op template:\n" + ot));

View File

@ -16,15 +16,15 @@
package io.nosqlbench.engine.api.activityimpl.uniform; package io.nosqlbench.engine.api.activityimpl.uniform;
import io.nosqlbench.api.config.standard.NBConfigModel;
import io.nosqlbench.api.config.standard.NBConfiguration;
import io.nosqlbench.api.config.standard.NBReconfigurable;
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser; import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
import io.nosqlbench.engine.api.activityapi.core.ActivityType; import io.nosqlbench.engine.api.activityapi.core.ActivityType;
import io.nosqlbench.engine.api.activityconfig.OpsLoader; import io.nosqlbench.engine.api.activityconfig.OpsLoader;
import io.nosqlbench.engine.api.activityconfig.yaml.OpsDocList; import io.nosqlbench.engine.api.activityconfig.yaml.OpsDocList;
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
import io.nosqlbench.engine.api.activityimpl.SimpleActivity; import io.nosqlbench.engine.api.activityimpl.SimpleActivity;
import io.nosqlbench.api.config.standard.NBConfigModel;
import io.nosqlbench.api.config.standard.NBConfiguration;
import io.nosqlbench.api.config.standard.NBReconfigurable;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -39,7 +39,10 @@ public class StandardActivityType<A extends StandardActivity<?,?>> extends Simpl
private final Map<String,DriverAdapter> adapters = new HashMap<>(); private final Map<String,DriverAdapter> adapters = new HashMap<>();
public StandardActivityType(DriverAdapter<?,?> adapter, ActivityDef activityDef) { public StandardActivityType(DriverAdapter<?,?> adapter, ActivityDef activityDef) {
super(activityDef); super(activityDef
.deprecate("type","driver")
.deprecate("yaml", "workload")
);
this.adapters.put(adapter.getAdapterName(),adapter); this.adapters.put(adapter.getAdapterName(),adapter);
if (adapter instanceof ActivityDefAware) { if (adapter instanceof ActivityDefAware) {
((ActivityDefAware) adapter).setActivityDef(activityDef); ((ActivityDefAware) adapter).setActivityDef(activityDef);

View File

@ -139,7 +139,7 @@ public class NBCLIScenarioParser {
if (selectedScenario.containsKey(stepname)) { if (selectedScenario.containsKey(stepname)) {
namedSteps.put(stepname,selectedScenario.get(stepname)); namedSteps.put(stepname,selectedScenario.get(stepname));
} else { } else {
throw new BasicError("Unable to find named scenario.step'" + scenarioName + "' in workload '" + workloadName throw new BasicError("Unable to find named scenario.step '" + scenarioName + "' in workload '" + workloadName
+ "', but you can pick from one of: " + selectedScenario.keySet().stream().map(n -> nameparts[0].concat(".").concat(n)).collect(Collectors.joining(", "))); + "', but you can pick from one of: " + selectedScenario.keySet().stream().map(n -> nameparts[0].concat(".").concat(n)).collect(Collectors.joining(", ")));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,6 +41,7 @@ public class ActivityLoader {
} }
public synchronized Activity loadActivity(ActivityDef activityDef) { public synchronized Activity loadActivity(ActivityDef activityDef) {
activityDef= activityDef.deprecate("yaml","workload").deprecate("type","driver");
Activity activity = new StandardActivityType(activityDef).getAssembledActivity(activityDef, activityMap); Activity activity = new StandardActivityType(activityDef).getAssembledActivity(activityDef, activityMap);
activityMap.put(activity.getAlias(),activity); activityMap.put(activity.getAlias(),activity);
logger.debug("Resolved activity for alias '" + activityDef.getAlias() + "'"); logger.debug("Resolved activity for alias '" + activityDef.getAlias() + "'");

View File

@ -18,6 +18,7 @@ package io.nosqlbench.api.engine.activityimpl;
import io.nosqlbench.api.config.NBNamedElement; import io.nosqlbench.api.config.NBNamedElement;
import io.nosqlbench.api.engine.util.Unit; import io.nosqlbench.api.engine.util.Unit;
import io.nosqlbench.api.errors.BasicError;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -213,4 +214,22 @@ public class ActivityDef implements NBNamedElement {
public String getName() { public String getName() {
return getAlias(); return getAlias();
} }
public ActivityDef deprecate(String deprecatedName, String newName) {
Object deprecatedParam = this.parameterMap.get(deprecatedName);
if (deprecatedParam==null) {
return this;
}
if (deprecatedParam instanceof CharSequence chars) {
if (this.parameterMap.containsKey(newName)) {
throw new BasicError("You have specified activity param '" + deprecatedName + "' in addition to the valid name '" + newName +"'. Remove '" + deprecatedName + "'.");
} else {
logger.warn("Auto replacing deprecated activity param '" + deprecatedName + "="+ chars +"' with new '" + newName +"="+ chars +"'.");
parameterMap.put(newName,parameterMap.remove(deprecatedName));
}
} else {
throw new BasicError("Can't replace deprecated name with value of type " + deprecatedName.getClass().getCanonicalName());
}
return this;
}
} }

View File

@ -10,13 +10,16 @@ scenarios:
# a scale parameter or a custom MathContext, but not both. The scale parameter # a scale parameter or a custom MathContext, but not both. The scale parameter
# is not supported for String or Double input forms. # is not supported for String or Double input forms.
# As of Java 17, the roundingMode enums are UP DOWN CEILING FLOOR HALF_UP HALF_DOWN HALF_EVEN UNNECESSARY
# and the precision must be zero or greater
bindings: bindings:
# convert an example double with some fractional values, then convert it to BigDecimal # convert an example double with some fractional values, then convert it to BigDecimal
from_double: ToDouble(); Div(100.0d); ToBigDecimal(); from_double: ToDouble(); Div(100.0d); ToBigDecimal();
# convert doubles to BigDecimal, with custom precision and rounding # convert doubles to BigDecimal, with custom precision and rounding
from_double_custom5: ToDouble(); Div(100.0d); ToBigDecimal('precision=5 roundingMode=HALF'); from_double_custom5: ToDouble(); Div(100.0d); ToBigDecimal('precision=5 roundingMode=HALF_EVEN');
# convert directly to BigDecimal from long as whole numbers # convert directly to BigDecimal from long as whole numbers
from_long: ToBigDecimal(); from_long: ToBigDecimal();

View File

@ -21,9 +21,6 @@ bindings:
# control the size of the extracted sample with a hash range # control the size of the extracted sample with a hash range
hashed_bb_sizerange: ByteBufferSizedHashed(HashRange(1,10)); ToHexString(); hashed_bb_sizerange: ByteBufferSizedHashed(HashRange(1,10)); ToHexString();
# control the size of the extracted sample based on a continuous function
hashed_bb_size_normal: ByteBufferSizedHashed(Normal(5.0, 1.0)); ToHexString();
# control the size of the extracted sample based on a discrete function # control the size of the extracted sample based on a discrete function
hashed_bb_size_binomial: ByteBufferSizedHashed(Binomial(8,0.5)); ToHexString(); hashed_bb_size_binomial: ByteBufferSizedHashed(Binomial(8,0.5)); ToHexString();

View File

@ -5,12 +5,12 @@ description: |
scenarios: scenarios:
default: run driver===stdout format=readout default: run driver===stdout format=readout
names: run driver===stdout format=readout bindings=names names: run driver===stdout format=readout bindings='names.*'
cities: run driver===stdout format=readout bindings=cities cities: run driver===stdout format=readout bindings='cities.*'
states: run driver===stdout format=readout bindings=states states: run driver===stdout format=readout bindings='states.*'
zips: run driver===stdout format=readout bindings=zips zips: run driver===stdout format=readout bindings='zips.*'
counties: run driver===stdout format=readout bindings=counties counties: run driver===stdout format=readout bindings='counties.*'
countries: run driver===stdout format=readout bindings=country countries: run driver===stdout format=readout bindings='country.*'
# Each binding is named, so the bindings is a map of names to # Each binding is named, so the bindings is a map of names to

View File

@ -21,10 +21,10 @@ bindings:
# The TypeOf() function tells you the java class of its input # The TypeOf() function tells you the java class of its input
typeof: TypeOf(); typeof: ToJavaInstant(); TypeOf();
# The Show() function provides a snapshot of what is in the thread-local # The Show() function provides a snapshot of what is in the thread-local
# variable map as a String # variable map as a String
show: Show(); show: SaveLong('var42'); Show();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,7 +39,7 @@ public class MathContextReader {
} }
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
throw new BasicError("'" + name + "' was not a valid format for a new MathContext(String), try something " + throw new BasicError("'" + name + "' was not a valid format for a new MathContext(String), try something " +
"like 'precision=17 roundingMode=UP"); "like 'precision=17 roundingMode=UP', original exception:" + iae);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ public class CountryNames extends CSVSampler implements LongFunction<String> {
@Example("CountryNames()") @Example("CountryNames()")
public CountryNames() { public CountryNames() {
super("COUNTRY_NAME","n/a","name","countries.csv"); super("COUNTRY_NAME","n/a","name","data/countries.csv");
} }
} }