You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/04/12 00:48:58 UTC
svn commit: r1091245 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/test: ./ decaf/util/concurrent/
Author: tabish
Date: Mon Apr 11 22:48:57 2011
New Revision: 1091245
URL: http://svn.apache.org/viewvc?rev=1091245&view=rev
Log:
Squeeze some more unit tests in before getting the release ready.
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.cpp (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.h (with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.h
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=1091245&r1=1091244&r2=1091245&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Mon Apr 11 22:48:57 2011
@@ -208,6 +208,7 @@ cc_sources = \
decaf/util/concurrent/CopyOnWriteArraySetTest.cpp \
decaf/util/concurrent/CountDownLatchTest.cpp \
decaf/util/concurrent/ExecutorsTest.cpp \
+ decaf/util/concurrent/ExecutorsTestSupport.cpp \
decaf/util/concurrent/LinkedBlockingQueueTest.cpp \
decaf/util/concurrent/MutexTest.cpp \
decaf/util/concurrent/SynchronousQueueTest.cpp \
@@ -431,6 +432,7 @@ h_sources = \
decaf/util/concurrent/CopyOnWriteArraySetTest.h \
decaf/util/concurrent/CountDownLatchTest.h \
decaf/util/concurrent/ExecutorsTest.h \
+ decaf/util/concurrent/ExecutorsTestSupport.h \
decaf/util/concurrent/LinkedBlockingQueueTest.h \
decaf/util/concurrent/MutexTest.h \
decaf/util/concurrent/SynchronousQueueTest.h \
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.cpp?rev=1091245&r1=1091244&r2=1091245&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.cpp Mon Apr 11 22:48:57 2011
@@ -53,35 +53,6 @@ namespace {
}
};
- class NoOpRunnable : public Runnable {
- public:
-
- NoOpRunnable() : Runnable() {
- }
-
- virtual ~NoOpRunnable() {}
-
- virtual void run() {
- }
- };
-
- class SimpleThreadFactory : public ThreadFactory{
- public:
-
- virtual Thread* newThread(Runnable* task) {
- return new Thread(task);
- }
- };
-
- void joinPool(Pointer<ExecutorService>& exec) {
- try {
- exec->shutdown();
- CPPUNIT_ASSERT(exec->awaitTermination(5000, TimeUnit::MILLISECONDS));
- } catch(InterruptedException& ie) {
- CPPUNIT_FAIL("Unexpected exception");
- }
- }
-
}
////////////////////////////////////////////////////////////////////////////////
@@ -125,7 +96,7 @@ void ExecutorsTest::testNewFixedThreadPo
e->execute(new NoOpRunnable());
e->execute(new NoOpRunnable());
- joinPool(e);
+ joinPool(e.get());
}
////////////////////////////////////////////////////////////////////////////////
@@ -137,7 +108,7 @@ void ExecutorsTest::testNewFixedThreadPo
e->execute(new NoOpRunnable());
e->execute(new NoOpRunnable());
- joinPool(e);
+ joinPool(e.get());
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.h?rev=1091245&r1=1091244&r2=1091245&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTest.h Mon Apr 11 22:48:57 2011
@@ -18,14 +18,13 @@
#ifndef _DECAF_UTIL_CONCURRENT_EXECUTORSTEST_H_
#define _DECAF_UTIL_CONCURRENT_EXECUTORSTEST_H_
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
+#include <decaf/util/concurrent/ExecutorsTestSupport.h>
namespace decaf {
namespace util {
namespace concurrent {
- class ExecutorsTest : public CppUnit::TestFixture {
+ class ExecutorsTest : public ExecutorsTestSupport {
CPPUNIT_TEST_SUITE( ExecutorsTest );
CPPUNIT_TEST( testDefaultThreadFactory );
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.cpp?rev=1091245&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.cpp Mon Apr 11 22:48:57 2011
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+#include "ExecutorsTestSupport.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+
+///////////////////////////////////////////////////////////////////////////////
+const int ExecutorsTestSupport::SHORT_DELAY_MS = 50;
+const int ExecutorsTestSupport::SMALL_DELAY_MS = 50 * 5;
+const int ExecutorsTestSupport::MEDIUM_DELAY_MS = 50 * 10;
+const int ExecutorsTestSupport::LONG_DELAY_MS = 50 * 50;
+
+///////////////////////////////////////////////////////////////////////////////
+ExecutorsTestSupport::ExecutorsTestSupport() : threadFailed(false) {
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ExecutorsTestSupport::~ExecutorsTestSupport() {
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::setUp() {
+ threadFailed = false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::tearDown() {
+ CPPUNIT_ASSERT(!threadFailed);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::unexpectedException() {
+ CPPUNIT_FAIL("Unexpected exception");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::threadFail(const std::string& reason) {
+ threadFailed = true;
+ CPPUNIT_FAIL(reason);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::threadUnexpectedException() {
+ threadFailed = true;
+ CPPUNIT_FAIL("Unexpected exception");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::threadUnexpectedException(Throwable& ex) {
+ threadFailed = true;
+ CPPUNIT_FAIL(std::string("Unexpected exception: ") + ex.getMessage());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::shouldThrow() {
+ CPPUNIT_FAIL("Should throw exception");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::joinPool(ExecutorService& exec) {
+
+ try {
+ exec.shutdown();
+ CPPUNIT_ASSERT(exec.awaitTermination(LONG_DELAY_MS, TimeUnit::MILLISECONDS));
+ } catch(InterruptedException& ie) {
+ CPPUNIT_FAIL("Unexpected exception");
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ExecutorsTestSupport::joinPool(ExecutorService* exec) {
+
+ try {
+ exec->shutdown();
+ CPPUNIT_ASSERT(exec->awaitTermination(LONG_DELAY_MS, TimeUnit::MILLISECONDS));
+ } catch(InterruptedException& ie) {
+ CPPUNIT_FAIL("Unexpected exception");
+ }
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.h?rev=1091245&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.h Mon Apr 11 22:48:57 2011
@@ -0,0 +1,177 @@
+/*
+ * 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.
+ */
+
+#ifndef _DECAF_UTIL_CONCURRENT_EXECUTORSTESTSUPPORT_H_
+#define _DECAF_UTIL_CONCURRENT_EXECUTORSTESTSUPPORT_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/Runnable.h>
+
+#include <decaf/lang/Throwable.h>
+#include <decaf/util/concurrent/ThreadFactory.h>
+#include <decaf/util/concurrent/ExecutorService.h>
+#include <decaf/util/concurrent/ThreadPoolExecutor.h>
+
+namespace decaf {
+namespace util {
+namespace concurrent {
+
+ using decaf::lang::Thread;
+ using decaf::lang::Runnable;
+
+ class ExecutorsTestSupport : public CppUnit::TestFixture {
+ public:
+
+ static const int SHORT_DELAY_MS;
+ static const int SMALL_DELAY_MS;
+ static const int MEDIUM_DELAY_MS;
+ static const int LONG_DELAY_MS;
+
+ protected:
+
+ bool threadFailed;
+
+ public:
+
+ ExecutorsTestSupport();
+ virtual ~ExecutorsTestSupport();
+
+ virtual void setUp();
+ virtual void tearDown();
+
+ protected:
+
+ void threadFail(const std::string& reason);
+ void threadUnexpectedException();
+ void threadUnexpectedException(decaf::lang::Throwable& ex);
+
+ void unexpectedException();
+ void shouldThrow();
+
+ void joinPool(ExecutorService* exec);
+ void joinPool(ExecutorService& exec);
+
+ public:
+
+ class NoOpRunnable : public decaf::lang::Runnable {
+ public:
+
+ NoOpRunnable() : decaf::lang::Runnable() {
+ }
+
+ virtual ~NoOpRunnable() {}
+
+ virtual void run() {
+ }
+ };
+
+ class ShortRunnable : public decaf::lang::Runnable {
+ private:
+
+ ExecutorsTestSupport* parent;
+
+ public:
+
+ ShortRunnable(ExecutorsTestSupport* parent) : decaf::lang::Runnable() {
+ }
+
+ virtual ~ShortRunnable() {}
+
+ virtual void run() {
+ try {
+ Thread::sleep(SHORT_DELAY_MS);
+ } catch(decaf::lang::Exception& e) {
+ parent->threadUnexpectedException(e);
+ }
+ }
+ };
+
+ class SmallRunnable : public decaf::lang::Runnable {
+ private:
+
+ ExecutorsTestSupport* parent;
+
+ public:
+
+ SmallRunnable(ExecutorsTestSupport* parent) : decaf::lang::Runnable() {
+ }
+
+ virtual ~SmallRunnable() {}
+
+ virtual void run() {
+ try {
+ Thread::sleep(SMALL_DELAY_MS);
+ } catch(decaf::lang::Exception& e) {
+ parent->threadUnexpectedException(e);
+ }
+ }
+ };
+
+ class MediumRunnable : public decaf::lang::Runnable {
+ private:
+
+ ExecutorsTestSupport* parent;
+
+ public:
+
+ MediumRunnable(ExecutorsTestSupport* parent) : decaf::lang::Runnable() {
+ }
+
+ virtual ~MediumRunnable() {}
+
+ virtual void run() {
+ try {
+ Thread::sleep(MEDIUM_DELAY_MS);
+ } catch(decaf::lang::Exception& e) {
+ parent->threadUnexpectedException(e);
+ }
+ }
+ };
+
+ class SimpleThreadFactory : public ThreadFactory {
+ public:
+
+ SimpleThreadFactory() : ThreadFactory() {
+ }
+
+ virtual ~SimpleThreadFactory() {}
+
+ virtual Thread* newThread(Runnable* task) {
+ return new Thread(task);
+ }
+ };
+
+ class NoOpREHandler : public RejectedExecutionHandler {
+ public:
+
+ NoOpREHandler() : RejectedExecutionHandler() {
+ }
+
+ virtual ~NoOpREHandler() {}
+
+ virtual void rejectedExecution(Runnable* r, ThreadPoolExecutor* executor) {
+ }
+ };
+
+ };
+
+}}}
+
+#endif /* _DECAF_UTIL_CONCURRENT_EXECUTORSTESTSUPPORT_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ExecutorsTestSupport.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.cpp?rev=1091245&r1=1091244&r2=1091245&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.cpp Mon Apr 11 22:48:57 2011
@@ -92,6 +92,35 @@ namespace {
}
};
+ class DefaultThreadFactoryRunnable : public Runnable {
+ private:
+
+ CountDownLatch* shutdown;
+
+ public:
+
+ DefaultThreadFactoryRunnable(CountDownLatch* shutdown) : Runnable(), shutdown(shutdown) {
+ }
+
+ virtual ~DefaultThreadFactoryRunnable() {}
+
+ virtual void run() {
+ this->shutdown->await();
+ }
+
+ void signalDone() {
+ this->shutdown->countDown();
+ }
+ };
+
+ class SimpleThreadFactory : public ThreadFactory{
+ public:
+
+ virtual Thread* newThread(Runnable* task) {
+ return new Thread(task);
+ }
+ };
+
}
///////////////////////////////////////////////////////////////////////////////
@@ -262,3 +291,233 @@ void ThreadPoolExecutorTest::testTasksTh
pool.shutdown();
}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testPrestartCoreThread() {
+
+ ThreadPoolExecutor p2(2, 2, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+
+ CPPUNIT_ASSERT_EQUAL(0, p2.getPoolSize());
+ CPPUNIT_ASSERT(p2.prestartCoreThread());
+ CPPUNIT_ASSERT_EQUAL(1, p2.getPoolSize());
+ CPPUNIT_ASSERT(p2.prestartCoreThread());
+ CPPUNIT_ASSERT_EQUAL(2, p2.getPoolSize());
+ CPPUNIT_ASSERT(!p2.prestartCoreThread());
+ CPPUNIT_ASSERT_EQUAL(2, p2.getPoolSize());
+
+ joinPool(&p2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testPrestartAllCoreThreads() {
+
+ ThreadPoolExecutor p2(2, 2, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT_EQUAL(0, p2.getPoolSize());
+ p2.prestartAllCoreThreads();
+ CPPUNIT_ASSERT_EQUAL(2, p2.getPoolSize());
+ p2.prestartAllCoreThreads();
+ CPPUNIT_ASSERT_EQUAL(2, p2.getPoolSize());
+
+ joinPool(&p2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetCompletedTaskCount() {
+
+ ThreadPoolExecutor p2(2, 2, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT_EQUAL(0LL, p2.getCompletedTaskCount());
+ p2.execute(new ShortRunnable(this));
+
+ try {
+ Thread::sleep(SMALL_DELAY_MS);
+ } catch(Exception& e){
+ CPPUNIT_FAIL("Caught unknown exception");
+ }
+
+ CPPUNIT_ASSERT_EQUAL(1LL, p2.getCompletedTaskCount());
+ p2.shutdown();
+
+ joinPool(&p2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetCorePoolSize() {
+
+ ThreadPoolExecutor p1(1, 1, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT_EQUAL(1, p1.getCorePoolSize());
+ joinPool(&p1);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetKeepAliveTime() {
+
+ ThreadPoolExecutor p2(2, 2, 1000, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT_EQUAL(1LL, p2.getKeepAliveTime(TimeUnit::SECONDS));
+ joinPool(&p2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetThreadFactory() {
+
+ ThreadFactory* tf = new SimpleThreadFactory();
+ ThreadPoolExecutor p(1,2,LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>(), tf, new NoOpREHandler());
+ CPPUNIT_ASSERT_EQUAL(tf, p.getThreadFactory());
+ joinPool(&p);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testSetThreadFactory() {
+
+ ThreadPoolExecutor p(1,2,LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ ThreadFactory* tf = new SimpleThreadFactory();
+ p.setThreadFactory(tf);
+ CPPUNIT_ASSERT_EQUAL(tf, p.getThreadFactory());
+ joinPool(&p);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testSetThreadFactoryNull() {
+
+ ThreadPoolExecutor p(1,2,LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ try {
+ p.setThreadFactory(NULL);
+ shouldThrow();
+ } catch(...) {
+ }
+
+ joinPool(&p);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetRejectedExecutionHandler() {
+
+ RejectedExecutionHandler* h = new NoOpREHandler();
+ ThreadPoolExecutor p(1,2,LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>(), h);
+ CPPUNIT_ASSERT_EQUAL(h, p.getRejectedExecutionHandler());
+ joinPool(p);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testSetRejectedExecutionHandler() {
+
+ ThreadPoolExecutor p(1,2,LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ RejectedExecutionHandler* h = new NoOpREHandler();
+ p.setRejectedExecutionHandler(h);
+ CPPUNIT_ASSERT_EQUAL(h, p.getRejectedExecutionHandler());
+ joinPool(p);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testSetRejectedExecutionHandlerNull() {
+
+ ThreadPoolExecutor p(1,2,LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should have thrown a NullPointerException",
+ p.setRejectedExecutionHandler(NULL),
+ NullPointerException );
+
+ joinPool(p);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetLargestPoolSize() {
+
+ ThreadPoolExecutor p2(2, 2, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ try {
+ CPPUNIT_ASSERT_EQUAL(0, p2.getLargestPoolSize());
+ p2.execute(new MediumRunnable(this));
+ p2.execute(new MediumRunnable(this));
+ Thread::sleep(SHORT_DELAY_MS);
+ CPPUNIT_ASSERT_EQUAL(2, p2.getLargestPoolSize());
+ } catch(Exception& e){
+ unexpectedException();
+ }
+
+ joinPool(p2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetMaximumPoolSize() {
+
+ ThreadPoolExecutor p2(2, 2, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT_EQUAL(2, p2.getMaximumPoolSize());
+ joinPool(p2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetPoolSize() {
+
+ ThreadPoolExecutor p1(1, 1, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT_EQUAL(0, p1.getPoolSize());
+ p1.execute(new MediumRunnable(this));
+ CPPUNIT_ASSERT_EQUAL(1, p1.getPoolSize());
+ joinPool(p1);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testGetTaskCount() {
+
+ ThreadPoolExecutor p1(1, 1, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ try {
+ CPPUNIT_ASSERT_EQUAL(0LL, p1.getTaskCount());
+ p1.execute(new MediumRunnable(this));
+ Thread::sleep(SHORT_DELAY_MS);
+ CPPUNIT_ASSERT_EQUAL(1LL, p1.getTaskCount());
+ } catch(Exception& e){
+ unexpectedException();
+ }
+ joinPool(p1);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testIsShutdown() {
+
+ ThreadPoolExecutor p1(1, 1, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT(!p1.isShutdown());
+ p1.shutdown();
+ CPPUNIT_ASSERT(p1.isShutdown());
+ joinPool(p1);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testIsTerminated() {
+
+ ThreadPoolExecutor p1(1, 1, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT(!p1.isTerminated());
+ try {
+ p1.execute(new MediumRunnable(this));
+ } catch(...) {
+ }
+
+ p1.shutdown();
+
+ try {
+ CPPUNIT_ASSERT(p1.awaitTermination(LONG_DELAY_MS, TimeUnit::MILLISECONDS));
+ CPPUNIT_ASSERT(p1.isTerminated());
+ } catch(Exception& e){
+ unexpectedException();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void ThreadPoolExecutorTest::testIsTerminating() {
+
+ ThreadPoolExecutor p1(1, 1, LONG_DELAY_MS, TimeUnit::MILLISECONDS, new LinkedBlockingQueue<Runnable*>());
+ CPPUNIT_ASSERT(!p1.isTerminating());
+ try {
+ p1.execute(new SmallRunnable(this));
+ CPPUNIT_ASSERT(!p1.isTerminating());
+ } catch(...) {
+ }
+
+ p1.shutdown();
+
+ try {
+ CPPUNIT_ASSERT(p1.awaitTermination(LONG_DELAY_MS, TimeUnit::MILLISECONDS));
+ CPPUNIT_ASSERT(p1.isTerminated());
+ CPPUNIT_ASSERT(!p1.isTerminating());
+ } catch(Exception& e){
+ unexpectedException();
+ }
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.h?rev=1091245&r1=1091244&r2=1091245&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ThreadPoolExecutorTest.h Mon Apr 11 22:48:57 2011
@@ -18,9 +18,7 @@
#ifndef _DECAF_UTIL_CONCURRENT_THREADPOOLEXECUTORTEST_H_
#define _DECAF_UTIL_CONCURRENT_THREADPOOLEXECUTORTEST_H_
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-
+#include <decaf/util/concurrent/ExecutorsTestSupport.h>
#include <decaf/util/concurrent/CountDownLatch.h>
#include <decaf/util/concurrent/Concurrent.h>
#include <decaf/lang/Thread.h>
@@ -32,7 +30,7 @@ namespace decaf{
namespace util{
namespace concurrent{
- class ThreadPoolExecutorTest : public CppUnit::TestFixture {
+ class ThreadPoolExecutorTest : public ExecutorsTestSupport {
private:
CPPUNIT_TEST_SUITE( ThreadPoolExecutorTest );
@@ -41,6 +39,24 @@ namespace concurrent{
CPPUNIT_TEST( testMoreTasksThanMaxPoolSize );
CPPUNIT_TEST( testTasksThatThrow );
CPPUNIT_TEST( testAwaitTermination );
+ CPPUNIT_TEST( testPrestartCoreThread );
+ CPPUNIT_TEST( testPrestartAllCoreThreads );
+ CPPUNIT_TEST( testGetCompletedTaskCount );
+ CPPUNIT_TEST( testGetCorePoolSize );
+ CPPUNIT_TEST( testGetKeepAliveTime );
+ CPPUNIT_TEST( testGetThreadFactory );
+ CPPUNIT_TEST( testSetThreadFactory );
+ CPPUNIT_TEST( testSetThreadFactoryNull );
+ CPPUNIT_TEST( testGetRejectedExecutionHandler );
+ CPPUNIT_TEST( testSetRejectedExecutionHandler );
+ CPPUNIT_TEST( testSetRejectedExecutionHandlerNull );
+ CPPUNIT_TEST( testGetLargestPoolSize );
+ CPPUNIT_TEST( testGetMaximumPoolSize );
+ CPPUNIT_TEST( testGetPoolSize );
+ //CPPUNIT_TEST( testGetTaskCount );
+ CPPUNIT_TEST( testIsShutdown );
+ CPPUNIT_TEST( testIsTerminated );
+ CPPUNIT_TEST( testIsTerminating );
CPPUNIT_TEST_SUITE_END();
private:
@@ -57,6 +73,24 @@ namespace concurrent{
void testMoreTasksThanMaxPoolSize();
void testTasksThatThrow();
void testAwaitTermination();
+ void testPrestartCoreThread();
+ void testPrestartAllCoreThreads();
+ void testGetCompletedTaskCount();
+ void testGetCorePoolSize();
+ void testGetKeepAliveTime();
+ void testGetThreadFactory();
+ void testSetThreadFactory();
+ void testSetThreadFactoryNull();
+ void testGetRejectedExecutionHandler();
+ void testSetRejectedExecutionHandler();
+ void testSetRejectedExecutionHandlerNull();
+ void testGetLargestPoolSize();
+ void testGetMaximumPoolSize();
+ void testGetPoolSize();
+ void testGetTaskCount();
+ void testIsShutdown();
+ void testIsTerminated();
+ void testIsTerminating();
};