Merge bug24234
authorSimon MacMullen <simon@rabbitmq.com>
Wed Feb 08 11:59:58 2012 +0000 (2012-02-08)
changeset 193180d0846c9808
parent 1923 f486e2f73a61
parent 1902 eaeb800d4b7c
child 1944 dde4e80efefd
child 1947 b2f7827b2ab7
child 1954 feecb394b212
child 1955 e193ab64c840
Merge bug24234
test/src/com/rabbitmq/client/test/functional/Transactions.java
     1.1 --- a/test/src/com/rabbitmq/client/test/functional/Transactions.java	Tue Feb 07 10:21:16 2012 +0000
     1.2 +++ b/test/src/com/rabbitmq/client/test/functional/Transactions.java	Wed Feb 08 11:59:58 2012 +0000
     1.3 @@ -329,4 +329,127 @@
     1.4          basicAck(tags[2], false);
     1.5          txCommit();
     1.6      }
     1.7 +
     1.8 +    private abstract class NackMethod {
     1.9 +        abstract public void nack(long tag, boolean requeue)
    1.10 +            throws IOException;
    1.11 +
    1.12 +        public void nack(boolean requeue)
    1.13 +            throws IOException
    1.14 +        {
    1.15 +            nack(latestTag, requeue);
    1.16 +        }
    1.17 +
    1.18 +        public void nack()
    1.19 +            throws IOException
    1.20 +        {
    1.21 +            nack(latestTag, true);
    1.22 +        }
    1.23 +    }
    1.24 +
    1.25 +    private NackMethod basicNack = new NackMethod() {
    1.26 +            public void nack(long tag, boolean requeue)
    1.27 +                throws IOException
    1.28 +            {
    1.29 +                channel.basicNack(tag, false, requeue);
    1.30 +            }
    1.31 +        };
    1.32 +
    1.33 +    private NackMethod basicReject = new NackMethod() {
    1.34 +            public void nack(long tag, boolean requeue)
    1.35 +                throws IOException
    1.36 +            {
    1.37 +                channel.basicReject(tag, requeue);
    1.38 +            }
    1.39 +        };
    1.40 +
    1.41 +    /*
    1.42 +      messages with nacks get requeued after the transaction commit.
    1.43 +      messages with nacks with requeue = false are not requeued.
    1.44 +    */
    1.45 +    public void commitNacks(NackMethod method)
    1.46 +        throws IOException
    1.47 +    {
    1.48 +        basicPublish();
    1.49 +        basicPublish();
    1.50 +        txSelect();
    1.51 +        basicGet();
    1.52 +        method.nack();
    1.53 +        basicGet();
    1.54 +        method.nack(false);
    1.55 +        assertNull(basicGet());
    1.56 +        txCommit();
    1.57 +        assertNotNull(basicGet());
    1.58 +        assertNull(basicGet());
    1.59 +    }
    1.60 +
    1.61 +    public void rollbackNacks(NackMethod method)
    1.62 +        throws IOException
    1.63 +    {
    1.64 +        basicPublish();
    1.65 +        txSelect();
    1.66 +        basicGet();
    1.67 +        method.nack(true);
    1.68 +        txRollback();
    1.69 +        assertNull(basicGet());
    1.70 +    }
    1.71 +
    1.72 +    public void commitAcksAndNacks(NackMethod method)
    1.73 +        throws IOException
    1.74 +    {
    1.75 +        for (int i = 0; i < 3; i++) {
    1.76 +            basicPublish();
    1.77 +        }
    1.78 +        txSelect();
    1.79 +        long tags[] = new long[3];
    1.80 +        for (int i = 0; i < 3; i++) {
    1.81 +            tags[i] = basicGet().getEnvelope().getDeliveryTag();
    1.82 +        }
    1.83 +        basicAck(tags[1], false);
    1.84 +        basicAck(tags[0], false);
    1.85 +        method.nack(tags[2], false);
    1.86 +        txRollback();
    1.87 +        basicAck(tags[2], false);
    1.88 +        method.nack(tags[0], true);
    1.89 +        method.nack(tags[1], false);
    1.90 +        txCommit();
    1.91 +        assertNotNull(basicGet());
    1.92 +        assertNull(basicGet());
    1.93 +    }
    1.94 +
    1.95 +    public void testCommitNacks()
    1.96 +        throws IOException
    1.97 +    {
    1.98 +        commitNacks(basicNack);
    1.99 +    }
   1.100 +
   1.101 +    public void testRollbackNacks()
   1.102 +        throws IOException
   1.103 +    {
   1.104 +        rollbackNacks(basicNack);
   1.105 +    }
   1.106 +
   1.107 +    public void testCommitAcksAndNacks()
   1.108 +        throws IOException
   1.109 +    {
   1.110 +        commitAcksAndNacks(basicNack);
   1.111 +    }
   1.112 +
   1.113 +    public void testCommitRejects()
   1.114 +        throws IOException
   1.115 +    {
   1.116 +        commitNacks(basicReject);
   1.117 +    }
   1.118 +
   1.119 +    public void testRollbackRejects()
   1.120 +        throws IOException
   1.121 +    {
   1.122 +        rollbackNacks(basicReject);
   1.123 +    }
   1.124 +
   1.125 +    public void testCommitAcksAndRejects()
   1.126 +        throws IOException
   1.127 +    {
   1.128 +        commitAcksAndNacks(basicReject);
   1.129 +    }
   1.130  }