Search in sources :

Example 6 with ConnectionContext

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

the class TestJMSJobEventListener method testOnCoordinatorActionWaitingEvent.

@Test
public void testOnCoordinatorActionWaitingEvent() throws ParseException {
    JMSJobEventListener wfEventListner = new JMSJobEventListener();
    wfEventListner.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.WAITING, "user1", "wf-app-name1", nominalTime, startDate, "missingDep1");
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListner.getTopic(cae));
        wfEventListner.onCoordinatorActionEvent(cae);
        TextMessage message = (TextMessage) consumer.receive(5000);
        assertFalse(message.getText().contains("endTime"));
        assertFalse(message.getText().contains("errorCode"));
        assertFalse(message.getText().contains("errorMessage"));
        CoordinatorActionMessage coordActionWaitingMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(CoordinatorAction.Status.WAITING, coordActionWaitingMessage.getStatus());
        assertEquals(startDate, coordActionWaitingMessage.getStartTime());
        assertEquals(nominalTime, coordActionWaitingMessage.getNominalTime());
        assertEquals("caJobId1", coordActionWaitingMessage.getParentId());
        assertEquals("caId1", coordActionWaitingMessage.getId());
        assertEquals(MessageType.JOB, coordActionWaitingMessage.getMessageType());
        assertEquals(AppType.COORDINATOR_ACTION, coordActionWaitingMessage.getAppType());
        assertEquals(EventStatus.WAITING, coordActionWaitingMessage.getEventStatus());
        assertEquals("user1", coordActionWaitingMessage.getUser());
        assertEquals("wf-app-name1", coordActionWaitingMessage.getAppName());
        assertEquals("missingDep1", coordActionWaitingMessage.getMissingDependency());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : CoordinatorActionMessage(org.apache.oozie.client.event.message.CoordinatorActionMessage) MessageConsumer(javax.jms.MessageConsumer) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 7 with ConnectionContext

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

the class TestJMSJobEventListener method testOnCoordinatorActionStartEvent.

@Test
public void testOnCoordinatorActionStartEvent() 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.RUNNING, "user1", "wf-app-name1", nominalTime, startDate, null);
    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("endTime"));
        assertFalse(message.getText().contains("errorCode"));
        assertFalse(message.getText().contains("errorMessage"));
        assertFalse(message.getText().contains("missingDependency"));
        CoordinatorActionMessage coordActionStartMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(CoordinatorAction.Status.RUNNING, coordActionStartMessage.getStatus());
        assertEquals(startDate, coordActionStartMessage.getStartTime());
        assertEquals("caJobId1", coordActionStartMessage.getParentId());
        assertEquals("caId1", coordActionStartMessage.getId());
        assertEquals(MessageType.JOB, coordActionStartMessage.getMessageType());
        assertEquals(AppType.COORDINATOR_ACTION, coordActionStartMessage.getAppType());
        assertEquals(EventStatus.STARTED, coordActionStartMessage.getEventStatus());
        assertEquals("user1", coordActionStartMessage.getUser());
        assertEquals("wf-app-name1", coordActionStartMessage.getAppName());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : CoordinatorActionMessage(org.apache.oozie.client.event.message.CoordinatorActionMessage) MessageConsumer(javax.jms.MessageConsumer) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 8 with ConnectionContext

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

the class TestJMSJobEventListener method testOnCoordinatorJobSuccessEvent.

@Test
public void testOnCoordinatorJobSuccessEvent() 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.SUCCEEDED, "user1", "wf-app-name1", nominalTime, startDate, null);
    cae.setEndTime(endDate);
    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("errorCode"));
        assertFalse(message.getText().contains("errorMessage"));
        assertFalse(message.getText().contains("missingDependency"));
        CoordinatorActionMessage coordActionSuccessMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(CoordinatorAction.Status.SUCCEEDED, coordActionSuccessMessage.getStatus());
        assertEquals(startDate, coordActionSuccessMessage.getStartTime());
        assertEquals(endDate, coordActionSuccessMessage.getEndTime());
        assertEquals("caJobId1", coordActionSuccessMessage.getParentId());
        assertEquals("caId1", coordActionSuccessMessage.getId());
        assertEquals(MessageType.JOB, coordActionSuccessMessage.getMessageType());
        assertEquals(AppType.COORDINATOR_ACTION, coordActionSuccessMessage.getAppType());
        assertEquals(EventStatus.SUCCESS, coordActionSuccessMessage.getEventStatus());
        assertEquals("user1", coordActionSuccessMessage.getUser());
        assertEquals("wf-app-name1", coordActionSuccessMessage.getAppName());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : CoordinatorActionMessage(org.apache.oozie.client.event.message.CoordinatorActionMessage) MessageConsumer(javax.jms.MessageConsumer) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 9 with ConnectionContext

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

the class TestJMSJobEventListener method testOnWorkflowJobStartedEvent.

@Test
public void testOnWorkflowJobStartedEvent() throws ParseException {
    JMSJobEventListener wfEventListener = new JMSJobEventListener();
    wfEventListener.init(conf);
    Date startDate = DateUtils.parseDateUTC("2012-07-22T00:00Z");
    WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.RUNNING, "user1", "wf-app-name1", startDate, null);
    ConnectionContext jmsContext = getConnectionContext();
    try {
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe));
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        assertFalse(message.getText().contains("endTime"));
        WorkflowJobMessage wfStartMessage = JMSMessagingUtils.getEventMessage(message);
        assertEquals(WorkflowJob.Status.RUNNING, wfStartMessage.getStatus());
        assertEquals(startDate, wfStartMessage.getStartTime());
        assertEquals("wfId1", wfStartMessage.getId());
        assertEquals("caId1", wfStartMessage.getParentId());
        assertEquals(MessageType.JOB, wfStartMessage.getMessageType());
        assertEquals(AppType.WORKFLOW_JOB, wfStartMessage.getAppType());
        assertEquals(EventStatus.STARTED, wfStartMessage.getEventStatus());
        assertEquals("user1", wfStartMessage.getUser());
        assertEquals("wf-app-name1", wfStartMessage.getAppName());
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) WorkflowJobMessage(org.apache.oozie.client.event.message.WorkflowJobMessage) ConnectionContext(org.apache.oozie.jms.ConnectionContext) Date(java.util.Date) TextMessage(javax.jms.TextMessage) ParseException(java.text.ParseException) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Example 10 with ConnectionContext

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

the class TestJMSJobEventListener method testConnectionDrop.

@Test
public void testConnectionDrop() {
    Random random = new Random();
    try {
        services.destroy();
        services = new Services();
        Configuration conf = services.getConf();
        conf.set(Services.CONF_SERVICE_EXT_CLASSES, JMSAccessorService.class.getName() + "," + JMSTopicService.class.getName());
        int randomPort = 30000 + random.nextInt(10000);
        String brokerURl = "tcp://localhost:" + randomPort;
        conf.set(JMSJobEventListener.JMS_CONNECTION_PROPERTIES, "java.naming.factory.initial#" + ActiveMQConnFactory + ";" + "java.naming.provider.url#" + brokerURl + ";connectionFactoryNames#" + "ConnectionFactory");
        services.init();
        JMSJobEventListener wfEventListener = new JMSJobEventListener();
        wfEventListener.init(conf);
        BrokerService broker = new BrokerService();
        broker.setDataDirectory(getTestCaseDir());
        broker.addConnector(brokerURl);
        broker.start();
        ConnectionContext jmsContext = getConnectionContext();
        assertNotNull(jmsContext);
        broker.stop();
        jmsContext = getConnectionContext();
        // Exception Listener should have removed the old conn context
        assertNull(jmsContext);
        broker = new BrokerService();
        broker.setDataDirectory(getTestCaseDir());
        broker.addConnector(brokerURl);
        broker.start();
        WorkflowJobEvent wfe = new WorkflowJobEvent("wfId1", "caId1", WorkflowJob.Status.FAILED, "user1", "wf-app-name1", new Date(), new Date());
        jmsContext = getConnectionContext();
        Session session = jmsContext.createSession(Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = jmsContext.createConsumer(session, wfEventListener.getTopic(wfe));
        wfEventListener.onWorkflowJobEvent(wfe);
        TextMessage message = (TextMessage) consumer.receive(5000);
        assertNotNull(message);
        broker.stop();
        wfEventListener.destroy();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Configuration(org.apache.hadoop.conf.Configuration) JMSAccessorService(org.apache.oozie.service.JMSAccessorService) Date(java.util.Date) ParseException(java.text.ParseException) Services(org.apache.oozie.service.Services) Random(java.util.Random) ConnectionContext(org.apache.oozie.jms.ConnectionContext) BrokerService(org.apache.activemq.broker.BrokerService) TextMessage(javax.jms.TextMessage) JMSJobEventListener(org.apache.oozie.jms.JMSJobEventListener) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ConnectionContext (org.apache.oozie.jms.ConnectionContext)24 Test (org.junit.Test)18 ParseException (java.text.ParseException)15 Date (java.util.Date)15 MessageConsumer (javax.jms.MessageConsumer)15 Session (javax.jms.Session)15 TextMessage (javax.jms.TextMessage)15 JMSJobEventListener (org.apache.oozie.jms.JMSJobEventListener)15 DefaultConnectionContext (org.apache.oozie.jms.DefaultConnectionContext)8 WorkflowJobMessage (org.apache.oozie.client.event.message.WorkflowJobMessage)7 CoordinatorActionMessage (org.apache.oozie.client.event.message.CoordinatorActionMessage)5 Configuration (org.apache.hadoop.conf.Configuration)4 JMSConnectionInfo (org.apache.oozie.jms.JMSConnectionInfo)4 URI (java.net.URI)3 BrokerService (org.apache.activemq.broker.BrokerService)3 MessageReceiver (org.apache.oozie.jms.MessageReceiver)2 JMSAccessorService (org.apache.oozie.service.JMSAccessorService)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1