Skip to content

Commit

Permalink
Fixed incorrect wait methods in ShellTest utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Aug 26, 2013
1 parent 226a20d commit 2020c1c
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Result execute(String line, int quantity, TimeUnit unit)
{
if (System.currentTimeMillis() > (start + TimeUnit.MILLISECONDS.convert(quantity, unit)))
{
throw new TimeoutException("Timeout expired waiting for command [" + line + "].");
throw throwTimeout("Timeout expired waiting for command [" + line + "].");
}

try
Expand All @@ -145,7 +145,7 @@ public Result execute(String line, int quantity, TimeUnit unit)
throw new RuntimeException("Failed to execute command.", e);
}
return result;
};
}

@Override
public void waitForStdOutChanged(final String value, int quantity, TimeUnit unit) throws TimeoutException
Expand Down Expand Up @@ -220,13 +220,12 @@ private void waitForStream(Callable<?> task, ByteArrayOutputStream stream, int q
}

long start = System.currentTimeMillis();
while (System.currentTimeMillis() < (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& stream.size() == size)
while (stream.size() == size)
{
if (System.currentTimeMillis() >= (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& stream.size() == size)
{
throw new TimeoutException("Timeout occurred while waiting for stream.");
throw throwTimeout("Timeout occurred while waiting for stream to be written.");
}

try
Expand All @@ -235,7 +234,7 @@ private void waitForStream(Callable<?> task, ByteArrayOutputStream stream, int q
}
catch (InterruptedException e)
{
throw new RuntimeException("Interrupted while waiting for Shell to respond.", e);
throw new RuntimeException("Interrupted while waiting for stream to be written.", e);
}
}
}
Expand All @@ -254,13 +253,12 @@ private void waitForStreamValue(Callable<?> task, ByteArrayOutputStream stream,
}

long start = System.currentTimeMillis();
while (System.currentTimeMillis() < (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& !new String(stream.toByteArray()).contains(expected))
while (!new String(stream.toByteArray()).contains(expected))
{
if (System.currentTimeMillis() >= (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& !new String(stream.toByteArray()).contains(expected))
{
throw new TimeoutException("Timeout occurred while waiting for stream.");
throw throwTimeout("Timeout occurred while waiting for stream value [" + expected + "].");
}

try
Expand All @@ -269,7 +267,7 @@ private void waitForStreamValue(Callable<?> task, ByteArrayOutputStream stream,
}
catch (InterruptedException e)
{
throw new RuntimeException("Interrupted while waiting for Shell to respond.", e);
throw new RuntimeException("Interrupted while waiting for stream value [" + expected + "].", e);
}
}
}
Expand All @@ -288,12 +286,13 @@ public void waitForBufferChanged(Callable<?> task, int quantity, TimeUnit unit)
}

long start = System.currentTimeMillis();
while (System.currentTimeMillis() < (start + TimeUnit.MILLISECONDS.convert(quantity, unit)))
while (buffer.equals(getBuffer().getLine().length()))
{
if (System.currentTimeMillis() >= (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& buffer.equals(getBuffer().getLine().length()))
&& buffer.equals(getBuffer().getLine()))
{
throw new TimeoutException("Timeout occurred while waiting for buffer.");
throw throwTimeout("Timeout occurred while waiting for buffer value to change from [" + buffer
+ "].");
}

try
Expand All @@ -302,7 +301,7 @@ public void waitForBufferChanged(Callable<?> task, int quantity, TimeUnit unit)
}
catch (InterruptedException e)
{
throw new RuntimeException("Interrupted while waiting for Shell to respond.", e);
throw new RuntimeException("Interrupted while waiting for buffer value to change from [" + buffer + "].", e);
}
}
}
Expand All @@ -321,13 +320,12 @@ public void waitForBufferValue(Callable<?> task, int quantity, TimeUnit unit, St
}

long start = System.currentTimeMillis();
while (System.currentTimeMillis() < (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& !getBuffer().getLine().equals(expected))
while (!getBuffer().getLine().equals(expected))
{
if (System.currentTimeMillis() >= (start + TimeUnit.MILLISECONDS.convert(quantity, unit))
&& !getBuffer().getLine().equals(expected))
{
throw new TimeoutException("Timeout occurred while waiting for buffer.");
throw throwTimeout("Timeout occurred while waiting for buffer to equal value [" + expected + "].");
}

try
Expand All @@ -336,9 +334,11 @@ public void waitForBufferValue(Callable<?> task, int quantity, TimeUnit unit, St
}
catch (InterruptedException e)
{
throw new RuntimeException("Interrupted while waiting for Shell to respond.", e);
throw new RuntimeException("Interrupted while waiting for buffer to equal value [" + expected + "].", e);
}
}

System.out.println("returning");
}

@Override
Expand Down Expand Up @@ -464,6 +464,12 @@ public void sendCompletionSignal() throws IOException
getStdIn().write(completeChar.getFirstValue());
}

private TimeoutException throwTimeout(String message) throws TimeoutException
{
return new TimeoutException(message + "\n\nSTDOUT: " + provider.getStdOut().toString() + "\n\nSTDERR: "
+ provider.getStdErr().toString());
};

@Override
public void clearScreen() throws IOException
{
Expand Down

0 comments on commit 2020c1c

Please sign in to comment.