Repository: cassandra
Updated Branches:
  refs/heads/trunk 2ab629937 -> 704374408


Make Stress exit with non-zero status after failure

patch by Stefania Alborghetti; reviewed by Benjamin Lerer for CASSANDRA-10340


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/70437440
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/70437440
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/70437440

Branch: refs/heads/trunk
Commit: 70437440853c8af6a2c6c63214bc1bd477e3e504
Parents: 2ab6299
Author: Stefania Alborghetti <[email protected]>
Authored: Thu Mar 17 15:35:08 2016 +0100
Committer: Benjamin Lerer <[email protected]>
Committed: Thu Mar 17 15:38:46 2016 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../src/org/apache/cassandra/stress/Stress.java | 26 +++++++-----
 .../apache/cassandra/stress/StressAction.java   | 20 +++++++---
 .../stress/settings/StressSettings.java         | 42 ++++++++++----------
 4 files changed, 52 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/70437440/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4366c08..149b1d1 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.6
+ * Stress should exit with non-zero status after failure (CASSANDRA-10340)
  * Add client to cqlsh SHOW_SESSION (CASSANDRA-8958)
  * Fix nodetool tablestats keyspace level metrics (CASSANDRA-11226)
  * Store repair options in parent_repair_history (CASSANDRA-11244)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/70437440/tools/stress/src/org/apache/cassandra/stress/Stress.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/Stress.java 
b/tools/stress/src/org/apache/cassandra/stress/Stress.java
index aeddb4a..874f515 100644
--- a/tools/stress/src/org/apache/cassandra/stress/Stress.java
+++ b/tools/stress/src/org/apache/cassandra/stress/Stress.java
@@ -58,19 +58,31 @@ public final class Stress
         if (FBUtilities.isWindows())
             WindowsTimer.startTimerPeriod(1);
 
+        int exitCode = run(arguments);
+
+        if (FBUtilities.isWindows())
+            WindowsTimer.endTimerPeriod(1);
+
+        System.exit(exitCode);
+    }
+
+
+    private static int run(String[] arguments)
+    {
         try
         {
-
             final StressSettings settings;
             try
             {
                 settings = StressSettings.parse(arguments);
+                if (settings == null)
+                    return 0; // special settings action
             }
             catch (IllegalArgumentException e)
             {
+                System.out.printf("%s\n", e.getMessage());
                 printHelpMessage();
-                e.printStackTrace();
-                return;
+                return 1;
             }
 
             MultiPrintStream logout = settings.log.getOutput();
@@ -128,14 +140,10 @@ public final class Stress
         catch (Throwable t)
         {
             t.printStackTrace();
-        }
-        finally
-        {
-            if (FBUtilities.isWindows())
-                WindowsTimer.endTimerPeriod(1);
-            System.exit(0);
+            return 1;
         }
 
+        return 0;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/70437440/tools/stress/src/org/apache/cassandra/stress/StressAction.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/StressAction.java 
b/tools/stress/src/org/apache/cassandra/stress/StressAction.java
index ebe6270..94a41d2 100644
--- a/tools/stress/src/org/apache/cassandra/stress/StressAction.java
+++ b/tools/stress/src/org/apache/cassandra/stress/StressAction.java
@@ -79,6 +79,9 @@ public class StressAction implements Runnable
             output.println("FAILURE");
 
         settings.disconnect();
+
+        if (!success)
+            throw new RuntimeException("Failed to execute stress action");
     }
 
     // type provided separately to support recursive call for mixed command 
with each command type it is performing
@@ -101,8 +104,11 @@ public class StressAction implements Runnable
             // we need to warm up all the nodes in the cluster ideally, but we 
may not be the only stress instance;
             // so warm up all the nodes we're speaking to only.
             output.println(String.format("Warming up %s with %d 
iterations...", single.desc(), iterations));
-            run(single, threads, iterations, 0, null, null, warmupOutput, 
true);
+            boolean success = null != run(single, threads, iterations, 0, 
null, null, warmupOutput, true);
+            if (!success)
+                throw new RuntimeException("Failed to execute warmup");
         }
+
     }
 
     // TODO : permit varying more than just thread count
@@ -332,13 +338,10 @@ public class StressAction implements Runnable
                     catch (Exception e)
                     {
                         if (output == null)
-                        {
                             System.err.println(e.getMessage());
-                            success = false;
-                            System.exit(-1);
-                        }
+                        else
+                            e.printStackTrace(output);
 
-                        e.printStackTrace(output);
                         success = false;
                         workManager.stop();
                         metrics.cancel();
@@ -346,6 +349,11 @@ public class StressAction implements Runnable
                     }
                 }
             }
+            catch (Exception e)
+            {
+                System.err.println(e.getMessage());
+                success = false;
+            }
             finally
             {
                 done.countDown();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/70437440/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
----------------------------------------------------------------------
diff --git 
a/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java 
b/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
index 6625bc8..069454d 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
@@ -184,6 +184,8 @@ public class StressSettings implements Serializable
     }
 
     private static volatile JavaDriverClient client;
+    private static volatile int numFailures;
+    private static int MAX_NUM_FAILURES = 10;
 
     public JavaDriverClient getJavaDriverClient()
     {
@@ -195,9 +197,12 @@ public class StressSettings implements Serializable
         if (client != null)
             return client;
 
-        try
+        synchronized (this)
         {
-            synchronized (this)
+            if (numFailures >= MAX_NUM_FAILURES)
+                throw new RuntimeException("Failed to create client too many 
times");
+
+            try
             {
                 String currentNode = node.randomNode();
                 if (client != null)
@@ -211,10 +216,11 @@ public class StressSettings implements Serializable
 
                 return client = c;
             }
-        }
-        catch (Exception e)
-        {
-            throw new RuntimeException(e);
+            catch (Exception e)
+            {
+                numFailures +=1;
+                throw new RuntimeException(e);
+            }
         }
     }
 
@@ -228,22 +234,14 @@ public class StressSettings implements Serializable
 
     public static StressSettings parse(String[] args)
     {
-        try
-        {
-            args = repairParams(args);
-            final Map<String, String[]> clArgs = parseMap(args);
-            if (clArgs.containsKey("legacy"))
-                return Legacy.build(Arrays.copyOfRange(args, 1, args.length));
-            if (SettingsMisc.maybeDoSpecial(clArgs))
-                System.exit(1);
-            return get(clArgs);
-        }
-        catch (IllegalArgumentException e)
-        {
-            System.out.println(e.getMessage());
-            System.exit(1);
-            throw new AssertionError();
-        }
+        args = repairParams(args);
+        final Map<String, String[]> clArgs = parseMap(args);
+        if (clArgs.containsKey("legacy"))
+            return Legacy.build(Arrays.copyOfRange(args, 1, args.length));
+        if (SettingsMisc.maybeDoSpecial(clArgs))
+            return null;
+        return get(clArgs);
+
     }
 
     private static String[] repairParams(String[] args)

Reply via email to