Skip to content
Snippets Groups Projects
Commit 3b3688e5 authored by Sean Busbey's avatar Sean Busbey
Browse files

Merge pull request #408 from petergaultney/master

[client] Added basic command line argument error messages to Client.java
parents 1eb6f38a 07118370
No related branches found
No related tags found
No related merge requests found
...@@ -66,7 +66,7 @@ class StatusThread extends Thread ...@@ -66,7 +66,7 @@ class StatusThread extends Thread
* @param statusIntervalSeconds The number of seconds between status updates. * @param statusIntervalSeconds The number of seconds between status updates.
*/ */
public StatusThread(CountDownLatch completeLatch, List<ClientThread> clients, public StatusThread(CountDownLatch completeLatch, List<ClientThread> clients,
String label, boolean standardstatus, int statusIntervalSeconds) String label, boolean standardstatus, int statusIntervalSeconds)
{ {
_completeLatch=completeLatch; _completeLatch=completeLatch;
_clients=clients; _clients=clients;
...@@ -117,7 +117,7 @@ class StatusThread extends Thread ...@@ -117,7 +117,7 @@ class StatusThread extends Thread
* @return The current operation count. * @return The current operation count.
*/ */
private long computeStats(final long startTimeMs, long startIntervalMs, long endIntervalMs, 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"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
long totalops=0; long totalops=0;
...@@ -147,7 +147,7 @@ class StatusThread extends Thread ...@@ -147,7 +147,7 @@ class StatusThread extends Thread
msg.append(d.format(curthroughput)).append(" current ops/sec; "); msg.append(d.format(curthroughput)).append(" current ops/sec; ");
} }
if (todoops != 0) { 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()); msg.append(Measurements.getMeasurements().getSummary());
...@@ -194,32 +194,32 @@ class StatusThread extends Thread ...@@ -194,32 +194,32 @@ class StatusThread extends Thread
* i.e. if there are hours or days worth of seconds, use them. * i.e. if there are hours or days worth of seconds, use them.
*/ */
class RemainingFormatter { class RemainingFormatter {
public static StringBuilder format(long seconds) { public static StringBuilder format(long seconds) {
StringBuilder time = new StringBuilder(); StringBuilder time = new StringBuilder();
long days = TimeUnit.SECONDS.toDays(seconds); long days = TimeUnit.SECONDS.toDays(seconds);
if (days > 0) { if (days > 0) {
time.append(days).append(" days "); time.append(days).append(" days ");
seconds -= TimeUnit.DAYS.toSeconds(days); seconds -= TimeUnit.DAYS.toSeconds(days);
} }
long hours = TimeUnit.SECONDS.toHours(seconds); long hours = TimeUnit.SECONDS.toHours(seconds);
if (hours > 0) { if (hours > 0) {
time.append(hours).append(" hours "); time.append(hours).append(" hours ");
seconds -= TimeUnit.HOURS.toSeconds(hours); seconds -= TimeUnit.HOURS.toSeconds(hours);
} }
/* Only include minute granularity if we're < 1 day. */ /* Only include minute granularity if we're < 1 day. */
if (days < 1) { if (days < 1) {
long minutes = TimeUnit.SECONDS.toMinutes(seconds); long minutes = TimeUnit.SECONDS.toMinutes(seconds);
if (minutes > 0) { if (minutes > 0) {
time.append(minutes).append(" minutes "); time.append(minutes).append(" minutes ");
seconds -= TimeUnit.MINUTES.toSeconds(seconds); seconds -= TimeUnit.MINUTES.toSeconds(seconds);
} }
} }
/* Only bother to include seconds if we're < 1 minute */ /* Only bother to include seconds if we're < 1 minute */
if (time.length() == 0) { if (time.length() == 0) {
time.append(seconds).append(" seconds "); time.append(seconds).append(" seconds ");
} }
return time; return time;
} }
} }
/** /**
...@@ -480,13 +480,13 @@ public class Client ...@@ -480,13 +480,13 @@ public class Client
System.out.println("Usage: java com.yahoo.ycsb.Client [options]"); System.out.println("Usage: java com.yahoo.ycsb.Client [options]");
System.out.println("Options:"); System.out.println("Options:");
System.out.println(" -threads n: execute using n threads (default: 1) - can also be specified as the \n" + 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" + 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(" -load: run the loading phase of the workload");
System.out.println(" -t: run the transactions phase of the workload (default)"); 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" + 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(" -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(" 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;"); System.out.println(" -p name=value: specify a property to be passed to the DB and workloads;");
...@@ -521,7 +521,7 @@ public class Client ...@@ -521,7 +521,7 @@ public class Client
* @throws IOException Either failed to write to output stream or failed to close it. * @throws IOException Either failed to write to output stream or failed to close it.
*/ */
private static void exportMeasurements(Properties props, int opcount, long runtime) private static void exportMeasurements(Properties props, int opcount, long runtime)
throws IOException throws IOException
{ {
MeasurementsExporter exporter = null; MeasurementsExporter exporter = null;
try try
...@@ -545,7 +545,7 @@ public class Client ...@@ -545,7 +545,7 @@ public class Client
} catch (Exception e) } catch (Exception e)
{ {
System.err.println("Could not find exporter " + exporterStr System.err.println("Could not find exporter " + exporterStr
+ ", will use default text reporter."); + ", will use default text reporter.");
e.printStackTrace(); e.printStackTrace();
exporter = new TextMeasurementsExporter(out); exporter = new TextMeasurementsExporter(out);
} }
...@@ -582,6 +582,7 @@ public class Client ...@@ -582,6 +582,7 @@ public class Client
if (args.length==0) if (args.length==0)
{ {
usageMessage(); usageMessage();
System.out.println("At least one argument specifying a workload is required.");
System.exit(0); System.exit(0);
} }
...@@ -593,6 +594,7 @@ public class Client ...@@ -593,6 +594,7 @@ public class Client
if (argindex>=args.length) if (argindex>=args.length)
{ {
usageMessage(); usageMessage();
System.out.println("Missing argument value for -threads.");
System.exit(0); System.exit(0);
} }
int tcount=Integer.parseInt(args[argindex]); int tcount=Integer.parseInt(args[argindex]);
...@@ -605,6 +607,7 @@ public class Client ...@@ -605,6 +607,7 @@ public class Client
if (argindex>=args.length) if (argindex>=args.length)
{ {
usageMessage(); usageMessage();
System.out.println("Missing argument value for -target.");
System.exit(0); System.exit(0);
} }
int ttarget=Integer.parseInt(args[argindex]); int ttarget=Integer.parseInt(args[argindex]);
...@@ -632,6 +635,7 @@ public class Client ...@@ -632,6 +635,7 @@ public class Client
if (argindex>=args.length) if (argindex>=args.length)
{ {
usageMessage(); usageMessage();
System.out.println("Missing argument value for -db.");
System.exit(0); System.exit(0);
} }
props.setProperty(DB_PROPERTY,args[argindex]); props.setProperty(DB_PROPERTY,args[argindex]);
...@@ -643,6 +647,7 @@ public class Client ...@@ -643,6 +647,7 @@ public class Client
if (argindex>=args.length) if (argindex>=args.length)
{ {
usageMessage(); usageMessage();
System.out.println("Missing argument value for -l.");
System.exit(0); System.exit(0);
} }
label=args[argindex]; label=args[argindex];
...@@ -654,6 +659,7 @@ public class Client ...@@ -654,6 +659,7 @@ public class Client
if (argindex>=args.length) if (argindex>=args.length)
{ {
usageMessage(); usageMessage();
System.out.println("Missing argument value for -P.");
System.exit(0); System.exit(0);
} }
String propfile=args[argindex]; String propfile=args[argindex];
...@@ -666,6 +672,7 @@ public class Client ...@@ -666,6 +672,7 @@ public class Client
} }
catch (IOException e) catch (IOException e)
{ {
System.out.println("Unable to open the properties file " + propfile);
System.out.println(e.getMessage()); System.out.println(e.getMessage());
System.exit(0); System.exit(0);
} }
...@@ -685,12 +692,14 @@ public class Client ...@@ -685,12 +692,14 @@ public class Client
if (argindex>=args.length) if (argindex>=args.length)
{ {
usageMessage(); usageMessage();
System.out.println("Missing argument value for -p");
System.exit(0); System.exit(0);
} }
int eq=args[argindex].indexOf('='); int eq=args[argindex].indexOf('=');
if (eq<0) if (eq<0)
{ {
usageMessage(); usageMessage();
System.out.println("Argument '-p' expected to be in key=value format (e.g., -p operationcount=99999)");
System.exit(0); System.exit(0);
} }
...@@ -702,8 +711,8 @@ public class Client ...@@ -702,8 +711,8 @@ public class Client
} }
else else
{ {
System.out.println("Unknown option "+args[argindex]);
usageMessage(); usageMessage();
System.out.println("Unknown option " + args[argindex]);
System.exit(0); System.exit(0);
} }
...@@ -713,9 +722,15 @@ public class Client ...@@ -713,9 +722,15 @@ public class Client
} }
} }
if (argindex!=args.length) if (argindex != args.length)
{ {
usageMessage(); 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); System.exit(0);
} }
...@@ -736,6 +751,7 @@ public class Client ...@@ -736,6 +751,7 @@ public class Client
if (!checkRequiredProperties(props)) if (!checkRequiredProperties(props))
{ {
System.out.println("Failed check required properties.");
System.exit(0); System.exit(0);
} }
...@@ -769,21 +785,21 @@ public class Client ...@@ -769,21 +785,21 @@ public class Client
//but only do so if it is taking longer than 2 seconds //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) //(showing the message right away if the setup wasn't taking very long was confusing people)
Thread warningthread=new Thread() Thread warningthread=new Thread()
{
@Override
public void run()
{ {
try @Override
public void run()
{ {
sleep(2000); try
} {
catch (InterruptedException e) sleep(2000);
{ }
return; 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(); warningthread.start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment