Search in sources :

Example 11 with JMSConnectionInfo

use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.

the class TestJMSAccessorService method testUnRegisterTopic.

@Test
public void testUnRegisterTopic() {
    try {
        HCatAccessorService hcatService = services.get(HCatAccessorService.class);
        JMSAccessorService jmsService = services.get(JMSAccessorService.class);
        String server = "hcat.server.com:5080";
        String topic = "hcatalog.mydb.mytable";
        JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
        jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(server));
        MessageReceiver receiver1 = jmsService.getMessageReceiver(connInfo, topic);
        assertNotNull(receiver1);
        jmsService.unregisterFromNotification(connInfo, topic);
        receiver1 = jmsService.getMessageReceiver(connInfo, topic);
        assertEquals(null, receiver1);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception encountered : " + e);
    }
}
Also used : HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) MessageReceiver(org.apache.oozie.jms.MessageReceiver) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) Test(org.junit.Test)

Example 12 with JMSConnectionInfo

use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.

the class TestJMSAccessorService method testConnection.

@Test
public void testConnection() throws Exception {
    HCatAccessorService hcatService = services.get(HCatAccessorService.class);
    JMSAccessorService jmsService = services.get(JMSAccessorService.class);
    // both servers should connect to default JMS server
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcatserver.blue.server.com:8020"));
    ConnectionContext ctxt1 = jmsService.createConnectionContext(connInfo);
    assertTrue(ctxt1.isConnectionInitialized());
    JMSConnectionInfo connInfo1 = hcatService.getJMSConnectionInfo(new URI("http://unknown:80"));
    ConnectionContext ctxt2 = jmsService.createConnectionContext(connInfo1);
    assertTrue(ctxt2.isConnectionInitialized());
    assertEquals(ctxt1, ctxt2);
    ctxt1.close();
}
Also used : JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) ConnectionContext(org.apache.oozie.jms.ConnectionContext) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) URI(java.net.URI) Test(org.junit.Test)

Example 13 with JMSConnectionInfo

use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.

the class TestJMSAccessorService method testRegisterSingleConsumerPerTopic.

@Test
public void testRegisterSingleConsumerPerTopic() {
    try {
        HCatAccessorService hcatService = services.get(HCatAccessorService.class);
        JMSAccessorService jmsService = services.get(JMSAccessorService.class);
        String server = "hcat.server.com:5080";
        String topic = "hcat.mydb.mytable";
        JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
        jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(server));
        MessageReceiver receiver1 = jmsService.getMessageReceiver(connInfo, topic);
        jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(server));
        MessageReceiver receiver2 = jmsService.getMessageReceiver(connInfo, topic);
        assertEquals(receiver1, receiver2);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception encountered : " + e);
    }
}
Also used : HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) MessageReceiver(org.apache.oozie.jms.MessageReceiver) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) Test(org.junit.Test)

Example 14 with JMSConnectionInfo

use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.

the class TestJMSAccessorService method testConnectionRetryExceptionListener.

@Test
public void testConnectionRetryExceptionListener() throws Exception {
    services.destroy();
    services = super.setupServicesForHCatalog();
    int randomPort = 30000 + random.nextInt(10000);
    String brokerURL = "tcp://localhost:" + randomPort;
    String jndiPropertiesString = "java.naming.factory.initial#" + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + brokerURL + ";" + "connectionFactoryNames#" + "ConnectionFactory";
    Configuration servicesConf = services.getConf();
    servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
    servicesConf.set(JMSAccessorService.CONF_RETRY_MAX_ATTEMPTS, "3");
    servicesConf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, "default=" + jndiPropertiesString);
    services.init();
    HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
    JMSAccessorService jmsService = Services.get().get(JMSAccessorService.class);
    String publisherAuthority = "hcat.server.com:5080";
    String topic = "topic.topic1";
    // Start the broker
    BrokerService broker = new BrokerService();
    broker.addConnector(brokerURL);
    broker.setDataDirectory(getTestCaseDir());
    broker.start();
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
    jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(publisherAuthority));
    assertTrue(jmsService.isListeningToTopic(connInfo, topic));
    assertFalse(jmsService.isConnectionInRetryList(connInfo));
    assertFalse(jmsService.isTopicInRetryList(connInfo, topic));
    ConnectionContext connCtxt = jmsService.createConnectionContext(connInfo);
    broker.stop();
    try {
        connCtxt.createSession(Session.AUTO_ACKNOWLEDGE);
        fail("Exception expected");
    } catch (Exception e) {
        Thread.sleep(100);
        assertFalse(jmsService.isListeningToTopic(connInfo, topic));
        assertTrue(jmsService.isConnectionInRetryList(connInfo));
        assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
    }
    broker = new BrokerService();
    broker.addConnector(brokerURL);
    broker.setDataDirectory(getTestCaseDir());
    broker.start();
    Thread.sleep(1000);
    assertTrue(jmsService.isListeningToTopic(connInfo, topic));
    assertFalse(jmsService.isConnectionInRetryList(connInfo));
    assertFalse(jmsService.isTopicInRetryList(connInfo, topic));
    broker.stop();
    jmsService.destroy();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) ConnectionContext(org.apache.oozie.jms.ConnectionContext) DefaultConnectionContext(org.apache.oozie.jms.DefaultConnectionContext) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) Test(org.junit.Test)

Example 15 with JMSConnectionInfo

use of org.apache.oozie.jms.JMSConnectionInfo in project oozie by apache.

the class TestJMSAccessorService method testConnectionRetryMaxAttempt.

@Test
public void testConnectionRetryMaxAttempt() throws Exception {
    services.destroy();
    services = super.setupServicesForHCatalog();
    String jndiPropertiesString = "java.naming.factory.initial#" + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + "tcp://localhost:12345;connectionFactoryNames#ConnectionFactory";
    Configuration servicesConf = services.getConf();
    servicesConf.set(JMSAccessorService.CONF_RETRY_INITIAL_DELAY, "1");
    servicesConf.set(JMSAccessorService.CONF_RETRY_MAX_ATTEMPTS, "1");
    servicesConf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, "default=" + jndiPropertiesString);
    services.init();
    HCatAccessorService hcatService = Services.get().get(HCatAccessorService.class);
    JMSAccessorService jmsService = Services.get().get(JMSAccessorService.class);
    String publisherAuthority = "hcat.server.com:5080";
    String topic = "topic.topic1";
    JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcat.server.com:8020"));
    jmsService.registerForNotification(connInfo, topic, new HCatMessageHandler(publisherAuthority));
    assertTrue(jmsService.isConnectionInRetryList(connInfo));
    assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
    assertFalse(jmsService.isListeningToTopic(connInfo, topic));
    Thread.sleep(1100);
    // Should not retry again as max attempt is 1
    assertTrue(jmsService.isConnectionInRetryList(connInfo));
    assertTrue(jmsService.isTopicInRetryList(connInfo, topic));
    assertFalse(jmsService.isListeningToTopic(connInfo, topic));
    assertEquals(1, jmsService.getNumConnectionAttempts(connInfo));
    assertFalse(jmsService.retryConnection(connInfo));
    jmsService.destroy();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HCatMessageHandler(org.apache.oozie.dependency.hcat.HCatMessageHandler) JMSConnectionInfo(org.apache.oozie.jms.JMSConnectionInfo) URI(java.net.URI) Test(org.junit.Test)

Aggregations

JMSConnectionInfo (org.apache.oozie.jms.JMSConnectionInfo)17 URI (java.net.URI)10 Test (org.junit.Test)10 Configuration (org.apache.hadoop.conf.Configuration)8 HCatMessageHandler (org.apache.oozie.dependency.hcat.HCatMessageHandler)5 ConnectionContext (org.apache.oozie.jms.ConnectionContext)4 BrokerService (org.apache.activemq.broker.BrokerService)3 DefaultConnectionContext (org.apache.oozie.jms.DefaultConnectionContext)3 MessageReceiver (org.apache.oozie.jms.MessageReceiver)2 HCatURI (org.apache.oozie.util.HCatURI)2 MappingRule (org.apache.oozie.util.MappingRule)2 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 JMSConnectionInfoBean (org.apache.oozie.client.rest.JMSConnectionInfoBean)1 JMSAccessorService (org.apache.oozie.service.JMSAccessorService)1 JMSTopicService (org.apache.oozie.service.JMSTopicService)1