use of net.morimekta.console.args.ArgumentException in project providence by morimekta.
the class TestRunner method main.
public static void main(String... args) throws InterruptedException, TException, IOException {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "off");
ArgumentParser parser = new ArgumentParser("it-serialization", "SNAPSHOT", "Serialization speed Integration test");
TestOptions options = new TestOptions();
try {
parser.add(new Flag("--help", "h?", "Show this help message", options.help::set));
parser.add(new Flag("--no_progress", "s", "No progress output", options.no_progress::set));
parser.add(new Option("--runs", "R", "RUNS", "Number of runs to do", i32(options.runs::set), "100"));
parser.add(new Option("--generate", "g", "NUM", "Number of messages to generate", i32(options.generate::set), "10"));
parser.add(new Option("--fill_rate", "r", "FRACT", "Fill rate, 0.0 - 1.0 of fields in generated classes", dbl(options.generator::setFillRate), "1.0"));
parser.add(new Option("--load", null, "FILE", "File to load data from. Required test to match content", file(options.file::set)));
parser.add(new Option("--format", "f", "FMT", "Which format to test", oneOf(Format.class, options.format::set), "all"));
parser.add(new Argument("test", "Which test to run", oneOf(TestOptions.Test.class, options.test::set), "all"));
parser.parse(args);
if (options.help.get()) {
System.out.println("Usage: " + parser.getSingleLineUsage());
System.out.println();
parser.printUsage(System.out);
System.exit(0);
}
parser.validate();
if (options.test.get() == null || options.test.get() == TestOptions.Test.containers) {
new TestRunner<>(net.morimekta.test.providence.serialization.containers.ManyContainers.kDescriptor, net.morimekta.test.thrift.serialization.containers.ManyContainers::new, options).run();
}
if (options.test.get() == null || options.test.get() == TestOptions.Test.fields) {
new TestRunner<>(net.morimekta.test.providence.serialization.messages.ManyFields.kDescriptor, net.morimekta.test.thrift.serialization.messages.ManyFields::new, options).run();
}
if (options.test.get() == null || options.test.get() == TestOptions.Test.r_fields) {
new TestRunner<>(net.morimekta.test.providence.serialization.messages.ManyRequiredFields.kDescriptor, net.morimekta.test.thrift.serialization.messages.ManyRequiredFields::new, options).run();
}
if (options.test.get() == null || options.test.get() == TestOptions.Test.deep) {
new TestRunner<>(net.morimekta.test.providence.serialization.deep.DeepStructure.kDescriptor, net.morimekta.test.thrift.serialization.deep.DeepStructure::new, options).run();
}
System.out.println();
System.exit(0);
} catch (ArgumentException e) {
System.err.println("Argument: " + e.getMessage());
System.err.println();
System.err.println("Usage: " + parser.getSingleLineUsage());
System.err.println();
parser.printUsage(System.err);
} catch (TException e) {
e.printStackTrace();
System.err.println("TException" + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
}
use of net.morimekta.console.args.ArgumentException in project providence by morimekta.
the class ConvertOptions method getServiceDefinition.
public PService getServiceDefinition() throws ParseException, IOException {
ProgramRegistry registry = getProgramRegistry();
PService srv = registry.getService(type, null);
if (srv == null) {
String programName = type.substring(0, type.lastIndexOf("."));
programName = programName.replaceAll("[-.]", "_");
Map<String, File> includeMap = FormatUtils.getIncludeMap(getRc(), includes);
String filePath = includeMap.get(programName).toString();
CProgram document = registry.registryForPath(filePath).getProgram();
Set<String> services = new TreeSet<>(document.getServices().stream().map(s -> s.getQualifiedName()).collect(Collectors.toSet()));
throw new ArgumentException("Unknown service %s in %s.\n" + "Found %s", type, ReflectionUtils.programNameFromPath(type), services.size() == 0 ? "none" : Strings.join(", ", services));
}
return srv;
}
use of net.morimekta.console.args.ArgumentException in project providence by morimekta.
the class GeneratorOptions method getGenerator.
public Generator getGenerator(TypeLoader loader) throws ArgumentException, GeneratorException, IOException {
net.morimekta.providence.generator.GeneratorOptions generatorOptions = new net.morimekta.providence.generator.GeneratorOptions();
generatorOptions.generator_program_name = "pvdgen";
generatorOptions.program_version = Utils.getVersionString();
try {
return gen.factory.createGenerator(getFileManager(), generatorOptions, gen.options);
} catch (GeneratorException e) {
throw new ArgumentException(e, e.getMessage());
}
}
use of net.morimekta.console.args.ArgumentException in project providence by morimekta.
the class GeneratorSpecParser method parse.
@Override
public GeneratorSpec parse(String spec) {
Map<String, GeneratorFactory> factoryMap = generatorFactoryMap.get();
ArrayList<String> options = new ArrayList<>();
String[] gen = spec.split("[:]");
if (gen.length > 2) {
throw new ArgumentException("Invalid generator spec, only one ':' allowed: " + spec);
}
GeneratorFactory factory = factoryMap.get(gen[0].toLowerCase());
if (factory == null) {
throw new ArgumentException("Unknown output language " + gen[0]);
}
if (gen.length == 2) {
Collections.addAll(options, gen[1].split("[,]"));
}
return new GeneratorSpec(factory, options);
}
use of net.morimekta.console.args.ArgumentException in project providence by morimekta.
the class RPC method run.
@SuppressWarnings("unchecked")
void run(String... args) {
try {
ArgumentParser cli = options.getArgumentParser("pvdrpc", "Providence RPC Tool");
try {
cli.parse(args);
if (options.showHelp()) {
System.out.println("Providence RPC Tool - " + getVersionString());
System.out.println("Usage: " + cli.getSingleLineUsage());
System.out.println();
System.out.println("Example code to run:");
System.out.println("$ cat call.json | pvdrpc -I thrift/ -s cal.Calculator http://localhost:8080/service");
System.out.println("$ pvdrpc -i binary,file:my.data -f json_protocol -I thrift/ -s cal.Calculator http://localhost:8080/service");
System.out.println();
cli.printUsage(System.out);
System.out.println();
System.out.println("Available formats are:");
for (Format format : Format.values()) {
System.out.println(String.format(" - %-20s : %s", format.name(), format.desc));
}
return;
} else if (options.showVersion()) {
System.out.println("Providence RPC Tool - " + getVersionString());
return;
}
cli.validate();
MessageReader in = options.getInput();
MessageWriter out = options.getOutput();
PService service = options.getDefinition();
PServiceCallHandler handler = options.getHandler();
PServiceCall call = in.read(service);
in.close();
PServiceCall resp = handler.handleCall(call, service);
out.write(resp);
out.separator();
out.close();
if (options.out.base64mime && options.out.file == null) {
System.out.println();
}
return;
} catch (ConnectException e) {
System.out.flush();
System.err.format("Unable to connect to %s: %s%n", options.endpoint, e.getMessage());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (HttpResponseException e) {
System.out.flush();
System.err.println("Received " + e.getStatusCode() + " " + e.getStatusMessage());
System.err.println(" - from: " + options.endpoint);
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (ArgumentException e) {
System.out.flush();
System.err.println(e.getMessage());
System.err.println("Usage: " + cli.getSingleLineUsage());
System.err.println();
System.err.println("Run $ pvdrpc --help # for available options.");
} catch (SerializerException e) {
System.out.flush();
System.err.println("Serializer error: " + e.asString());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
} catch (UncheckedIOException | IOException e) {
System.out.flush();
System.err.println("I/O error: " + e.getMessage());
if (options.verbose()) {
System.out.flush();
e.printStackTrace();
}
} catch (IllegalArgumentException e) {
System.out.flush();
System.err.println("Internal Error: " + e.getMessage());
if (options.verbose()) {
System.err.println();
e.printStackTrace();
}
}
} catch (RuntimeException | IOException e) {
System.out.flush();
System.err.println("Unchecked exception: " + e.getMessage());
if (options.verbose()) {
System.out.flush();
e.printStackTrace();
}
}
System.err.flush();
exit(1);
}
Aggregations