Search in sources :

Example 1 with Publisher

use of com.yahoo.bullet.pubsub.Publisher in project bullet-storm by yahoo.

the class LoopBolt method createPublisher.

@Override
protected Publisher createPublisher() throws PubSubException {
    PubSub pubSub = PubSub.from(config);
    // Map is always not null and is validated to be a proper BulletStormConfig
    Map<String, Object> overrides = (Map<String, Object>) config.getAs(BulletStormConfig.LOOP_BOLT_PUBSUB_OVERRIDES, Map.class);
    log.info("Loaded pubsub overrides: {}", overrides);
    BulletStormConfig modified = new BulletStormConfig(config);
    overrides.forEach(modified::set);
    pubSub.switchContext(PubSub.Context.QUERY_SUBMISSION, modified);
    log.info("Switched the PubSub into query submission mode");
    Publisher publisher = pubSub.getPublisher();
    log.info("Setup PubSub: {} with Publisher: {}", pubSub, publisher);
    return publisher;
}
Also used : PubSub(com.yahoo.bullet.pubsub.PubSub) Publisher(com.yahoo.bullet.pubsub.Publisher) Map(java.util.Map)

Example 2 with Publisher

use of com.yahoo.bullet.pubsub.Publisher in project bullet-storm by yahoo.

the class DRPCPubSubTest method testQuerySubmissionSingleInstanceTypes.

@Test
public void testQuerySubmissionSingleInstanceTypes() throws Exception {
    config.set(DRPCConfig.PUBSUB_CONTEXT_NAME, PubSub.Context.QUERY_SUBMISSION.name());
    DRPCPubSub pubSub = new DRPCPubSub(config);
    Publisher publisher = pubSub.getPublisher();
    Subscriber subscriber = pubSub.getSubscriber();
    Assert.assertTrue(publisher instanceof DRPCQueryResultPubscriber);
    Assert.assertTrue(subscriber instanceof DRPCQueryResultPubscriber);
}
Also used : Subscriber(com.yahoo.bullet.pubsub.Subscriber) Publisher(com.yahoo.bullet.pubsub.Publisher) Test(org.testng.annotations.Test)

Example 3 with Publisher

use of com.yahoo.bullet.pubsub.Publisher in project bullet-storm by yahoo.

the class DRPCPubSubTest method testQuerySubmissionMultipleInstancesAreTheSameInstances.

@Test
public void testQuerySubmissionMultipleInstancesAreTheSameInstances() throws Exception {
    config.set(DRPCConfig.PUBSUB_CONTEXT_NAME, PubSub.Context.QUERY_SUBMISSION.name());
    DRPCPubSub pubSub = new DRPCPubSub(config);
    List<Publisher> publishers = pubSub.getPublishers(10);
    List<Subscriber> subscribers = pubSub.getSubscribers(20);
    Assert.assertEquals(publishers.size(), 10);
    // If we ask for more, the size is the same as the first call
    Assert.assertEquals(subscribers.size(), 10);
    // If we ask for less, the size is the same as the first call
    Assert.assertEquals(pubSub.getSubscribers(1).size(), 10);
    // If we ask for the same, the size is the same as the first call
    Assert.assertEquals(pubSub.getSubscribers(10).size(), 10);
    // The corresponding items are the same
    IntStream.range(0, 9).forEach(i -> Assert.assertTrue(publishers.get(i) == subscribers.get(i)));
    Publisher publisher = pubSub.getPublisher();
    Subscriber subscriber = pubSub.getSubscriber();
    // If you ask for one, it's the first one in the list
    Assert.assertTrue(publisher == subscriber);
    Assert.assertTrue(publishers.get(0) == publisher);
}
Also used : Subscriber(com.yahoo.bullet.pubsub.Subscriber) Publisher(com.yahoo.bullet.pubsub.Publisher) Test(org.testng.annotations.Test)

Example 4 with Publisher

use of com.yahoo.bullet.pubsub.Publisher in project bullet-core by yahoo.

the class RESTPubSubTest method testGetPublishers.

@Test
public void testGetPublishers() throws PubSubException {
    BulletConfig config = new BulletConfig("src/test/resources/test_config.yaml");
    config.set(BulletConfig.PUBSUB_CONTEXT_NAME, "QUERY_SUBMISSION");
    RESTPubSub pubSub = new RESTPubSub(config);
    List<Publisher> publishers = pubSub.getPublishers(8);
    Assert.assertNotNull(publishers);
    Assert.assertTrue(publishers.get(0) instanceof RESTQueryPublisher);
    Assert.assertTrue(publishers.get(7) instanceof RESTQueryPublisher);
    config.set(BulletConfig.PUBSUB_CONTEXT_NAME, "QUERY_PROCESSING");
    pubSub = new RESTPubSub(config);
    publishers = pubSub.getPublishers(8);
    Assert.assertNotNull(publishers);
    Assert.assertTrue(publishers.get(0) instanceof RESTResultPublisher);
    Assert.assertTrue(publishers.get(7) instanceof RESTResultPublisher);
}
Also used : Publisher(com.yahoo.bullet.pubsub.Publisher) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 5 with Publisher

use of com.yahoo.bullet.pubsub.Publisher in project bullet-core by yahoo.

the class RESTPubSubTest method testGetPublisher.

@Test
public void testGetPublisher() throws PubSubException {
    BulletConfig config = new BulletConfig("src/test/resources/test_config.yaml");
    config.set(BulletConfig.PUBSUB_CONTEXT_NAME, "QUERY_SUBMISSION");
    RESTPubSub pubSub = new RESTPubSub(config);
    Publisher publisher = pubSub.getPublisher();
    Assert.assertNotNull(publisher);
    Assert.assertTrue(publisher instanceof RESTQueryPublisher);
    config.set(BulletConfig.PUBSUB_CONTEXT_NAME, "QUERY_PROCESSING");
    pubSub = new RESTPubSub(config);
    publisher = pubSub.getPublisher();
    Assert.assertNotNull(publisher);
    Assert.assertTrue(publisher instanceof RESTResultPublisher);
}
Also used : Publisher(com.yahoo.bullet.pubsub.Publisher) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Aggregations

Publisher (com.yahoo.bullet.pubsub.Publisher)8 Test (org.testng.annotations.Test)6 Subscriber (com.yahoo.bullet.pubsub.Subscriber)4 BulletConfig (com.yahoo.bullet.common.BulletConfig)2 PubSub (com.yahoo.bullet.pubsub.PubSub)2 Map (java.util.Map)1