use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class TestJMSJobEventListener method testCoordinatorActionSelectorsNegative.
@Test
public void testCoordinatorActionSelectorsNegative() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.FAILED, "user1", "wf-app-name1", nominalTime, startDate, null);
ConnectionContext jmsContext = getConnectionContext();
try {
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
// Pass a selector which wont match and assert for null message
String selector = JMSHeaderConstants.USER + "='Non_matching_user'";
MessageConsumer consumer = jmsContext.createConsumer(session, coordEventListener.getTopic(cae), selector);
coordEventListener.onCoordinatorActionEvent(cae);
TextMessage message = (TextMessage) consumer.receive(5000);
assertNull(message);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class TestJMSJobEventListener method testWorkflowJobSelectorsAnd.
@Test
public void testWorkflowJobSelectorsAnd() {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
wfEventListener.init(conf);
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1", "wf-app-name1", new Date(), new Date());
ConnectionContext jmsContext = getConnectionContext();
try {
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
// Pass a selector using AND condition
String selector = JMSHeaderConstants.EVENT_STATUS + "='FAILURE' AND " + JMSHeaderConstants.APP_TYPE + "='WORKFLOW_JOB' AND " + JMSHeaderConstants.MESSAGE_TYPE + "='JOB'";
MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe), selector);
wfEventListener.onWorkflowJobEvent(wfe);
TextMessage message = (TextMessage) consumer.receive(5000);
WorkflowJobMessage wfFailMessage = JMSMessagingUtils.getEventMessage(message);
Assert.assertEquals(WorkflowJob.Status.FAILED, wfFailMessage.getStatus());
assertEquals("user1", wfFailMessage.getUser());
assertEquals(MessageType.JOB, wfFailMessage.getMessageType());
wfEventListener.destroy();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class TestJMSJobEventListener method testWorkflowJobSelectors.
@Test
public void testWorkflowJobSelectors() throws ParseException {
JMSJobEventListener wfEventListener = new JMSJobEventListener();
wfEventListener.init(conf);
WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user_1", "wf-app-name1", new Date(), new Date());
ConnectionContext jmsContext = getConnectionContext();
try {
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
String selector = JMSHeaderConstants.USER + "='user_1'";
MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe), selector);
wfEventListener.onWorkflowJobEvent(wfe);
TextMessage message = (TextMessage) consumer.receive(5000);
WorkflowJobMessage wfFailMessage = JMSMessagingUtils.getEventMessage(message);
Assert.assertEquals(WorkflowJob.Status.FAILED, wfFailMessage.getStatus());
assertEquals("user_1", wfFailMessage.getUser());
assertEquals(MessageType.JOB, wfFailMessage.getMessageType());
wfEventListener.destroy();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class TestJMSJobEventListener method testOnCoordinatorJobFailureEvent.
@Test
public void testOnCoordinatorJobFailureEvent() throws ParseException {
JMSJobEventListener coordEventListener = new JMSJobEventListener();
coordEventListener.init(conf);
Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
Date nominalTime = DateUtils.parseDateUTC("2011-07-11T00:00Z");
Date endDate = new Date();
CoordinatorActionEvent cae = new CoordinatorActionEvent("caId1", "caJobId1", CoordinatorAction.Status.FAILED, "user1", "wf-app-name1", nominalTime, startDate, null);
cae.setEndTime(endDate);
cae.setErrorCode("E0101");
cae.setErrorMessage("dummyError");
ConnectionContext jmsContext = getConnectionContext();
try {
Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = jmsContext.createConsumer(session, coordEventListener.getTopic(cae));
coordEventListener.onCoordinatorActionEvent(cae);
TextMessage message = (TextMessage) consumer.receive(5000);
assertFalse(message.getText().contains("missingDependency"));
CoordinatorActionMessage coordActionFailMessage = JMSMessagingUtils.getEventMessage(message);
assertEquals(CoordinatorAction.Status.FAILED, coordActionFailMessage.getStatus());
assertEquals(startDate, coordActionFailMessage.getStartTime());
assertEquals(endDate, coordActionFailMessage.getEndTime());
assertEquals("caJobId1", coordActionFailMessage.getParentId());
assertEquals("caId1", coordActionFailMessage.getId());
assertEquals(MessageType.JOB, coordActionFailMessage.getMessageType());
assertEquals(AppType.COORDINATOR_ACTION, coordActionFailMessage.getAppType());
assertEquals(EventStatus.FAILURE, coordActionFailMessage.getEventStatus());
assertEquals("user1", coordActionFailMessage.getUser());
assertEquals("wf-app-name1", coordActionFailMessage.getAppName());
assertEquals("E0101", coordActionFailMessage.getErrorCode());
assertEquals("dummyError", coordActionFailMessage.getErrorMessage());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.oozie.jms.ConnectionContext in project oozie by apache.
the class JMSAccessorService method createConnectionContext.
public ConnectionContext createConnectionContext(JMSConnectionInfo connInfo) {
ConnectionContext connCtxt = connectionMap.get(connInfo);
if (connCtxt == null) {
try {
connCtxt = getConnectionContextImpl();
connCtxt.createConnection(connInfo.getJNDIProperties());
connCtxt.setExceptionListener(new JMSExceptionListener(connInfo, connCtxt, true));
connectionMap.put(connInfo, connCtxt);
LOG.info("Connection established to JMS Server for [{0}]", connInfo);
} catch (Exception e) {
LOG.warn("Exception while establishing connection to JMS Server for [{0}]", connInfo, e);
return null;
}
}
return connCtxt;
}
Aggregations