use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class JMSAccessorService method getConnectionContextImpl.
private ConnectionContext getConnectionContextImpl() {
Class<?> defaultClazz = ConfigurationService.getClass(conf, JMS_CONNECTION_CONTEXT_IMPL);
ConnectionContext connCtx = null;
if (defaultClazz == DefaultConnectionContext.class) {
connCtx = new DefaultConnectionContext();
} else {
connCtx = (ConnectionContext) ReflectionUtils.newInstance(defaultClazz, null);
}
return connCtx;
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class TestJMSAccessorService method testConnectionContext.
@Test
public void testConnectionContext() throws ServiceException {
try {
services.destroy();
services = super.setupServicesForHCatalog();
Configuration conf = services.getConf();
// set the connection factory name
String jmsURL = "hcat://${1}.${2}.server.com:8020=java.naming.factory.initial#" + "org.apache.activemq.jndi.ActiveMQInitialContextFactory" + ";java.naming.provider.url#vm://localhost?broker.persistent=false;" + "connectionFactoryNames#dynamicFactories/hcat.prod.${1}";
conf.set(HCatAccessorService.JMS_CONNECTIONS_PROPERTIES, jmsURL);
services.init();
HCatAccessorService hcatService = services.get(HCatAccessorService.class);
JMSConnectionInfo connInfo = hcatService.getJMSConnectionInfo(new URI("hcat://hcatserver.blue.server.com:8020"));
assertEquals("java.naming.factory.initial#org.apache.activemq.jndi.ActiveMQInitialContextFactory;java.naming.provider.url#" + "vm://localhost?broker.persistent=false;connectionFactoryNames#dynamicFactories/hcat.prod.hcatserver", connInfo.getJNDIPropertiesString());
ConnectionContext ctx1 = new DefaultConnectionContext();
ctx1.createConnection(connInfo.getJNDIProperties());
BrokerService broker = new BrokerService();
broker.setDataDirectory(getTestCaseDir());
// Without this stop testConnectionRetry fails with
// javax.management.InstanceAlreadyExistsException: org.apache.activemq:BrokerName=localhost,Type=Broker
broker.stop();
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception " + e);
}
}
use of org.apache.oozie.jms.ConnectionContext 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();
}
use of org.apache.oozie.jms.ConnectionContext 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();
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class TestJMSJobEventListener method getConnectionContext.
private ConnectionContext getConnectionContext() {
Configuration conf = services.getConf();
String jmsProps = conf.get(JMSJobEventListener.JMS_CONNECTION_PROPERTIES);
JMSConnectionInfo connInfo = new JMSConnectionInfo(jmsProps);
JMSAccessorService jmsService = Services.get().get(JMSAccessorService.class);
ConnectionContext jmsContext = jmsService.createProducerConnectionContext(connInfo);
return jmsContext;
}
Aggregations