Author: tabish
Date: Thu Nov 15 16:01:18 2012
New Revision: 1409856
URL: http://svn.apache.org/viewvc?rev=1409856&view=rev
Log:
Move test to client and remove an empty folder.
Added:
activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/
activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
(with props)
activemq/trunk/activemq-client/src/test/resources/
activemq/trunk/activemq-client/src/test/resources/log4j.properties (with
props)
Removed:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/mqtt/
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
Added:
activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java?rev=1409856&view=auto
==============================================================================
---
activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
(added)
+++
activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
Thu Nov 15 16:01:18 2012
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.usage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MemoryUsageTest {
+
+ MemoryUsage underTest;
+ ThreadPoolExecutor executor;
+
+ @Test
+ public final void testPercentUsageNeedsNoThread() {
+ int activeThreadCount = Thread.activeCount();
+ underTest.setLimit(10);
+ underTest.start();
+ underTest.increaseUsage(1);
+ assertEquals("usage is correct", 10, underTest.getPercentUsage());
+ assertEquals("no new thread created withough listener or
callback",activeThreadCount, Thread.activeCount());
+ }
+
+ @Test
+ public final void testAddUsageListenerStartsThread() throws Exception {
+ int activeThreadCount = Thread.activeCount();
+ underTest = new MemoryUsage();
+ underTest.setExecutor(executor);
+ underTest.setLimit(10);
+ underTest.start();
+ final CountDownLatch called = new CountDownLatch(1);
+ final String[] listnerThreadNameHolder = new String[1];
+ underTest.addUsageListener(new UsageListener() {
+ public void onUsageChanged(Usage usage, int oldPercentUsage,
+ int newPercentUsage) {
+ called.countDown();
+ listnerThreadNameHolder[0] = Thread.currentThread().toString();
+ }
+ });
+ underTest.increaseUsage(1);
+ assertTrue("listner was called", called.await(30, TimeUnit.SECONDS));
+ assertTrue("listner called from another thread",
!Thread.currentThread().toString().equals(listnerThreadNameHolder[0]));
+ assertEquals("usage is correct", 10, underTest.getPercentUsage());
+ assertEquals("new thread created with listener", activeThreadCount +
1, Thread.activeCount());
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ underTest = new MemoryUsage();
+ this.executor = new ThreadPoolExecutor(1, 10, 30, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
+ public Thread newThread(Runnable runnable) {
+ Thread thread = new Thread(runnable, "Usage Async Task");
+ thread.setDaemon(true);
+ return thread;
+ }
+ });
+ underTest.setExecutor(this.executor);
+
+ }
+
+ @After
+ public void tearDown() {
+ assertNotNull(underTest);
+ underTest.stop();
+ if (this.executor != null) {
+ this.executor.shutdownNow();
+ }
+ }
+}
Propchange:
activemq/trunk/activemq-client/src/test/java/org/apache/activemq/usage/MemoryUsageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/trunk/activemq-client/src/test/resources/log4j.properties
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/test/resources/log4j.properties?rev=1409856&view=auto
==============================================================================
--- activemq/trunk/activemq-client/src/test/resources/log4j.properties (added)
+++ activemq/trunk/activemq-client/src/test/resources/log4j.properties Thu Nov
15 16:01:18 2012
@@ -0,0 +1,42 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, out, stdout
+
+#log4j.logger.org.apache.activemq.broker.scheduler=DEBUG
+#log4j.logger.org.apache.activemq.network.DemandForwardingBridgeSupport=DEBUG
+#log4j.logger.org.apache.activemq.transport.failover=TRACE
+#log4j.logger.org.apache.activemq.store.jdbc=TRACE
+#log4j.logger.org.apache.activemq.broker.region.cursors.AbstractStoreCursor=DEBUG
+#log4j.logger.org.apache.activemq.store.jdbc.JDBCMessageStore=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p
%-30.30c{1} - %m%n
+#log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p
%-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector}
%-10.10X{activemq.destination} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} -
%m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1}
- %-10.10X{activemq.broker} %-20.20X{activemq.connector}
%-10.10X{activemq.destination} - %m%n
+log4j.appender.out.file=target/activemq-test.log
+log4j.appender.out.append=true
Propchange: activemq/trunk/activemq-client/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/trunk/activemq-client/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:executable = *