Exemplo n.º 1
0
TEST(MessageFilterTest, testNullMessageFilter) {
  Hedwig::Configuration* conf = new MessageFilterConfiguration();
  std::auto_ptr<Hedwig::Configuration> confptr(conf);
  
  Hedwig::Client* client = new Hedwig::Client(*conf);
  std::auto_ptr<Hedwig::Client> clientptr(client);

  Hedwig::Subscriber& sub = client->getSubscriber();

  std::string topic = "testNullMessageFilter";
  std::string subid = "myTestSubid";

  sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH);

  GapCheckingMessageHandlerCallback * cb =
    new GapCheckingMessageHandlerCallback(sub, 0, 0, 0, true);
  Hedwig::MessageHandlerCallbackPtr handler(cb);
  Hedwig::ClientMessageFilterPtr filter(new ModMessageFilter());

  ASSERT_THROW(sub.startDeliveryWithFilter(topic, subid, handler,
                                           Hedwig::ClientMessageFilterPtr()),
               Hedwig::NullMessageFilterException);
  ASSERT_THROW(sub.startDeliveryWithFilter(topic, subid, 
                                           Hedwig::MessageHandlerCallbackPtr(), filter),
               Hedwig::NullMessageHandlerException);
}
Exemplo n.º 2
0
  void testAsyncSubcribeAndUnsubscribe() {
    SimpleWaitCondition* cond1 = new SimpleWaitCondition();
    std::auto_ptr<SimpleWaitCondition> cond1ptr(cond1);
    SimpleWaitCondition* cond2 = new SimpleWaitCondition();
    std::auto_ptr<SimpleWaitCondition> cond2ptr(cond2);

    Hedwig::Configuration* conf = new TestServerConfiguration();
    std::auto_ptr<Hedwig::Configuration> confptr(conf);

    Hedwig::Client* client = new Hedwig::Client(*conf);
    std::auto_ptr<Hedwig::Client> clientptr(client);

    Hedwig::Subscriber& sub = client->getSubscriber();
   
    Hedwig::OperationCallbackPtr testcb1(new TestCallback(cond1));
    Hedwig::OperationCallbackPtr testcb2(new TestCallback(cond2));

    sub.asyncSubscribe("testTopic", "mySubscriberId-4", Hedwig::SubscribeRequest::CREATE_OR_ATTACH, testcb1);
    cond1->wait();
    CPPUNIT_ASSERT(cond1->wasSuccess());
    
    sub.asyncUnsubscribe("testTopic", "mySubscriberId-4", testcb2);
    cond2->wait();
    CPPUNIT_ASSERT(cond2->wasSuccess());
  }
Exemplo n.º 3
0
  void testSyncSubscribeAttach() {
    Hedwig::Configuration* conf = new TestServerConfiguration();
    std::auto_ptr<Hedwig::Configuration> confptr(conf);

    Hedwig::Client* client = new Hedwig::Client(*conf);
    std::auto_ptr<Hedwig::Client> clientptr(client);

    Hedwig::Subscriber& sub = client->getSubscriber();
    
    CPPUNIT_ASSERT_THROW(sub.subscribe("iAmATopicWhoDoesNotExist", "mySubscriberId-2", Hedwig::SubscribeRequest::ATTACH), Hedwig::ClientException);
  }
Exemplo n.º 4
0
  void testSyncSubscribe() {
    Hedwig::Configuration* conf = new TestServerConfiguration();
    std::auto_ptr<Hedwig::Configuration> confptr(conf);
    
    Hedwig::Client* client = new Hedwig::Client(*conf);
    std::auto_ptr<Hedwig::Client> clientptr(client);

    Hedwig::Subscriber& sub = client->getSubscriber();
    
    sub.subscribe("testTopic", "mySubscriberId-1", Hedwig::SubscribeRequest::CREATE_OR_ATTACH);
  }
Exemplo n.º 5
0
  void testUnsubscribeWithoutSubscribe() {
    Hedwig::Configuration* conf = new TestServerConfiguration();
    std::auto_ptr<Hedwig::Configuration> confptr(conf);
    
    Hedwig::Client* client = new Hedwig::Client(*conf);
    std::auto_ptr<Hedwig::Client> clientptr(client);

    Hedwig::Subscriber& sub = client->getSubscriber();
    
    CPPUNIT_ASSERT_THROW(sub.unsubscribe("testTopic", "mySubscriberId-7"), Hedwig::NotSubscribedException);
  }
Exemplo n.º 6
0
  void testSubscribeTwice() {
    Hedwig::Configuration* conf = new TestServerConfiguration();
    std::auto_ptr<Hedwig::Configuration> confptr(conf);
    
    Hedwig::Client* client = new Hedwig::Client(*conf);
    std::auto_ptr<Hedwig::Client> clientptr(client);

    Hedwig::Subscriber& sub = client->getSubscriber();
    
    sub.subscribe("testTopic", "mySubscriberId-8", Hedwig::SubscribeRequest::CREATE_OR_ATTACH);
    CPPUNIT_ASSERT_THROW(sub.subscribe("testTopic", "mySubscriberId-8", Hedwig::SubscribeRequest::CREATE_OR_ATTACH), Hedwig::AlreadySubscribedException);
  }
Exemplo n.º 7
0
TEST(MessageFilterTest, testMessageFilter) {
  Hedwig::Configuration* conf = new MessageFilterConfiguration();
  std::auto_ptr<Hedwig::Configuration> confptr(conf);
  
  Hedwig::Client* client = new Hedwig::Client(*conf);
  std::auto_ptr<Hedwig::Client> clientptr(client);

  Hedwig::Subscriber& sub = client->getSubscriber();
  Hedwig::Publisher& pub = client->getPublisher();

  std::string topic = "testMessageFilter";
  std::string subid = "myTestSubid";
  sub.subscribe(topic, subid, Hedwig::SubscribeRequest::CREATE_OR_ATTACH);
  sub.closeSubscription(topic, subid);

  publishNums(pub, topic, 0, 100, 2);
  receiveNumModM(sub, topic, subid, 0, 50, 2, true);
}