post-merge fix-ups

This commit is contained in:
Jonathan Shook
2021-06-22 11:10:42 -05:00
339 changed files with 1331 additions and 1251 deletions

View File

@@ -7,7 +7,7 @@
<parent>
<groupId>io.nosqlbench</groupId>
<artifactId>mvn-defaults</artifactId>
<version>4.15.48-SNAPSHOT</version>
<version>4.15.51-SNAPSHOT</version>
<relativePath>../mvn-defaults</relativePath>
</parent>
@@ -23,14 +23,14 @@
<dependency>
<groupId>io.nosqlbench</groupId>
<version>4.15.48-SNAPSHOT</version>
<version>4.15.51-SNAPSHOT</version>
<artifactId>nb-api</artifactId>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>virtdata-lang</artifactId>
<version>4.15.48-SNAPSHOT</version>
<version>4.15.51-SNAPSHOT</version>
</dependency>

View File

@@ -48,8 +48,6 @@ public class FunctionManifestProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
List<Element> ts = new ArrayList<>();
try {
if (writer==null) {
writer = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/functions")

View File

@@ -24,10 +24,10 @@ public enum FunctionType {
R_T(Function.class, Object.class, Object.class);
private final Class<?> functionClass;
private Class<?> inputClass;
private Class<?> returnClass;
private ValueType returnValueType;
private ValueType inputValueType;
private final Class<?> inputClass;
private final Class<?> returnClass;
private final ValueType returnValueType;
private final ValueType inputValueType;
FunctionType(Class<?> functionClass, Class<?> inputClass, Class<?> returnClass) {
this.functionClass = functionClass;

View File

@@ -29,7 +29,7 @@ public enum ValueType implements Comparator<ValueType> {
OBJECT(Object.class, 8);
private final Class<?> clazz;
private int precedence;
private final int precedence;
ValueType(Class<?> clazz, int precedence) {
this.clazz = clazz;

View File

@@ -3,14 +3,18 @@ package io.nosqlbench.virtdata.core.templates;
import java.util.Objects;
public class BindPoint {
private String anchor;
private String bindspec;
private final String anchor;
private final String bindspec;
public BindPoint(String anchor, String bindspec) {
this.anchor = anchor;
this.bindspec = bindspec;
}
public static BindPoint of(String userid, String bindspec) {
return new BindPoint(userid,bindspec);
}
public String getAnchor() {
return anchor;
}
@@ -30,6 +34,11 @@ public class BindPoint {
return Objects.equals(bindspec, bindPoint.bindspec);
}
@Override
public int hashCode() {
return Objects.hash(anchor, bindspec);
}
@Override
public String toString() {
return "BindPoint{" +

View File

@@ -0,0 +1,41 @@
package io.nosqlbench.virtdata.core.templates;
import io.nosqlbench.nb.api.errors.BasicError;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BindPointParser implements Function<String, List<String>> {
public final static Pattern BINDPOINT_ANCHOR = Pattern.compile("(\\{((?<anchor>\\w+[-_\\d\\w.]*)})|(\\{\\{(?<extended>[^}]+)}}))");
@Override
public List<String> apply(String template) {
Matcher m = BINDPOINT_ANCHOR.matcher(template);
int lastMatch = 0;
List<String> spans = new ArrayList<>();
while (m.find()) {
String pre = template.substring(lastMatch, m.start());
lastMatch=m.end();
spans.add(pre);
String anchor = m.group("anchor");
if (anchor == null) {
anchor = m.group("extended");
if (anchor == null) {
throw new BasicError("Unable to parse: " + template);
}
}
spans.add(anchor);
}
spans.add(lastMatch >= 0 ? template.substring(lastMatch) : template);
return spans;
}
}

View File

@@ -0,0 +1,94 @@
package io.nosqlbench.virtdata.core.templates;
import java.util.Objects;
/**
* A capture point is a named variable which should be extracted from a payload or result type
* using a native driver API. The result is meant to be provided to the NoSQLBench runtime
* during cycle execution, and stored in a scoped context of variables which can be re-used within
* other operations.
* <hr/>
* <H2>Format</H2>
*
* <pre>{@code
* select [username as u1] from users where userid={userid};
* }</pre>
*
* In the example above, the span <em>[username as u1]</em> is recognized as a capture point.
* The name of the variable to be captured is <em>username</em>. It is to be captured under
* a different variable name <em>u1</em>.
*
* If the name is the same in both cases, i.e. the variable is named in the result type as it
* should be known after extraction, then you can elide the <em>as u1</em> clause as in this example:
*
* <pre>{@code
* select [username] from users where userid={userid};
* }</pre>
*
* During op mapping, any capture points are condensed down to the native driver vernacular by
* removing the square brackets from the op template. Thus, the result of parsing the above would
* yield a form compatible with a native driver. For example, converting to prepared statement form
* would yield:
*
* <pre>{@code
* select username from users where userid=:userid
* }</pre>
*
* For details on the <em>{userid}</em> form, see {@link BindPoint}
*/
public class CapturePoint {
private final String name;
private final String asName;
public CapturePoint(String name, String asName) {
this.name = name;
this.asName = asName;
}
public String getName() {
return name;
}
/**
* Create a CapturePoint with the specified anchorName, and an optional aliasName.
* If aliasName is null, then the anchorName is used as the alias.
*
* @param anchorName The name of the capture variable in the native form
* @param aliasName The name of the captured value as seen by consumers
* @return A new CapturePoint
*/
public static CapturePoint of(String anchorName, String aliasName) {
Objects.requireNonNull(anchorName);
return new CapturePoint(anchorName, aliasName == null ? anchorName : aliasName);
}
/**
* Create a CapturePoint with the specified anchorName, and the same aliasName.
*
* @param anchorName The name of the capture variable in the native form and as seen by consumers.
* @return A new CapturePoint
*/
public static CapturePoint of(String anchorName) {
Objects.requireNonNull(anchorName);
return new CapturePoint(anchorName, anchorName);
}
@Override
public String toString() {
return "[" + getName() + (name.equals(asName) ? "" : " as " + asName) + "]";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CapturePoint that = (CapturePoint) o;
return Objects.equals(name, that.name) && Objects.equals(asName, that.asName);
}
@Override
public int hashCode() {
return Objects.hash(name, asName);
}
}

View File

@@ -0,0 +1,71 @@
package io.nosqlbench.virtdata.core.templates;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CapturePointParser implements Function<String, CapturePointParser.Result> {
public final static Pattern CAPTUREPOINT_PATTERN = Pattern.compile(
"(\\[(?<capture>\\w+[-_\\d\\w.]*)(\\s+[aA][sS]\\s+(?<alias>\\w+[-_\\d\\w.]*))?])"
);
@Override
public Result apply(String template) {
StringBuilder raw = new StringBuilder();
Matcher m = CAPTUREPOINT_PATTERN.matcher(template);
List<CapturePoint> captures = new ArrayList<>();
while (m.find()) {
CapturePoint captured = CapturePoint.of(m.group("capture"), m.group("alias"));
captures.add(captured);
m.appendReplacement(raw,captured.getName());
}
m.appendTail(raw);
return new Result(raw.toString(),captures);
}
public final static class Result {
private final String rawTemplate;
private final List<CapturePoint> captures;
public Result(String rawTemplate, List<CapturePoint> captures) {
this.rawTemplate = rawTemplate;
this.captures = captures;
}
public String getRawTemplate() {
return this.rawTemplate;
}
public List<CapturePoint> getCaptures() {
return this.captures;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Result result = (Result) o;
return Objects.equals(rawTemplate, result.rawTemplate) && Objects.equals(captures, result.captures);
}
@Override
public int hashCode() {
return Objects.hash(rawTemplate, captures);
}
@Override
public String toString() {
return "Result{" +
"rawTemplate='" + rawTemplate + '\'' +
", captures=" + captures +
'}';
}
}
}

View File

@@ -17,20 +17,36 @@
package io.nosqlbench.virtdata.core.templates;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.security.InvalidParameterException;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
// TODO: Consider using "Driver Adapter" or "Workload Adapter" instead of ActivityType
/**
* A parsed template is a form of a raw template which has been parsed for its
* named anchors and sanity checked against a set of provided bindings.
* A ParsedTemplate represents any string provided by a user which is meant to be
* a prototype for an operation. Grammars used by native drivers can be decorated
* with named injection and extraction points for data, known respectively as
* {@link BindPoint}s and {@link CapturePoint}s.
*
* The syntax used for bind points and capture points is standard across all
* high-level drivers. As such, this class captures the definition of
* decorative syntax and the rules for parsing them out.
*
* The key responsibilities of ParsedTemplate are:
* <UL>
* <LI>recognize bind points within statement templates</LI>
* <LI>recognize capture points within statement templates</LI>
* <LI>render statement templates with bind and capture points elided using a native syntax for variables</LI>
* <LI>provide metadata to drivers about defined bind and capture points</LI>
* <LI>provide a text template for re-assembly with injected data</LI>
* </UL>
*
* Once the parsed template is constructed, the method {@link ParsedTemplate#orError()}
* should <em>always</em> called before it is used.
@@ -65,82 +81,74 @@ import java.util.stream.StreamSupport;
*/
public class ParsedTemplate {
public enum Form {
private final static Logger logger = LogManager.getLogger(ParsedTemplate.class);
private final List<CapturePoint> captures;
private final String rawtemplate;
/**
* The type of a parsed template depends on the structure of the bindings provided.
*/
public enum Type {
/**
* A literal template is one which has no bindings that need to be provided to render a specific statement.
* These templates are basically static statements.
* Example: <em>{@code truncate testks.testtable;}</em>
*/
literal,
rawbind,
template,
/**
* A bindref template is one which has only a single bind point and no leading or trailing text.
* It represents a single value which is to be injected, with no clear indication as to whether the
* value should be in string form or not. These are used when referencing objects by bind point name.
* Callers which use rawbind templates where Strings are needed should convert them with {@link Object#toString()}}
* Example: <em>{@code {myvalue}}</em>
*/
bindref,
/**
* A string template is one which is neither a literal template nor a bindref template. This includes
* any template which has any amount of literal text and any template with more than one bind point.
*/
concat
}
/**
* The canonical template pattern follows the pattern of an opening curly brace,
* followed by a word character, followed by any contiguous
* combination of dashes, underscores, digits, words, and dots, followed by
* a closing curly brace.</LI>
*
* <H2>Examples</H2>
* <pre>
* {var1}
* {var2.var3__-var5}
* </pre>
*/
public final static Pattern STANDARD_ANCHOR = Pattern.compile("\\{(?<anchor>\\w+[-_\\d\\w.]*)}");
public final static Pattern EXTENDED_ANCHOR = Pattern.compile("\\{\\{(?<anchor>.*?)}}");
private final static Logger logger = LogManager.getLogger(ParsedTemplate.class);
// private final Pattern[] patterns;
/**
* Spans is an even-odd form of (literal, variable, ..., ..., literal)
* Thus a 1-length span is a single literal
* Thus a 1-length span is a single literal, and a 3 length span has a single bind point
**/
private final String[] spans;
// private final String rawtemplate;
/**
* A map of binding names and recipes (or null)
*/
private final Map<String, String> bindings = new LinkedHashMap<>();
/**
* Construct a new ParsedTemplate from the provided statement template.
*
* @param rawtemplate The string that contains literal sections and anchor sections interspersed
* @param providedBindings The bindings that are provided for the template to be parsed
*/
public ParsedTemplate(String rawtemplate, Map<String, String> providedBindings) {
this(rawtemplate, providedBindings, STANDARD_ANCHOR, EXTENDED_ANCHOR);
}
private final BindPointParser bindPointParser = new BindPointParser();
private final CapturePointParser capturePointParser = new CapturePointParser();
/**
* Parse the given raw template, check the bind points against the provide bindings, and
* provide detailed template checks for validity.
*
* <H4>Overriding Patterns</H4>
* <P>
* If patterns are not provided then {@link ParsedTemplate#STANDARD_ANCHOR} are used, which includes
* the ability to match {var1} and ?var1 style anchors. If patterns are
* provided, then they must be compatible with the {@link Matcher#find()} method, and must also
* have a named group with the name 'anchor', as in (?&lt;anchor&gt;...)
* </P>
*
* @param rawtemplate A string template which contains optionally embedded named anchors
* @param availableBindings The bindings which are provided by the user to fulfill the named anchors in this raw template
* @param parserPatterns The patterns which match the named anchor format and extract anchor names from the raw template
*/
public ParsedTemplate(String rawtemplate, Map<String, String> availableBindings, Pattern... parserPatterns) {
public ParsedTemplate(String rawtemplate, Map<String, String> availableBindings) {
this.bindings.putAll(availableBindings);
this.spans = parse(rawtemplate, availableBindings, parserPatterns);
this.rawtemplate = rawtemplate;
CapturePointParser.Result captureData = capturePointParser.apply(rawtemplate);
this.captures = captureData.getCaptures();
List<String> spanData = bindPointParser.apply(captureData.getRawTemplate());
this.spans = spanData.toArray(new String[0]);
}
public Form getForm() {
public Type getType() {
if (this.spans.length == 1) {
return Form.literal;
return Type.literal;
} else if (this.spans[0].isEmpty() && this.spans[2].isEmpty()) {
return Form.rawbind;
return Type.bindref;
} else {
return Form.template;
return Type.concat;
}
}
@@ -151,59 +159,6 @@ public class ParsedTemplate {
return this;
}
/**
* After this method runs, the following conditions should apply:
* <ul>
* <li>spans will contain all the literal and variable sections in order, starting a literal, even if it is empty</li>
* <li>spans will be an odd number in length, meaning that the last section will also be a literal, even if it is empty</li>
* <li>specificBindings will contain an ordered map of the binding definitions</li>
* </ul>
*/
private String[] parse(String rawtemplate, Map<String, String> providedBindings, Pattern[] patterns) {
List<String> spans = new ArrayList<>();
String statement = rawtemplate;
int patternsMatched = 0;
int lastMatch = 0;
for (Pattern pattern : patterns) {
if (!pattern.toString().contains("?<anchor>")) {
throw new InvalidParameterException("The provided pattern '" + pattern + "' must contain a named group called anchor," +
"as in '(?<anchor>...)'");
}
Matcher m = pattern.matcher(rawtemplate);
if (!m.find()) { // sanity check that this matcher works at all or go to the next pattern
continue;
}
while (m.find(lastMatch)) {
String pre = statement.substring(lastMatch, m.start());
spans.add(pre);
String tokenName = m.group("anchor");
lastMatch = m.end();
spans.add(tokenName);
}
break; // If the last matcher worked at all, only do one cycle
}
if (lastMatch >= 0) {
spans.add(statement.substring(lastMatch));
} else {
spans.add(statement);
}
return spans.toArray(new String[0]);
}
public String toString() {
String sb = "\n parsed: " +
StreamSupport.stream(Arrays.spliterator(spans), false)
@@ -245,7 +200,7 @@ public class ParsedTemplate {
}
/**
* @return a list of anchors as fou nd in the raw template.
* @return a list of anchors as found in the raw template.
*/
public List<String> getAnchors() {
List<String> anchors = new ArrayList<>();
@@ -265,7 +220,7 @@ public class ParsedTemplate {
* @throws InvalidParameterException if the template has an error,
* such as an anchor which has no provided binding.
*/
public List<BindPoint> getCheckedBindPoints() {
public List<BindPoint> getBindPoints() {
List<BindPoint> bindpoints = new ArrayList<>();
for (int i = 1; i < spans.length; i += 2) {
if (!bindings.containsKey(spans[i])) {
@@ -277,7 +232,7 @@ public class ParsedTemplate {
return bindpoints;
}
public List<BindPoint> getUncheckedBindPoints() {
private List<BindPoint> getUncheckedBindPoints() {
List<BindPoint> bindpoints = new ArrayList<>();
for (int i = 1; i < spans.length; i += 2) {
bindpoints.add(new BindPoint(spans[i], bindings.getOrDefault(spans[i], null)));
@@ -329,4 +284,8 @@ public class ParsedTemplate {
}
}
public List<CapturePoint> getCaptures() {
return this.captures;
}
}

View File

@@ -1,119 +0,0 @@
package io.nosqlbench.virtdata.core.templates;
import io.nosqlbench.virtdata.core.templates.BindPoint;
import io.nosqlbench.virtdata.core.templates.ParsedTemplate;
import org.junit.Test;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import static org.assertj.core.api.Assertions.assertThat;
public class ParsedTemplateTest {
private final Map<String, String> bindings = new HashMap<>() {{
put("bindname1", "bindspec1");
put("bindname2", "bindspec2");
}};
private final String rawNothing = "This has no anchors";
private final String oneCurly = "A {curly} brace.";
private final String oneQuestion = " A ?question anchor.";
private final String oneExtraneous = "An {this is an extraneous form} invalid anchor.";
@Test
public void testShouldMatchRawLiteral() {
ParsedTemplate pt = new ParsedTemplate(rawNothing, bindings);
assertThat(pt.getSpans()).containsExactly("This has no anchors");
assertThat(pt.getSpecificBindings()).isEmpty();
assertThat(pt.getExtraBindings()).hasSameElementsAs(bindings.keySet());
assertThat(pt.getMissingBindings()).isEmpty();
}
@Test
public void testShoudlMatchCurlyBraces() {
ParsedTemplate pt = new ParsedTemplate(oneCurly, bindings);
assertThat(pt.getSpans()).containsExactly("A ", "curly", " brace.");
assertThat(pt.getSpecificBindings().isEmpty());
assertThat(pt.getMissingBindings()).contains("curly");
assertThat(pt.getExtraBindings()).hasSameElementsAs(bindings.keySet());
}
@Test
public void testShouldMatchQuestionMark() {
ParsedTemplate pt = new ParsedTemplate(oneQuestion, bindings);
assertThat(pt.getSpans()).containsExactly(" A ", "question", " anchor.");
assertThat(pt.getSpecificBindings()).isEmpty();
assertThat(pt.getMissingBindings()).containsExactly("question");
assertThat(pt.getExtraBindings()).hasSameElementsAs(bindings.keySet());
}
@Test
public void testShouldIgnoreExtraneousAnchors() {
ParsedTemplate pt = new ParsedTemplate(oneExtraneous, bindings);
assertThat(pt.getSpans()).containsExactly("An {this is an extraneous form} invalid anchor.");
assertThat(pt.getSpecificBindings()).isEmpty();
assertThat(pt.getMissingBindings()).isEmpty();
assertThat(pt.getExtraBindings()).hasSameElementsAs(bindings.keySet());
}
@Test
public void testShouldMatchLiteralVariableOnly() {
String literalVariableOnly = "literal {bindname1}";
ParsedTemplate pt = new ParsedTemplate(literalVariableOnly, bindings);
assertThat(pt.getSpans()).containsExactly("literal ", "bindname1", "");
assertThat(pt.getSpecificBindings()).containsOnlyKeys("bindname1");
assertThat(pt.getMissingBindings()).isEmpty();
assertThat(pt.getExtraBindings()).containsExactly("bindname2");
}
@Test
public void testShouldMatchVariableLiteralOnly() {
String variableLiteralOnly = "{bindname2} literal";
ParsedTemplate pt = new ParsedTemplate(variableLiteralOnly, bindings);
assertThat(pt.getSpans()).containsExactly("", "bindname2", " literal");
assertThat(pt.getSpecificBindings()).containsOnlyKeys("bindname2");
assertThat(pt.getMissingBindings()).isEmpty();
assertThat(pt.getExtraBindings()).containsExactly("bindname1");
}
@Test
public void testShouldMatchProvidedValidPattern() {
String basic = "A [provided] pattern.";
Pattern p = Pattern.compile("\\[(?<anchor>\\w[_a-zA-Z]+)]");
ParsedTemplate pt = new ParsedTemplate(basic, bindings, p);
assertThat(pt.getSpans()).containsExactly("A ", "provided", " pattern.");
assertThat(pt.getSpecificBindings()).isEmpty();
assertThat(pt.getMissingBindings()).containsExactly("provided");
assertThat(pt.getExtraBindings()).containsAll(bindings.keySet());
}
//, expectedExceptionsMessageRegExp = ".*must contain a named group called anchor.*"
@Test(expected= InvalidParameterException.class)
public void testShouldErrorOnInvalidPattern() {
String wontuse = "This won't get used.";
Pattern p = Pattern.compile("\\[(\\w[_a-zA-Z]+)]");
ParsedTemplate pt = new ParsedTemplate(wontuse, bindings, p);
}
@Test
public void testPositionalExpansionShouldBeValid() {
String multi = "A {bindname1} of {bindname2} sort.";
ParsedTemplate pt = new ParsedTemplate(multi, bindings);
assertThat(pt.getSpans()).containsExactly("A ", "bindname1", " of ", "bindname2", " sort.");
assertThat(pt.getSpecificBindings()).containsOnlyKeys("bindname1", "bindname2");
assertThat(pt.getMissingBindings()).isEmpty();
assertThat(pt.getExtraBindings()).isEmpty();
assertThat(pt.getPositionalStatement(s -> "##")).isEqualTo("A ## of ## sort.");
assertThat(pt.getPositionalStatement(s -> "[[" + s + "]]")).isEqualTo("A [[bindname1]] of [[bindname2]] sort.");
assertThat(pt.getBindPoints()).containsExactly(
new BindPoint("bindname1", "bindspec1"),
new BindPoint("bindname2", "bindspec2")
);
}
}

View File

@@ -1,7 +1,7 @@
package io.nosqlbench.virtdata.annotations;
import io.nosqlbench.virtdata.api.annotations.ExampleData;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,6 +1,6 @@
package io.nosqlbench.virtdata.api.bindings;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.function.*;

View File

@@ -1,9 +1,10 @@
package io.nosqlbench.virtdata.core;
import io.nosqlbench.virtdata.core.bindings.CompatibilityFixups;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class CompatibilityFixupsTest {
@Test
@@ -30,7 +31,5 @@ public class CompatibilityFixupsTest {
@Test
public void testParsingSanity() {
assertThat(CompatibilityFixups.fixup("long -> Add(5) -> long")).isEqualTo("long -> Add(5) -> long");
}
}

View File

@@ -1,7 +1,7 @@
package io.nosqlbench.virtdata.core;
import io.nosqlbench.virtdata.core.bindings.ResolvedFunction;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.function.LongUnaryOperator;

View File

@@ -2,7 +2,7 @@ package io.nosqlbench.virtdata.core;
import io.nosqlbench.virtdata.core.bindings.ResolverDiagnostics;
import io.nosqlbench.virtdata.core.bindings.VirtDataComposer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class VirtDataComposerTest {

View File

@@ -2,7 +2,7 @@ package io.nosqlbench.virtdata.core;
import io.nosqlbench.virtdata.core.bindings.BindingsTemplate;
import io.nosqlbench.virtdata.core.bindings.VirtData;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -3,7 +3,7 @@ package io.nosqlbench.virtdata.core.composers;
import io.nosqlbench.virtdata.core.bindings.DataMapper;
import io.nosqlbench.virtdata.core.bindings.FunctionType;
import io.nosqlbench.virtdata.core.bindings.DataMapperFunctionMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;

View File

@@ -1,13 +1,14 @@
package io.nosqlbench.virtdata.core.composers;
import io.nosqlbench.virtdata.core.bindings.DataMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.function.Function;
import java.util.function.LongFunction;
import java.util.function.LongUnaryOperator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public class FunctionAssemblerTest {
@@ -51,13 +52,14 @@ public class FunctionAssemblerTest {
assertThat(aLong).isEqualTo(15);
}
@Test(expected = ClassCastException.class)
public void testLongFunctionLongFunctionMistyped() throws Exception {
@Test
public void testLongFunctionLongFunctionMistyped() {
FunctionComposer fass = new FunctionAssembly();
fass.andThen(new LongAddFiveFunction());
fass.andThen(new GenericStringCat());
DataMapper<String> dataMapper = fass.getDataMapper();
dataMapper.get(5);
assertThatExceptionOfType(ClassCastException.class)
.isThrownBy(() -> dataMapper.get(5));
}
@Test
@@ -79,12 +81,13 @@ public class FunctionAssemblerTest {
// assertThat(s).isEqualTo("Cat5");
// }
@Test(expected= ClassCastException.class)
@Test
public void testFunctionFunctionMistyped() {
FunctionComposer fass = new FunctionAssembly();
fass.andThen(new GenericStringCat());
DataMapper<String> dataMapper = fass.getDataMapper();
String s = dataMapper.get(5);
assertThatExceptionOfType(ClassCastException.class)
.isThrownBy(() -> dataMapper.get(5));
}
@Test

View File

@@ -1,7 +1,7 @@
package io.nosqlbench.virtdata.core.config;
import io.nosqlbench.nb.api.config.ConfigData;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;

View File

@@ -0,0 +1,22 @@
package io.nosqlbench.virtdata.core.templates;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class BindPointParserTest {
@Test
public void testBindPointParser() {
BindPointParser bpp = new BindPointParser();
assertThat(bpp.apply("test {one}")).containsExactly("test ","one","");
assertThat(bpp.apply("test {one} {{two three}}")).containsExactly("test ","one"," ","two three","");
}
@Test
public void testBindPointParserBypass() {
BindPointParser bpp = new BindPointParser();
assertThat(bpp.apply("")).containsExactly("");
}
}

View File

@@ -0,0 +1,31 @@
package io.nosqlbench.virtdata.core.templates;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class CapturePointTest {
@Test
public void testBasicCaptures() {
CapturePointParser cpp = new CapturePointParser();
assertThat(cpp.apply("test [point1] [point2 as alias3]")).isEqualTo(
new CapturePointParser.Result("test point1 point2",
List.of(
CapturePoint.of("point1"),
CapturePoint.of("point2","alias3")
))
);
}
@Test
public void testBypass() {
CapturePointParser cpp = new CapturePointParser();
assertThat(cpp.apply("")).isEqualTo(
new CapturePointParser.Result("", List.of())
);
}
}

View File

@@ -1,8 +1,9 @@
package io.nosqlbench.virtdata.core.templates;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Test;
import java.util.Map;
import java.util.Optional;
@@ -11,40 +12,79 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ParsedTemplateTest {
private final Map<String, String> bindings = Map.of(
"bindname1", "bindspec1",
"bindname2", "bindspec2");
@Test
public void testParsedTemplate() {
ParsedTemplate pt = new ParsedTemplate("test template", Map.of());
assertThat(pt.getAnchors()).isEmpty();
assertThat(pt.getCheckedBindPoints()).isEmpty();
assertThat(pt.getSpans()).contains("test template");
public void testShouldMatchRawLiteral() {
String rawNothing = "This has no anchors";
ParsedTemplate pt = new ParsedTemplate(rawNothing, bindings);
assertThat(pt.getSpans()).containsExactly("This has no anchors");
assertThat(pt.getBindPoints()).isEmpty();
assertThat(pt.getMissing()).isEmpty();
}
@Test
public void testBindPoints() {
ParsedTemplate pt = new ParsedTemplate("test template {missing1}", Map.of("b1","v1"));
assertThat(pt.getSpans()).contains("test template ");
assertThat(pt.getAnchors()).containsExactly("missing1");
assertThat(pt.getUncheckedBindPoints()).containsExactly(new BindPoint("missing1",null));
public void testShouldIgnoreExtraneousAnchors() {
String oneExtraneous = "An {this is an extraneous form} invalid anchor.";
ParsedTemplate pt = new ParsedTemplate(oneExtraneous, bindings);
assertThat(pt.getSpans()).containsExactly("An {this is an extraneous form} invalid anchor.");
assertThat(pt.getBindPoints()).isEmpty();
assertThat(pt.getMissing()).isEmpty();
}
@Test
public void testSingleBinding() {
ParsedTemplate pt = new ParsedTemplate("{single}", Map.of());
Optional<BindPoint> sb = pt.asBinding();
assertThat(sb).isPresent();
assertThat(sb).contains(new BindPoint("single",null));
public void testShouldAllowArbitraryNonGreedyInExtendedBindPoint() {
String oneExtendedBindPoint = "An {{this is an extended form}} {{and another}} invalid anchor.";
ParsedTemplate pt = new ParsedTemplate(oneExtendedBindPoint, bindings);
assertThat(pt.getSpans()).containsExactly("An ","this is an extended form"," ","and another"," invalid anchor.");
assertThat(pt.getAnchors()).containsExactly("this is an extended form","and another");
}
@Test
public void testJsonFormat() {
ParsedTemplate pt = new ParsedTemplate("test template {missing1}", Map.of("b1","v1"));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String format = gson.toJson(pt);
System.out.println(format);
public void testShouldMatchLiteralVariableOnly() {
String literalVariableOnly = "literal {bindname1}";
ParsedTemplate pt = new ParsedTemplate(literalVariableOnly, bindings);
assertThat(pt.getSpans()).containsExactly("literal ", "bindname1", "");
assertThat(pt.getAnchors()).containsOnly("bindname1");
assertThat(pt.getMissing()).isEmpty();
}
@Test
public void testShouldMatchVariableLiteralOnly() {
String variableLiteralOnly = "{bindname2} literal";
ParsedTemplate pt = new ParsedTemplate(variableLiteralOnly, bindings);
assertThat(pt.getSpans()).containsExactly("", "bindname2", " literal");
assertThat(pt.getAnchors()).containsOnly("bindname2");
assertThat(pt.getMissing()).isEmpty();
}
@Test
public void testPositionalExpansionShouldBeValid() {
String multi = "A {bindname1} of {bindname2} sort.";
ParsedTemplate pt = new ParsedTemplate(multi, bindings);
assertThat(pt.getSpans()).containsExactly("A ", "bindname1", " of ", "bindname2", " sort.");
assertThat(pt.getAnchors()).containsOnly("bindname1", "bindname2");
assertThat(pt.getMissing()).isEmpty();
assertThat(pt.getPositionalStatement(s -> "##")).isEqualTo("A ## of ## sort.");
assertThat(pt.getPositionalStatement(s -> "[[" + s + "]]")).isEqualTo("A [[bindname1]] of [[bindname2]] sort.");
assertThat(pt.getBindPoints()).containsExactly(
new BindPoint("bindname1", "bindspec1"),
new BindPoint("bindname2", "bindspec2")
);
}
@Test
public void shouldMatchBasicCapturePoint() {
ParsedTemplate pt = new ParsedTemplate(
"select [u],[v as v1] from users where userid={userid}", Map.of("userid", "NumberNameToString()")
);
assertThat(pt.getAnchors()).containsExactly("userid");
assertThat(pt.getType()).isEqualTo(ParsedTemplate.Type.concat);
assertThat(pt.getCaptures()).containsExactly(CapturePoint.of("u"),CapturePoint.of("v","v1"));
}
}

View File

@@ -1,18 +1,20 @@
package io.nosqlbench.virtdata.core.templates;
import io.nosqlbench.virtdata.core.bindings.BindingsTemplate;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public class StringBindingsTemplateTest {
// , expectedExceptionsMessageRegExp = ".*not provided in the bindings: \\[two, three\\]")
@Test(expected = RuntimeException.class)
@Test
public void testUnqualifiedBindings() {
BindingsTemplate bt1 = new BindingsTemplate();
bt1.addFieldBinding("one", "Identity()");
String template="{one} {two} {three}\n";
StringBindingsTemplate sbt = new StringBindingsTemplate(template,bt1);
StringBindings resolved = sbt.resolve();
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(sbt::resolve);
}
}

View File

@@ -1,7 +1,6 @@
package io.nosqlbench.virtdata.core.templates;
import io.nosqlbench.virtdata.core.templates.StringCompositor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -12,7 +11,6 @@ public class StringCompositorTest {
StringCompositor c = new StringCompositor("A");
String[] spans = c.parseTemplate("A\\{ {one}two");
assertThat(spans).containsExactly("A\\{ ", "one", "two");
}
@Test
@@ -28,5 +26,4 @@ public class StringCompositorTest {
// String[] spans = c.parseTemplate("A\\{B}C");
// assertThat(spans).containsExactly("A\\{B}C");
// }
}

View File

@@ -1,7 +1,7 @@
package io.nosqlbench.virtdata.core.templates;
import io.nosqlbench.virtdata.core.bindings.ValueType;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -7,8 +7,8 @@ import java.util.function.LongFunction;
@ThreadSafeMapper
public class TestableTemplate implements LongFunction<String> {
private LongFunction<?>[] funcs;
private String separator;
private final LongFunction<?>[] funcs;
private final String separator;
public TestableTemplate(String separator, LongFunction<?>... funcs) {
this.funcs = funcs;

View File

@@ -1,6 +1,6 @@
package io.nosqlbench.virtdata.testmappers;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -6,7 +6,7 @@ import java.util.function.LongUnaryOperator;
@ThreadSafeMapper
public class TestingRepeater implements LongUnaryOperator {
private int repeat;
private final int repeat;
public TestingRepeater(int repeat) {
this.repeat = repeat;

View File

@@ -1,7 +1,7 @@
package io.nosqlbench.virtdata.util;
import io.nosqlbench.virtdata.core.bindings.StringObjectPromoter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -47,9 +47,9 @@ public class StringObjectPromoterTest {
@Test
public void testBigDecimalFallback() {
Object o = StringObjectPromoter.promote("1"+String.valueOf(Double.MAX_VALUE));
Object o = StringObjectPromoter.promote("1"+ Double.MAX_VALUE);
assertThat(o).isInstanceOf(BigDecimal.class);
assertThat(o).isEqualTo(new BigDecimal("1"+String.valueOf(Double.MAX_VALUE)));
assertThat(o).isEqualTo(new BigDecimal("1"+ Double.MAX_VALUE));
}
@Test

View File

@@ -1,12 +1,14 @@
package io.nosqlbench.virtdata.util;
import io.nosqlbench.virtdata.api.bindings.VirtDataFunctions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.security.InvalidParameterException;
import java.util.function.Function;
import java.util.function.LongFunction;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
public class VirtDataFunctionsTest {
@Test
@@ -16,11 +18,10 @@ public class VirtDataFunctionsTest {
long f2 = adapted.apply(42L);
}
@Test(expected = InvalidParameterException.class)
@Test
public void testWrongLongUnaryConversion() {
Function<Long,Integer> fl = (Long l) -> Math.max(l.intValue(),43);
LongFunction<Long> adapted = VirtDataFunctions.adapt(fl, LongFunction.class, Long.class, true);
long f2 = adapted.apply(42L);
Function<Long,Integer> fl = (Long l) -> Math.max(l.intValue(), 43);
assertThatExceptionOfType(InvalidParameterException.class)
.isThrownBy(() -> VirtDataFunctions.adapt(fl, LongFunction.class, Long.class, true));
}
}