Search in sources :

Example 1 with ConsumerBase

use of com.yahoo.pulsar.client.impl.ConsumerBase in project pulsar by yahoo.

the class ResendRequestTest method printIncomingMessageQueue.

private BlockingQueue<Message> printIncomingMessageQueue(Consumer consumer) throws Exception {
    BlockingQueue<Message> imq = null;
    ConsumerBase c = (ConsumerBase) consumer;
    Field field = ConsumerBase.class.getDeclaredField("incomingMessages");
    field.setAccessible(true);
    imq = (BlockingQueue<Message>) field.get(c);
    log.info("Incoming MEssage Queue: {}", imq);
    return imq;
}
Also used : Field(java.lang.reflect.Field) ConsumerBase(com.yahoo.pulsar.client.impl.ConsumerBase) Message(com.yahoo.pulsar.client.api.Message)

Example 2 with ConsumerBase

use of com.yahoo.pulsar.client.impl.ConsumerBase in project pulsar by yahoo.

the class ClientErrorsTest method subscribeFailDoesNotFailOtherConsumer.

private void subscribeFailDoesNotFailOtherConsumer(String topic1, String topic2) throws Exception {
    PulsarClient client = PulsarClient.create("http://127.0.0.1:" + WEB_SERVICE_PORT);
    final AtomicInteger counter = new AtomicInteger(0);
    mockBrokerService.setHandleSubscribe((ctx, subscribe) -> {
        if (counter.incrementAndGet() == 2) {
            // fail second producer
            ctx.writeAndFlush(Commands.newError(subscribe.getRequestId(), ServerError.AuthenticationError, "msg"));
            return;
        }
        ctx.writeAndFlush(Commands.newSuccess(subscribe.getRequestId()));
    });
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    ConsumerBase consumer1 = (ConsumerBase) client.subscribe(topic1, "sub1", conf);
    ConsumerBase consumer2 = null;
    try {
        consumer2 = (ConsumerBase) client.subscribe(topic2, "sub1", conf);
        fail("Should have failed");
    } catch (Exception e) {
    // ok
    }
    assertTrue(consumer1.isConnected());
    assertFalse(consumer2 != null && consumer2.isConnected());
    mockBrokerService.resetHandleSubscribe();
    client.close();
}
Also used : ConsumerBase(com.yahoo.pulsar.client.impl.ConsumerBase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConsumerConfiguration(com.yahoo.pulsar.client.api.ConsumerConfiguration) PulsarClient(com.yahoo.pulsar.client.api.PulsarClient) LookupException(com.yahoo.pulsar.client.api.PulsarClientException.LookupException) ExecutionException(java.util.concurrent.ExecutionException) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException)

Aggregations

ConsumerBase (com.yahoo.pulsar.client.impl.ConsumerBase)2 ConsumerConfiguration (com.yahoo.pulsar.client.api.ConsumerConfiguration)1 Message (com.yahoo.pulsar.client.api.Message)1 PulsarClient (com.yahoo.pulsar.client.api.PulsarClient)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 LookupException (com.yahoo.pulsar.client.api.PulsarClientException.LookupException)1 Field (java.lang.reflect.Field)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1