mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
Moved the invalid driver checker to CmdParser
This commit is contained in:
parent
34dc3264ec
commit
0efa075f99
@ -221,17 +221,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
|||||||
|
|
||||||
final NBCLIOptions options = new NBCLIOptions(args, Mode.ParseAllOptions);
|
final NBCLIOptions options = new NBCLIOptions(args, Mode.ParseAllOptions);
|
||||||
|
|
||||||
for (Cmd cmd : options.getCommands()) {
|
|
||||||
Map<String, String> cmdArgMap = cmd.getArgMap();
|
|
||||||
if (cmdArgMap.containsKey("driver")) {
|
|
||||||
String driverName = cmdArgMap.get("driver");
|
|
||||||
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 + '\'');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NBCLI.logger = LogManager.getLogger("NBCLI");
|
NBCLI.logger = LogManager.getLogger("NBCLI");
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2020-2024 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.cli;
|
|
||||||
|
|
||||||
import io.nosqlbench.nb.api.errors.BasicError;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
|
|
||||||
|
|
||||||
public class NBCLITest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNonExistentDriverThrowsError() {
|
|
||||||
final NBCLI cli = new NBCLI("nb5");
|
|
||||||
assertThatExceptionOfType(BasicError.class)
|
|
||||||
.isThrownBy(() -> cli.applyDirect(new String[] {"run", "driver=nonexistent"}))
|
|
||||||
.withMessageContaining("Unable to load default driver adapter 'nonexistent'");;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -16,8 +16,10 @@
|
|||||||
|
|
||||||
package io.nosqlbench.engine.core.lifecycle.session;
|
package io.nosqlbench.engine.core.lifecycle.session;
|
||||||
|
|
||||||
|
import io.nosqlbench.adapter.diag.DriverAdapterLoader;
|
||||||
import io.nosqlbench.engine.cmdstream.Cmd;
|
import io.nosqlbench.engine.cmdstream.Cmd;
|
||||||
import io.nosqlbench.engine.cmdstream.CmdArg;
|
import io.nosqlbench.engine.cmdstream.CmdArg;
|
||||||
|
import io.nosqlbench.nb.annotations.ServiceSelector;
|
||||||
import io.nosqlbench.nb.api.errors.BasicError;
|
import io.nosqlbench.nb.api.errors.BasicError;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -75,6 +77,14 @@ public class CmdParser {
|
|||||||
if (params.containsKey(param.name())) {
|
if (params.containsKey(param.name())) {
|
||||||
throw new BasicError("Duplicate occurrence of option: " + 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()));
|
params.put(param.name(),CmdArg.of(cmd.name(),param.name(),param.op(),param.value()));
|
||||||
}
|
}
|
||||||
cmds.add(new Cmd(cmd.name(),params));
|
cmds.add(new Cmd(cmd.name(),params));
|
||||||
|
@ -106,4 +106,11 @@ class CmdParserTest {
|
|||||||
.withMessageContaining("Duplicate occurrence of option: threads");
|
.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'");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user