|
ActiveMQ example source code file (ManagedConnectionFactoryTest.java)
The ActiveMQ ManagedConnectionFactoryTest.java source code/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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.apache.activemq.ra; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.PrintWriter; import java.io.Serializable; import java.util.HashSet; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.QueueConnectionFactory; import javax.jms.TopicConnectionFactory; import javax.resource.Referenceable; import javax.resource.ResourceException; import javax.resource.spi.ConnectionRequestInfo; import javax.resource.spi.ManagedConnection; import javax.resource.spi.ManagedConnectionFactory; import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; /** * */ public class ManagedConnectionFactoryTest extends TestCase { private static final String DEFAULT_HOST = "vm://localhost?broker.persistent=false&broker.schedulerSupport=false"; private static final String REMOTE_HOST = "vm://remotehost?broker.persistent=false&broker.schedulerSupport=false"; private ActiveMQManagedConnectionFactory managedConnectionFactory; /** * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { managedConnectionFactory = new ActiveMQManagedConnectionFactory(); managedConnectionFactory.setServerUrl(DEFAULT_HOST); managedConnectionFactory.setUserName(ActiveMQConnectionFactory.DEFAULT_USER); managedConnectionFactory.setPassword(ActiveMQConnectionFactory.DEFAULT_PASSWORD); } public void testConnectionFactoryAllocation() throws ResourceException, JMSException { // Make sure that the ConnectionFactory is asking the connection manager // to // allocate the connection. final boolean allocateRequested[] = new boolean[] { false }; Object cf = managedConnectionFactory.createConnectionFactory(new ConnectionManagerAdapter() { private static final long serialVersionUID = 1699499816530099939L; public Object allocateConnection(ManagedConnectionFactory connectionFactory, ConnectionRequestInfo info) throws ResourceException { allocateRequested[0] = true; return super.allocateConnection(connectionFactory, info); } }); // We should be getting a JMS Connection Factory. assertTrue(cf instanceof ConnectionFactory); ConnectionFactory connectionFactory = (ConnectionFactory)cf; // Make sure that the connection factory is using the // ConnectionManager.. Connection connection = connectionFactory.createConnection(); assertTrue(allocateRequested[0]); // Make sure that the returned connection is of the expected type. assertTrue(connection != null); assertTrue(connection instanceof ManagedConnectionProxy); } public void testConnectionFactoryConnectionMatching() throws ResourceException, JMSException { ActiveMQConnectionRequestInfo ri1 = new ActiveMQConnectionRequestInfo(); ri1.setServerUrl(DEFAULT_HOST); ri1.setUserName(ActiveMQConnectionFactory.DEFAULT_USER); ri1.setPassword(ActiveMQConnectionFactory.DEFAULT_PASSWORD); ActiveMQConnectionRequestInfo ri2 = new ActiveMQConnectionRequestInfo(); ri2.setServerUrl(REMOTE_HOST); ri2.setUserName(ActiveMQConnectionFactory.DEFAULT_USER); ri2.setPassword(ActiveMQConnectionFactory.DEFAULT_PASSWORD); assertNotSame(ri1, ri2); ManagedConnection connection1 = managedConnectionFactory.createManagedConnection(null, ri1); ManagedConnection connection2 = managedConnectionFactory.createManagedConnection(null, ri2); assertTrue(connection1 != connection2); HashSet<ManagedConnection> set = new HashSet Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ ManagedConnectionFactoryTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.