Skip to content

Commit 0afa4cf

Browse files
committed
refactor
1 parent 289bbd1 commit 0afa4cf

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

test/src/com/rabbitmq/client/test/functional/Transactions.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ private void basicAck()
8888
basicAck(latestTag, false);
8989
}
9090

91+
private long[] publishSelectAndGet(int n)
92+
throws IOException
93+
{
94+
for (int i = 0; i < n; i++) {
95+
basicPublish();
96+
}
97+
98+
txSelect();
99+
100+
long tags[] = new long[n];
101+
for (int i = 0; i < n; i++) {
102+
tags[i] = basicGet().getEnvelope().getDeliveryTag();
103+
}
104+
105+
return tags;
106+
}
107+
91108
/*
92109
publishes are embargoed until commit
93110
*/
@@ -174,19 +191,11 @@ public void testCommitAcks()
174191
public void testCommitAcksOutOfOrder()
175192
throws IOException
176193
{
177-
basicPublish();
178-
basicPublish();
179-
basicPublish();
180-
basicPublish();
181-
txSelect();
182-
GetResponse resp1 = basicGet();
183-
GetResponse resp2 = basicGet();
184-
GetResponse resp3 = basicGet();
185-
GetResponse resp4 = basicGet();
186-
channel.basicNack(resp4.getEnvelope().getDeliveryTag(), false, false);
187-
channel.basicNack(resp3.getEnvelope().getDeliveryTag(), false, false);
188-
channel.basicAck(resp2.getEnvelope().getDeliveryTag(), false);
189-
channel.basicAck(resp1.getEnvelope().getDeliveryTag(), false);
194+
long tags[] = publishSelectAndGet(4);
195+
channel.basicNack(tags[3], false, false);
196+
channel.basicNack(tags[2], false, false);
197+
channel.basicAck(tags[1], false);
198+
channel.basicAck(tags[0], false);
190199
txCommit();
191200
}
192201

@@ -334,14 +343,7 @@ public void testCommitWithDeletedQueue()
334343
public void testShuffleAcksBeforeRollback()
335344
throws IOException
336345
{
337-
for (int i = 0; i < 3; i++) {
338-
basicPublish();
339-
}
340-
txSelect();
341-
long tags[] = new long[3];
342-
for (int i = 0; i < 3; i++) {
343-
tags[i] = basicGet().getEnvelope().getDeliveryTag();
344-
}
346+
long tags[] = publishSelectAndGet(3);
345347
basicAck(tags[2], false);
346348
basicAck(tags[1], false);
347349
txRollback();
@@ -418,14 +420,7 @@ public void rollbackNacks(NackMethod method)
418420
public void commitAcksAndNacks(NackMethod method)
419421
throws IOException
420422
{
421-
for (int i = 0; i < 3; i++) {
422-
basicPublish();
423-
}
424-
txSelect();
425-
long tags[] = new long[3];
426-
for (int i = 0; i < 3; i++) {
427-
tags[i] = basicGet().getEnvelope().getDeliveryTag();
428-
}
423+
long tags[] = publishSelectAndGet(3);
429424
basicAck(tags[1], false);
430425
basicAck(tags[0], false);
431426
method.nack(tags[2], false);

0 commit comments

Comments
 (0)