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

[client] Added basic command line argument error messages to Client.java #408

Merged
merged 1 commit into from
Feb 15, 2016
Merged
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
112 changes: 64 additions & 48 deletions core/src/main/java/com/yahoo/ycsb/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class StatusThread extends Thread
* @param statusIntervalSeconds The number of seconds between status updates.
*/
public StatusThread(CountDownLatch completeLatch, List<ClientThread> clients,
String label, boolean standardstatus, int statusIntervalSeconds)
String label, boolean standardstatus, int statusIntervalSeconds)
{
_completeLatch=completeLatch;
_clients=clients;
Expand Down Expand Up @@ -117,7 +117,7 @@ public void run()
* @return The current operation count.
*/
private long computeStats(final long startTimeMs, long startIntervalMs, long endIntervalMs,
long lastTotalOps) {
long lastTotalOps) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");

long totalops=0;
Expand Down Expand Up @@ -147,7 +147,7 @@ private long computeStats(final long startTimeMs, long startIntervalMs, long end
msg.append(d.format(curthroughput)).append(" current ops/sec; ");
}
if (todoops != 0) {
msg.append("est completion in ").append(RemainingFormatter.format(estremaining));
msg.append("est completion in ").append(RemainingFormatter.format(estremaining));
}

msg.append(Measurements.getMeasurements().getSummary());
Expand Down Expand Up @@ -194,32 +194,32 @@ private boolean waitForClientsUntil(long deadline) {
* i.e. if there are hours or days worth of seconds, use them.
*/
class RemainingFormatter {
public static StringBuilder format(long seconds) {
StringBuilder time = new StringBuilder();
long days = TimeUnit.SECONDS.toDays(seconds);
if (days > 0) {
time.append(days).append(" days ");
seconds -= TimeUnit.DAYS.toSeconds(days);
}
long hours = TimeUnit.SECONDS.toHours(seconds);
if (hours > 0) {
time.append(hours).append(" hours ");
seconds -= TimeUnit.HOURS.toSeconds(hours);
}
/* Only include minute granularity if we're < 1 day. */
if (days < 1) {
long minutes = TimeUnit.SECONDS.toMinutes(seconds);
if (minutes > 0) {
time.append(minutes).append(" minutes ");
seconds -= TimeUnit.MINUTES.toSeconds(seconds);
}
}
/* Only bother to include seconds if we're < 1 minute */
if (time.length() == 0) {
time.append(seconds).append(" seconds ");
}
return time;
}
public static StringBuilder format(long seconds) {
StringBuilder time = new StringBuilder();
long days = TimeUnit.SECONDS.toDays(seconds);
if (days > 0) {
time.append(days).append(" days ");
seconds -= TimeUnit.DAYS.toSeconds(days);
}
long hours = TimeUnit.SECONDS.toHours(seconds);
if (hours > 0) {
time.append(hours).append(" hours ");
seconds -= TimeUnit.HOURS.toSeconds(hours);
}
/* Only include minute granularity if we're < 1 day. */
if (days < 1) {
long minutes = TimeUnit.SECONDS.toMinutes(seconds);
if (minutes > 0) {
time.append(minutes).append(" minutes ");
seconds -= TimeUnit.MINUTES.toSeconds(seconds);
}
}
/* Only bother to include seconds if we're < 1 minute */
if (time.length() == 0) {
time.append(seconds).append(" seconds ");
}
return time;
}
}

/**
Expand Down Expand Up @@ -475,13 +475,13 @@ public static void usageMessage()
System.out.println("Usage: java com.yahoo.ycsb.Client [options]");
System.out.println("Options:");
System.out.println(" -threads n: execute using n threads (default: 1) - can also be specified as the \n" +
" \"threadcount\" property using -p");
" \"threadcount\" property using -p");
System.out.println(" -target n: attempt to do n operations per second (default: unlimited) - can also\n" +
" be specified as the \"target\" property using -p");
" be specified as the \"target\" property using -p");
System.out.println(" -load: run the loading phase of the workload");
System.out.println(" -t: run the transactions phase of the workload (default)");
System.out.println(" -db dbname: specify the name of the DB to use (default: com.yahoo.ycsb.BasicDB) - \n" +
" can also be specified as the \"db\" property using -p");
" can also be specified as the \"db\" property using -p");
System.out.println(" -P propertyfile: load properties from the given file. Multiple files can");
System.out.println(" be specified, and will be processed in the order specified");
System.out.println(" -p name=value: specify a property to be passed to the DB and workloads;");
Expand Down Expand Up @@ -516,7 +516,7 @@ public static boolean checkRequiredProperties(Properties props)
* @throws IOException Either failed to write to output stream or failed to close it.
*/
private static void exportMeasurements(Properties props, int opcount, long runtime)
throws IOException
throws IOException
{
MeasurementsExporter exporter = null;
try
Expand All @@ -540,7 +540,7 @@ private static void exportMeasurements(Properties props, int opcount, long runti
} catch (Exception e)
{
System.err.println("Could not find exporter " + exporterStr
+ ", will use default text reporter.");
+ ", will use default text reporter.");
e.printStackTrace();
exporter = new TextMeasurementsExporter(out);
}
Expand Down Expand Up @@ -577,6 +577,7 @@ public static void main(String[] args)
if (args.length==0)
{
usageMessage();
System.out.println("At least one argument specifying a workload is required.");
System.exit(0);
}

Expand All @@ -588,6 +589,7 @@ public static void main(String[] args)
if (argindex>=args.length)
{
usageMessage();
System.out.println("Missing argument value for -threads.");
System.exit(0);
}
int tcount=Integer.parseInt(args[argindex]);
Expand All @@ -600,6 +602,7 @@ else if (args[argindex].compareTo("-target")==0)
if (argindex>=args.length)
{
usageMessage();
System.out.println("Missing argument value for -target.");
System.exit(0);
}
int ttarget=Integer.parseInt(args[argindex]);
Expand Down Expand Up @@ -627,6 +630,7 @@ else if (args[argindex].compareTo("-db")==0)
if (argindex>=args.length)
{
usageMessage();
System.out.println("Missing argument value for -db.");
System.exit(0);
}
props.setProperty(DB_PROPERTY,args[argindex]);
Expand All @@ -638,6 +642,7 @@ else if (args[argindex].compareTo("-l")==0)
if (argindex>=args.length)
{
usageMessage();
System.out.println("Missing argument value for -l.");
System.exit(0);
}
label=args[argindex];
Expand All @@ -649,6 +654,7 @@ else if (args[argindex].compareTo("-P")==0)
if (argindex>=args.length)
{
usageMessage();
System.out.println("Missing argument value for -P.");
System.exit(0);
}
String propfile=args[argindex];
Expand All @@ -661,6 +667,7 @@ else if (args[argindex].compareTo("-P")==0)
}
catch (IOException e)
{
System.out.println("Unable to open the properties file " + propfile);
System.out.println(e.getMessage());
System.exit(0);
}
Expand All @@ -680,12 +687,14 @@ else if (args[argindex].compareTo("-p")==0)
if (argindex>=args.length)
{
usageMessage();
System.out.println("Missing argument value for -p");
System.exit(0);
}
int eq=args[argindex].indexOf('=');
if (eq<0)
{
usageMessage();
System.out.println("Argument '-p' expected to be in key=value format (e.g., -p operationcount=99999)");
System.exit(0);
}

Expand All @@ -697,8 +706,8 @@ else if (args[argindex].compareTo("-p")==0)
}
else
{
System.out.println("Unknown option "+args[argindex]);
usageMessage();
System.out.println("Unknown option " + args[argindex]);
System.exit(0);
}

Expand All @@ -708,9 +717,15 @@ else if (args[argindex].compareTo("-p")==0)
}
}

if (argindex!=args.length)
if (argindex != args.length)
{
usageMessage();
if (argindex < args.length) {
System.out.println("An argument value without corresponding argument specifier (e.g., -p, -s) was found. "
+ "We expected an argument specifier and instead found " + args[argindex]);
} else {
System.out.println("An argument specifier without corresponding value was found at the end of the supplied command line arguments.");
}
System.exit(0);
}

Expand All @@ -731,6 +746,7 @@ else if (args[argindex].compareTo("-p")==0)

if (!checkRequiredProperties(props))
{
System.out.println("Failed check required properties.");
System.exit(0);
}

Expand Down Expand Up @@ -762,21 +778,21 @@ else if (args[argindex].compareTo("-p")==0)
//but only do so if it is taking longer than 2 seconds
//(showing the message right away if the setup wasn't taking very long was confusing people)
Thread warningthread=new Thread()
{
@Override
public void run()
{
try
@Override
public void run()
{
sleep(2000);
}
catch (InterruptedException e)
{
return;
try
{
sleep(2000);
}
catch (InterruptedException e)
{
return;
}
System.err.println(" (might take a few minutes for large data sets)");
}
System.err.println(" (might take a few minutes for large data sets)");
}
};
};

warningthread.start();

Expand Down