Skip to content

Commit

Permalink
upgrade clap
Browse files Browse the repository at this point in the history
  • Loading branch information
jimexist committed Feb 2, 2022
1 parent 88a9be9 commit de64bd7
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 222 deletions.
2 changes: 1 addition & 1 deletion integration-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ logging = ["tracing-subscriber"]
arrow = { path = "../arrow" }
arrow-flight = { path = "../arrow-flight" }
async-trait = "0.1.41"
clap = "2.33"
clap = { version = "3", features = ["derive", "env"] }
futures = "0.3"
hex = "0.4"
prost = "0.9"
Expand Down
19 changes: 12 additions & 7 deletions integration-testing/src/bin/arrow-file-to-stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
// specific language governing permissions and limitations
// under the License.

use std::env;
use std::fs::File;
use std::io::{self, BufReader};

use arrow::error::Result;
use arrow::ipc::reader::FileReader;
use arrow::ipc::writer::StreamWriter;
use clap::Parser;
use std::fs::File;
use std::io::{self, BufReader};

#[derive(Debug, Parser)]
#[clap(author, version, about("Read an arrow file and stream to stdout"), long_about = None)]
struct Args {
#[clap(short, long)]
file_name: String,
}

fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
let filename = &args[1];
let f = File::open(filename)?;
let args = Args::parse();
let f = File::open(&args.file_name)?;
let reader = BufReader::new(f);
let mut reader = FileReader::try_new(reader)?;
let schema = reader.schema();
Expand Down
70 changes: 33 additions & 37 deletions integration-testing/src/bin/arrow-json-integration-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,48 @@
// specific language governing permissions and limitations
// under the License.

use std::fs::File;

use clap::{App, Arg};

use arrow::error::{ArrowError, Result};
use arrow::ipc::reader::FileReader;
use arrow::ipc::writer::FileWriter;
use arrow::util::integration_util::*;
use arrow_integration_testing::read_json_file;
use clap::Parser;
use std::fs::File;

#[derive(clap::ArgEnum, Debug, Clone)]
enum Mode {
ArrowToJson,
JsonToArrow,
Validate,
}

#[derive(Debug, Parser)]
#[clap(author, version, about("rust arrow-json-integration-test"), long_about = None)]
struct Args {
#[clap(long, help("The path to the JSON file to read."))]
integration: String,
#[clap(long, help("path to ARROW file"))]
arrow: String,
#[clap(long, help("path to JSON file"))]
json: String,
#[clap(arg_enum, long, default_value_t = Mode::Validate, help="mode of integration testing tool")]
mode: Mode,
#[clap(long, help("mode of integration testing tool"))]
verbose: bool,
}

fn main() -> Result<()> {
let matches = App::new("rust arrow-json-integration-test")
.arg(Arg::with_name("integration")
.long("integration"))
.arg(Arg::with_name("arrow")
.long("arrow")
.help("path to ARROW file")
.takes_value(true))
.arg(Arg::with_name("json")
.long("json")
.help("path to JSON file")
.takes_value(true))
.arg(Arg::with_name("mode")
.long("mode")
.help("mode of integration testing tool (ARROW_TO_JSON, JSON_TO_ARROW, VALIDATE)")
.takes_value(true)
.default_value("VALIDATE"))
.arg(Arg::with_name("verbose")
.long("verbose")
.help("enable/disable verbose mode"))
.get_matches();

let arrow_file = matches
.value_of("arrow")
.expect("must provide path to arrow file");
let json_file = matches
.value_of("json")
.expect("must provide path to json file");
let mode = matches.value_of("mode").unwrap();
let verbose = true; //matches.value_of("verbose").is_some();
let args = Args::parse();

let arrow_file = args.arrow;
let json_file = args.json;
let mode = args.mode;
let verbose = args.verbose;

match mode {
"JSON_TO_ARROW" => json_to_arrow(json_file, arrow_file, verbose),
"ARROW_TO_JSON" => arrow_to_json(arrow_file, json_file, verbose),
"VALIDATE" => validate(arrow_file, json_file, verbose),
_ => panic!("mode {} not supported", mode),
Mode::JsonToArrow => json_to_arrow(&json_file, &arrow_file, verbose),
Mode::ArrowToJson => arrow_to_json(&arrow_file, &json_file, verbose),
Mode::Validate => validate(&arrow_file, &json_file, verbose),
}
}

Expand Down
59 changes: 32 additions & 27 deletions integration-testing/src/bin/flight-test-integration-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,49 @@
// under the License.

use arrow_integration_testing::flight_client_scenarios;

use clap::{App, Arg};

use clap::Parser;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

#[derive(clap::ArgEnum, Debug, Clone)]
enum Scenario {
Middleware,
AuthBasicProto,
Customized,
}

#[derive(Debug, Parser)]
#[clap(author, version, about("rust flight-test-integration-client"), long_about = None)]
struct Args {
#[clap(long)]
host: String,
#[clap(long)]
port: u16,
#[clap(long)]
path: String,
#[clap(long, arg_enum, default_value_t = Scenario::Customized)]
scenario: Scenario,
}

#[tokio::main]
async fn main() -> Result {
#[cfg(feature = "logging")]
tracing_subscriber::fmt::init();

let matches = App::new("rust flight-test-integration-client")
.arg(Arg::with_name("host").long("host").takes_value(true))
.arg(Arg::with_name("port").long("port").takes_value(true))
.arg(Arg::with_name("path").long("path").takes_value(true))
.arg(
Arg::with_name("scenario")
.long("scenario")
.takes_value(true),
)
.get_matches();

let host = matches.value_of("host").expect("Host is required");
let port = matches.value_of("port").expect("Port is required");
let args = Args::parse();
let host = args.host;
let port = args.port;

match matches.value_of("scenario") {
Some("middleware") => {
flight_client_scenarios::middleware::run_scenario(host, port).await?
match args.scenario {
Scenario::Middleware => {
flight_client_scenarios::middleware::run_scenario(&host, port).await?
}
Some("auth:basic_proto") => {
flight_client_scenarios::auth_basic_proto::run_scenario(host, port).await?
Scenario::AuthBasicProto => {
flight_client_scenarios::auth_basic_proto::run_scenario(&host, port).await?
}
Some(scenario_name) => unimplemented!("Scenario not found: {}", scenario_name),
None => {
let path = matches
.value_of("path")
.expect("Path is required if scenario is not specified");
flight_client_scenarios::integration_test::run_scenario(host, port, path)
Scenario::Customized => {
let path = args.path;
flight_client_scenarios::integration_test::run_scenario(&host, port, &path)
.await?;
}
}
Expand Down
41 changes: 23 additions & 18 deletions integration-testing/src/bin/flight-test-integration-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,44 @@
// specific language governing permissions and limitations
// under the License.

use clap::{App, Arg};

use arrow_integration_testing::flight_server_scenarios;
use clap::Parser;

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

#[derive(clap::ArgEnum, Debug, Clone)]
enum Scenario {
Middleware,
AuthBasicProto,
Customized,
}

#[derive(Debug, Parser)]
#[clap(author, version, about("rust flight-test-integration-server"), long_about = None)]
struct Args {
#[clap(long)]
port: u16,
#[clap(long, arg_enum, default_value_t = Scenario::Customized)]
scenario: Scenario,
}

#[tokio::main]
async fn main() -> Result {
#[cfg(feature = "logging")]
tracing_subscriber::fmt::init();

let matches = App::new("rust flight-test-integration-server")
.about("Integration testing server for Flight.")
.arg(Arg::with_name("port").long("port").takes_value(true))
.arg(
Arg::with_name("scenario")
.long("scenario")
.takes_value(true),
)
.get_matches();

let port = matches.value_of("port").unwrap_or("0");
let args = Args::parse();
let port = args.port;

match matches.value_of("scenario") {
Some("middleware") => {
match args.scenario {
Scenario::Middleware => {
flight_server_scenarios::middleware::scenario_setup(port).await?
}
Some("auth:basic_proto") => {
Scenario::AuthBasicProto => {
flight_server_scenarios::auth_basic_proto::scenario_setup(port).await?
}
Some(scenario_name) => unimplemented!("Scenario not found: {}", scenario_name),
None => {
Scenario::Customized => {
flight_server_scenarios::integration_test::scenario_setup(port).await?;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;

type Client = FlightServiceClient<tonic::transport::Channel>;

pub async fn run_scenario(host: &str, port: &str) -> Result {
pub async fn run_scenario(host: &str, port: u16) -> Result {
let url = format!("http://{}:{}", host, port);
let mut client = FlightServiceClient::connect(url).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;

type Client = FlightServiceClient<tonic::transport::Channel>;

pub async fn run_scenario(host: &str, port: &str, path: &str) -> Result {
pub async fn run_scenario(host: &str, port: u16, path: &str) -> Result {
let url = format!("http://{}:{}", host, port);

let client = FlightServiceClient::connect(url).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tonic::{Request, Status};
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

pub async fn run_scenario(host: &str, port: &str) -> Result {
pub async fn run_scenario(host: &str, port: u16) -> Result {
let url = format!("http://{}:{}", host, port);
let conn = tonic::transport::Endpoint::new(url)?.connect().await?;
let mut client = FlightServiceClient::with_interceptor(conn, middleware_interceptor);
Expand Down
2 changes: 1 addition & 1 deletion integration-testing/src/flight_server_scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod middleware;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

pub async fn listen_on(port: &str) -> Result<SocketAddr> {
pub async fn listen_on(port: u16) -> Result<SocketAddr> {
let addr: SocketAddr = format!("0.0.0.0:{}", port).parse()?;

let listener = TcpListener::bind(addr).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use prost::Message;

use crate::{AUTH_PASSWORD, AUTH_USERNAME};

pub async fn scenario_setup(port: &str) -> Result {
pub async fn scenario_setup(port: u16) -> Result {
let service = AuthBasicProtoScenarioImpl {
username: AUTH_USERNAME.into(),
password: AUTH_PASSWORD.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type TonicStream<T> = Pin<Box<dyn Stream<Item = T> + Send + Sync + 'static>>;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

pub async fn scenario_setup(port: &str) -> Result {
pub async fn scenario_setup(port: u16) -> Result {
let addr = super::listen_on(port).await?;

let service = FlightServiceImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type TonicStream<T> = Pin<Box<dyn Stream<Item = T> + Send + Sync + 'static>>;
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

pub async fn scenario_setup(port: &str) -> Result {
pub async fn scenario_setup(port: u16) -> Result {
let service = MiddlewareScenarioImpl {};
let svc = FlightServiceServer::new(service);
let addr = super::listen_on(port).await?;
Expand Down
2 changes: 1 addition & 1 deletion parquet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ chrono = { version = "0.4", default-features = false }
num-bigint = "0.4"
arrow = { path = "../arrow", version = "8.0.0", optional = true, default-features = false, features = ["ipc"] }
base64 = { version = "0.13", optional = true }
clap = { version = "2.33.3", optional = true }
clap = { version = "3", optional = true, features = ["derive", "env"] }
serde_json = { version = "1.0", features = ["preserve_order"], optional = true }
rand = "0.8"

Expand Down
Loading

0 comments on commit de64bd7

Please sign in to comment.