@@ -88,6 +88,23 @@ private void basicAck()
88
88
basicAck (latestTag , false );
89
89
}
90
90
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
+
91
108
/*
92
109
publishes are embargoed until commit
93
110
*/
@@ -174,19 +191,11 @@ public void testCommitAcks()
174
191
public void testCommitAcksOutOfOrder ()
175
192
throws IOException
176
193
{
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 );
190
199
txCommit ();
191
200
}
192
201
@@ -334,14 +343,7 @@ public void testCommitWithDeletedQueue()
334
343
public void testShuffleAcksBeforeRollback ()
335
344
throws IOException
336
345
{
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 );
345
347
basicAck (tags [2 ], false );
346
348
basicAck (tags [1 ], false );
347
349
txRollback ();
@@ -418,14 +420,7 @@ public void rollbackNacks(NackMethod method)
418
420
public void commitAcksAndNacks (NackMethod method )
419
421
throws IOException
420
422
{
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 );
429
424
basicAck (tags [1 ], false );
430
425
basicAck (tags [0 ], false );
431
426
method .nack (tags [2 ], false );
0 commit comments