Skip to content

Commit 7cf6bf7

Browse files
author
Francesco Mazzoli
committed
Abstracted the nacks/rejects test, removed the third basicGet() in the first test.
1 parent 8afdf0f commit 7cf6bf7

File tree

1 file changed

+65
-53
lines changed

1 file changed

+65
-53
lines changed

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

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,45 @@ private void basicNack(long tag, boolean multiple, boolean requeue)
9494
channel.basicNack(tag, multiple, requeue);
9595
}
9696

97-
private void basicNack(boolean requeue)
98-
throws IOException
99-
{
100-
basicNack(latestTag, false, requeue);
101-
}
102-
103-
private void basicNack()
104-
throws IOException
105-
{
106-
basicNack(latestTag, false, true);
107-
}
108-
10997
private void basicReject(long tag, boolean requeue)
11098
throws IOException
11199
{
112100
channel.basicReject(tag, requeue);
113101
}
114102

115-
private void basicReject(boolean requeue)
116-
throws IOException
117-
{
118-
basicReject(latestTag, requeue);
119-
}
103+
private abstract class GenericNack {
104+
abstract public void nack(long tag, boolean requeue)
105+
throws IOException;
120106

121-
private void basicReject()
122-
throws IOException
123-
{
124-
basicReject(latestTag, true);
107+
public void nack(boolean requeue)
108+
throws IOException
109+
{
110+
nack(latestTag, requeue);
111+
}
112+
113+
public void nack()
114+
throws IOException
115+
{
116+
nack(latestTag, true);
117+
}
125118
}
126119

120+
private GenericNack genNack = new GenericNack() {
121+
public void nack(long tag, boolean requeue)
122+
throws IOException
123+
{
124+
basicNack(tag, false, requeue);
125+
}
126+
};
127+
128+
private GenericNack genReject = new GenericNack() {
129+
public void nack(long tag, boolean requeue)
130+
throws IOException
131+
{
132+
basicReject(tag, requeue);
133+
}
134+
};
135+
127136
/*
128137
publishes are embargoed until commit
129138
*/
@@ -370,35 +379,34 @@ public void testShuffleAcksBeforeRollback()
370379
messages with nacks get requeued after the transaction commit.
371380
messages with nacks with requeue = false are not requeued.
372381
*/
373-
public void testCommitNacks()
382+
public void commitNacks(GenericNack genNack)
374383
throws IOException
375384
{
376385
basicPublish();
377386
basicPublish();
378387
txSelect();
379388
basicGet();
380-
basicNack();
389+
genNack.nack();
381390
basicGet();
382-
basicNack(false);
391+
genNack.nack(false);
383392
assertNull(basicGet());
384393
txCommit();
385394
assertNotNull(basicGet());
386-
basicGet();
387395
assertNull(basicGet());
388396
}
389397

390-
public void testRollbackNacks()
398+
public void rollbackNacks(GenericNack genNack)
391399
throws IOException
392400
{
393401
basicPublish();
394402
txSelect();
395403
basicGet();
396-
basicNack(true);
404+
genNack.nack(true);
397405
txRollback();
398406
assertNull(basicGet());
399407
}
400408

401-
public void testCommitAcksAndNacks()
409+
public void commitAcksAndNacks(GenericNack genNack)
402410
throws IOException
403411
{
404412
for (int i = 0; i < 3; i++) {
@@ -411,45 +419,49 @@ public void testCommitAcksAndNacks()
411419
}
412420
basicAck(tags[1], false);
413421
basicAck(tags[0], false);
414-
basicNack(tags[2], false, false);
422+
genNack.nack(tags[2], false);
415423
txRollback();
416424
basicAck(tags[2], false);
417-
basicNack(tags[0], false, true);
418-
basicNack(tags[1], false, false);
425+
genNack.nack(tags[0], true);
426+
genNack.nack(tags[1], false);
419427
txCommit();
420428
assertNotNull(basicGet());
421429
assertNull(basicGet());
422430
}
423431

424-
/*
425-
messages with rejects get requeued after the transaction commit.
426-
messages with rejects with requeue = false are not requeued.
427-
*/
432+
public void testCommitNacks()
433+
throws IOException
434+
{
435+
commitNacks(genNack);
436+
}
437+
438+
public void testRollbackNacks()
439+
throws IOException
440+
{
441+
rollbackNacks(genNack);
442+
}
443+
444+
public void testCommitAcksAndNacks()
445+
throws IOException
446+
{
447+
commitAcksAndNacks(genNack);
448+
}
449+
428450
public void testCommitRejects()
429451
throws IOException
430452
{
431-
basicPublish();
432-
basicPublish();
433-
txSelect();
434-
basicGet();
435-
basicReject();
436-
basicGet();
437-
basicReject(false);
438-
assertNull(basicGet());
439-
txCommit();
440-
assertNotNull(basicGet());
441-
basicGet();
442-
assertNull(basicGet());
453+
commitNacks(genReject);
443454
}
444455

445456
public void testRollbackRejects()
446457
throws IOException
447458
{
448-
basicPublish();
449-
txSelect();
450-
basicGet();
451-
basicReject(true);
452-
txRollback();
453-
assertNull(basicGet());
459+
rollbackNacks(genReject);
460+
}
461+
462+
public void testCommitAcksAndRejects()
463+
throws IOException
464+
{
465+
commitAcksAndNacks(genReject);
454466
}
455467
}

0 commit comments

Comments
 (0)