stress tool to return appropriate exit code on failure
patch by Tyler Patterson; reviewed by Pavel Yaskevich for CASSANDRA-4188
diff --git a/CHANGES.txt b/CHANGES.txt
index bd508c6..ad301db 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,7 @@
* Avoids possible deadlock during bootstrap (CASSANDRA-4159)
* fix stress tool that hangs forever on timeout or error (CASSANDRA-4128)
* Fix super columns bug where cache is not updated (CASSANDRA-4190)
+ * stress tool to return appropriate exit code on failure (CASSANDRA-4188)
1.0.9
diff --git a/tools/stress/src/org/apache/cassandra/stress/Stress.java b/tools/stress/src/org/apache/cassandra/stress/Stress.java
index c5e65f8..b490d69 100644
--- a/tools/stress/src/org/apache/cassandra/stress/Stress.java
+++ b/tools/stress/src/org/apache/cassandra/stress/Stress.java
@@ -66,7 +66,7 @@
{
while (!socket.isClosed() && (line = inp.readLine()) != null)
{
- if (line.equals("END"))
+ if (line.equals("END") || line.equals("FAILURE"))
{
out.writeInt(1);
break;
@@ -88,7 +88,10 @@
}
else
{
- new StressAction(session, outStream).start();
+ StressAction stressAction = new StressAction(session, outStream);
+ stressAction.start();
+ stressAction.join();
+ System.exit(stressAction.getReturnCode());
}
}
diff --git a/tools/stress/src/org/apache/cassandra/stress/StressAction.java b/tools/stress/src/org/apache/cassandra/stress/StressAction.java
index f0a9f49..d043b66 100644
--- a/tools/stress/src/org/apache/cassandra/stress/StressAction.java
+++ b/tools/stress/src/org/apache/cassandra/stress/StressAction.java
@@ -37,6 +37,11 @@
private volatile boolean stop = false;
+ public static final int SUCCESS = 0;
+ public static final int FAILURE = 1;
+
+ private volatile int returnCode = -1;
+
public StressAction(Session session, PrintStream out)
{
client = session;
@@ -137,11 +142,28 @@
}
}
+ // if any consumer failed, set the return code to failure.
+ returnCode = SUCCESS;
if (producer.isAlive())
+ {
producer.interrupt(); // if producer is still alive it means that we had errors in the consumers
+ returnCode = FAILURE;
+ }
+ for (Consumer consumer : consumers)
+ if (consumer.getReturnCode() == FAILURE)
+ returnCode = FAILURE;
- // marking an end of the output to the client
- output.println("END");
+ if (returnCode == SUCCESS)
+ // marking an end of the output to the client
+ output.println("END");
+ else
+ output.println("FAILURE");
+
+ }
+
+ public int getReturnCode()
+ {
+ return returnCode;
}
/**
@@ -184,6 +206,7 @@
{
private final int items;
private volatile boolean stop = false;
+ private volatile int returnCode = StressAction.SUCCESS;
public Consumer(int toConsume)
{
@@ -208,11 +231,13 @@
if (output == null)
{
System.err.println(e.getMessage());
+ returnCode = StressAction.FAILURE;
System.exit(-1);
}
output.println(e.getMessage());
+ returnCode = StressAction.FAILURE;
break;
}
}
@@ -222,6 +247,11 @@
{
stop = true;
}
+
+ public int getReturnCode()
+ {
+ return returnCode;
+ }
}
private Operation createOperation(int index)