예제 #1
0
 public void testConnectionRecoveryWithDisabledTopologyRecovery()
     throws IOException, InterruptedException, TimeoutException {
   AutorecoveringConnection c = newRecoveringConnection(true);
   Channel ch = c.createChannel();
   String q = "java-client.test.recovery.q2";
   ch.queueDeclare(q, false, true, false, null);
   ch.queueDeclarePassive(q);
   assertTrue(c.isOpen());
   try {
     CountDownLatch shutdownLatch = prepareForShutdown(c);
     CountDownLatch recoveryLatch = prepareForRecovery(c);
     Host.closeConnection(c);
     wait(shutdownLatch);
     wait(recoveryLatch);
     assertTrue(c.isOpen());
     ch.queueDeclarePassive(q);
     fail("expected passive declaration to throw");
   } catch (java.io.IOException e) {
     // expected
   } finally {
     c.abort();
   }
 }
예제 #2
0
  public void testBasicAckAfterChannelRecovery()
      throws IOException, InterruptedException, TimeoutException {
    final AtomicInteger consumed = new AtomicInteger(0);
    int n = 5;
    final CountDownLatch latch = new CountDownLatch(n);
    Consumer consumer =
        new DefaultConsumer(channel) {
          @Override
          public void handleDelivery(
              String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
              throws IOException {
            try {
              if (consumed.intValue() > 0 && consumed.intValue() % 4 == 0) {
                CountDownLatch recoveryLatch = prepareForRecovery(connection);
                Host.closeConnection((AutorecoveringConnection) connection);
                ConnectionRecovery.wait(recoveryLatch);
              }
              channel.basicAck(envelope.getDeliveryTag(), false);
            } catch (InterruptedException e) {
              // ignore
            } finally {
              consumed.incrementAndGet();
              latch.countDown();
            }
          }
        };

    String q = channel.queueDeclare().getQueue();
    channel.basicConsume(q, consumer);
    AutorecoveringConnection publishingConnection = newRecoveringConnection(false);
    Channel publishingChannel = publishingConnection.createChannel();
    for (int i = 0; i < n; i++) {
      publishingChannel.basicPublish("", q, null, "msg".getBytes());
    }
    wait(latch);
    publishingConnection.abort();
  }