diff options
Diffstat (limited to 'qpid/java/client/src/test/java/org/apache')
9 files changed, 218 insertions, 564 deletions
diff --git a/qpid/java/client/src/test/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java b/qpid/java/client/src/test/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java new file mode 100644 index 0000000000..5323ad28bf --- /dev/null +++ b/qpid/java/client/src/test/java/org/apache/mina/transport/vmpipe/support/VmPipeIdleStatusChecker.java @@ -0,0 +1,125 @@ +/* + * + * 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.mina.transport.vmpipe.support; + +import org.apache.mina.common.IdleStatus; + +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * This file is a patch to override MINA, because of the IdentityHashMap bug. Workaround to be supplied in MINA 1.0.7. + * This patched file will be removed once upgraded onto a newer MINA. + * + * Dectects idle sessions and fires <tt>sessionIdle</tt> events to them. + * + * @author The Apache Directory Project (mina-dev@directory.apache.org) + */ +public class VmPipeIdleStatusChecker +{ + private static final VmPipeIdleStatusChecker INSTANCE = new VmPipeIdleStatusChecker(); + + public static VmPipeIdleStatusChecker getInstance() + { + return INSTANCE; + } + + private final Map sessions = new HashMap(); // will use as a set + + private final Worker worker = new Worker(); + + private VmPipeIdleStatusChecker() + { + worker.start(); + } + + public void addSession(VmPipeSessionImpl session) + { + synchronized (sessions) + { + sessions.put(session, session); + } + } + + private class Worker extends Thread + { + private Worker() + { + super("VmPipeIdleStatusChecker"); + setDaemon(true); + } + + public void run() + { + for (;;) + { + try + { + Thread.sleep(1000); + } + catch (InterruptedException e) + { } + + long currentTime = System.currentTimeMillis(); + + synchronized (sessions) + { + Iterator it = sessions.keySet().iterator(); + while (it.hasNext()) + { + VmPipeSessionImpl session = (VmPipeSessionImpl) it.next(); + if (!session.isConnected()) + { + it.remove(); + } + else + { + notifyIdleSession(session, currentTime); + } + } + } + } + } + } + + private void notifyIdleSession(VmPipeSessionImpl session, long currentTime) + { + notifyIdleSession0(session, currentTime, session.getIdleTimeInMillis(IdleStatus.BOTH_IDLE), IdleStatus.BOTH_IDLE, + Math.max(session.getLastIoTime(), session.getLastIdleTime(IdleStatus.BOTH_IDLE))); + notifyIdleSession0(session, currentTime, session.getIdleTimeInMillis(IdleStatus.READER_IDLE), IdleStatus.READER_IDLE, + Math.max(session.getLastReadTime(), session.getLastIdleTime(IdleStatus.READER_IDLE))); + notifyIdleSession0(session, currentTime, session.getIdleTimeInMillis(IdleStatus.WRITER_IDLE), IdleStatus.WRITER_IDLE, + Math.max(session.getLastWriteTime(), session.getLastIdleTime(IdleStatus.WRITER_IDLE))); + } + + private void notifyIdleSession0(VmPipeSessionImpl session, long currentTime, long idleTime, IdleStatus status, + long lastIoTime) + { + if ((idleTime > 0) && (lastIoTime != 0) && ((currentTime - lastIoTime) >= idleTime)) + { + session.increaseIdleCount(status); + session.getFilterChain().fireSessionIdle(session, status); + } + } + +} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java b/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java index 5972bf3fae..da44822ec3 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/client/MockAMQConnection.java @@ -79,6 +79,11 @@ public class MockAMQConnection extends AMQConnection super(connectionURL, sslConfig); } + protected MockAMQConnection(String username, String password, String clientName, String virtualHost) + { + super(username, password, clientName, virtualHost); + } + @Override public ProtocolVersion makeBrokerConnection(BrokerDetails brokerDetail) throws IOException { diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java index e159ceb148..f520a21ba0 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/client/protocol/AMQProtocolHandlerTest.java @@ -20,24 +20,23 @@ */ package org.apache.qpid.client.protocol; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - import junit.framework.TestCase; - -import org.apache.qpid.AMQException; -import org.apache.qpid.client.AMQAuthenticationException; -import org.apache.qpid.client.MockAMQConnection; -import org.apache.qpid.client.state.AMQState; -import org.apache.qpid.framing.AMQBody; import org.apache.qpid.framing.AMQFrame; +import org.apache.qpid.framing.AMQBody; import org.apache.qpid.framing.AMQMethodBody; import org.apache.qpid.framing.amqp_8_0.BasicRecoverOkBodyImpl; +import org.apache.qpid.AMQException; import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.transport.TestNetworkConnection; +import org.apache.qpid.transport.TestNetworkDriver; +import org.apache.qpid.client.MockAMQConnection; +import org.apache.qpid.client.AMQAuthenticationException; +import org.apache.qpid.client.state.AMQState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + /** * This is a test address QPID-1431 where frame listeners would fail to be notified of an incomming exception. * @@ -73,8 +72,8 @@ public class AMQProtocolHandlerTest extends TestCase public void setUp() throws Exception { //Create a new ProtocolHandler with a fake connection. - _handler = new AMQProtocolHandler(new MockAMQConnection("amqp://guest:guest@client/test?brokerlist='tcp://localhost:1'")); - _handler.setNetworkConnection(new TestNetworkConnection()); + _handler = new AMQProtocolHandler(new MockAMQConnection("amqp://guest:guest@client/test?brokerlist='vm://:1'")); + _handler.setNetworkDriver(new TestNetworkDriver()); AMQBody body = BasicRecoverOkBodyImpl.getFactory().newInstance(null, 1); _blockFrame = new AMQFrame(0, body); diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java deleted file mode 100644 index 9e23f722eb..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernameHashedPasswordCallbackHandlerTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * 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.qpid.client.security; - -import java.security.MessageDigest; -import java.util.Arrays; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.client.MockAMQConnection; -import org.apache.qpid.client.protocol.AMQProtocolHandler; -import org.apache.qpid.client.protocol.AMQProtocolSession; - -/** - * Unit tests for the UsernameHashPasswordCallbackHandler. This callback handler is - * used by the CRAM-MD5-HASHED SASL mechanism. - * - */ -public class UsernameHashedPasswordCallbackHandlerTest extends TestCase -{ - private AMQCallbackHandler _callbackHandler = new UsernameHashedPasswordCallbackHandler(); // Class under test - private static final String PROMPT_UNUSED = "unused"; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - final String url = "amqp://username:password@client/test?brokerlist='tcp://localhost:1'"; - _callbackHandler.initialise(new AMQConnectionURL(url)); - } - - /** - * Tests that the callback handler can correctly retrieve the username from the connection url. - */ - public void testNameCallback() throws Exception - { - final String expectedName = "username"; - NameCallback nameCallback = new NameCallback(PROMPT_UNUSED); - - assertNull("Unexpected name before test", nameCallback.getName()); - _callbackHandler.handle(new Callback[] {nameCallback}); - assertEquals("Unexpected name", expectedName, nameCallback.getName()); - } - - /** - * Tests that the callback handler can correctly retrieve the password from the connection url - * and calculate a MD5. - */ - public void testDigestedPasswordCallback() throws Exception - { - final char[] expectedPasswordDigested = getHashPassword("password"); - - PasswordCallback passwordCallback = new PasswordCallback(PROMPT_UNUSED, false); - assertNull("Unexpected password before test", passwordCallback.getPassword()); - _callbackHandler.handle(new Callback[] {passwordCallback}); - assertTrue("Unexpected password", Arrays.equals(expectedPasswordDigested, passwordCallback.getPassword())); - } - - private char[] getHashPassword(final String password) throws Exception - { - MessageDigest md5Digester = MessageDigest.getInstance("MD5"); - final byte[] digest = md5Digester.digest(password.getBytes("UTF-8")); - - char[] hash = new char[digest.length]; - - int index = 0; - for (byte b : digest) - { - hash[index++] = (char) b; - } - - return hash; - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java deleted file mode 100644 index 83ddfd72fa..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/security/UsernamePasswordCallbackHandlerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * 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.qpid.client.security; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; - -import junit.framework.TestCase; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.client.MockAMQConnection; -import org.apache.qpid.client.protocol.AMQProtocolHandler; -import org.apache.qpid.client.protocol.AMQProtocolSession; - -/** - * Unit tests for the UsernamePasswordCallbackHandler. - * - */ -public class UsernamePasswordCallbackHandlerTest extends TestCase -{ - private AMQCallbackHandler _callbackHandler = new UsernamePasswordCallbackHandler(); // Class under test - private static final String PROMPT_UNUSED = "unused"; - - @Override - protected void setUp() throws Exception - { - super.setUp(); - - final String url = "amqp://username:password@client/test?brokerlist='tcp://localhost:1'"; - - _callbackHandler.initialise(new AMQConnectionURL(url)); - } - - /** - * Tests that the callback handler can correctly retrieve the username from the connection url. - */ - public void testNameCallback() throws Exception - { - final String expectedName = "username"; - NameCallback nameCallback = new NameCallback(PROMPT_UNUSED); - - assertNull("Unexpected name before test", nameCallback.getName()); - _callbackHandler.handle(new Callback[] {nameCallback}); - assertEquals("Unexpected name", expectedName, nameCallback.getName()); - } - - /** - * Tests that the callback handler can correctly retrieve the password from the connection url. - */ - public void testPasswordCallback() throws Exception - { - final String expectedPassword = "password"; - PasswordCallback passwordCallback = new PasswordCallback(PROMPT_UNUSED, false); - assertNull("Unexpected password before test", passwordCallback.getPassword()); - _callbackHandler.handle(new Callback[] {passwordCallback}); - assertEquals("Unexpected password", expectedPassword, new String(passwordCallback.getPassword())); - } -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/jms/FailoverPolicyTest.java b/qpid/java/client/src/test/java/org/apache/qpid/jms/FailoverPolicyTest.java deleted file mode 100644 index 438995aedc..0000000000 --- a/qpid/java/client/src/test/java/org/apache/qpid/jms/FailoverPolicyTest.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * - * 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.qpid.jms; - -import javax.jms.ConnectionConsumer; -import javax.jms.ConnectionMetaData; -import javax.jms.Destination; -import javax.jms.ExceptionListener; -import javax.jms.JMSException; -import javax.jms.ServerSessionPool; -import javax.jms.Topic; - -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.jms.failover.FailoverExchangeMethod; -import org.apache.qpid.jms.failover.FailoverMethod; -import org.apache.qpid.jms.failover.FailoverRoundRobinServers; -import org.apache.qpid.jms.failover.FailoverSingleServer; -import org.apache.qpid.jms.failover.NoFailover; - -import junit.framework.TestCase; - -/** - * Tests the ability of FailoverPolicy to instantiate the correct FailoverMethod. - * - * This test presently does <i>not</i> test {@link FailoverPolicy#FailoverPolicy(FailoverMethod) or - * {@link FailoverPolicy#addMethod(FailoverMethod)} as it appears that this functionality - * is no longer in use. - * - */ -public class FailoverPolicyTest extends TestCase -{ - private FailoverPolicy _failoverPolicy = null; // class under test - private String _url; - private Connection _connection = null; - private ConnectionURL _connectionUrl = null; - - /** - * Tests single server method is selected for a brokerlist with one broker when - * the failover option is not specified. - */ - public void testBrokerListWithOneBrokerDefaultsToSingleServerPolicy() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverSingleServer); - } - - /** - * Tests round robin method is selected for a brokerlist with two brokers when - * the failover option is not specified. - */ - public void testBrokerListWithTwoBrokersDefaultsToRoundRobinPolicy() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverRoundRobinServers); - } - - /** - * Tests single server method is selected for a brokerlist with one broker when - * the failover option passed as 'singlebroker'. - */ - public void testExplictFailoverOptionSingleBroker() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='singlebroker'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverSingleServer); - } - - /** - * Tests round robin method is selected for a brokerlist with two brokers when - * the failover option passed as 'roundrobin'. - */ - public void testExplictFailoverOptionRoundrobin() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'&failover='roundrobin'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverRoundRobinServers); - } - - /** - * Tests no failover method is selected for a brokerlist with one broker when - * the failover option passed as 'nofailover'. - */ - public void testExplictFailoverOptionNofailover() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='nofailover'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof NoFailover); - } - - /** - * Tests failover exchange method is selected for a brokerlist with one broker when - * the failover option passed as 'failover_exchange'. - */ - public void testExplictFailoverOptionFailoverExchange() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='failover_exchange'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof FailoverExchangeMethod); - } - - /** - * Tests that a custom method can be selected for a brokerlist with one brokers when - * the failover option passed as a qualified class-name. - */ - public void testExplictFailoverOptionDynamicallyLoadedFailoverMethod() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='org.apache.qpid.jms.FailoverPolicyTest$MyFailoverMethod'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - _failoverPolicy = new FailoverPolicy(_connectionUrl, _connection); - - assertTrue("Unexpected failover method", _failoverPolicy.getCurrentMethod() instanceof MyFailoverMethod); - } - - /** - * Tests that an unknown method caused an exception. - */ - public void testUnknownFailoverMethod() throws Exception - { - _url = "amqp://user:pass@clientid/test?brokerlist='tcp://localhost:5672'&failover='unknown'"; - _connectionUrl = new AMQConnectionURL(_url); - _connection = createStubConnection(); - - try - { - new FailoverPolicy(_connectionUrl, _connection); - fail("Exception not thrown"); - } - catch(IllegalArgumentException iae) - { - // PASS - } - } - - private Connection createStubConnection() - { - return new Connection() - { - - @Override - public Session createSession(boolean transacted, - int acknowledgeMode, int prefetch) throws JMSException - { - return null; - } - - @Override - public Session createSession(boolean transacted, - int acknowledgeMode, int prefetchHigh, int prefetchLow) - throws JMSException - { - return null; - } - - @Override - public ConnectionListener getConnectionListener() - { - return null; - } - - @Override - public long getMaximumChannelCount() throws JMSException - { - return 0; - } - - @Override - public void setConnectionListener(ConnectionListener listener) - { - } - - @Override - public void close() throws JMSException - { - } - - @Override - public ConnectionConsumer createConnectionConsumer( - Destination arg0, String arg1, ServerSessionPool arg2, - int arg3) throws JMSException - { - return null; - } - - @Override - public ConnectionConsumer createDurableConnectionConsumer( - Topic arg0, String arg1, String arg2, - ServerSessionPool arg3, int arg4) throws JMSException - { - return null; - } - - @Override - public javax.jms.Session createSession(boolean arg0, int arg1) - throws JMSException - { - return null; - } - - @Override - public String getClientID() throws JMSException - { - return null; - } - - @Override - public ExceptionListener getExceptionListener() throws JMSException - { - return null; - } - - @Override - public ConnectionMetaData getMetaData() throws JMSException - { - return null; - } - - @Override - public void setClientID(String arg0) throws JMSException - { - } - - @Override - public void setExceptionListener(ExceptionListener arg0) - throws JMSException - { - } - - @Override - public void start() throws JMSException - { - } - - @Override - public void stop() throws JMSException - { - } - }; - } - - // Class used to test the ability of FailoverPolicy to load an implementation. - static class MyFailoverMethod implements FailoverMethod - { - public MyFailoverMethod(ConnectionURL connectionDetails) - { - } - - @Override - public void attainedConnection() - { - } - - @Override - public boolean failoverAllowed() - { - return false; - } - - @Override - public BrokerDetails getCurrentBrokerDetails() - { - return null; - } - - @Override - public BrokerDetails getNextBrokerDetails() - { - return null; - } - - @Override - public String methodName() - { - return null; - } - - @Override - public void reset() - { - } - - @Override - public void setBroker(BrokerDetails broker) - { - } - - @Override - public void setRetries(int maxRetries) - { - } - } - -} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java index 9095f94960..1b27ff6300 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java @@ -43,6 +43,15 @@ public class BrokerDetailsTest extends TestCase assertTrue(broker.getProperty("immediatedelivery").equals("true")); } + public void testVMBroker() throws URLSyntaxException + { + String url = "vm://:2"; + + AMQBrokerDetails broker = new AMQBrokerDetails(url); + assertTrue(broker.getTransport().equals("vm")); + assertEquals(broker.getPort(), 2); + } + public void testTransportsDefaultToTCP() throws URLSyntaxException { String url = "localhost:5672"; diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java index 4624b36fea..2be3720c20 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java @@ -300,6 +300,53 @@ public class ConnectionURLTest extends TestCase assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); } + public void testSinglevmURL() throws URLSyntaxException + { + String url = "amqp://guest:guest@/test?brokerlist='vm://:2'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + assertTrue(connectionurl.getFailoverMethod() == null); + assertTrue(connectionurl.getUsername().equals("guest")); + assertTrue(connectionurl.getPassword().equals("guest")); + assertTrue(connectionurl.getVirtualHost().equals("/test")); + + assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + assertTrue(service.getTransport().equals("vm")); + assertTrue(service.getHost().equals("")); + assertTrue(service.getPort() == 2); + + } + + public void testFailoverVMURL() throws URLSyntaxException + { + String url = "amqp://ritchiem:bob@/test?brokerlist='vm://:2;vm://:3',failover='roundrobin'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); + assertTrue(connectionurl.getUsername().equals("ritchiem")); + assertTrue(connectionurl.getPassword().equals("bob")); + assertTrue(connectionurl.getVirtualHost().equals("/test")); + + assertTrue(connectionurl.getBrokerCount() == 2); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + assertTrue(service.getTransport().equals("vm")); + assertTrue(service.getHost().equals("")); + assertTrue(service.getPort() == 2); + + service = connectionurl.getBrokerDetails(1); + assertTrue(service.getTransport().equals("vm")); + assertTrue(service.getHost().equals("")); + assertTrue(service.getPort() == 3); + } + + public void testNoVirtualHostURL() { String url = "amqp://user@?brokerlist='tcp://localhost:5672'"; @@ -440,6 +487,27 @@ public class ConnectionURLTest extends TestCase } + public void testSocketProtocol() throws URLSyntaxException + { + String url = "amqp://guest:guest@id/test" + "?brokerlist='socket://VM-Unique-socketID'"; + + try + { + AMQConnectionURL curl = new AMQConnectionURL(url); + assertNotNull(curl); + assertEquals(1, curl.getBrokerCount()); + assertNotNull(curl.getBrokerDetails(0)); + assertEquals(BrokerDetails.SOCKET, curl.getBrokerDetails(0).getTransport()); + assertEquals("VM-Unique-socketID", curl.getBrokerDetails(0).getHost()); + assertEquals("URL does not toString as expected", + url.replace(":guest", ":********"), curl.toString()); + } + catch (URLSyntaxException e) + { + fail(e.getMessage()); + } + } + public void testSingleTransportMultiOptionOnBrokerURL() throws URLSyntaxException { String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672?foo='jim'&bar='bob'&fred='jimmy'',routingkey='jim',timeout='200',immediatedelivery='true'"; @@ -481,37 +549,6 @@ public class ConnectionURLTest extends TestCase assertTrue("String representation should contain options and values", url.toString().contains("maxprefetch='12345'")); } - public void testHostNamesWithUnderScore() throws URLSyntaxException - { - String url = "amqp://guest:guest@clientid/test?brokerlist='tcp://under_score:6672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - BrokerDetails service = connectionurl.getBrokerDetails(0); - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("under_score")); - assertTrue(service.getPort() == 6672); - - url = "amqp://guest:guest@clientid/test?brokerlist='tcp://under_score'"; - - connectionurl = new AMQConnectionURL(url); - - assertTrue(connectionurl.getUsername().equals("guest")); - assertTrue(connectionurl.getPassword().equals("guest")); - assertTrue(connectionurl.getVirtualHost().equals("/test")); - - assertTrue(connectionurl.getBrokerCount() == 1); - service = connectionurl.getBrokerDetails(0); - assertTrue(service.getTransport().equals("tcp")); - assertTrue(service.getHost().equals("under_score")); - assertTrue(service.getPort() == 5672); - } - public static junit.framework.Test suite() { return new junit.framework.TestSuite(ConnectionURLTest.class); diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java index 4637c6e505..47c0359b94 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java @@ -195,10 +195,4 @@ public class TestAMQSession extends AMQSession<BasicMessageConsumer_0_8, BasicMe { return false; } - - @Override - public AMQException getLastException() - { - return null; - } } |