Package org.apache.hedwig.client.api

Examples of org.apache.hedwig.client.api.Subscriber


    // also works when it is a hub subscriber and we're expecting the
    // subscriberId to be in the "hub" specific format.
    @Test
    public void testSyncHubSubscribeWithInvalidSubscriberId() throws Exception {
        Client hubClient = new HedwigHubClient(new ClientConfiguration());
        Subscriber hubSubscriber = hubClient.getSubscriber();
        boolean subscribeSuccess = false;
        try {
            hubSubscriber.subscribe(getTopic(0), localSubscriberId, CreateOrAttach.CREATE_OR_ATTACH);
        } catch (InvalidSubscriberIdException e) {
            subscribeSuccess = true;
        } catch (Exception ex) {
            subscribeSuccess = false;
        }
View Full Code Here


    }

    @Test
    public void testAsyncHubSubscribeWithInvalidSubscriberId() throws Exception {
        Client hubClient = new HedwigHubClient(new ClientConfiguration());
        Subscriber hubSubscriber = hubClient.getSubscriber();
        hubSubscriber.asyncSubscribe(getTopic(0), localSubscriberId, CreateOrAttach.CREATE_OR_ATTACH, new TestCallback(
                                         queue), null);
        assertFalse(queue.take());
        hubClient.close();
    }
View Full Code Here

    }

    @Test
    public void testSyncHubUnsubscribeWithInvalidSubscriberId() throws Exception {
        Client hubClient = new HedwigHubClient(new ClientConfiguration());
        Subscriber hubSubscriber = hubClient.getSubscriber();
        boolean unsubscribeSuccess = false;
        try {
            hubSubscriber.unsubscribe(getTopic(0), localSubscriberId);
        } catch (InvalidSubscriberIdException e) {
            unsubscribeSuccess = true;
        } catch (Exception ex) {
            unsubscribeSuccess = false;
        }
View Full Code Here

    }

    @Test
    public void testAsyncHubUnsubscribeWithInvalidSubscriberId() throws Exception {
        Client hubClient = new HedwigHubClient(new ClientConfiguration());
        Subscriber hubSubscriber = hubClient.getSubscriber();
        hubSubscriber.asyncUnsubscribe(getTopic(0), localSubscriberId, new TestCallback(queue), null);
        assertFalse(queue.take());
        hubClient.close();
    }
View Full Code Here

    @Test
    public void testBasicBounding() throws Exception {
        Client client = new HedwigClient(new MessageBoundClientConfiguration(5));
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        ByteString topic = ByteString.copyFromUtf8("basicBoundingTopic");
        ByteString subid = ByteString.copyFromUtf8("basicBoundingSubId");
        sub.subscribe(topic, subid, CreateOrAttach.CREATE);
        sub.closeSubscription(topic, subid);

        sendXExpectLastY(pub, sub, topic, subid, 1000, 5);

        client.close();
    }
View Full Code Here

    public void testMultipleSubscribers() throws Exception {
        ByteString topic = ByteString.copyFromUtf8("multiSubTopic");

        Client client = new HedwigClient(new ClientConfiguration());
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        SubscriptionOptions options5 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE).setMessageBound(5).build();
        SubscriptionOptions options20 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE).setMessageBound(20).build();
        SubscriptionOptions optionsUnbounded = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE).build();

        ByteString subid5 = ByteString.copyFromUtf8("bound5SubId");
        ByteString subid20 = ByteString.copyFromUtf8("bound20SubId");
        ByteString subidUnbounded = ByteString.copyFromUtf8("noboundSubId");

        sub.subscribe(topic, subid5, options5);
        sub.closeSubscription(topic, subid5);
        sendXExpectLastY(pub, sub, topic, subid5, 1000, 5);

        sub.subscribe(topic, subid20, options20);
        sub.closeSubscription(topic, subid20);
        sendXExpectLastY(pub, sub, topic, subid20, 1000, 20);

        sub.subscribe(topic, subidUnbounded, optionsUnbounded);
        sub.closeSubscription(topic, subidUnbounded);

        sendXExpectLastY(pub, sub, topic, subidUnbounded, 10000, 10000);
        sub.unsubscribe(topic, subidUnbounded);

        sendXExpectLastY(pub, sub, topic, subid20, 1000, 20);
        sub.unsubscribe(topic, subid20);

        sendXExpectLastY(pub, sub, topic, subid5, 1000, 5);
        sub.unsubscribe(topic, subid5);

        client.close();
    }
View Full Code Here

    @Test
    public void testLedgerGC() throws Exception {
        Client client = new HedwigClient(new MessageBoundClientConfiguration());
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        String ledgersPath = "/hedwig/standalone/topics/testGCTopic/ledgers";
        ByteString topic = ByteString.copyFromUtf8("testGCTopic");
        ByteString subid = ByteString.copyFromUtf8("testGCSubId");
        sub.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH);
        sub.closeSubscription(topic, subid);

        for (int i = 1; i <= 100; i++) {
            pub.publish(topic, Message.newBuilder().setBody(
                                ByteString.copyFromUtf8(String.valueOf(i))).build());
        }
View Full Code Here

                @Override
                public HedwigSocketAddress getDefaultServerHedwigSocketAddress() {
                    return getDefaultHedwigAddress();
                }
            });
        Subscriber subscriber2 = client2.getSubscriber();
        Publisher publisher2 = client2.getPublisher();
        SynchronousQueue<SubscriptionEvent> eventQueue2 =
            new SynchronousQueue<SubscriptionEvent>();
        subscriber2.addSubscriptionListener(new TestSubscriptionListener(eventQueue2));
        try {
            subscriber2.subscribe(topic, subscriberId, options);
        } catch (PubSubException.ServiceDownException e) {
            fail("Should not reach here!");
        }

        SynchronousQueue<Boolean> consumeQueue2 = new SynchronousQueue<Boolean>();
        subscriber2.startDelivery(topic, subscriberId, new TestMessageHandler(consumeQueue2));

        assertEquals(SubscriptionEvent.SUBSCRIPTION_FORCED_CLOSED, eventQueue.take());
        assertTrue(eventQueue2.isEmpty());

        // Now publish some messages for the topic to be consumed by the
View Full Code Here

        int messageWindowSize = DEFAULT_MESSAGE_WINDOW_SIZE;
        ThrottleDeliveryClientConfiguration conf =
            new ThrottleDeliveryClientConfiguration();
        HedwigClient client = new HedwigClient(conf);
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        ByteString topic = ByteString.copyFromUtf8("testServerSideThrottle");
        ByteString subid = ByteString.copyFromUtf8("serverThrottleSub");
        sub.subscribe(topic, subid, CreateOrAttach.CREATE);
        sub.closeSubscription(topic, subid);

        // throttle with hub server's setting
        throttleX(pub, sub, topic, subid, DEFAULT_MESSAGE_WINDOW_SIZE);

        messageWindowSize = DEFAULT_MESSAGE_WINDOW_SIZE / 2;
        // throttle with a lower value than hub server's setting
        SubscriptionOptions.Builder optionsBuilder = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE)
            .setMessageWindowSize(messageWindowSize);
        topic = ByteString.copyFromUtf8("testServerSideThrottleWithLowerValue");
        sub.subscribe(topic, subid, optionsBuilder.build());
        sub.closeSubscription(topic, subid);
        throttleX(pub, sub, topic, subid, messageWindowSize);

        messageWindowSize = DEFAULT_MESSAGE_WINDOW_SIZE + 5;
        // throttle with a higher value than hub server's setting
        optionsBuilder = SubscriptionOptions.newBuilder()
                         .setCreateOrAttach(CreateOrAttach.CREATE)
                         .setMessageWindowSize(messageWindowSize);
        topic = ByteString.copyFromUtf8("testServerSideThrottleWithHigherValue");
        sub.subscribe(topic, subid, optionsBuilder.build());
        sub.closeSubscription(topic, subid);
        throttleX(pub, sub, topic, subid, messageWindowSize);

        client.close();
    }
View Full Code Here

    }

    private void runSubAfterCloseSubTest(boolean sharedSubscriptionChannel) throws Exception {
        HedwigClient client = new HedwigClient(new TestClientConfiguration(sharedSubscriptionChannel));
        Publisher publisher = client.getPublisher();
        final Subscriber subscriber = client.getSubscriber();

        final ByteString topic = ByteString.copyFromUtf8("TestSubAfterCloseSub-" + sharedSubscriptionChannel);
        final ByteString subid = ByteString.copyFromUtf8("mysub");

        final CountDownLatch wakeupLatch = new CountDownLatch(1);
        final CountDownLatch closeLatch = new CountDownLatch(1);
        final CountDownLatch subLatch = new CountDownLatch(1);
        final CountDownLatch deliverLatch = new CountDownLatch(1);

        try {
            subscriber.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH);
            sleepDeliveryManager(wakeupLatch);
            subscriber.asyncCloseSubscription(topic, subid, new Callback<Void>() {
                @Override
                public void operationFinished(Object ctx, Void resultOfOperation) {
                    closeLatch.countDown();
                }
                @Override
                public void operationFailed(Object ctx, PubSubException exception) {
                    logger.error("Closesub failed : ", exception);
                }
            }, null);
            subscriber.asyncSubscribe(topic, subid, CreateOrAttach.ATTACH, new Callback<Void>() {
                @Override
                public void operationFinished(Object ctx, Void resultOfOperation) {
                    try {
                        subscriber.startDelivery(topic, subid, new MessageHandler() {
                            @Override
                            public void deliver(ByteString topic, ByteString subid, Message msg,
                                                Callback<Void> callback, Object context) {
                                deliverLatch.countDown();
                            }
View Full Code Here

TOP

Related Classes of org.apache.hedwig.client.api.Subscriber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.