mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
standard activity improvements
This commit is contained in:
parent
d9296eef95
commit
06d43b8c55
@ -39,7 +39,7 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public interface ActivityType<A extends Activity> {
|
public interface ActivityType<A extends Activity> {
|
||||||
|
|
||||||
SimpleServiceLoader<ActivityType> FINDER = new SimpleServiceLoader<ActivityType>(ActivityType.class);
|
SimpleServiceLoader<ActivityType> FINDER = new SimpleServiceLoader<>(ActivityType.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of an activity from the activity type.
|
* Create an instance of an activity from the activity type.
|
||||||
|
@ -23,10 +23,12 @@ public class StandardAction<A extends StandardActivity<O>, O extends Runnable> i
|
|||||||
|
|
||||||
private final A activity;
|
private final A activity;
|
||||||
private final OpSource<O> opsource;
|
private final OpSource<O> opsource;
|
||||||
|
private final int slot;
|
||||||
|
|
||||||
public StandardAction(A activity, OpSource<O> opsource) {
|
public StandardAction(A activity, int slot) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.opsource = opsource;
|
this.opsource = activity.getOpSource();
|
||||||
|
this.slot = slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,12 +41,12 @@ public class StandardAction<A extends StandardActivity<O>, O extends Runnable> i
|
|||||||
|
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
int code= 0;
|
int code= 0;
|
||||||
Throwable error = null;
|
|
||||||
while (tries++ <= activity.getMaxTries()) {
|
while (tries++ <= activity.getMaxTries()) {
|
||||||
|
Throwable error = null;
|
||||||
long startedAt = System.nanoTime();
|
long startedAt = System.nanoTime();
|
||||||
try (Timer.Context ct = activity.getInstrumentation().getOrCreateExecuteTimer().time()) {
|
try (Timer.Context ct = activity.getInstrumentation().getOrCreateExecuteTimer().time()) {
|
||||||
op.run();
|
op.run();
|
||||||
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
error = e;
|
error = e;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||||
|
|
||||||
|
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
|
||||||
|
import io.nosqlbench.engine.api.activityapi.core.Activity;
|
||||||
|
|
||||||
|
public class StandardActionDispenser implements ActionDispenser {
|
||||||
|
private final StandardActivity<?> activity;
|
||||||
|
|
||||||
|
public <A extends Activity> StandardActionDispenser(StandardActivity<?> activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StandardAction<?,?> getAction(int slot) {
|
||||||
|
return new StandardAction<>(activity,slot);
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,15 @@
|
|||||||
package io.nosqlbench.engine.api.activityimpl.uniform;
|
package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||||
|
|
||||||
|
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
|
||||||
import io.nosqlbench.engine.api.activityapi.planning.OpSource;
|
import io.nosqlbench.engine.api.activityapi.planning.OpSource;
|
||||||
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||||
import io.nosqlbench.engine.api.activityimpl.DiagRunnableOpMapper;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
||||||
import io.nosqlbench.engine.api.activityimpl.SimpleActivity;
|
import io.nosqlbench.engine.api.activityimpl.SimpleActivity;
|
||||||
|
import io.nosqlbench.engine.api.templating.ParsedCommand;
|
||||||
|
import io.nosqlbench.nb.api.errors.OpConfigError;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,28 +19,37 @@ import java.util.function.Function;
|
|||||||
*
|
*
|
||||||
* @param <O> A type of runnable which wraps the operations for this type of driver.
|
* @param <O> A type of runnable which wraps the operations for this type of driver.
|
||||||
*/
|
*/
|
||||||
public abstract class StandardActivity<O extends Runnable> extends SimpleActivity {
|
public class StandardActivity<O extends Runnable> extends SimpleActivity {
|
||||||
|
|
||||||
private OpSource<O> opsource;
|
private final DriverAdapter<O> adapter;
|
||||||
|
private final OpSource<O> opsource;
|
||||||
|
|
||||||
public StandardActivity(ActivityDef activityDef) {
|
public StandardActivity(DriverAdapter<O> adapter, ActivityDef activityDef) {
|
||||||
super(activityDef);
|
super(activityDef);
|
||||||
|
this.adapter = adapter;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Function<ParsedCommand, OpDispenser<O>> opmapper = adapter.getOpMapper();
|
||||||
|
Function<Map<String, Object>, Map<String, Object>> preprocessor = adapter.getPreprocessor();
|
||||||
|
OpSequence<OpDispenser<O>> seq = createOpSourceFromCommands(opmapper,List.of(preprocessor));
|
||||||
|
opsource= OpSource.of(seq);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (e instanceof OpConfigError) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
throw new OpConfigError("Error mapping workload template to operations: " + e.getMessage(), null, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized OpSource<O> getOpsource() {
|
public OpSource<O> getOpSource() {
|
||||||
if (this.opsource == null) {
|
|
||||||
Function<OpTemplate, OpDispenser<O>> dispenserMapper = getOpMapperFunction();
|
|
||||||
}
|
|
||||||
return opsource;
|
return opsource;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Function<OpTemplate, OpDispenser<O>> getOpMapperFunction();
|
// public Function<OpTemplate, OpDispenser<? extends Runnable>> getRunnableOpFunction() {
|
||||||
|
// DiagRunnableOpMapper mapper = new DiagRunnableOpMapper();
|
||||||
|
// return mapper::apply;
|
||||||
public Function<OpTemplate, OpDispenser<? extends Runnable>> getRunnableOpFunction() {
|
// }
|
||||||
DiagRunnableOpMapper mapper = new DiagRunnableOpMapper();
|
|
||||||
return mapper::apply;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||||
|
|
||||||
|
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
|
||||||
|
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
||||||
|
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||||
|
import io.nosqlbench.nb.api.spi.SimpleServiceLoader;
|
||||||
|
|
||||||
|
public class StandardActivityType<A extends StandardActivity<?>> implements ActivityType<A> {
|
||||||
|
|
||||||
|
public static SimpleServiceLoader<DriverAdapter> FINDER = new SimpleServiceLoader<DriverAdapter>(DriverAdapter.class);
|
||||||
|
private final DriverAdapter<?> adapter;
|
||||||
|
|
||||||
|
public StandardActivityType(DriverAdapter<?> adapter) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public A getActivity(ActivityDef activityDef) {
|
||||||
|
return (A) new StandardActivity(adapter,activityDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionDispenser getActionDispenser(A activity) {
|
||||||
|
return new StandardActionDispenser(activity);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user