Package org.codehaus.activemq.advisories

Source Code of org.codehaus.activemq.advisories.ConsumerAdvisorTest

/**
*
* Copyright 2004 Protique Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/

package org.codehaus.activemq.advisories;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import junit.framework.TestCase;
import org.codehaus.activemq.ActiveMQConnectionFactory;
import org.codehaus.activemq.message.ConsumerInfo;
import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
/**
* A helper class for listening for MessageConsumer advisories
*/



/**
*
* ConsumerAdvisorTest
*/
public class ConsumerAdvisorTest extends TestCase implements ConsumerAdvisoryEventListener{
   
    private Connection connection;
    private Session session;
    private Destination destination;
    private String destinationName = "foo.bar";
    private SynchronizedBoolean started;
   
   
    protected void setUp() throws Exception{
        started = new SynchronizedBoolean(false);
        ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory("vm://localhost");
        connection = fac.createConnection();
        session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        destination = session.createTopic(destinationName);
        connection.start();
    }
   
    protected void tearDown() throws  Exception{
        connection.close();
    }
    public void testAdvisories() throws Exception{
        ConsumerAdvisor test = new ConsumerAdvisor(connection,destination);
        test.addListener(this);
        test.start();
        MessageConsumer consumer = session.createConsumer(destination);
        synchronized(started){
            if (!started.get()){
                started.wait(2000);
            }
        }
        assertTrue(started.get());
        session.close();
        synchronized(started){
            if (started.get()){
                started.wait(2000);
            }
        }
        assertFalse(started.get());
    }

    public void onEvent(ConsumerAdvisoryEvent event) {
        ConsumerInfo info = event.getInfo();
        started.set(info.isStarted());
        synchronized(started){
            started.notify();
        }
       
    }
   
}
TOP

Related Classes of org.codehaus.activemq.advisories.ConsumerAdvisorTest

TOP
Copyright © 2018 www.massapi.com. 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.