Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added to check if the driver is invalid #1933

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package io.nosqlbench.engine.core.lifecycle.session;

import io.nosqlbench.adapter.diag.DriverAdapterLoader;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.cmdstream.CmdArg;
import io.nosqlbench.nb.annotations.ServiceSelector;
import io.nosqlbench.nb.api.errors.BasicError;

import java.util.*;
Expand Down Expand Up @@ -75,6 +77,14 @@ public static LinkedList<Cmd> parseArgvCommands(LinkedList<String> args) {
if (params.containsKey(param.name())) {
throw new BasicError("Duplicate occurrence of option: " + param.name());
}
if (Objects.equals(param.name(), "driver")) {
String driverName = param.value();
Optional<? extends DriverAdapterLoader> driverAdapter =
ServiceSelector.of(driverName, ServiceLoader.load(DriverAdapterLoader.class)).get();
if (driverAdapter.isEmpty()) {
throw new BasicError("Unable to load default driver adapter '" + driverName + '\'');
}
}
params.put(param.name(),CmdArg.of(cmd.name(),param.name(),param.op(),param.value()));
}
cmds.add(new Cmd(cmd.name(),params));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ public void testThatDuplicateParameterThrowsBasicError() {
.withMessageContaining("Duplicate occurrence of option: threads");
}

@Test
public void testNonExistentDriverThrowsError() {
assertThatExceptionOfType(BasicError.class)
.isThrownBy(() -> CmdParser.parseArgvCommands(new LinkedList<>(List.of("run", "driver=nonexistant"))))
.withMessageContaining("Unable to load default driver adapter 'nonexistant'");
}

}