stress tool to return appropriate exit code on failure

patch by Tyler Patterson; reviewed by Pavel Yaskevich for CASSANDRA-4188
This commit is contained in:
Pavel Yaskevich 2012-05-03 03:29:34 +03:00
parent 48a22695f4
commit f20badb685
3 changed files with 38 additions and 4 deletions

View File

@ -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

View File

@ -66,7 +66,7 @@ public final class Stress
{
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 @@ public final class Stress
}
else
{
new StressAction(session, outStream).start();
StressAction stressAction = new StressAction(session, outStream);
stressAction.start();
stressAction.join();
System.exit(stressAction.getReturnCode());
}
}

View File

@ -37,6 +37,11 @@ public class StressAction extends Thread
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 @@ public class StressAction extends Thread
}
}
// 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 @@ public class StressAction extends Thread
{
private final int items;
private volatile boolean stop = false;
private volatile int returnCode = StressAction.SUCCESS;
public Consumer(int toConsume)
{
@ -208,11 +231,13 @@ public class StressAction extends Thread
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 @@ public class StressAction extends Thread
{
stop = true;
}
public int getReturnCode()
{
return returnCode;
}
}
private Operation createOperation(int index)