Esempio n. 1
0
 void publishInts(ByteString topic, int start, int num) throws Exception {
   for (int i = 0; i < num; i++) {
     org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.Message msg =
         org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.Message.newBuilder()
             .setBody(ByteString.copyFromUtf8("" + (start + i)))
             .build();
     publisher.publish(topic, msg);
   }
 }
Esempio n. 2
0
 org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.MessageSeqId publish(
     ByteString topic, ByteString data) throws Exception {
   org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.Message message =
       org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.Message.newBuilder()
           .setBody(data)
           .build();
   publisher.publish(topic, message);
   return null;
 }
Esempio n. 3
0
    void sendXExpectLastY(ByteString topic, ByteString subid, final int x, final int y)
        throws Exception {
      for (int i = 0; i < x; i++) {
        publisher.publish(
            topic,
            org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.Message.newBuilder()
                .setBody(ByteString.copyFromUtf8(String.valueOf(i)))
                .build());
      }
      subscriber.subscribe(
          topic,
          subid,
          org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.SubscribeRequest.CreateOrAttach
              .ATTACH);

      final AtomicInteger expected = new AtomicInteger(x - y);
      final CountDownLatch latch = new CountDownLatch(1);
      subscriber.startDelivery(
          topic,
          subid,
          new org.apache.hw_v4_1_0.hedwig.client.api.MessageHandler() {
            @Override
            public synchronized void deliver(
                ByteString topic,
                ByteString subscriberId,
                org.apache.hw_v4_1_0.hedwig.protocol.PubSubProtocol.Message msg,
                org.apache.hw_v4_1_0.hedwig.util.Callback<Void> callback,
                Object context) {
              try {
                int value = Integer.valueOf(msg.getBody().toStringUtf8());
                if (value == expected.get()) {
                  expected.incrementAndGet();
                } else {
                  logger.error(
                      "Did not receive expected value, expected {}, got {}", expected.get(), value);
                  expected.set(0);
                  latch.countDown();
                }
                if (expected.get() == x) {
                  latch.countDown();
                }
                callback.operationFinished(context, null);
              } catch (Exception e) {
                logger.error("Received bad message", e);
                latch.countDown();
              }
            }
          });
      assertTrue(
          "Timed out waiting for messages Y is " + y + " expected is currently " + expected.get(),
          latch.await(10, TimeUnit.SECONDS));
      assertEquals("Should be expected message with " + x, x, expected.get());
      subscriber.stopDelivery(topic, subid);
      subscriber.closeSubscription(topic, subid);
      Thread.sleep(1000); // give server time to run disconnect logic (BOOKKEEPER-513)
    }