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

Upgrade clap to 3.0.0 #1261

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 11 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,22 @@
// 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 {
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
72 changes: 33 additions & 39 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,46 @@
// 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)]
#[clap(rename_all = "SCREAMING_SNAKE_CASE")]
enum Mode {
ArrowToJson,
JsonToArrow,
Validate,
}

#[derive(Debug, Parser)]
#[clap(author, version, about("rust arrow-json-integration-test"), long_about = None)]
struct Args {
#[clap(short, long)]
integration: bool,
#[clap(short, long, help("Path to ARROW file"))]
arrow: String,
#[clap(short, long, help("Path to JSON file"))]
json: String,
#[clap(arg_enum, short, long, default_value_t = Mode::Validate, help="Mode of integration testing tool")]
mode: Mode,
#[clap(short, long)]
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();

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),
let args = Args::parse();
let arrow_file = args.arrow;
let json_file = args.json;
let verbose = args.verbose;
match args.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
61 changes: 35 additions & 26 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,53 @@
// 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,
#[clap(name = "auth:basic_proto")]
AuthBasicProto,
}

#[derive(Debug, Parser)]
#[clap(author, version, about("rust flight-test-integration-client"), long_about = None)]
struct Args {
#[clap(long, help = "host of flight server")]
host: String,
#[clap(long, help = "port of flight server")]
port: u16,
#[clap(
short,
long,
help = "path to the descriptor file, only used when scenario is not provided"
)]
path: Option<String>,
#[clap(long, arg_enum)]
scenario: Option<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 {
Some(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?
Some(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)
let path = args.path.expect("No path is given");
flight_client_scenarios::integration_test::run_scenario(&host, port, &path)
.await?;
}
}
Expand Down
39 changes: 22 additions & 17 deletions integration-testing/src/bin/flight-test-integration-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,43 @@
// 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,
#[clap(name = "auth:basic_proto")]
AuthBasicProto,
}

#[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)]
scenario: Option<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 {
Some(Scenario::Middleware) => {
flight_server_scenarios::middleware::scenario_setup(port).await?
}
Some("auth:basic_proto") => {
Some(Scenario::AuthBasicProto) => {
flight_server_scenarios::auth_basic_proto::scenario_setup(port).await?
}
Some(scenario_name) => unimplemented!("Scenario not found: {}", scenario_name),
None => {
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"
futures = { version = "0.3", optional = true }
Expand Down
Loading