Skip to content

Commit 657ab2a

Browse files
author
Steve Powell
committed
Fixed recursion in rpc() call.
Fixed Permissions tests to clearup *before* running in case of previous failure.
1 parent f505ab2 commit 657ab2a

File tree

3 files changed

+57
-28
lines changed

3 files changed

+57
-28
lines changed

src/com/rabbitmq/client/impl/AMQChannel.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import com.rabbitmq.utility.BlockingValueOrException;
2929

3030
/**
31-
* Base class modelling an AMQ channel. Subclasses implement close()
32-
* and processAsync(), and may choose to override
33-
* processShutdownSignal().
31+
* Base class modelling an AMQ channel. Subclasses implement {@link #close()}
32+
* and {@link #processAsync()}, and may choose to override
33+
* {@link processShutdownSignal()} and {@link rpc()}.
3434
*
3535
* @see ChannelN
3636
* @see Connection
@@ -123,7 +123,7 @@ public AMQCommand exnWrappingRpc(Method m)
123123
throws IOException
124124
{
125125
try {
126-
return rpc(m);
126+
return privateRpc(m);
127127
} catch (AlreadyClosedException ace) {
128128
// Do not wrap it since it means that connection/channel
129129
// was closed in some action in the past
@@ -190,6 +190,12 @@ public void ensureIsOpen()
190190
*/
191191
public AMQCommand rpc(Method m)
192192
throws IOException, ShutdownSignalException
193+
{
194+
return privateRpc(m);
195+
}
196+
197+
private AMQCommand privateRpc(Method m)
198+
throws IOException, ShutdownSignalException
193199
{
194200
SimpleBlockingRpcContinuation k = new SimpleBlockingRpcContinuation();
195201
rpc(m, k);

test/src/com/rabbitmq/client/test/server/Permissions.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class Permissions extends BrokerTestCase
3737
{
3838

39-
protected Channel adminCh;
39+
private Channel adminCh;
4040

4141
public Permissions()
4242
{
@@ -50,6 +50,7 @@ public Permissions()
5050
protected void setUp()
5151
throws IOException
5252
{
53+
deleteRestrictedAccount();
5354
addRestrictedAccount();
5455
super.setUp();
5556
}
@@ -74,11 +75,11 @@ protected void addRestrictedAccount()
7475
protected void deleteRestrictedAccount()
7576
throws IOException
7677
{
77-
Host.rabbitmqctl("clear_permissions -p /test testadmin");
78-
Host.rabbitmqctl("clear_permissions -p /test test");
79-
Host.rabbitmqctl("delete_vhost /test");
80-
Host.rabbitmqctl("delete_user testadmin");
81-
Host.rabbitmqctl("delete_user test");
78+
Host.rabbitmqctlIgnoreErrors("clear_permissions -p /test testadmin");
79+
Host.rabbitmqctlIgnoreErrors("clear_permissions -p /test test");
80+
Host.rabbitmqctlIgnoreErrors("delete_vhost /test");
81+
Host.rabbitmqctlIgnoreErrors("delete_user testadmin");
82+
Host.rabbitmqctlIgnoreErrors("delete_user test");
8283
}
8384

8485
protected void createResources()
@@ -357,7 +358,7 @@ protected void runTest(boolean exp, String name, WithName test)
357358
}
358359
}
359360

360-
public interface WithName {
361+
private interface WithName {
361362
public void with(String name) throws IOException;
362363
}
363364

test/src/com/rabbitmq/tools/Host.java

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,40 @@ private static String capture(InputStream is)
3636
return buff.toString();
3737
}
3838

39-
public static void executeCommand(String command)
40-
throws IOException
39+
public static void executeCommand(String command) throws IOException
40+
{
41+
Process pr = executeCommandProcess(command);
42+
String stdout = capture(pr.getInputStream());
43+
String stderr = capture(pr.getErrorStream());
44+
45+
int ev = waitForExitValue(pr);
46+
if (ev != 0) {
47+
throw new IOException("unexpected command exit value: " + ev +
48+
"\nstdout:\n" + stdout +
49+
"\nstderr:\n" + stderr + "\n");
50+
}
51+
}
52+
53+
private static int waitForExitValue(Process pr) {
54+
while(true) {
55+
try {
56+
pr.waitFor();
57+
break;
58+
} catch (InterruptedException e) {}
59+
}
60+
return pr.exitValue();
61+
}
62+
63+
public static void executeCommandIgnoringErrors(String command) throws IOException
64+
{
65+
Process pr = executeCommandProcess(command);
66+
// String stdout = capture(pr.getInputStream());
67+
// String stderr = capture(pr.getErrorStream());
68+
69+
waitForExitValue(pr);
70+
}
71+
72+
private static Process executeCommandProcess(String command) throws IOException
4173
{
4274
String[] finalCommand;
4375
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
@@ -52,24 +84,14 @@ public static void executeCommand(String command)
5284
finalCommand[1] = "-c";
5385
finalCommand[2] = command;
5486
}
55-
final Process pr = Runtime.getRuntime().exec(finalCommand);
56-
final String stdout = capture(pr.getInputStream());
57-
final String stderr = capture(pr.getErrorStream());
58-
while(true) {
59-
try {
60-
pr.waitFor();
61-
break;
62-
} catch (InterruptedException e) {}
63-
}
64-
int ev = pr.exitValue();
65-
if (ev != 0) {
66-
throw new IOException("unexpected command exit value: " + ev +
67-
"\nstdout:\n" + stdout +
68-
"\nstderr:\n" + stderr + "\n");
69-
}
87+
return Runtime.getRuntime().exec(finalCommand);
7088
}
7189

7290
public static void rabbitmqctl(String command) throws IOException {
7391
executeCommand("../rabbitmq-server/scripts/rabbitmqctl " + command);
7492
}
93+
94+
public static void rabbitmqctlIgnoreErrors(String command) throws IOException {
95+
executeCommandIgnoringErrors("../rabbitmq-server/scripts/rabbitmqctl " + command);
96+
}
7597
}

0 commit comments

Comments
 (0)