Package org.fcrepo.server.messaging

Examples of org.fcrepo.server.messaging.JMSManager


    @Test
    public void testVMMessage() throws Exception {
        String topic = "jmsmanager.test";
        properties.setProperty("topic." + topic, topic);
        JMSManager jmsMgr = new JMSManager(properties);
        jmsMgr.listen(topic, this);
        jmsMgr.send(topic, messageText);
        checkMessage(topic, DestinationType.Topic, messageText);
        jmsMgr.close();
    }
View Full Code Here


    }

    @Test
    public void testCreateTopic() throws Exception {
        String topic = "jmsmanager.test";
        JMSManager jmsMgr = new JMSManager(properties);
        jmsMgr.createDestination(topic, DestinationType.Topic);
        jmsMgr.listen(topic, this);
        jmsMgr.send(topic, messageText);
        checkMessage(topic, DestinationType.Topic, messageText);
        jmsMgr.close();
    }
View Full Code Here

    }

    @Test
    public void testCreateQueue() throws Exception {
        String queue = "jmsmanager";
        JMSManager jmsMgr = new JMSManager(properties);
        jmsMgr.createDestination(queue, DestinationType.Queue);
        jmsMgr.listen(queue, this);
        jmsMgr.send(queue, messageText);
        checkMessage(queue, DestinationType.Queue, messageText);
        jmsMgr.close();
    }
View Full Code Here

    }

    @Test
    public void testSendToDestination() throws Exception {
        String topic = "jmsmanager.test";
        JMSManager jmsMgr = new JMSManager(properties);
        Destination destination =
            jmsMgr.createDestination(topic, DestinationType.Topic);
        TextMessage textMessage = jmsMgr.createTextMessage(topic, messageText);
        jmsMgr.listen(destination, this);
        jmsMgr.send(destination, textMessage);
        checkMessage(topic, DestinationType.Topic, messageText);
        jmsMgr.close();
    }
View Full Code Here

    }

    @Test
    public void testMessageSelectors() throws Exception {
        String topic = "jmsmanager.test";
        JMSManager jmsMgr = new JMSManager(properties);
        jmsMgr.createDestination(topic, DestinationType.Topic);

        String messageSelector = "jmsProperty IN ('selectMe')";
        jmsMgr.listen(topic, messageSelector, this);

        TextMessage textMessage = jmsMgr.createTextMessage(topic, messageText);
        textMessage.setStringProperty("jmsProperty", "selectMe");
        jmsMgr.send(topic, textMessage);
        checkMessage(topic, DestinationType.Topic, messageText);

        textMessage = jmsMgr.createTextMessage(topic, messageText);
        textMessage.setStringProperty("jmsProperty", "doNotSelectMe");
        jmsMgr.send(topic, textMessage);
        checkNoMessage();

        jmsMgr.close();
    }
View Full Code Here

    @Test
    public void testDurableSubscription() throws Exception {
        // Connect and ensure that a message can be received
        String topic = "jmsmanager.test.durable";
        JMSManager jmsMgr = new JMSManager(properties, "clientId1");
        jmsMgr.listenDurable(topic, this);
        jmsMgr.send(topic, messageText);
        checkMessage(topic, DestinationType.Topic, messageText);

        // Check for listener durability
        String message2 = "Message Number 2";
        jmsMgr.stopDurable(topic);
        jmsMgr.send(topic, message2);
        checkNoMessage();
        jmsMgr.listenDurable(topic, this);
        checkMessage(topic, DestinationType.Topic, message2);

        // Check unsubscribe
        String message3 = "Message Number 3";
        jmsMgr.unsubscribeDurable(topic);
        jmsMgr.send(topic, message3);
        checkNoMessage();
        jmsMgr.close();
    }
View Full Code Here

    }

    @Test
    public void testSendMessages() throws Exception {
        String topic = "jmsmanager.test";
        JMSManager jmsMgr = new JMSManager(properties);
        jmsMgr.createDestination(topic, DestinationType.Topic);
        jmsMgr.listen(topic, this);

        TextMessage textMessage = jmsMgr.createTextMessage(topic, messageText);
        jmsMgr.send(topic, textMessage);
        checkMessage(topic, DestinationType.Topic, messageText);

        BytesMessage bytesMessage = jmsMgr.createBytesMessage(topic);
        bytesMessage.writeBytes(messageText.getBytes());
        jmsMgr.send(topic, bytesMessage);
        checkMessage(topic, DestinationType.Topic, null);

        ObjectMessage objectMessage = jmsMgr.createObjectMessage(topic, messageText);
        jmsMgr.send(topic, objectMessage);
        checkMessage(topic, DestinationType.Topic, null);

        MapMessage mapMessage = jmsMgr.createMapMessage(topic);
        mapMessage.setString("key", messageText);
        jmsMgr.send(topic, mapMessage);
        checkMessage(topic, DestinationType.Topic, null);

        StringBuffer serializableObj = new StringBuffer(messageText);
        jmsMgr.send(topic, serializableObj);
        checkMessage(topic, DestinationType.Topic, null);

        jmsMgr.close();
    }
View Full Code Here

    }

    @Test
    public void testMessageVolume() throws Exception {
        String topic = "jmsmanager.test";
        JMSManager jmsMgr = new JMSManager(properties);
        jmsMgr.createDestination(topic, DestinationType.Topic);
        jmsMgr.listen(topic, this);

        int sentMessages = 0;
        for(int i=0; i<timeout; i++) {
            jmsMgr.send(topic, messageText);
            ++sentMessages;
        }

        long startTime = System.currentTimeMillis();
        boolean timeExpired = false;
        while (messageCount < sentMessages) {
            if (timeExpired) {
                fail("Sent " + sentMessages + " messages but only received "
                        + messageCount + " messages");
            }
            if (System.currentTimeMillis() > (startTime + timeout)) {
                timeExpired = true;
            }
        }

        jmsMgr.close();
    }
View Full Code Here

    @Test
    public void testInvalidProperties() throws Exception {
        // Null properties
        try {
            new JMSManager(null);
            fail("Creating a JMSManager with null properties " +
                 "should throw an exception");
        } catch(MessagingException expected) {
            assertTrue(expected.getMessage().contains("properties"));
        }

        // Missing all properties
        properties = new Properties();

        try {
            new JMSManager(properties);
            fail("Creating a JMSManager with no properties " +
                 "should throw an exception");
        } catch(MessagingException expected) {
            assertTrue(expected.getMessage().contains(Context.INITIAL_CONTEXT_FACTORY));
        }

        // Missing provider url property
        properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                               "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
                               "ConnectionFactory");

        try {
            new JMSManager(properties);
            fail("Creating a JMSManager with no provider url " +
                 "property should throw an exception");
        } catch(MessagingException expected) {
            assertTrue(expected.getMessage().contains(Context.PROVIDER_URL));
        }

        // Missing initial context factory property
        properties = new Properties();
        properties.setProperty(Context.PROVIDER_URL,
                               "vm://localhost");
        properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
                               "ConnectionFactory");

        try {
            new JMSManager(properties);
            fail("Creating a JMSManager with no initial context factory " +
                 "property should throw an exception");
        } catch(MessagingException expected) {
            assertTrue(expected.getMessage().contains(Context.INITIAL_CONTEXT_FACTORY));
        }

        // Invalid initial context factory
        properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                               "test.InvalidInitialContextFactory");
        properties.setProperty(Context.PROVIDER_URL,
                               "vm://localhost");
        properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
                               "ConnectionFactory");
        try {
            new JMSManager(properties);
            fail("Starting a JMSManager with an invalid initial " +
                 "context factory should throw an exception");
        } catch(MessagingException expected) {}

        // Invalid provider url
        properties = new Properties();
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                               "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        properties.setProperty(Context.PROVIDER_URL,
                               "tcp://localhost:00000");
        properties.setProperty(JMSManager.CONNECTION_FACTORY_NAME,
                               "ConnectionFactory");
        try {
            new JMSManager(properties);
            fail("Starting a JMSManager with an invalid " +
                 "provider url should throw an exception");
        } catch(MessagingException expected) {}
    }
View Full Code Here

     * Context.INITIAL_CONTEXT_FACTORY and Context.PROVIDER_URL
     * @throws Exception
     */
    public Listener(String topicName, Properties jndiProps)
            throws Exception {
        jmsMgr = new JMSManager(jndiProps);
        System.out.println("*** Listening for messages on topic: " + topicName);
        jmsMgr.listen(topicName, this);

    }
View Full Code Here

TOP

Related Classes of org.fcrepo.server.messaging.JMSManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.