Examples of HedwigClient


Examples of org.apache.hedwig.client.HedwigClient

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

        Client client = new HedwigClient(new HubClientConfiguration());
        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

Examples of org.apache.hedwig.client.HedwigClient

    @Test(timeout=60000)
    public void testUpdateMessageBound() throws Exception {
        ByteString topic = ByteString.copyFromUtf8("UpdateMessageBound");

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

        SubscriptionOptions options5 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE_OR_ATTACH).setMessageBound(5).build();
        SubscriptionOptions options20 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE_OR_ATTACH).setMessageBound(20).build();
        SubscriptionOptions options10 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE_OR_ATTACH).setMessageBound(10).build();

        ByteString subid = ByteString.copyFromUtf8("updateSubId");

        sub.subscribe(topic, subid, options5);
        sub.closeSubscription(topic, subid);
        sendXExpectLastY(pub, sub, topic, subid, 50, 5);

        // update bound to 20
        sub.subscribe(topic, subid, options20);
        sub.closeSubscription(topic, subid);
        sendXExpectLastY(pub, sub, topic, subid, 50, 20);

        // update bound to 10
        sub.subscribe(topic, subid, options10);
        sub.closeSubscription(topic, subid);
        sendXExpectLastY(pub, sub, topic, subid, 50, 10);

        // message bound is not provided, no update
        sub.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH);
        sub.closeSubscription(topic, subid);
        sendXExpectLastY(pub, sub, topic, subid, 50, 10);

        client.close();
    }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

        client.close();
    }

    @Test(timeout=60000)
    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());
        }
        LedgerRanges r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
        assertEquals("Should only have 1 ledger yet", 1, r.getRangesList().size());
        long firstLedger = r.getRangesList().get(0).getLedgerId();

        stopHubServers();
        startHubServers();

        pub.publish(topic, Message.newBuilder().setBody(
                            ByteString.copyFromUtf8(String.valueOf(0xdeadbeef))).build());

        r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
        assertEquals("Should have 2 ledgers after restart", 2, r.getRangesList().size());

        for (int i = 100; i <= 200; i++) {
            pub.publish(topic, Message.newBuilder().setBody(
                                ByteString.copyFromUtf8(String.valueOf(i))).build());
        }
        Thread.sleep(5000); // give GC a chance to happen

        r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
        long secondLedger = r.getRangesList().get(0).getLedgerId();

        assertEquals("Should only have 1 ledger after GC", 1, r.getRangesList().size());

        // ensure original ledger doesn't exist
        String firstLedgerPath = String.format("/ledgers/L%010d", firstLedger);
        String secondLedgerPath = String.format("/ledgers/L%010d", secondLedger);
        assertNull("Ledger should not exist", bktb.getZooKeeperClient().exists(firstLedgerPath, false));
        assertNotNull("Ledger should exist", bktb.getZooKeeperClient().exists(secondLedgerPath, false));

        client.close();
    }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

        super.setUp();
        if (mode == Mode.PROXY) {
            proxy = new HedwigProxy(proxyConf, new LoggingExceptionHandler());
            proxy.start();
        }
        client = new HedwigClient(getClientConfiguration());
        publisher = client.getPublisher();
        subscriber = client.getSubscriber();
    }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

    // This tests out the manual sending of consume messages to the server
    // instead of relying on the automatic sending by the client lib for it.
    @Test(timeout=10000)
    public void testManualConsumeClient() throws Exception {
        HedwigClient myClient = new HedwigClient(new TestClientConfiguration() {
            @Override
            public boolean isAutoSendConsumeMessageEnabled() {
                return false;
            }

        });
        Subscriber mySubscriber = myClient.getSubscriber();
        Publisher myPublisher = myClient.getPublisher();
        ByteString myTopic = getTopic(0);
        // Subscribe to a topic and start delivery on it
        mySubscriber.asyncSubscribe(myTopic, localSubscriberId, CreateOrAttach.CREATE_OR_ATTACH,
                                    new TestCallback(queue), null);
        assertTrue(queue.take());
        startDelivery(mySubscriber, myTopic, localSubscriberId, new TestMessageHandler(consumeQueue));
        // Publish some messages
        int batchSize = 10;
        for (int i = 0; i < batchSize; i++) {
            myPublisher.asyncPublish(myTopic, getMsg(i), new TestCallback(queue), null);
            assertTrue(queue.take());
            assertTrue(consumeQueue.take());
        }
        // Now manually send a consume message for each message received
        for (int i = 0; i < batchSize; i++) {
            boolean success = true;
            try {
                mySubscriber.consume(myTopic, localSubscriberId, MessageSeqId.newBuilder().setLocalComponent(i + 1)
                                     .build());
            } catch (ClientNotSubscribedException e) {
                success = false;
            }
            assertTrue(success);
        }
        // Since the consume call eventually does an async write to the Netty
        // channel, the writing of the consume requests may not have completed
        // yet before we stop the client. Sleep a little before we stop the
        // client just so error messages are not logged.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error("Thread was interrupted while waiting to stop client for manual consume test!!", e);
        }
        myClient.close();
    }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

        // start region gain
        startRegion(regionId);

        // sub it again
        for (Map.Entry<String, HedwigClient> entry : regionClientsMap.entrySet()) {
            HedwigClient client = entry.getValue();
            for (int i = 0; i < batchSize; i++) {
                client.getSubscriber().asyncSubscribe(ByteString.copyFromUtf8("Topic" + i),
                                                      ByteString.copyFromUtf8("LocalSubscriber"), CreateOrAttach.CREATE_OR_ATTACH,
                                                      new TestCallback(queue), null);
                assertTrue(queue.take());
            }
        }

        // Start delivery for local subscribers in all regions
        for (Map.Entry<String, HedwigClient> entry : regionClientsMap.entrySet()) {
            HedwigClient client = entry.getValue();
            for (int i = 0; i < batchSize; i++) {
                client.getSubscriber().startDelivery(ByteString.copyFromUtf8("Topic" + i),
                                                     ByteString.copyFromUtf8("LocalSubscriber"), new TestMessageHandler(consumeQueue));
            }
        }

        // Now start publishing messages for the subscribed topics in one of the
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

    public void testAttachExistingSubscriptionsWhenARegionDown() throws Exception {
        int batchSize = 10;
       
        // sub it remotely to make subscriptions existed
        for (Map.Entry<String, HedwigClient> entry : regionClientsMap.entrySet()) {
            HedwigClient client = entry.getValue();
            for (int i = 0; i < batchSize; i++) {
                client.getSubscriber().asyncSubscribe(ByteString.copyFromUtf8("Topic" + i),
                                                      ByteString.copyFromUtf8("LocalSubscriber"), CreateOrAttach.CREATE_OR_ATTACH,
                                                      new TestCallback(queue), null);
                assertTrue(queue.take());
            }
        }

        // stop regions
        for (int i=0; i<numRegions; i++) {
            stopRegion(i);
        }
        // start regions again
        for (int i=0; i<numRegions; i++) {
            startRegion(i);
        }

        // first shut down a region
        Random r = new Random();
        int regionId = r.nextInt(numRegions);
        stopRegion(regionId);
        // subscribe to topics when a region shuts down
        // it should succeed since the subscriptions existed before
        for (HedwigClient client : regionClientsMap.values()) {
            for (int i = 0; i < batchSize; i++) {
                client.getSubscriber().asyncSubscribe(ByteString.copyFromUtf8("Topic" + i),
                                                      ByteString.copyFromUtf8("LocalSubscriber"), CreateOrAttach.CREATE_OR_ATTACH,
                                                      new TestCallback(queue), null);
                assertTrue(queue.take());
            }
        }

        // Start delivery for local subscribers in all regions
        for (Map.Entry<String, HedwigClient> entry : regionClientsMap.entrySet()) {
            HedwigClient client = entry.getValue();
            for (int i = 0; i < batchSize; i++) {
                client.getSubscriber().startDelivery(ByteString.copyFromUtf8("Topic" + i),
                                                     ByteString.copyFromUtf8("LocalSubscriber"), new TestMessageHandler(consumeQueue));
            }
        }

        // start region again
        startRegion(regionId);
        // wait for retry
        Thread.sleep(3 * TEST_RETRY_REMOTE_SUBSCRIBE_INTERVAL_VALUE);

        String regionName = REGION_PREFIX + regionId;
        HedwigClient client = regionClientsMap.get(regionName);
        for (int i = 0; i < batchSize; i++) {
            client.getSubscriber().asyncSubscribe(ByteString.copyFromUtf8("Topic" + i),
                                                  ByteString.copyFromUtf8("LocalSubscriber"), CreateOrAttach.CREATE_OR_ATTACH,
                                                  new TestCallback(queue), null);
            assertTrue(queue.take());
            client.getSubscriber().startDelivery(ByteString.copyFromUtf8("Topic" + i),
                    ByteString.copyFromUtf8("LocalSubscriber"), new TestMessageHandler(consumeQueue));
        }

        // Now start publishing messages for the subscribed topics in one of the
        // regions and verify that it gets delivered and consumed in all of the
        // other ones.       
        Publisher publisher = client.getPublisher();
        for (int i = 0; i < batchSize; i++) {
            publisher.asyncPublish(ByteString.copyFromUtf8("Topic" + i), Message.newBuilder().setBody(
                                   ByteString.copyFromUtf8(regionName + "-Message" + i)).build(), new TestCallback(queue), null);
            assertTrue(queue.take());
        }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

    @Override
    @Before
    public void setUp() throws Exception {
        super.setUp();
        client = new HedwigClient(new TestClientConfiguration());
        publisher = client.getPublisher();
        subscriber = client.getSubscriber();
    }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

    }
   
    @Override
    public void setUp() throws Exception {
        super.setUp();
        client = new HedwigClient(new HubClientConfiguration());

        publisher = client.getPublisher();
        subscriber = client.getSubscriber();
    }
View Full Code Here

Examples of org.apache.hedwig.client.HedwigClient

    private final Publisher publisher;
    private final Subscriber subscriber;
    private final CommandLine cmd;

    public HedwigBenchmark(ClientConfiguration cfg, CommandLine cmd) {
        client = new HedwigClient(cfg);
        publisher = client.getPublisher();
        subscriber = client.getSubscriber();
        this.cmd = cmd;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.