mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
modularize methods for verifiers
This commit is contained in:
parent
5032779ad7
commit
a98ff2e465
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.engine.extensions.vectormath;
|
||||||
|
|
||||||
|
import com.datastax.oss.driver.api.core.cql.Row;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CqlUtils {
|
||||||
|
|
||||||
|
public static long[] cqlRowFieldsToLongArray(String fieldName, List<Row> rows) {
|
||||||
|
return rows.stream().mapToLong(r -> r.getLong(fieldName)).toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] cqlRowFieldsToStringArray(String fieldName, List<Row> rows) {
|
||||||
|
return rows.stream().map(r -> r.getString(fieldName)).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] cqlRowListToIntArray(String fieldName, List<Row> rows) {
|
||||||
|
return rows.stream().mapToInt(r -> r.getInt(fieldName)).toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -18,19 +18,19 @@ package io.nosqlbench.engine.extensions.vectormath;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class,selector = "vectormath")
|
@Service(value = ComputeFunctionsPluginInfo.class,selector = "cql_utils")
|
||||||
public class VectorMathPluginInfo implements ScriptingPluginInfo<VectorMath> {
|
public class CqlUtilsPluginInfo implements ComputeFunctionsPluginInfo<CqlUtils> {
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "various methods and utilities for working with vector math in a scripted environment";
|
return "various methods and utilities for working with vector math in a scripted environment";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VectorMath getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
public CqlUtils getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||||
return new VectorMath();
|
return new CqlUtils();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.engine.extensions.vectormath;
|
|
||||||
|
|
||||||
import com.datastax.oss.driver.api.core.cql.Row;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class VectorMath {
|
|
||||||
|
|
||||||
public static long[] rowFieldsToLongArray(String fieldName, List<Row> rows) {
|
|
||||||
return rows.stream().mapToLong(r -> r.getLong(fieldName)).toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] rowFieldsToStringArray(String fieldName, List<Row> rows) {
|
|
||||||
return rows.stream().map(r -> r.getString(fieldName)).toArray(String[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long[] stringArrayAsALongArray(String[] strings) {
|
|
||||||
long[] longs = new long[strings.length];
|
|
||||||
for (int i = 0; i < longs.length; i++) {
|
|
||||||
longs[i]=Long.parseLong(strings[i]);
|
|
||||||
}
|
|
||||||
return longs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] stringArrayAsIntArray(String[] strings) {
|
|
||||||
int[] ints = new int[strings.length];
|
|
||||||
for (int i = 0; i < ints.length; i++) {
|
|
||||||
ints[i]=Integer.parseInt(strings[i]);
|
|
||||||
}
|
|
||||||
return ints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] rowListToIntArray(String fieldName, List<Row> rows) {
|
|
||||||
return rows.stream().mapToInt(r -> r.getInt(fieldName)).toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double computeRecall(long[] referenceIndexes, long[] sampleIndexes) {
|
|
||||||
Arrays.sort(referenceIndexes);
|
|
||||||
Arrays.sort(sampleIndexes);
|
|
||||||
long[] intersection = Intersections.find(referenceIndexes,sampleIndexes);
|
|
||||||
return (double)intersection.length/(double)referenceIndexes.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double computeRecall(int[] referenceIndexes, int[] sampleIndexes) {
|
|
||||||
Arrays.sort(referenceIndexes);
|
|
||||||
Arrays.sort(sampleIndexes);
|
|
||||||
int[] intersection = Intersections.find(referenceIndexes,sampleIndexes);
|
|
||||||
return (double)intersection.length/(double)referenceIndexes.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -14,27 +14,19 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.nosqlbench.engine.extensions.vectormath;
|
package io.nosqlbench.engine.extensions.scriptingutils;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import io.pinecone.proto.QueryResponse;
|
||||||
class VectorMathTest {
|
import io.pinecone.proto.ScoredVector;
|
||||||
|
|
||||||
private VectorMath vm = new VectorMath();
|
public class PineconeScriptingUtils {
|
||||||
|
|
||||||
@Test
|
public static String[] responseIdsToStringArray(QueryResponse response) {
|
||||||
void computeRecallForRowListVsLongIndexList() {
|
return response.getMatchesList().stream().map(ScoredVector::getId).toArray(String[]::new);
|
||||||
VectorMath.computeRecall(new long[]{}, new long[]{});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public static int[] responseIdsToIntArray(QueryResponse response) {
|
||||||
void computeRecallForRowListVsIntIndexList() {
|
return response.getMatchesList().stream().mapToInt(r -> Integer.parseInt(r.getId())).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void computeRecallForRowListVsIntIndexArray() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void computeRecallForRowListVsLongIndexArray() {
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -14,23 +14,23 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.nosqlbench.engine.extensions.vectormath;
|
package io.nosqlbench.engine.extensions.scriptingutils;
|
||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class,selector = "pinecone_vectormath")
|
@Service(value = ComputeFunctionsPluginInfo.class,selector = "pinecone_utils")
|
||||||
public class PineconeVectorMathPluginInfo implements ScriptingPluginInfo<PineconeVectorMath> {
|
public class PineconeScriptingUtilsPluginInfo implements ComputeFunctionsPluginInfo<PineconeScriptingUtils> {
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "various methods and utilities for working with vector math in a scripted environment";
|
return "various methods and utilities for working with vector math in a scripted environment";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PineconeVectorMath getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
public PineconeScriptingUtils getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||||
return new PineconeVectorMath();
|
return new PineconeScriptingUtils();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.engine.extensions.vectormath;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class PineconeIntersections {
|
|
||||||
|
|
||||||
public static long[] find(long[] reference, long[] sample) {
|
|
||||||
long[] result = new long[reference.length];
|
|
||||||
int a_index = 0, b_index = 0, acc_index = -1;
|
|
||||||
long a_element, b_element;
|
|
||||||
while (a_index < reference.length && b_index < sample.length) {
|
|
||||||
a_element = reference[a_index];
|
|
||||||
b_element = sample[b_index];
|
|
||||||
if (a_element == b_element) {
|
|
||||||
result = resize(result);
|
|
||||||
result[++acc_index] = a_element;
|
|
||||||
a_index++;
|
|
||||||
b_index++;
|
|
||||||
} else if (b_element < a_element) {
|
|
||||||
b_index++;
|
|
||||||
} else {
|
|
||||||
a_index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Arrays.copyOfRange(result,0,acc_index+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] find(int[] reference, int[] sample) {
|
|
||||||
int[] result = new int[reference.length];
|
|
||||||
int a_index = 0, b_index = 0, acc_index = -1;
|
|
||||||
int a_element, b_element;
|
|
||||||
while (a_index < reference.length && b_index < sample.length) {
|
|
||||||
a_element = reference[a_index];
|
|
||||||
b_element = sample[b_index];
|
|
||||||
if (a_element == b_element) {
|
|
||||||
result = resize(result);
|
|
||||||
result[++acc_index] = a_element;
|
|
||||||
a_index++;
|
|
||||||
b_index++;
|
|
||||||
} else if (b_element < a_element) {
|
|
||||||
b_index++;
|
|
||||||
} else {
|
|
||||||
a_index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Arrays.copyOfRange(result,0,acc_index+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] resize(int[] arr) {
|
|
||||||
int len = arr.length;
|
|
||||||
int[] copy = new int[len + 1];
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
copy[i] = arr[i];
|
|
||||||
}
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long[] resize(long[] arr) {
|
|
||||||
int len = arr.length;
|
|
||||||
long[] copy = new long[len + 1];
|
|
||||||
for (int i = 0; i < len; i++) {
|
|
||||||
copy[i] = arr[i];
|
|
||||||
}
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.engine.extensions.vectormath;
|
|
||||||
|
|
||||||
import io.pinecone.proto.QueryResponse;
|
|
||||||
import io.pinecone.proto.ScoredVector;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class PineconeVectorMath {
|
|
||||||
|
|
||||||
public static long[] stringArrayAsALongArray(String[] strings) {
|
|
||||||
long[] longs = new long[strings.length];
|
|
||||||
for (int i = 0; i < longs.length; i++) {
|
|
||||||
longs[i]=Long.parseLong(strings[i]);
|
|
||||||
}
|
|
||||||
return longs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] stringArrayAsIntArray(String[] strings) {
|
|
||||||
int[] ints = new int[strings.length];
|
|
||||||
for (int i = 0; i < ints.length; i++) {
|
|
||||||
ints[i]=Integer.parseInt(strings[i]);
|
|
||||||
}
|
|
||||||
return ints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] idsToStringArray(QueryResponse response) {
|
|
||||||
return response.getMatchesList().stream().map(ScoredVector::getId).toArray(String[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] idsToIntArray(QueryResponse response) {
|
|
||||||
return response.getMatchesList().stream().mapToInt(r -> Integer.parseInt(r.getId())).toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double computeRecall(long[] referenceIndexes, long[] sampleIndexes) {
|
|
||||||
Arrays.sort(referenceIndexes);
|
|
||||||
Arrays.sort(sampleIndexes);
|
|
||||||
long[] intersection = PineconeIntersections.find(referenceIndexes,sampleIndexes);
|
|
||||||
return (double)intersection.length/(double)referenceIndexes.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double computeRecall(int[] referenceIndexes, int[] sampleIndexes) {
|
|
||||||
Arrays.sort(referenceIndexes);
|
|
||||||
Arrays.sort(sampleIndexes);
|
|
||||||
int[] intersection = PineconeIntersections.find(referenceIndexes,sampleIndexes);
|
|
||||||
return (double)intersection.length/(double)referenceIndexes.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -68,7 +68,8 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
|||||||
/**
|
/**
|
||||||
* package imports used with "verifiers" or "expected-result" are accumulated here
|
* package imports used with "verifiers" or "expected-result" are accumulated here
|
||||||
*/
|
*/
|
||||||
private final List verifierImports = new ArrayList();
|
private final List<String> verifierImports = new ArrayList<>();
|
||||||
|
private final List<Class<?>> verifierStaticImports = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* optional invokable functions which throw exceptions when results are not verifiable.
|
* optional invokable functions which throw exceptions when results are not verifiable.
|
||||||
* This variable is kept here for diagnostics and debugging. The actual instance used within
|
* This variable is kept here for diagnostics and debugging. The actual instance used within
|
||||||
@ -129,7 +130,7 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
|||||||
try {
|
try {
|
||||||
initBlocks.forEach((initName, stringTemplate) -> {
|
initBlocks.forEach((initName, stringTemplate) -> {
|
||||||
GroovyCycleFunction<?> initFunction =
|
GroovyCycleFunction<?> initFunction =
|
||||||
new GroovyCycleFunction<>(initName,stringTemplate,verifierImports,variables);
|
new GroovyCycleFunction<>(initName,stringTemplate,verifierImports,verifierStaticImports,variables);
|
||||||
logger.info("configured verifier init:" + initFunction);
|
logger.info("configured verifier init:" + initFunction);
|
||||||
initFunction.setVariable("_parsed_op",op);
|
initFunction.setVariable("_parsed_op",op);
|
||||||
initFunction.apply(0L);
|
initFunction.apply(0L);
|
||||||
@ -143,7 +144,7 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
|||||||
try {
|
try {
|
||||||
namedVerifiers.forEach((verifierName,stringTemplate) -> {
|
namedVerifiers.forEach((verifierName,stringTemplate) -> {
|
||||||
GroovyBooleanCycleFunction verifier =
|
GroovyBooleanCycleFunction verifier =
|
||||||
new GroovyBooleanCycleFunction(verifierName, stringTemplate, verifierImports, variables);
|
new GroovyBooleanCycleFunction(verifierName, stringTemplate, verifierImports, verifierStaticImports, variables);
|
||||||
logger.info("configured verifier:" + verifier);
|
logger.info("configured verifier:" + verifier);
|
||||||
verifierFunctions.add(verifier);
|
verifierFunctions.add(verifier);
|
||||||
});
|
});
|
||||||
@ -153,7 +154,7 @@ public abstract class BaseOpDispenser<T extends Op, S> implements OpDispenser<T>
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
op.takeAsOptionalStringTemplate(EXPECTED_RESULT)
|
op.takeAsOptionalStringTemplate(EXPECTED_RESULT)
|
||||||
.map(tpl -> new GroovyObjectEqualityFunction(op.getName()+"-"+EXPECTED_RESULT, tpl, verifierImports, variables))
|
.map(tpl -> new GroovyObjectEqualityFunction(op.getName()+"-"+EXPECTED_RESULT, tpl, verifierImports, verifierStaticImports, variables))
|
||||||
.map(vl -> {
|
.map(vl -> {
|
||||||
logger.info("Configured equality verifier: " + vl);
|
logger.info("Configured equality verifier: " + vl);
|
||||||
return vl;
|
return vl;
|
||||||
|
@ -23,8 +23,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GroovyBooleanCycleFunction extends GroovyCycleFunction<Boolean> {
|
public class GroovyBooleanCycleFunction extends GroovyCycleFunction<Boolean> {
|
||||||
|
|
||||||
public GroovyBooleanCycleFunction(String name, ParsedTemplateString template, List<String> imports, Binding binding) {
|
public GroovyBooleanCycleFunction(String name, ParsedTemplateString template, List<String> imports, List<Class<?>> staticSymbolImports, Binding binding) {
|
||||||
super(name, template, imports, binding);
|
super(name, template, imports, staticSymbolImports, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,7 @@ import groovy.lang.GroovyShell;
|
|||||||
import groovy.lang.Script;
|
import groovy.lang.Script;
|
||||||
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
|
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
|
||||||
import io.nosqlbench.api.extensions.SandboxExtensionFinder;
|
import io.nosqlbench.api.extensions.SandboxExtensionFinder;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.virtdata.core.bindings.Bindings;
|
import io.nosqlbench.virtdata.core.bindings.Bindings;
|
||||||
import io.nosqlbench.virtdata.core.bindings.BindingsTemplate;
|
import io.nosqlbench.virtdata.core.bindings.BindingsTemplate;
|
||||||
import io.nosqlbench.virtdata.core.templates.BindPoint;
|
import io.nosqlbench.virtdata.core.templates.BindPoint;
|
||||||
@ -39,12 +39,14 @@ public class GroovyCycleFunction<T> implements CycleFunction<T> {
|
|||||||
private final static Logger logger = LogManager.getLogger(GroovyBooleanCycleFunction.class);
|
private final static Logger logger = LogManager.getLogger(GroovyBooleanCycleFunction.class);
|
||||||
private final String name;
|
private final String name;
|
||||||
private final List<String> imports;
|
private final List<String> imports;
|
||||||
private final List<String> enabledServices = new ArrayList<>(List.of("vectormath"));
|
// private final List<String> enabledServices = new ArrayList<>(List.of("vectormath"));
|
||||||
|
private final List<String> enabledServices = new ArrayList<>();
|
||||||
|
|
||||||
protected String scriptText; // Groovy script as provided
|
protected String scriptText; // Groovy script as provided
|
||||||
protected final Script script; // Groovy Script as compiled
|
protected final Script script; // Groovy Script as compiled
|
||||||
protected final Binding variableBindings; // Groovy binding layer
|
protected final Binding variableBindings; // Groovy binding layer
|
||||||
protected final Bindings bindingFunctions; // NB bindings
|
protected final Bindings bindingFunctions; // NB bindings
|
||||||
|
private final List<Class<?>> staticImports;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a cycle function from basic types
|
* Instantiate a cycle function from basic types
|
||||||
@ -56,10 +58,11 @@ public class GroovyCycleFunction<T> implements CycleFunction<T> {
|
|||||||
* @param imports
|
* @param imports
|
||||||
* The package imports to be installed into the execution environment
|
* The package imports to be installed into the execution environment
|
||||||
*/
|
*/
|
||||||
public GroovyCycleFunction(String name, String scriptText, Map<String, String> bindingSpecs, List<String> imports, Binding binding) {
|
public GroovyCycleFunction(String name, String scriptText, Map<String, String> bindingSpecs, List<String> imports, List<Class<?>> staticImports, Binding binding) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.scriptText = scriptText;
|
this.scriptText = scriptText;
|
||||||
this.imports = imports;
|
this.imports = imports;
|
||||||
|
this.staticImports = staticImports;
|
||||||
|
|
||||||
// scripting env variable bindings
|
// scripting env variable bindings
|
||||||
this.variableBindings = binding!=null? binding : new Binding();
|
this.variableBindings = binding!=null? binding : new Binding();
|
||||||
@ -67,12 +70,13 @@ public class GroovyCycleFunction<T> implements CycleFunction<T> {
|
|||||||
// virtdata bindings to be evaluated at cycle time
|
// virtdata bindings to be evaluated at cycle time
|
||||||
this.bindingFunctions = new BindingsTemplate().addFieldBindings(bindingSpecs).resolveBindings();
|
this.bindingFunctions = new BindingsTemplate().addFieldBindings(bindingSpecs).resolveBindings();
|
||||||
|
|
||||||
this.script = compileScript(this.scriptText, imports, binding);
|
this.script = compileScript(this.scriptText, imports, staticImports, binding);
|
||||||
addServices();
|
addServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addServices() {
|
private void addServices() {
|
||||||
for (final ScriptingPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
for (final ComputeFunctionsPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
||||||
|
staticImports.addAll(extensionDescriptor.autoImportStaticMethodClasses());
|
||||||
if (!extensionDescriptor.isAutoLoading()) {
|
if (!extensionDescriptor.isAutoLoading()) {
|
||||||
logger.info(() -> "Not loading " + extensionDescriptor + ", autoloading is false");
|
logger.info(() -> "Not loading " + extensionDescriptor + ", autoloading is false");
|
||||||
continue;
|
continue;
|
||||||
@ -94,28 +98,35 @@ public class GroovyCycleFunction<T> implements CycleFunction<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroovyCycleFunction(String name, ParsedTemplateString template, List<String> imports, Binding binding) {
|
public GroovyCycleFunction(String name, ParsedTemplateString template, List<String> imports, List<Class<?>> staticImports, Binding binding) {
|
||||||
this(
|
this(
|
||||||
name,
|
name,
|
||||||
template.getPositionalStatement(),
|
template.getPositionalStatement(),
|
||||||
resolveBindings(template.getBindPoints()),
|
resolveBindings(template.getBindPoints()),
|
||||||
imports,
|
imports,
|
||||||
|
staticImports,
|
||||||
binding
|
binding
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Script compileScript(String scriptText, List<String> imports, Binding binding) {
|
private Script compileScript(String scriptText, List<String> imports, List<Class<?>> staticImports, Binding binding) {
|
||||||
// add classes which are in the imports to the groovy evaluation context
|
// add classes which are in the imports to the groovy evaluation context
|
||||||
String[] verifiedClasses = expandClassNames(imports);
|
String[] verifiedClasses = expandClassNames(imports);
|
||||||
|
String[] verifiedStaticImports = expandStaticImports(staticImports);
|
||||||
|
|
||||||
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
||||||
ImportCustomizer importer = new ImportCustomizer().addImports(verifiedClasses);
|
ImportCustomizer importer = new ImportCustomizer().addImports(verifiedClasses);
|
||||||
|
importer.addStaticStars(verifiedStaticImports);
|
||||||
compilerConfiguration.addCompilationCustomizers(importer);
|
compilerConfiguration.addCompilationCustomizers(importer);
|
||||||
|
|
||||||
GroovyShell gshell = new GroovyShell(binding!=null? binding:new Binding(), compilerConfiguration);
|
GroovyShell gshell = new GroovyShell(binding!=null? binding:new Binding(), compilerConfiguration);
|
||||||
return gshell.parse(scriptText);
|
return gshell.parse(scriptText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] expandStaticImports(List<Class<?>> staticImports) {
|
||||||
|
return staticImports.stream().map(Class::getCanonicalName).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
private static Map<String, String> resolveBindings(List<BindPoint> bindPoints) {
|
private static Map<String, String> resolveBindings(List<BindPoint> bindPoints) {
|
||||||
return new BindingsTemplate(bindPoints).getMap();
|
return new BindingsTemplate(bindPoints).getMap();
|
||||||
}
|
}
|
||||||
@ -166,16 +177,17 @@ public class GroovyCycleFunction<T> implements CycleFunction<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public CycleFunction<T> newInstance() {
|
public CycleFunction<T> newInstance() {
|
||||||
return new GroovyCycleFunction<T>(name, scriptText, bindingFunctions, imports, this.variableBindings.getVariables());
|
return new GroovyCycleFunction<T>(name, scriptText, bindingFunctions, imports, staticImports, this.variableBindings.getVariables());
|
||||||
}
|
}
|
||||||
|
|
||||||
private GroovyCycleFunction(String name, String scriptText, Bindings bindingFunctions, List<String> imports, Map originalBinding) {
|
private GroovyCycleFunction(String name, String scriptText, Bindings bindingFunctions, List<String> imports, List<Class<?>> staticImports, Map originalBinding) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.scriptText = scriptText;
|
this.scriptText = scriptText;
|
||||||
this.bindingFunctions = bindingFunctions;
|
this.bindingFunctions = bindingFunctions;
|
||||||
this.imports = imports;
|
this.imports = imports;
|
||||||
|
this.staticImports = staticImports;
|
||||||
|
|
||||||
this.script = compileScript(scriptText, imports, new Binding());
|
this.script = compileScript(scriptText, imports, staticImports, new Binding());
|
||||||
this.variableBindings = script.getBinding();
|
this.variableBindings = script.getBinding();
|
||||||
originalBinding.forEach((k,v) -> variableBindings.setVariable(k.toString(),v));
|
originalBinding.forEach((k,v) -> variableBindings.setVariable(k.toString(),v));
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ public class GroovyObjectEqualityFunction extends GroovyCycleFunction<Boolean> {
|
|||||||
|
|
||||||
private Object result;
|
private Object result;
|
||||||
|
|
||||||
public GroovyObjectEqualityFunction(String name, ParsedTemplateString template, List<String> imports, Binding binding) {
|
public GroovyObjectEqualityFunction(String name, ParsedTemplateString template, List<String> imports, List<Class<?>> staticImports, Binding binding) {
|
||||||
super(name, template, imports, binding);
|
super(name, template, imports, staticImports, binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,8 +25,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
public class CompoundCycleFunctionTest {
|
public class CompoundCycleFunctionTest {
|
||||||
|
|
||||||
private final GroovyCycleFunction<Boolean> truthy = new GroovyCycleFunction<>("truthy", "true;", Map.of(), List.of(),null);
|
private final GroovyCycleFunction<Boolean> truthy = new GroovyCycleFunction<>("truthy", "true;", Map.of(), List.of(), List.of(),null);
|
||||||
private final GroovyCycleFunction<Boolean> falsy = new GroovyCycleFunction<>("falsy", "false;", Map.of(), List.of(), null);
|
private final GroovyCycleFunction<Boolean> falsy = new GroovyCycleFunction<>("falsy", "false;", Map.of(), List.of(), List.of(), null);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReducerFirstOrLastResult() {
|
public void testReducerFirstOrLastResult() {
|
||||||
|
@ -36,7 +36,7 @@ public class GroovyBooleanCycleFunctionTest {
|
|||||||
Map.of("numbername", "NumberNameToString()")
|
Map.of("numbername", "NumberNameToString()")
|
||||||
);
|
);
|
||||||
List<String> imports = List.of();
|
List<String> imports = List.of();
|
||||||
GroovyBooleanCycleFunction function = new GroovyBooleanCycleFunction("test1", parsedTemplate, imports, null);
|
GroovyBooleanCycleFunction function = new GroovyBooleanCycleFunction("test1", parsedTemplate, imports, List.of(), null);
|
||||||
Boolean result = function.apply(2);
|
Boolean result = function.apply(2);
|
||||||
assertThat(result).isTrue();
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class GroovyBooleanCycleFunctionTest {
|
|||||||
Map.of("numbername", "NumberNameToString()")
|
Map.of("numbername", "NumberNameToString()")
|
||||||
);
|
);
|
||||||
List<String> imports = List.of();
|
List<String> imports = List.of();
|
||||||
GroovyCycleFunction function = new GroovyBooleanCycleFunction("test2", parsedTemplate, imports, null);
|
GroovyCycleFunction function = new GroovyBooleanCycleFunction("test2", parsedTemplate, imports, List.of(),null);
|
||||||
System.out.println(function);
|
System.out.println(function);
|
||||||
assertThatThrownBy(() -> function.apply(3L)).isInstanceOf(MissingPropertyException.class);
|
assertThatThrownBy(() -> function.apply(3L)).isInstanceOf(MissingPropertyException.class);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
|||||||
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
||||||
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
||||||
import io.nosqlbench.api.metadata.SystemId;
|
import io.nosqlbench.api.metadata.SystemId;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
import io.nosqlbench.engine.api.scripting.ScriptEnvBuffer;
|
||||||
import io.nosqlbench.engine.core.annotation.Annotators;
|
import io.nosqlbench.engine.core.annotation.Annotators;
|
||||||
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
|
||||||
@ -211,7 +211,7 @@ public class Scenario implements Callable<ExecutionMetricsResult>, NBLabeledElem
|
|||||||
this.scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
this.scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
||||||
this.scriptEngine.put("activities", new ActivityBindings(scenarioController));
|
this.scriptEngine.put("activities", new ActivityBindings(scenarioController));
|
||||||
|
|
||||||
for (final ScriptingPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
for (final ComputeFunctionsPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
||||||
if (!extensionDescriptor.isAutoLoading()) {
|
if (!extensionDescriptor.isAutoLoading()) {
|
||||||
this.logger.info(() -> "Not loading " + extensionDescriptor + ", autoloading is false");
|
this.logger.info(() -> "Not loading " + extensionDescriptor + ", autoloading is false");
|
||||||
continue;
|
continue;
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.engine.extensions.computefunctions;
|
||||||
|
|
||||||
|
import com.codahale.metrics.MetricRegistry;
|
||||||
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service(value = ComputeFunctionsPluginInfo.class,selector = "compute")
|
||||||
|
public class ComputeFunctionPluginInfo implements ComputeFunctionsPluginInfo<ComputeFunctions> {
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Various small math utilities.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ComputeFunctions getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||||
|
return new ComputeFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Class<?>> autoImportStaticMethodClasses() {
|
||||||
|
return List.of(ComputeFunctions.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.engine.extensions.computefunctions;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ComputeFunctions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the recall as the proportion of matching indices divided by the expected indices
|
||||||
|
* @param referenceIndexes long array of indices
|
||||||
|
* @param sampleIndexes long array of indices
|
||||||
|
* @return a fractional measure of matching vs expected indices
|
||||||
|
*/
|
||||||
|
public static double recall(long[] referenceIndexes, long[] sampleIndexes) {
|
||||||
|
Arrays.sort(referenceIndexes);
|
||||||
|
Arrays.sort(sampleIndexes);
|
||||||
|
long[] intersection = Intersections.find(referenceIndexes, sampleIndexes);
|
||||||
|
return (double) intersection.length / (double) referenceIndexes.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the recall as the proportion of matching indices divided by the expected indices
|
||||||
|
* @param referenceIndexes int array of indices
|
||||||
|
* @param sampleIndexes int array of indices
|
||||||
|
* @return a fractional measure of matching vs expected indices
|
||||||
|
*/
|
||||||
|
public static double recall(int[] referenceIndexes, int[] sampleIndexes) {
|
||||||
|
Arrays.sort(referenceIndexes);
|
||||||
|
Arrays.sort(sampleIndexes);
|
||||||
|
int intersection = Intersections.count(referenceIndexes, sampleIndexes);
|
||||||
|
return (double) intersection / (double) referenceIndexes.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the intersection of two long arrays
|
||||||
|
*/
|
||||||
|
public static long[] intersection(long[] a, long[] b) {
|
||||||
|
return Intersections.find(a,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the intersection of two int arrays
|
||||||
|
*/
|
||||||
|
public static int[] intersection(int[] reference, int[] sample) {
|
||||||
|
return Intersections.find(reference, sample);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the size of the intersection of two int arrays
|
||||||
|
*/
|
||||||
|
public static int intersectionSize(int[] reference, int[] sample) {
|
||||||
|
return Intersections.count(reference, sample);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -14,12 +14,31 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.nosqlbench.engine.extensions.vectormath;
|
package io.nosqlbench.engine.extensions.computefunctions;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Intersections {
|
public class Intersections {
|
||||||
|
|
||||||
|
public static int count(int[] reference, int[] sample) {
|
||||||
|
int a_index = 0, b_index = 0, matches = 0;
|
||||||
|
int a_element, b_element;
|
||||||
|
while (a_index < reference.length && b_index < sample.length) {
|
||||||
|
a_element = reference[a_index];
|
||||||
|
b_element = sample[b_index];
|
||||||
|
if (a_element == b_element) {
|
||||||
|
++matches;
|
||||||
|
a_index++;
|
||||||
|
b_index++;
|
||||||
|
} else if (b_element < a_element) {
|
||||||
|
b_index++;
|
||||||
|
} else {
|
||||||
|
a_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
public static long count(long[] reference, long[] sample) {
|
public static long count(long[] reference, long[] sample) {
|
||||||
int a_index = 0, b_index = 0, matches = 0;
|
int a_index = 0, b_index = 0, matches = 0;
|
||||||
long a_element, b_element;
|
long a_element, b_element;
|
||||||
@ -39,27 +58,6 @@ public class Intersections {
|
|||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long[] find(long[] reference, long[] sample) {
|
|
||||||
long[] result = new long[reference.length];
|
|
||||||
int a_index = 0, b_index = 0, acc_index = -1;
|
|
||||||
long a_element, b_element;
|
|
||||||
while (a_index < reference.length && b_index < sample.length) {
|
|
||||||
a_element = reference[a_index];
|
|
||||||
b_element = sample[b_index];
|
|
||||||
if (a_element == b_element) {
|
|
||||||
result = resize(result);
|
|
||||||
result[++acc_index] = a_element;
|
|
||||||
a_index++;
|
|
||||||
b_index++;
|
|
||||||
} else if (b_element < a_element) {
|
|
||||||
b_index++;
|
|
||||||
} else {
|
|
||||||
a_index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Arrays.copyOfRange(result,0,acc_index+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int[] find(int[] reference, int[] sample) {
|
public static int[] find(int[] reference, int[] sample) {
|
||||||
int[] result = new int[reference.length];
|
int[] result = new int[reference.length];
|
||||||
int a_index = 0, b_index = 0, acc_index = -1;
|
int a_index = 0, b_index = 0, acc_index = -1;
|
||||||
@ -80,15 +78,16 @@ public class Intersections {
|
|||||||
}
|
}
|
||||||
return Arrays.copyOfRange(result,0,acc_index+1);
|
return Arrays.copyOfRange(result,0,acc_index+1);
|
||||||
}
|
}
|
||||||
|
public static long[] find(long[] reference, long[] sample) {
|
||||||
public static int count(int[] reference, int[] sample) {
|
long[] result = new long[reference.length];
|
||||||
int a_index = 0, b_index = 0, matches = 0;
|
int a_index = 0, b_index = 0, acc_index = -1;
|
||||||
int a_element, b_element;
|
long a_element, b_element;
|
||||||
while (a_index < reference.length && b_index < sample.length) {
|
while (a_index < reference.length && b_index < sample.length) {
|
||||||
a_element = reference[a_index];
|
a_element = reference[a_index];
|
||||||
b_element = sample[b_index];
|
b_element = sample[b_index];
|
||||||
if (a_element == b_element) {
|
if (a_element == b_element) {
|
||||||
++matches;
|
result = resize(result);
|
||||||
|
result[++acc_index] = a_element;
|
||||||
a_index++;
|
a_index++;
|
||||||
b_index++;
|
b_index++;
|
||||||
} else if (b_element < a_element) {
|
} else if (b_element < a_element) {
|
||||||
@ -97,25 +96,22 @@ public class Intersections {
|
|||||||
a_index++;
|
a_index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return matches;
|
return Arrays.copyOfRange(result,0,acc_index+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] resize(int[] arr) {
|
private static int[] resize(int[] arr) {
|
||||||
int len = arr.length;
|
int len = arr.length;
|
||||||
int[] copy = new int[len + 1];
|
int[] copy = new int[len + 1];
|
||||||
for (int i = 0; i < len; i++) {
|
System.arraycopy(arr, 0, copy, 0, len);
|
||||||
copy[i] = arr[i];
|
|
||||||
}
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long[] resize(long[] arr) {
|
private static long[] resize(long[] arr) {
|
||||||
int len = arr.length;
|
int len = arr.length;
|
||||||
long[] copy = new long[len + 1];
|
long[] copy = new long[len + 1];
|
||||||
for (int i = 0; i < len; i++) {
|
System.arraycopy(arr, 0, copy, 0, len);
|
||||||
copy[i] = arr[i];
|
|
||||||
}
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.engine.extensions.conversions;
|
||||||
|
|
||||||
|
import com.codahale.metrics.MetricRegistry;
|
||||||
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service(value = ComputeFunctionsPluginInfo.class,selector = "convert")
|
||||||
|
public class ConversionUtilsPluginInfo implements ComputeFunctionsPluginInfo<ConverterUtils> {
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Utilities to convert between common basic data types";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConverterUtils getExtensionObject(Logger logger, MetricRegistry metricRegistry, LabeledScenarioContext scriptContext) {
|
||||||
|
return new ConverterUtils();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Class<?>> autoImportStaticMethodClasses() {
|
||||||
|
return List.of(ConverterUtils.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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.engine.extensions.conversions;
|
||||||
|
|
||||||
|
public class ConverterUtils {
|
||||||
|
public static int[] toIntArray(String[] strings) {
|
||||||
|
int[] ints = new int[strings.length];
|
||||||
|
for (int i = 0; i < ints.length; i++) {
|
||||||
|
ints[i]=Integer.parseInt(strings[i]);
|
||||||
|
}
|
||||||
|
return ints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long[] toLongArray(String[] strings) {
|
||||||
|
long[] longs = new long[strings.length];
|
||||||
|
for (int i = 0; i < longs.length; i++) {
|
||||||
|
longs[i]=Long.parseLong(strings[i]);
|
||||||
|
}
|
||||||
|
return longs;
|
||||||
|
}
|
||||||
|
}
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.csvmetrics;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "csvmetrics")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "csvmetrics")
|
||||||
public class CSVMetricsPluginData implements ScriptingPluginInfo<CSVMetricsPlugin> {
|
public class CSVMetricsPluginData implements ComputeFunctionsPluginInfo<CSVMetricsPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.csvoutput;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class,selector = "csvoutput")
|
@Service(value = ComputeFunctionsPluginInfo.class,selector = "csvoutput")
|
||||||
public class CsvOutputPluginData implements ScriptingPluginInfo<CsvOutputPluginInstance> {
|
public class CsvOutputPluginData implements ComputeFunctionsPluginInfo<CsvOutputPluginInstance> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.example;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "adder")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "adder")
|
||||||
public class ExamplePluginData implements ScriptingPluginInfo<ExamplePlugin> {
|
public class ExamplePluginData implements ComputeFunctionsPluginInfo<ExamplePlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.files;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "files")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "files")
|
||||||
public class FileAccessPluginData implements ScriptingPluginInfo<FileAccess> {
|
public class FileAccessPluginData implements ComputeFunctionsPluginInfo<FileAccess> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,15 +18,15 @@ package io.nosqlbench.engine.extensions.globalvars;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
|
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "globalvars")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "globalvars")
|
||||||
public class GlobalVarsScriptingPluginData implements ScriptingPluginInfo<ConcurrentHashMap<String, Object>> {
|
public class GlobalVarsComputeFunctionsPluginData implements ComputeFunctionsPluginInfo<ConcurrentHashMap<String, Object>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.histologger;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "histologger")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "histologger")
|
||||||
public class HdrHistoLogPluginData implements ScriptingPluginInfo<HdrHistoLogPlugin> {
|
public class HdrHistoLogPluginData implements ComputeFunctionsPluginInfo<HdrHistoLogPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.histostatslogger;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "histostatslogger")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "histostatslogger")
|
||||||
public class HistoStatsPluginData implements ScriptingPluginInfo<HistoStatsPlugin> {
|
public class HistoStatsPluginData implements ComputeFunctionsPluginInfo<HistoStatsPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.http;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "http")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "http")
|
||||||
public class HttpPluginData implements ScriptingPluginInfo<HttpPlugin> {
|
public class HttpPluginData implements ComputeFunctionsPluginInfo<HttpPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.optimizers;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "optimos")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "optimos")
|
||||||
public class BobyqaOptimizerPluginData implements ScriptingPluginInfo<BobyqaOptimizerPlugin> {
|
public class BobyqaOptimizerPluginData implements ComputeFunctionsPluginInfo<BobyqaOptimizerPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,14 +18,14 @@ package io.nosqlbench.engine.extensions.s3uploader;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
import io.nosqlbench.api.metadata.ScenarioMetadata;
|
||||||
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
import io.nosqlbench.api.metadata.ScenarioMetadataAware;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value = ScriptingPluginInfo.class, selector = "s3")
|
@Service(value = ComputeFunctionsPluginInfo.class, selector = "s3")
|
||||||
public class S3UploaderPluginData implements ScriptingPluginInfo<S3Uploader>, ScenarioMetadataAware {
|
public class S3UploaderPluginData implements ComputeFunctionsPluginInfo<S3Uploader>, ScenarioMetadataAware {
|
||||||
private ScenarioMetadata scenarioMetadata;
|
private ScenarioMetadata scenarioMetadata;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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.
|
||||||
@ -20,15 +20,12 @@ import com.codahale.metrics.Gauge;
|
|||||||
|
|
||||||
public class ScriptingGauge implements Gauge<Double> {
|
public class ScriptingGauge implements Gauge<Double> {
|
||||||
private double value;
|
private double value;
|
||||||
|
|
||||||
public ScriptingGauge(String name, double initialValue) {
|
public ScriptingGauge(String name, double initialValue) {
|
||||||
value = initialValue;
|
value = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(double value) {
|
public void update(double value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double getValue() {
|
public Double getValue() {
|
||||||
return value;
|
return value;
|
||||||
|
@ -18,7 +18,9 @@ package io.nosqlbench.engine.extensions.scriptingmetrics;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
|
import io.nosqlbench.api.config.NBLabeledElement;
|
||||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||||
|
import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class ScriptingMetrics {
|
public class ScriptingMetrics {
|
||||||
@ -27,17 +29,30 @@ public class ScriptingMetrics {
|
|||||||
private final LabeledScenarioContext scriptContext;
|
private final LabeledScenarioContext scriptContext;
|
||||||
|
|
||||||
public ScriptingMetrics(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
public ScriptingMetrics(final Logger logger, final MetricRegistry metricRegistry, final LabeledScenarioContext scriptContext) {
|
||||||
|
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.metricRegistry = metricRegistry;
|
this.metricRegistry = metricRegistry;
|
||||||
this.scriptContext = scriptContext;
|
this.scriptContext = scriptContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptingGauge newGauge(final String name, final double initialValue) {
|
public ScriptingGauge newStaticGauge(final String name, final double initialValue) {
|
||||||
final ScriptingGauge scriptingGauge = new ScriptingGauge(name, initialValue);
|
final ScriptingGauge scriptingGauge = new ScriptingGauge(name, initialValue);
|
||||||
ActivityMetrics.gauge(this.scriptContext,name, scriptingGauge);
|
ActivityMetrics.gauge(this.scriptContext,name, scriptingGauge);
|
||||||
this.logger.info(() -> "registered scripting gauge:" + name);
|
this.logger.info(() -> "registered scripting gauge:" + name);
|
||||||
return scriptingGauge;
|
return scriptingGauge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DoubleSummaryGauge newSummaryGauge(final String name) {
|
||||||
|
final DoubleSummaryGauge summaryGauge = ActivityMetrics.summaryGauge(scriptContext,name);
|
||||||
|
this.logger.info(() -> "registered summmary gauge:" + name);
|
||||||
|
return summaryGauge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DoubleSummaryGauge newSummaryGauge(NBLabeledElement context, final String name) {
|
||||||
|
final DoubleSummaryGauge summaryGauge = ActivityMetrics.summaryGauge(context,name);
|
||||||
|
this.logger.info(() -> "registered summmary gauge:" + name);
|
||||||
|
return summaryGauge;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.extensions.scriptingmetrics;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value= ScriptingPluginInfo.class, selector="scriptingmetrics")
|
@Service(value= ComputeFunctionsPluginInfo.class, selector="scriptingmetrics")
|
||||||
public class ScriptingMetricsPluginData implements ScriptingPluginInfo<ScriptingMetrics> {
|
public class ScriptingMetricsPluginData implements ComputeFunctionsPluginInfo<ScriptingMetrics> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -18,12 +18,12 @@ package io.nosqlbench.engine.shutdown;
|
|||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||||
import io.nosqlbench.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.api.extensions.ComputeFunctionsPluginInfo;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@Service(value=ScriptingPluginInfo.class,selector = "shutdown")
|
@Service(value= ComputeFunctionsPluginInfo.class,selector = "shutdown")
|
||||||
public class ShutdownHookPluginMetadata implements ScriptingPluginInfo<ShutdownHookPlugin> {
|
public class ShutdownHookPluginMetadata implements ComputeFunctionsPluginInfo<ShutdownHookPlugin> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -14,13 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.nosqlbench.engine.extensions.vectormath;
|
package io.nosqlbench.engine.extensions.computefunctions;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class IntersectionsTest {
|
class IntersectionsTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIntegerIntersection() {
|
public void testIntegerIntersection() {
|
||||||
int[] result = Intersections.find(new int[]{1,2,3,4,5},new int[]{4,5,6,7,8});
|
int[] result = Intersections.find(new int[]{1,2,3,4,5},new int[]{4,5,6,7,8});
|
||||||
@ -44,4 +46,5 @@ class IntersectionsTest {
|
|||||||
assertThat(result).isEqualTo(3);
|
assertThat(result).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -21,6 +21,8 @@ import io.nosqlbench.api.config.LabeledScenarioContext;
|
|||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any implementation of a SandboxExtension that is found in the runtime
|
* Any implementation of a SandboxExtension that is found in the runtime
|
||||||
* can be automatically loaded into the scenario scripting sandbox.
|
* can be automatically loaded into the scenario scripting sandbox.
|
||||||
@ -30,7 +32,7 @@ import org.apache.logging.log4j.Logger;
|
|||||||
* Each scenario gets its own instance of an object from this SandboxPlugin
|
* Each scenario gets its own instance of an object from this SandboxPlugin
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public interface ScriptingPluginInfo<T> {
|
public interface ComputeFunctionsPluginInfo<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a brief description of this extension.
|
* @return a brief description of this extension.
|
||||||
@ -61,4 +63,8 @@ public interface ScriptingPluginInfo<T> {
|
|||||||
default boolean isAutoLoading() {
|
default boolean isAutoLoading() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default List<Class<?>> autoImportStaticMethodClasses() {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
}
|
}
|
@ -23,14 +23,14 @@ import java.util.ServiceLoader;
|
|||||||
|
|
||||||
public class SandboxExtensionFinder {
|
public class SandboxExtensionFinder {
|
||||||
|
|
||||||
private final static List<ScriptingPluginInfo<?>> extensionDescriptors = new ArrayList<>();
|
private final static List<ComputeFunctionsPluginInfo<?>> extensionDescriptors = new ArrayList<>();
|
||||||
|
|
||||||
public static List<ScriptingPluginInfo<?>> findAll() {
|
public static List<ComputeFunctionsPluginInfo<?>> findAll() {
|
||||||
if (extensionDescriptors.isEmpty()) {
|
if (extensionDescriptors.isEmpty()) {
|
||||||
synchronized (SandboxExtensionFinder.class) {
|
synchronized (SandboxExtensionFinder.class) {
|
||||||
if (extensionDescriptors.isEmpty()) {
|
if (extensionDescriptors.isEmpty()) {
|
||||||
ServiceLoader<ScriptingPluginInfo> loader =
|
ServiceLoader<ComputeFunctionsPluginInfo> loader =
|
||||||
ServiceLoader.load(ScriptingPluginInfo.class);
|
ServiceLoader.load(ComputeFunctionsPluginInfo.class);
|
||||||
loader.iterator().forEachRemaining(extensionDescriptors::add);
|
loader.iterator().forEachRemaining(extensionDescriptors::add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user