From 469aa371040b2e0685f269937a4e49527a35e00c Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Mon, 23 Sep 2013 23:42:30 +0000 Subject: QPID-5160: add a qpid-test-utils module instead of making every modules tests rely on the tests dir from the common module git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1525738 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/java/bdbstore/build.xml | 2 +- qpid/java/bdbstore/jmx/build.xml | 2 +- qpid/java/broker-core/build.xml | 2 +- qpid/java/broker-plugins/access-control/build.xml | 2 +- .../broker-plugins/amqp-0-10-protocol/build.xml | 2 +- .../broker-plugins/amqp-0-8-protocol/build.xml | 2 +- .../protocol/v0_8/InternalTestProtocolSession.java | 127 +++++++-- .../broker-plugins/amqp-1-0-protocol/build.xml | 2 +- .../amqp-msg-conv-0-10-to-1-0/build.xml | 2 +- .../amqp-msg-conv-0-8-to-0-10/build.xml | 2 +- .../amqp-msg-conv-0-8-to-1-0/build.xml | 2 +- qpid/java/broker-plugins/derby-store/build.xml | 2 +- qpid/java/broker-plugins/jdbc-store/build.xml | 2 +- qpid/java/broker-plugins/management-http/build.xml | 2 +- qpid/java/broker-plugins/management-jmx/build.xml | 2 +- qpid/java/broker-plugins/memory-store/build.xml | 2 +- qpid/java/broker/build.xml | 2 +- qpid/java/build.deps | 1 + qpid/java/build.xml | 2 +- qpid/java/client/build.xml | 2 +- .../org/apache/qpid/client/AMQSession_0_8Test.java | 2 +- .../client/protocol/AMQProtocolHandlerTest.java | 2 +- .../apache/qpid/client/transport/MockSender.java | 49 ++++ .../client/transport/TestNetworkConnection.java | 163 ++++++++++++ qpid/java/common/build.xml | 1 + .../org/apache/qpid/test/utils/PortHelper.java | 127 --------- .../org/apache/qpid/test/utils/QpidTestCase.java | 284 --------------------- .../org/apache/qpid/test/utils/TestFileUtils.java | 153 ----------- .../apache/qpid/test/utils/TestSSLConstants.java | 37 --- .../java/org/apache/qpid/transport/MockSender.java | 47 ---- .../qpid/transport/TestNetworkConnection.java | 161 ------------ qpid/java/perftests/build.xml | 2 +- qpid/java/qpid-test-utils/build.xml | 26 ++ .../org/apache/qpid/test/utils/PortHelper.java | 127 +++++++++ .../org/apache/qpid/test/utils/QpidTestCase.java | 284 +++++++++++++++++++++ .../org/apache/qpid/test/utils/TestFileUtils.java | 233 +++++++++++++++++ .../apache/qpid/test/utils/TestSSLConstants.java | 37 +++ qpid/java/systests/build.xml | 2 +- .../MultiVersionProtocolEngineFactoryTest.java | 97 ++++++- .../client/protocol/AMQProtocolSessionTest.java | 115 ++++++++- 40 files changed, 1257 insertions(+), 856 deletions(-) create mode 100644 qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java create mode 100644 qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java delete mode 100644 qpid/java/common/src/test/java/org/apache/qpid/test/utils/PortHelper.java delete mode 100644 qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java delete mode 100644 qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java delete mode 100644 qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestSSLConstants.java delete mode 100644 qpid/java/common/src/test/java/org/apache/qpid/transport/MockSender.java delete mode 100644 qpid/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java create mode 100644 qpid/java/qpid-test-utils/build.xml create mode 100644 qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java create mode 100644 qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java create mode 100644 qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestFileUtils.java create mode 100644 qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java (limited to 'qpid/java') diff --git a/qpid/java/bdbstore/build.xml b/qpid/java/bdbstore/build.xml index 6262b24aad..975176c834 100644 --- a/qpid/java/bdbstore/build.xml +++ b/qpid/java/bdbstore/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/bdbstore/jmx/build.xml b/qpid/java/bdbstore/jmx/build.xml index 33e9b1e580..544cdef2fc 100644 --- a/qpid/java/bdbstore/jmx/build.xml +++ b/qpid/java/bdbstore/jmx/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-core/build.xml b/qpid/java/broker-core/build.xml index 2b3376c504..c8c54a6f70 100644 --- a/qpid/java/broker-core/build.xml +++ b/qpid/java/broker-core/build.xml @@ -20,7 +20,7 @@ --> - + diff --git a/qpid/java/broker-plugins/access-control/build.xml b/qpid/java/broker-plugins/access-control/build.xml index ac633ab369..0e718c80c9 100644 --- a/qpid/java/broker-plugins/access-control/build.xml +++ b/qpid/java/broker-plugins/access-control/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/amqp-0-10-protocol/build.xml b/qpid/java/broker-plugins/amqp-0-10-protocol/build.xml index 5aed89f43e..3537be172d 100644 --- a/qpid/java/broker-plugins/amqp-0-10-protocol/build.xml +++ b/qpid/java/broker-plugins/amqp-0-10-protocol/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/build.xml b/qpid/java/broker-plugins/amqp-0-8-protocol/build.xml index 5c8d5e3135..0ab2b0b833 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/build.xml +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/InternalTestProtocolSession.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/InternalTestProtocolSession.java index e8fda2bc65..5b1e5af7bd 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/InternalTestProtocolSession.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/InternalTestProtocolSession.java @@ -20,38 +20,38 @@ */ package org.apache.qpid.server.protocol.v0_8; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.security.Principal; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +import javax.security.auth.Subject; + import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.ContentHeaderBody; import org.apache.qpid.framing.abstraction.MessagePublishInfo; import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.server.protocol.AMQSessionModel; -import org.apache.qpid.server.protocol.v0_8.AMQChannel; -import org.apache.qpid.server.protocol.v0_8.AMQMessage; import org.apache.qpid.server.message.MessageContentSource; import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.protocol.v0_8.AMQProtocolEngine; +import org.apache.qpid.server.protocol.AMQSessionModel; import org.apache.qpid.server.protocol.v0_8.output.ProtocolOutputConverter; import org.apache.qpid.server.queue.QueueEntry; import org.apache.qpid.server.security.auth.AuthenticatedPrincipal; import org.apache.qpid.server.security.auth.UsernamePrincipal; import org.apache.qpid.server.subscription.ClientDeliveryMethod; import org.apache.qpid.server.subscription.Subscription; -import org.apache.qpid.server.protocol.v0_8.SubscriptionImpl; import org.apache.qpid.server.virtualhost.VirtualHost; -import org.apache.qpid.transport.TestNetworkConnection; - -import javax.security.auth.Subject; - -import java.security.Principal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; +import org.apache.qpid.transport.Sender; +import org.apache.qpid.transport.network.NetworkConnection; public class InternalTestProtocolSession extends AMQProtocolEngine implements ProtocolOutputConverter { @@ -266,4 +266,95 @@ public class InternalTestProtocolSession extends AMQProtocolEngine implements Pr } } } + + private static class TestNetworkConnection implements NetworkConnection + { + private String _remoteHost = "127.0.0.1"; + private String _localHost = "127.0.0.1"; + private int _port = 1; + private final Sender _sender; + + public TestNetworkConnection() + { + _sender = new Sender() + { + public void setIdleTimeout(int i) + { + } + + public void send(ByteBuffer msg) + { + } + + public void flush() + { + } + + public void close() + { + } + }; + } + + @Override + public SocketAddress getLocalAddress() + { + return new InetSocketAddress(_localHost, _port); + } + + @Override + public SocketAddress getRemoteAddress() + { + return new InetSocketAddress(_remoteHost, _port); + } + + @Override + public void setMaxReadIdle(int idleTime) + { + } + + @Override + public void setPeerPrincipal(Principal principal) + { + } + + @Override + public Principal getPeerPrincipal() + { + return null; + } + + @Override + public int getMaxReadIdle() + { + return 0; + } + + @Override + public int getMaxWriteIdle() + { + return 0; + } + + @Override + public void setMaxWriteIdle(int idleTime) + { + } + + @Override + public void close() + { + } + + @Override + public Sender getSender() + { + return _sender; + } + + @Override + public void start() + { + } + } } diff --git a/qpid/java/broker-plugins/amqp-1-0-protocol/build.xml b/qpid/java/broker-plugins/amqp-1-0-protocol/build.xml index 99620905db..00926c0787 100644 --- a/qpid/java/broker-plugins/amqp-1-0-protocol/build.xml +++ b/qpid/java/broker-plugins/amqp-1-0-protocol/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/amqp-msg-conv-0-10-to-1-0/build.xml b/qpid/java/broker-plugins/amqp-msg-conv-0-10-to-1-0/build.xml index 66a08ddc31..161a4c394c 100644 --- a/qpid/java/broker-plugins/amqp-msg-conv-0-10-to-1-0/build.xml +++ b/qpid/java/broker-plugins/amqp-msg-conv-0-10-to-1-0/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-0-10/build.xml b/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-0-10/build.xml index 0d83e18abe..26a89bfed9 100644 --- a/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-0-10/build.xml +++ b/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-0-10/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-1-0/build.xml b/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-1-0/build.xml index 8a8a4eadfa..f28b6760e5 100644 --- a/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-1-0/build.xml +++ b/qpid/java/broker-plugins/amqp-msg-conv-0-8-to-1-0/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/derby-store/build.xml b/qpid/java/broker-plugins/derby-store/build.xml index c0d1bcb4b1..95d3263fbc 100644 --- a/qpid/java/broker-plugins/derby-store/build.xml +++ b/qpid/java/broker-plugins/derby-store/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/jdbc-store/build.xml b/qpid/java/broker-plugins/jdbc-store/build.xml index f82c22119d..4a8e72898c 100644 --- a/qpid/java/broker-plugins/jdbc-store/build.xml +++ b/qpid/java/broker-plugins/jdbc-store/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/management-http/build.xml b/qpid/java/broker-plugins/management-http/build.xml index 188e64c885..05af45a289 100644 --- a/qpid/java/broker-plugins/management-http/build.xml +++ b/qpid/java/broker-plugins/management-http/build.xml @@ -19,7 +19,7 @@ - + diff --git a/qpid/java/broker-plugins/management-jmx/build.xml b/qpid/java/broker-plugins/management-jmx/build.xml index 98c821ed5c..0209ecbd7a 100644 --- a/qpid/java/broker-plugins/management-jmx/build.xml +++ b/qpid/java/broker-plugins/management-jmx/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker-plugins/memory-store/build.xml b/qpid/java/broker-plugins/memory-store/build.xml index 14567ad3d5..6d107b7803 100644 --- a/qpid/java/broker-plugins/memory-store/build.xml +++ b/qpid/java/broker-plugins/memory-store/build.xml @@ -18,7 +18,7 @@ --> - + diff --git a/qpid/java/broker/build.xml b/qpid/java/broker/build.xml index d0c976787a..53682f2e58 100644 --- a/qpid/java/broker/build.xml +++ b/qpid/java/broker/build.xml @@ -20,7 +20,7 @@ --> - + diff --git a/qpid/java/build.deps b/qpid/java/build.deps index 99ca19a60b..73691b6aec 100644 --- a/qpid/java/build.deps +++ b/qpid/java/build.deps @@ -96,6 +96,7 @@ client-example.test.libs=${test.libs} tools.test.libs= systests.libs=${test.libs} perftests.test.libs=${test.libs} +qpid-test-utils.libs = ${test.libs} ${geronimo-jms} broker-plugins-access-control.test.libs=${test.libs} broker-plugins-management-http.test.libs=${test.libs} diff --git a/qpid/java/build.xml b/qpid/java/build.xml index 03c50938d0..85117b739d 100644 --- a/qpid/java/build.xml +++ b/qpid/java/build.xml @@ -34,7 +34,7 @@ - + diff --git a/qpid/java/client/build.xml b/qpid/java/client/build.xml index 707bfda024..0375b83c65 100644 --- a/qpid/java/client/build.xml +++ b/qpid/java/client/build.xml @@ -21,7 +21,7 @@ - + diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java index d9caa68ef8..c56cf9a72b 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQSession_0_8Test.java @@ -21,10 +21,10 @@ package org.apache.qpid.client; import org.apache.qpid.AMQException; +import org.apache.qpid.client.transport.TestNetworkConnection; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.amqp_0_91.QueueDeclareOkBodyImpl; import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.TestNetworkConnection; import org.apache.qpid.transport.network.NetworkConnection; import org.apache.qpid.url.AMQBindingURL; 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 9a5ca33174..4c9448cb39 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 @@ -28,12 +28,12 @@ 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.client.transport.TestNetworkConnection; import org.apache.qpid.framing.AMQBody; import org.apache.qpid.framing.AMQFrame; import org.apache.qpid.framing.AMQMethodBody; import org.apache.qpid.framing.amqp_8_0.BasicRecoverOkBodyImpl; import org.apache.qpid.protocol.AMQConstant; -import org.apache.qpid.transport.TestNetworkConnection; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java b/qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java new file mode 100644 index 0000000000..7c3988c19a --- /dev/null +++ b/qpid/java/client/src/test/java/org/apache/qpid/client/transport/MockSender.java @@ -0,0 +1,49 @@ +/* + * + * 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.transport; + +import java.nio.ByteBuffer; + +import org.apache.qpid.transport.Sender; + +public class MockSender implements Sender +{ + + public void setIdleTimeout(int i) + { + + } + + public void send(ByteBuffer msg) + { + + } + + public void flush() + { + + } + + public void close() + { + + } +} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java b/qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java new file mode 100644 index 0000000000..1ec217e468 --- /dev/null +++ b/qpid/java/client/src/test/java/org/apache/qpid/client/transport/TestNetworkConnection.java @@ -0,0 +1,163 @@ +/* + * + * 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.transport; + +import java.security.Principal; +import org.apache.qpid.protocol.ProtocolEngineFactory; +import org.apache.qpid.ssl.SSLContextFactory; +import org.apache.qpid.transport.NetworkTransportConfiguration; +import org.apache.qpid.transport.Sender; +import org.apache.qpid.transport.network.NetworkConnection; + +import java.net.BindException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.ByteBuffer; + +/** + * Test implementation of IoSession, which is required for some tests. Methods not being used are not implemented, + * so if this class is being used and some methods are to be used, then please update those. + */ +public class TestNetworkConnection implements NetworkConnection +{ + private String _remoteHost = "127.0.0.1"; + private String _localHost = "127.0.0.1"; + private int _port = 1; + private SocketAddress _localAddress = null; + private SocketAddress _remoteAddress = null; + private final MockSender _sender; + + public TestNetworkConnection() + { + _sender = new MockSender(); + } + + + + public void bind(int port, InetAddress[] addresses, ProtocolEngineFactory protocolFactory, + NetworkTransportConfiguration config, SSLContextFactory sslFactory) throws BindException + { + + } + + public SocketAddress getLocalAddress() + { + return (_localAddress != null) ? _localAddress : new InetSocketAddress(_localHost, _port); + } + + public SocketAddress getRemoteAddress() + { + return (_remoteAddress != null) ? _remoteAddress : new InetSocketAddress(_remoteHost, _port); + } + + public void setMaxReadIdle(int idleTime) + { + + } + + @Override + public void setPeerPrincipal(Principal principal) + { + } + + @Override + public Principal getPeerPrincipal() + { + return null; + } + + @Override + public int getMaxReadIdle() + { + return 0; + } + + @Override + public int getMaxWriteIdle() + { + return 0; + } + + public void setMaxWriteIdle(int idleTime) + { + + } + + public void close() + { + + } + + public void flush() + { + + } + + public void send(ByteBuffer msg) + { + + } + + public void setIdleTimeout(int i) + { + + } + + public void setPort(int port) + { + _port = port; + } + + public int getPort() + { + return _port; + } + + public void setLocalHost(String host) + { + _localHost = host; + } + + public void setRemoteHost(String host) + { + _remoteHost = host; + } + + public void setLocalAddress(SocketAddress address) + { + _localAddress = address; + } + + public void setRemoteAddress(SocketAddress address) + { + _remoteAddress = address; + } + + public Sender getSender() + { + return _sender; + } + + public void start() + { + } +} diff --git a/qpid/java/common/build.xml b/qpid/java/common/build.xml index 184aad1abc..1c409cfc4e 100644 --- a/qpid/java/common/build.xml +++ b/qpid/java/common/build.xml @@ -20,6 +20,7 @@ --> + diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/PortHelper.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/PortHelper.java deleted file mode 100644 index d3586c364f..0000000000 --- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/PortHelper.java +++ /dev/null @@ -1,127 +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.test.utils; - -import java.io.IOException; -import java.net.DatagramSocket; -import java.net.ServerSocket; -import java.util.Set; - -import org.apache.log4j.Logger; - -public class PortHelper -{ - private static final Logger _logger = Logger.getLogger(PortHelper.class); - - private static final int DEFAULT_TIMEOUT_MILLIS = 5000; - - private int timeout = DEFAULT_TIMEOUT_MILLIS; - - public void waitUntilPortsAreFree(Set ports) - { - _logger.debug("Checking if ports " + ports + " are free..."); - - for (Integer port : ports) - { - waitUntilPortIsFree(port); - } - - _logger.debug("ports " + ports + " are free"); - } - - private void waitUntilPortIsFree(int port) - { - long startTime = System.currentTimeMillis(); - long deadline = startTime + timeout; - boolean alreadyFailed = false; - - while (true) - { - if (System.currentTimeMillis() > deadline) - { - throw new RuntimeException("Timed out after " + timeout + " ms waiting for port " + port + " to become available"); - } - - if (isPortAvailable(port)) - { - if(alreadyFailed) - { - _logger.debug("port " + port + " is now available"); - } - return; - } - else - { - alreadyFailed = true; - } - - try - { - Thread.sleep(500); - } - catch (InterruptedException e) - { - Thread.currentThread().interrupt(); - } - } - } - - public boolean isPortAvailable(int port) - { - ServerSocket serverSocket = null; - DatagramSocket datagramSocket = null; - - try - { - serverSocket = new ServerSocket(port); - serverSocket.setReuseAddress(true); // ensures that the port is subsequently usable - datagramSocket = new DatagramSocket(port); - datagramSocket.setReuseAddress(true); - return true; - } - catch (IOException e) - { - _logger.debug("port " + port + " is not free"); - return false; - } - finally - { - if (serverSocket != null) - { - try - { - serverSocket.close(); - } - catch (IOException e) - { - throw new RuntimeException("Couldn't close port " + port + " that we created to check its availability", e); - } - } - if(datagramSocket != null) - { - datagramSocket.close(); - } - } - } - - public void setTimeout(int timeout) - { - this.timeout = timeout; - } -} diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java deleted file mode 100644 index 8f556ece5a..0000000000 --- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/QpidTestCase.java +++ /dev/null @@ -1,284 +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.test.utils; - -import junit.framework.TestCase; -import junit.framework.TestResult; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; - - -public class QpidTestCase extends TestCase -{ - public static final String QPID_HOME = System.getProperty("QPID_HOME"); - public static final String TEST_RESOURCES_DIR = QPID_HOME + "/../test-profiles/test_resources/"; - public static final String TMP_FOLDER = System.getProperty("java.io.tmpdir"); - public static final String LOG4J_CONFIG_FILE_PATH = System.getProperty("log4j.configuration.file"); - - private static final Logger _logger = Logger.getLogger(QpidTestCase.class); - - private final Map _loggerLevelSetForTest = new HashMap(); - private final Map _propertiesSetForTest = new HashMap(); - - private String _testName; - - /** - * Some tests are excluded when the property test.excludes is set to true. - * An exclusion list is either a file (prop test.excludesfile) which contains one test name - * to be excluded per line or a String (prop test.excludeslist) where tests to be excluded are - * separated by " ". Excluded tests are specified following the format: - * className#testName where className is the class of the test to be - * excluded and testName is the name of the test to be excluded. - * className#* excludes all the tests of the specified class. - */ - static - { - if (Boolean.getBoolean("test.exclude")) - { - _logger.info("Some tests should be excluded, building the exclude list"); - String exclusionListURIs = System.getProperties().getProperty("test.excludefiles", ""); - String exclusionListString = System.getProperties().getProperty("test.excludelist", ""); - List exclusionList = new ArrayList(); - - for (String uri : exclusionListURIs.split(";\\s*")) - { - File file = new File(uri); - if (file.exists()) - { - _logger.info("Using exclude file: " + uri); - try - { - BufferedReader in = new BufferedReader(new FileReader(file)); - String excludedTest = in.readLine(); - do - { - exclusionList.add(excludedTest); - excludedTest = in.readLine(); - } - while (excludedTest != null); - } - catch (IOException e) - { - _logger.warn("Exception when reading exclusion list", e); - } - } - else - { - _logger.info("Specified exclude file does not exist: " + uri); - } - } - - if (!exclusionListString.equals("")) - { - _logger.info("Using excludeslist: " + exclusionListString); - for (String test : exclusionListString.split("\\s+")) - { - exclusionList.add(test); - } - } - - _exclusionList = exclusionList; - } - } - - protected static final String MESSAGE_STORE_CLASS_NAME_KEY = "messagestore.class.name"; - protected static final String CONFIGURATION_STORE_CLASS_NAME_KEY = "configurationstore.class.name"; - - protected static final String MEMORY_STORE_CLASS_NAME = "org.apache.qpid.server.store.MemoryMessageStore"; - - private static List _exclusionList; - - public QpidTestCase() - { - super(); - } - - public void run(TestResult testResult) - { - if (_exclusionList != null && (_exclusionList.contains(getClass().getPackage().getName() + ".*") || - _exclusionList.contains(getClass().getName() + "#*") || - _exclusionList.contains(getClass().getName() + "#" + getName()))) - { - _logger.info("Test: " + getName() + " is excluded"); - testResult.endTest(this); - } - else - { - super.run(testResult); - } - } - - public String getTestProfileMessageStoreClassName() - { - final String storeClass = System.getProperty(MESSAGE_STORE_CLASS_NAME_KEY); - _logger.debug("MESSAGE_STORE_CLASS_NAME_KEY " + storeClass); - - return storeClass != null ? storeClass : MEMORY_STORE_CLASS_NAME ; - } - - - public static final int MIN_PORT_NUMBER = 1; - public static final int MAX_PORT_NUMBER = 49151; - - - /** - * Gets the next available port starting at a port. - * - * @param fromPort the port to scan for availability - * @throws NoSuchElementException if there are no ports available - */ - public int getNextAvailable(int fromPort) - { - if ((fromPort < MIN_PORT_NUMBER) || (fromPort > MAX_PORT_NUMBER)) - { - throw new IllegalArgumentException("Invalid start port: " + fromPort); - } - - PortHelper portHelper = new PortHelper(); - for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) - { - if (portHelper.isPortAvailable(i)) { - return i; - } - } - - throw new NoSuchElementException("Could not find an available port above " + fromPort); - } - - public int findFreePort() - { - return getNextAvailable(10000); - } - - /** - * Set a System property for duration of this test only. The tearDown will - * guarantee to reset the property to its previous value after the test - * completes. - * - * @param property The property to set - * @param value the value to set it to, if null, the property will be cleared - */ - protected void setTestSystemProperty(final String property, final String value) - { - if (!_propertiesSetForTest.containsKey(property)) - { - // Record the current value so we can revert it later. - _propertiesSetForTest.put(property, System.getProperty(property)); - } - - if (value == null) - { - System.clearProperty(property); - } - else - { - System.setProperty(property, value); - } - - _logger.info("Set system property \"" + property + "\" to: \"" + value + "\""); - } - - /** - * Restore the System property values that were set by this test run. - */ - protected void revertTestSystemProperties() - { - if(!_propertiesSetForTest.isEmpty()) - { - _logger.debug("reverting " + _propertiesSetForTest.size() + " test properties"); - for (String key : _propertiesSetForTest.keySet()) - { - String value = _propertiesSetForTest.get(key); - if (value != null) - { - System.setProperty(key, value); - } - else - { - System.clearProperty(key); - } - } - - _propertiesSetForTest.clear(); - } - } - - /** - * Adjust the VMs Log4j Settings just for this test run - * - * @param logger the logger to change - * @param level the level to set - */ - protected void setLoggerLevel(Logger logger, Level level) - { - assertNotNull("Cannot set level of null logger", logger); - assertNotNull("Cannot set Logger("+logger.getName()+") to null level.",level); - - if (!_loggerLevelSetForTest.containsKey(logger)) - { - // Record the current value so we can revert it later. - _loggerLevelSetForTest.put(logger, logger.getLevel()); - } - - logger.setLevel(level); - } - - /** - * Restore the logging levels defined by this test. - */ - protected void revertLoggingLevels() - { - for (Logger logger : _loggerLevelSetForTest.keySet()) - { - logger.setLevel(_loggerLevelSetForTest.get(logger)); - } - - _loggerLevelSetForTest.clear(); - } - - protected void tearDown() throws java.lang.Exception - { - _logger.info("========== tearDown " + _testName + " =========="); - revertTestSystemProperties(); - revertLoggingLevels(); - } - - protected void setUp() throws Exception - { - _testName = getClass().getSimpleName() + "." + getName(); - _logger.info("========== start " + _testName + " =========="); - } - - protected String getTestName() - { - return _testName; - } -} diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java deleted file mode 100644 index 14dec8efad..0000000000 --- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestFileUtils.java +++ /dev/null @@ -1,153 +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.test.utils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import java.io.FileOutputStream; - -import junit.framework.TestCase; - -import org.apache.qpid.util.FileUtils; - -/** - * Utility methods intended to be used in unit tests that manipulate files - */ -public class TestFileUtils -{ - private static final String SYSTEM_TMP_DIR = System.getProperty("java.io.tmpdir"); - private static final String SUFFIX = "tmp"; - - /** - * Create and return a temporary directory that will be deleted on exit. - */ - public static File createTestDirectory() - { - String dirNameStem = TestFileUtils.class.getSimpleName() + "-testDir"; - return createTestDirectory(dirNameStem, true); - } - - /** - * Creates an empty directory with a name like /tmp/dirNameStem-12345678 - */ - public static File createTestDirectory(String dirNameStem, boolean deleteOnExit) - { - File testDir = new File(SYSTEM_TMP_DIR, dirNameStem + "-" + System.currentTimeMillis()); - if (testDir.exists()) - { - FileUtils.delete(testDir, true); - } - - testDir.mkdirs(); - - if (deleteOnExit) - { - testDir.deleteOnExit(); - } - - return testDir; - } - - public static File createTempFile(TestCase testcase) - { - return createTempFile(testcase, SUFFIX); - } - - public static File createTempFile(TestCase testcase, String suffix) - { - String prefix = testcase.getClass().getSimpleName() + "-" + testcase.getName(); - - File tmpFile; - try - { - tmpFile = File.createTempFile(prefix, suffix); - tmpFile.deleteOnExit(); - } - catch (IOException e) - { - throw new RuntimeException("Cannot create temporary file with prefix " + prefix + " and suffix " + SUFFIX, e); - } - - return tmpFile; - } - - /** - * Creates a temporary file from the resource name given, using the resource name as the file suffix. - * - * This is required because the tests use the jar files as their class path. - */ - public static File createTempFileFromResource(TestCase testCase, String resourceName) - { - File dst = createTempFile(testCase, resourceName); - InputStream in = testCase.getClass().getResourceAsStream(resourceName); - try - { - FileUtils.copy(in, dst); - } - catch (Exception e) - { - throw new RuntimeException("Cannot copy resource " + resourceName + - " to temp file " + dst.getAbsolutePath(), e); - } - dst.deleteOnExit(); - return dst; - } - - /** - * Creates a temporary file for given test with given suffix in file name. - * The given content is stored in the file using UTF-8 encoding. - */ - public static File createTempFile(TestCase testcase, String suffix, String content) - { - File file = createTempFile(testcase, suffix); - if (content != null) - { - FileOutputStream fos = null; - try - { - fos = new FileOutputStream(file); - fos.write(content.getBytes("UTF-8")); - fos.flush(); - } - catch (Exception e) - { - throw new RuntimeException("Cannot add the content into temp file " + file.getAbsolutePath(), e); - } - finally - { - if (fos != null) - { - try - { - fos.close(); - } - catch (IOException e) - { - throw new RuntimeException("Cannot close output stream into temp file " + file.getAbsolutePath(), e); - } - } - } - } - return file; - } -} diff --git a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestSSLConstants.java b/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestSSLConstants.java deleted file mode 100644 index c48f164d98..0000000000 --- a/qpid/java/common/src/test/java/org/apache/qpid/test/utils/TestSSLConstants.java +++ /dev/null @@ -1,37 +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.test.utils; - -public interface TestSSLConstants -{ - String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks"; - String UNTRUSTED_KEYSTORE = "test-profiles/test_resources/ssl/java_client_untrusted_keystore.jks"; - String KEYSTORE_PASSWORD = "password"; - String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks"; - String TRUSTSTORE_PASSWORD = "password"; - - String BROKER_KEYSTORE = "test-profiles/test_resources/ssl/java_broker_keystore.jks"; - String BROKER_KEYSTORE_PASSWORD = "password"; - - String BROKER_PEERSTORE = "test-profiles/test_resources/ssl/java_broker_peerstore.jks"; - String BROKER_PEERSTORE_PASSWORD = "password"; - - String BROKER_TRUSTSTORE = "test-profiles/test_resources/ssl/java_broker_truststore.jks"; - String BROKER_TRUSTSTORE_PASSWORD = "password"; -} diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/MockSender.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/MockSender.java deleted file mode 100644 index 4b38b7318a..0000000000 --- a/qpid/java/common/src/test/java/org/apache/qpid/transport/MockSender.java +++ /dev/null @@ -1,47 +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.transport; - -import java.nio.ByteBuffer; - -public class MockSender implements Sender -{ - - public void setIdleTimeout(int i) - { - - } - - public void send(ByteBuffer msg) - { - - } - - public void flush() - { - - } - - public void close() - { - - } -} diff --git a/qpid/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java b/qpid/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java deleted file mode 100644 index a19c2e7e43..0000000000 --- a/qpid/java/common/src/test/java/org/apache/qpid/transport/TestNetworkConnection.java +++ /dev/null @@ -1,161 +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.transport; - -import java.security.Principal; -import org.apache.qpid.protocol.ProtocolEngineFactory; -import org.apache.qpid.ssl.SSLContextFactory; -import org.apache.qpid.transport.network.NetworkConnection; - -import java.net.BindException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; - -/** - * Test implementation of IoSession, which is required for some tests. Methods not being used are not implemented, - * so if this class is being used and some methods are to be used, then please update those. - */ -public class TestNetworkConnection implements NetworkConnection -{ - private String _remoteHost = "127.0.0.1"; - private String _localHost = "127.0.0.1"; - private int _port = 1; - private SocketAddress _localAddress = null; - private SocketAddress _remoteAddress = null; - private final MockSender _sender; - - public TestNetworkConnection() - { - _sender = new MockSender(); - } - - - - public void bind(int port, InetAddress[] addresses, ProtocolEngineFactory protocolFactory, - NetworkTransportConfiguration config, SSLContextFactory sslFactory) throws BindException - { - - } - - public SocketAddress getLocalAddress() - { - return (_localAddress != null) ? _localAddress : new InetSocketAddress(_localHost, _port); - } - - public SocketAddress getRemoteAddress() - { - return (_remoteAddress != null) ? _remoteAddress : new InetSocketAddress(_remoteHost, _port); - } - - public void setMaxReadIdle(int idleTime) - { - - } - - @Override - public void setPeerPrincipal(Principal principal) - { - } - - @Override - public Principal getPeerPrincipal() - { - return null; - } - - @Override - public int getMaxReadIdle() - { - return 0; - } - - @Override - public int getMaxWriteIdle() - { - return 0; - } - - public void setMaxWriteIdle(int idleTime) - { - - } - - public void close() - { - - } - - public void flush() - { - - } - - public void send(ByteBuffer msg) - { - - } - - public void setIdleTimeout(int i) - { - - } - - public void setPort(int port) - { - _port = port; - } - - public int getPort() - { - return _port; - } - - public void setLocalHost(String host) - { - _localHost = host; - } - - public void setRemoteHost(String host) - { - _remoteHost = host; - } - - public void setLocalAddress(SocketAddress address) - { - _localAddress = address; - } - - public void setRemoteAddress(SocketAddress address) - { - _remoteAddress = address; - } - - public Sender getSender() - { - return _sender; - } - - public void start() - { - } -} diff --git a/qpid/java/perftests/build.xml b/qpid/java/perftests/build.xml index a97b33ef41..449dd7e89b 100644 --- a/qpid/java/perftests/build.xml +++ b/qpid/java/perftests/build.xml @@ -33,7 +33,7 @@ - + diff --git a/qpid/java/qpid-test-utils/build.xml b/qpid/java/qpid-test-utils/build.xml new file mode 100644 index 0000000000..4423c365f8 --- /dev/null +++ b/qpid/java/qpid-test-utils/build.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java new file mode 100644 index 0000000000..d3586c364f --- /dev/null +++ b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/PortHelper.java @@ -0,0 +1,127 @@ +/* + * 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.test.utils; + +import java.io.IOException; +import java.net.DatagramSocket; +import java.net.ServerSocket; +import java.util.Set; + +import org.apache.log4j.Logger; + +public class PortHelper +{ + private static final Logger _logger = Logger.getLogger(PortHelper.class); + + private static final int DEFAULT_TIMEOUT_MILLIS = 5000; + + private int timeout = DEFAULT_TIMEOUT_MILLIS; + + public void waitUntilPortsAreFree(Set ports) + { + _logger.debug("Checking if ports " + ports + " are free..."); + + for (Integer port : ports) + { + waitUntilPortIsFree(port); + } + + _logger.debug("ports " + ports + " are free"); + } + + private void waitUntilPortIsFree(int port) + { + long startTime = System.currentTimeMillis(); + long deadline = startTime + timeout; + boolean alreadyFailed = false; + + while (true) + { + if (System.currentTimeMillis() > deadline) + { + throw new RuntimeException("Timed out after " + timeout + " ms waiting for port " + port + " to become available"); + } + + if (isPortAvailable(port)) + { + if(alreadyFailed) + { + _logger.debug("port " + port + " is now available"); + } + return; + } + else + { + alreadyFailed = true; + } + + try + { + Thread.sleep(500); + } + catch (InterruptedException e) + { + Thread.currentThread().interrupt(); + } + } + } + + public boolean isPortAvailable(int port) + { + ServerSocket serverSocket = null; + DatagramSocket datagramSocket = null; + + try + { + serverSocket = new ServerSocket(port); + serverSocket.setReuseAddress(true); // ensures that the port is subsequently usable + datagramSocket = new DatagramSocket(port); + datagramSocket.setReuseAddress(true); + return true; + } + catch (IOException e) + { + _logger.debug("port " + port + " is not free"); + return false; + } + finally + { + if (serverSocket != null) + { + try + { + serverSocket.close(); + } + catch (IOException e) + { + throw new RuntimeException("Couldn't close port " + port + " that we created to check its availability", e); + } + } + if(datagramSocket != null) + { + datagramSocket.close(); + } + } + } + + public void setTimeout(int timeout) + { + this.timeout = timeout; + } +} diff --git a/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java new file mode 100644 index 0000000000..8f556ece5a --- /dev/null +++ b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -0,0 +1,284 @@ +/* + * + * 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.test.utils; + +import junit.framework.TestCase; +import junit.framework.TestResult; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; + + +public class QpidTestCase extends TestCase +{ + public static final String QPID_HOME = System.getProperty("QPID_HOME"); + public static final String TEST_RESOURCES_DIR = QPID_HOME + "/../test-profiles/test_resources/"; + public static final String TMP_FOLDER = System.getProperty("java.io.tmpdir"); + public static final String LOG4J_CONFIG_FILE_PATH = System.getProperty("log4j.configuration.file"); + + private static final Logger _logger = Logger.getLogger(QpidTestCase.class); + + private final Map _loggerLevelSetForTest = new HashMap(); + private final Map _propertiesSetForTest = new HashMap(); + + private String _testName; + + /** + * Some tests are excluded when the property test.excludes is set to true. + * An exclusion list is either a file (prop test.excludesfile) which contains one test name + * to be excluded per line or a String (prop test.excludeslist) where tests to be excluded are + * separated by " ". Excluded tests are specified following the format: + * className#testName where className is the class of the test to be + * excluded and testName is the name of the test to be excluded. + * className#* excludes all the tests of the specified class. + */ + static + { + if (Boolean.getBoolean("test.exclude")) + { + _logger.info("Some tests should be excluded, building the exclude list"); + String exclusionListURIs = System.getProperties().getProperty("test.excludefiles", ""); + String exclusionListString = System.getProperties().getProperty("test.excludelist", ""); + List exclusionList = new ArrayList(); + + for (String uri : exclusionListURIs.split(";\\s*")) + { + File file = new File(uri); + if (file.exists()) + { + _logger.info("Using exclude file: " + uri); + try + { + BufferedReader in = new BufferedReader(new FileReader(file)); + String excludedTest = in.readLine(); + do + { + exclusionList.add(excludedTest); + excludedTest = in.readLine(); + } + while (excludedTest != null); + } + catch (IOException e) + { + _logger.warn("Exception when reading exclusion list", e); + } + } + else + { + _logger.info("Specified exclude file does not exist: " + uri); + } + } + + if (!exclusionListString.equals("")) + { + _logger.info("Using excludeslist: " + exclusionListString); + for (String test : exclusionListString.split("\\s+")) + { + exclusionList.add(test); + } + } + + _exclusionList = exclusionList; + } + } + + protected static final String MESSAGE_STORE_CLASS_NAME_KEY = "messagestore.class.name"; + protected static final String CONFIGURATION_STORE_CLASS_NAME_KEY = "configurationstore.class.name"; + + protected static final String MEMORY_STORE_CLASS_NAME = "org.apache.qpid.server.store.MemoryMessageStore"; + + private static List _exclusionList; + + public QpidTestCase() + { + super(); + } + + public void run(TestResult testResult) + { + if (_exclusionList != null && (_exclusionList.contains(getClass().getPackage().getName() + ".*") || + _exclusionList.contains(getClass().getName() + "#*") || + _exclusionList.contains(getClass().getName() + "#" + getName()))) + { + _logger.info("Test: " + getName() + " is excluded"); + testResult.endTest(this); + } + else + { + super.run(testResult); + } + } + + public String getTestProfileMessageStoreClassName() + { + final String storeClass = System.getProperty(MESSAGE_STORE_CLASS_NAME_KEY); + _logger.debug("MESSAGE_STORE_CLASS_NAME_KEY " + storeClass); + + return storeClass != null ? storeClass : MEMORY_STORE_CLASS_NAME ; + } + + + public static final int MIN_PORT_NUMBER = 1; + public static final int MAX_PORT_NUMBER = 49151; + + + /** + * Gets the next available port starting at a port. + * + * @param fromPort the port to scan for availability + * @throws NoSuchElementException if there are no ports available + */ + public int getNextAvailable(int fromPort) + { + if ((fromPort < MIN_PORT_NUMBER) || (fromPort > MAX_PORT_NUMBER)) + { + throw new IllegalArgumentException("Invalid start port: " + fromPort); + } + + PortHelper portHelper = new PortHelper(); + for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) + { + if (portHelper.isPortAvailable(i)) { + return i; + } + } + + throw new NoSuchElementException("Could not find an available port above " + fromPort); + } + + public int findFreePort() + { + return getNextAvailable(10000); + } + + /** + * Set a System property for duration of this test only. The tearDown will + * guarantee to reset the property to its previous value after the test + * completes. + * + * @param property The property to set + * @param value the value to set it to, if null, the property will be cleared + */ + protected void setTestSystemProperty(final String property, final String value) + { + if (!_propertiesSetForTest.containsKey(property)) + { + // Record the current value so we can revert it later. + _propertiesSetForTest.put(property, System.getProperty(property)); + } + + if (value == null) + { + System.clearProperty(property); + } + else + { + System.setProperty(property, value); + } + + _logger.info("Set system property \"" + property + "\" to: \"" + value + "\""); + } + + /** + * Restore the System property values that were set by this test run. + */ + protected void revertTestSystemProperties() + { + if(!_propertiesSetForTest.isEmpty()) + { + _logger.debug("reverting " + _propertiesSetForTest.size() + " test properties"); + for (String key : _propertiesSetForTest.keySet()) + { + String value = _propertiesSetForTest.get(key); + if (value != null) + { + System.setProperty(key, value); + } + else + { + System.clearProperty(key); + } + } + + _propertiesSetForTest.clear(); + } + } + + /** + * Adjust the VMs Log4j Settings just for this test run + * + * @param logger the logger to change + * @param level the level to set + */ + protected void setLoggerLevel(Logger logger, Level level) + { + assertNotNull("Cannot set level of null logger", logger); + assertNotNull("Cannot set Logger("+logger.getName()+") to null level.",level); + + if (!_loggerLevelSetForTest.containsKey(logger)) + { + // Record the current value so we can revert it later. + _loggerLevelSetForTest.put(logger, logger.getLevel()); + } + + logger.setLevel(level); + } + + /** + * Restore the logging levels defined by this test. + */ + protected void revertLoggingLevels() + { + for (Logger logger : _loggerLevelSetForTest.keySet()) + { + logger.setLevel(_loggerLevelSetForTest.get(logger)); + } + + _loggerLevelSetForTest.clear(); + } + + protected void tearDown() throws java.lang.Exception + { + _logger.info("========== tearDown " + _testName + " =========="); + revertTestSystemProperties(); + revertLoggingLevels(); + } + + protected void setUp() throws Exception + { + _testName = getClass().getSimpleName() + "." + getName(); + _logger.info("========== start " + _testName + " =========="); + } + + protected String getTestName() + { + return _testName; + } +} diff --git a/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestFileUtils.java b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestFileUtils.java new file mode 100644 index 0000000000..d04413f06f --- /dev/null +++ b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestFileUtils.java @@ -0,0 +1,233 @@ +/* + * + * 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.test.utils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import java.io.FileOutputStream; + +import junit.framework.TestCase; + +/** + * Utility methods intended to be used in tests that manipulate files + */ +public class TestFileUtils +{ + private static final String SYSTEM_TMP_DIR = System.getProperty("java.io.tmpdir"); + private static final String SUFFIX = "tmp"; + + /** + * Create and return a temporary directory that will be deleted on exit. + */ + public static File createTestDirectory() + { + String dirNameStem = TestFileUtils.class.getSimpleName() + "-testDir"; + return createTestDirectory(dirNameStem, true); + } + + /** + * Creates an empty directory with a name like /tmp/dirNameStem-12345678 + */ + public static File createTestDirectory(String dirNameStem, boolean deleteOnExit) + { + File testDir = new File(SYSTEM_TMP_DIR, dirNameStem + "-" + System.currentTimeMillis()); + if (testDir.exists()) + { + delete(testDir, true); + } + + testDir.mkdirs(); + + if (deleteOnExit) + { + testDir.deleteOnExit(); + } + + return testDir; + } + + public static File createTempFile(TestCase testcase) + { + return createTempFile(testcase, SUFFIX); + } + + public static File createTempFile(TestCase testcase, String suffix) + { + String prefix = testcase.getClass().getSimpleName() + "-" + testcase.getName(); + + File tmpFile; + try + { + tmpFile = File.createTempFile(prefix, suffix); + tmpFile.deleteOnExit(); + } + catch (IOException e) + { + throw new RuntimeException("Cannot create temporary file with prefix " + prefix + " and suffix " + SUFFIX, e); + } + + return tmpFile; + } + + /** + * Creates a temporary file from the resource name given, using the resource name as the file suffix. + * + * This is required because the tests use the jar files as their class path. + */ + public static File createTempFileFromResource(TestCase testCase, String resourceName) + { + File dst = createTempFile(testCase, resourceName); + InputStream in = testCase.getClass().getResourceAsStream(resourceName); + try + { + copy(in, dst); + } + catch (Exception e) + { + throw new RuntimeException("Cannot copy resource " + resourceName + + " to temp file " + dst.getAbsolutePath(), e); + } + dst.deleteOnExit(); + return dst; + } + + /** + * Creates a temporary file for given test with given suffix in file name. + * The given content is stored in the file using UTF-8 encoding. + */ + public static File createTempFile(TestCase testcase, String suffix, String content) + { + File file = createTempFile(testcase, suffix); + if (content != null) + { + FileOutputStream fos = null; + try + { + fos = new FileOutputStream(file); + fos.write(content.getBytes("UTF-8")); + fos.flush(); + } + catch (Exception e) + { + throw new RuntimeException("Cannot add the content into temp file " + file.getAbsolutePath(), e); + } + finally + { + if (fos != null) + { + try + { + fos.close(); + } + catch (IOException e) + { + throw new RuntimeException("Cannot close output stream into temp file " + file.getAbsolutePath(), e); + } + } + } + } + return file; + } + + /** + * Delete a given file/directory, + * A directory will always require the recursive flag to be set. + * if a directory is specified and recursive set then delete the whole tree + * + * @param file the File object to start at + * @param recursive boolean to recurse if a directory is specified. + * + * @return true if and only if the file or directory is + * successfully deleted; false otherwise + */ + public static boolean delete(File file, boolean recursive) + { + boolean success = true; + + if (file.isDirectory()) + { + if (recursive) + { + File[] files = file.listFiles(); + + // This can occur if the file is deleted outside the JVM + if (files == null) + { + return false; + } + + for (int i = 0; i < files.length; i++) + { + success = delete(files[i], true) && success; + } + + return success && file.delete(); + } + + return false; + } + + return file.delete(); + } + + /** + * Copies the specified InputStream to the specified destination file. If the destination file does not exist, + * it is created. + * + * @param in The InputStream + * @param dst The destination file name. + * @throws IOException + */ + public static void copy(InputStream in, File dst) throws IOException + { + try + { + if (!dst.exists()) + { + dst.createNewFile(); + } + + OutputStream out = new FileOutputStream(dst); + + try + { + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) + { + out.write(buf, 0, len); + } + } + finally + { + out.close(); + } + } + finally + { + in.close(); + } + } +} diff --git a/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java new file mode 100644 index 0000000000..c48f164d98 --- /dev/null +++ b/qpid/java/qpid-test-utils/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java @@ -0,0 +1,37 @@ +/* + * 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.test.utils; + +public interface TestSSLConstants +{ + String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks"; + String UNTRUSTED_KEYSTORE = "test-profiles/test_resources/ssl/java_client_untrusted_keystore.jks"; + String KEYSTORE_PASSWORD = "password"; + String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks"; + String TRUSTSTORE_PASSWORD = "password"; + + String BROKER_KEYSTORE = "test-profiles/test_resources/ssl/java_broker_keystore.jks"; + String BROKER_KEYSTORE_PASSWORD = "password"; + + String BROKER_PEERSTORE = "test-profiles/test_resources/ssl/java_broker_peerstore.jks"; + String BROKER_PEERSTORE_PASSWORD = "password"; + + String BROKER_TRUSTSTORE = "test-profiles/test_resources/ssl/java_broker_truststore.jks"; + String BROKER_TRUSTSTORE_PASSWORD = "password"; +} diff --git a/qpid/java/systests/build.xml b/qpid/java/systests/build.xml index 68199fbc66..78bfeaec46 100644 --- a/qpid/java/systests/build.xml +++ b/qpid/java/systests/build.xml @@ -34,7 +34,7 @@ nn - or more contributor license agreements. See the NOTICE file - + diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java index 0d4b4ba9f8..c999be634b 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java @@ -22,7 +22,10 @@ package org.apache.qpid.server.protocol; import static org.mockito.Mockito.when; +import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.nio.ByteBuffer; +import java.security.Principal; import java.util.EnumSet; import java.util.Set; @@ -32,7 +35,8 @@ import org.apache.qpid.server.util.BrokerTestHelper; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.virtualhost.VirtualHostRegistry; import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.transport.TestNetworkConnection; +import org.apache.qpid.transport.Sender; +import org.apache.qpid.transport.network.NetworkConnection; public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase { @@ -202,4 +206,95 @@ public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase //expected } } + + private static class TestNetworkConnection implements NetworkConnection + { + private String _remoteHost = "127.0.0.1"; + private String _localHost = "127.0.0.1"; + private int _port = 1; + private final Sender _sender; + + public TestNetworkConnection() + { + _sender = new Sender() + { + public void setIdleTimeout(int i) + { + } + + public void send(ByteBuffer msg) + { + } + + public void flush() + { + } + + public void close() + { + } + }; + } + + @Override + public SocketAddress getLocalAddress() + { + return new InetSocketAddress(_localHost, _port); + } + + @Override + public SocketAddress getRemoteAddress() + { + return new InetSocketAddress(_remoteHost, _port); + } + + @Override + public void setMaxReadIdle(int idleTime) + { + } + + @Override + public void setPeerPrincipal(Principal principal) + { + } + + @Override + public Principal getPeerPrincipal() + { + return null; + } + + @Override + public int getMaxReadIdle() + { + return 0; + } + + @Override + public int getMaxWriteIdle() + { + return 0; + } + + @Override + public void setMaxWriteIdle(int idleTime) + { + } + + @Override + public void close() + { + } + + @Override + public Sender getSender() + { + return _sender; + } + + @Override + public void start() + { + } + } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java index 1a7e9dfc96..e893a58282 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java @@ -20,17 +20,20 @@ */ package org.apache.qpid.test.unit.client.protocol; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.security.Principal; + import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.protocol.AMQProtocolHandler; import org.apache.qpid.client.protocol.AMQProtocolSession; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.test.utils.QpidBrokerTestCase; -import org.apache.qpid.transport.TestNetworkConnection; - -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.UnknownHostException; +import org.apache.qpid.transport.Sender; +import org.apache.qpid.transport.network.NetworkConnection; public class AMQProtocolSessionTest extends QpidBrokerTestCase { @@ -97,4 +100,104 @@ public class AMQProtocolSessionTest extends QpidBrokerTestCase _testSession.getNetworkConnection().setLocalAddress(address); assertEquals("Wrong queue name", queueName, _testSession.genQueueName().asString()); } + + private static class TestNetworkConnection implements NetworkConnection + { + private String _remoteHost = "127.0.0.1"; + private String _localHost = "127.0.0.1"; + private int _port = 1; + private SocketAddress _localAddress = null; + private final Sender _sender; + + public TestNetworkConnection() + { + _sender = new Sender() + { + + public void setIdleTimeout(int i) + { + + } + + public void send(ByteBuffer msg) + { + + } + + public void flush() + { + + } + + public void close() + { + + } + }; + } + + @Override + public SocketAddress getLocalAddress() + { + return (_localAddress != null) ? _localAddress : new InetSocketAddress(_localHost, _port); + } + + @Override + public SocketAddress getRemoteAddress() + { + return new InetSocketAddress(_remoteHost, _port); + } + + @Override + public void setMaxReadIdle(int idleTime) + { + } + + @Override + public void setPeerPrincipal(Principal principal) + { + } + + @Override + public Principal getPeerPrincipal() + { + return null; + } + + @Override + public int getMaxReadIdle() + { + return 0; + } + + @Override + public int getMaxWriteIdle() + { + return 0; + } + + @Override + public void setMaxWriteIdle(int idleTime) + { + } + + @Override + public void close() + { + } + + public void setLocalAddress(SocketAddress address) + { + _localAddress = address; + } + + public Sender getSender() + { + return _sender; + } + + public void start() + { + } + } } -- cgit v1.2.1