Repository: qpid-jms Updated Branches: refs/heads/master 109bb5a38 -> eb9a58b39
Add test for creating many connections at once to try and reproduce some hangs that happen infrequently on create of a new connection. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/eb9a58b3 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/eb9a58b3 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/eb9a58b3 Branch: refs/heads/master Commit: eb9a58b3961813ae0fd6b899183209fef1fb7609 Parents: 109bb5a Author: Timothy Bish <tabish...@gmail.com> Authored: Wed Jan 14 13:49:00 2015 -0500 Committer: Timothy Bish <tabish...@gmail.com> Committed: Wed Jan 14 13:49:00 2015 -0500 ---------------------------------------------------------------------- .../jms/JmsConnectionInRandomBatchesTest.java | 104 +++++++++++++++++++ 1 file changed, 104 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/eb9a58b3/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionInRandomBatchesTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionInRandomBatchesTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionInRandomBatchesTest.java new file mode 100644 index 0000000..78cf03d --- /dev/null +++ b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionInRandomBatchesTest.java @@ -0,0 +1,104 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import javax.jms.Connection; + +import org.apache.qpid.jms.support.AmqpTestSupport; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test for creation of several open connections in a series of randomly + * sized batches over time. + */ +public class JmsConnectionInRandomBatchesTest extends AmqpTestSupport { + + private final List<Connection> batch = new ArrayList<Connection>(); + private final Random batchSizeGenerator = new Random(); + + private final int RANDOM_SIZE_MARKER = -1; + private final int MAX_BATCH_SIZE = 20; + private final int MAX_BATCH_ITERATIONS = 10; + + @Override + @Before + public void setUp() throws Exception { + batchSizeGenerator.setSeed(System.nanoTime()); + super.setUp(); + } + + @Override + @After + public void tearDown() throws Exception { + doCloseConnectionBatch(); + super.tearDown(); + } + + @Test + public void testSingleBatch() throws Exception { + doCreateConnectionBatch(MAX_BATCH_SIZE); + } + + @Test + public void testCreateManyBatches() throws Exception { + doCreateConnectionInBatches(MAX_BATCH_ITERATIONS, MAX_BATCH_SIZE); + } + + @Test + public void testCreateRandomSizedBatches() throws Exception { + doCreateConnectionInBatches(MAX_BATCH_ITERATIONS, RANDOM_SIZE_MARKER); + } + + private void doCreateConnectionInBatches(int count, int size) throws Exception { + for (int i = 0; i < count; ++i) { + if (size != RANDOM_SIZE_MARKER) { + doCreateConnectionBatch(size); + } else { + doCreateConnectionBatch(getNextBatchSize()); + } + doCloseConnectionBatch(); + } + } + + private void doCreateConnectionBatch(int size) throws Exception { + for (int i = 0; i < size; ++i) { + batch.add(createAmqpConnection()); + batch.get(i).start(); + } + } + + private void doCloseConnectionBatch() { + for (Connection connection : batch) { + try { + connection.close(); + } catch (Exception ex) { + } + } + + batch.clear(); + } + + private int getNextBatchSize() { + return batchSizeGenerator.nextInt(MAX_BATCH_SIZE) + 1; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org