Package org.activemq.advisories

Source Code of org.activemq.advisories.ConnectionAdvisorTest

/**
*
* 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.activemq.advisories;

import javax.jms.Connection;

import junit.framework.TestCase;

import org.activemq.ActiveMQConnectionFactory;
import org.activemq.message.ConnectionInfo;

import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
/**
* A helper class for listening for MessageConnection advisories
*/



/**
*
* ConnectionAdvisorTest
*/
public class ConnectionAdvisorTest extends TestCase implements ConnectionAdvisoryEventListener{
   
    private ActiveMQConnectionFactory fac;
    private Connection connection;
    private SynchronizedBoolean started;
   
   
    protected void setUp() throws Exception{
        started = new SynchronizedBoolean(false);
        fac = new ActiveMQConnectionFactory("vm://localhost");
        connection = fac.createConnection();
        connection.start();
    }
   
    protected void tearDown() throws  Exception{
        connection.close();
    }
    public void testAdvisories() throws Exception{
        ConnectionAdvisor test = new ConnectionAdvisor(connection);
        test.addListener(this);
        test.start();
        Connection testConnection = fac.createConnection();
        testConnection.start();
        synchronized(started){
            if (!started.get()){
                started.wait(5000);
            }
        }
        assertTrue(started.get());
       
    }

    public void onEvent(ConnectionAdvisoryEvent event) {
        System.out.println(event);
        ConnectionInfo info = event.getInfo();
        started.set(info.isStarted());
        synchronized(started){
            started.notify();
        }
       
    }
   
}
TOP

Related Classes of org.activemq.advisories.ConnectionAdvisorTest

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.