Author: tabish
Date: Mon Nov 16 22:28:39 2009
New Revision: 881015
URL: http://svn.apache.org/viewvc?rev=881015&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-250
Add the initial InactivityMonitor unit tests
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.cpp
(with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.h
(with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
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=881015&r1=881014&r2=881015&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Mon Nov 16
22:28:39 2009
@@ -50,6 +50,7 @@
activemq/transport/TransportRegistryTest.cpp \
activemq/transport/correlator/ResponseCorrelatorTest.cpp \
activemq/transport/failover/FailoverTransportTest.cpp \
+ activemq/transport/inactivity/InactivityMonitorTest.cpp \
activemq/transport/mock/MockTransportFactoryTest.cpp \
activemq/util/LongSequenceGeneratorTest.cpp \
activemq/util/MemoryUsageTest.cpp \
@@ -177,6 +178,7 @@
activemq/transport/TransportRegistryTest.h \
activemq/transport/correlator/ResponseCorrelatorTest.h \
activemq/transport/failover/FailoverTransportTest.h \
+ activemq/transport/inactivity/InactivityMonitorTest.h \
activemq/transport/mock/MockTransportFactoryTest.h \
activemq/util/LongSequenceGeneratorTest.h \
activemq/util/MemoryUsageTest.h \
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.cpp?rev=881015&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.cpp
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.cpp
Mon Nov 16 22:28:39 2009
@@ -0,0 +1,188 @@
+/*
+ * 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 "InactivityMonitorTest.h"
+
+#include <activemq/transport/inactivity/InactivityMonitor.h>
+#include <activemq/transport/mock/MockTransport.h>
+#include <activemq/transport/mock/MockTransportFactory.h>
+#include <activemq/transport/TransportListener.h>
+#include <activemq/commands/WireFormatInfo.h>
+#include <activemq/commands/ActiveMQMessage.h>
+
+#include <decaf/net/URI.h>
+#include <decaf/lang/Thread.h>
+
+#include <typeinfo>
+
+using namespace activemq;
+using namespace activemq::commands;
+using namespace activemq::transport;
+using namespace activemq::transport::mock;
+using namespace activemq::transport::inactivity;
+using namespace activemq::exceptions;
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+namespace {
+
+
////////////////////////////////////////////////////////////////////////////////
+ class MyTransportListener : public TransportListener {
+ public:
+
+ bool exceptionFired;
+ int commandsReceived;
+
+ public:
+
+ MyTransportListener() : exceptionFired( false ), commandsReceived( 0 )
{
+ }
+
+ virtual void onCommand( const Pointer<Command>& command ) {
+ this->commandsReceived++;
+ }
+
+ virtual void onException( const decaf::lang::Exception& ex ) {
+ this->exceptionFired = true;
+ }
+
+ virtual void transportInterrupted() {
+
+ }
+
+ virtual void transportResumed() {
+
+ }
+ };
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InactivityMonitorTest::InactivityMonitorTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InactivityMonitorTest::~InactivityMonitorTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InactivityMonitorTest::setUp() {
+
+ URI uri( "mock://mock?wireformat=openwire" );
+ MockTransportFactory factory;
+
+ this->transport = factory.createComposite( uri
).dynamicCast<MockTransport>();
+
+ this->localWireFormatInfo.reset( new WireFormatInfo() );
+
+ this->localWireFormatInfo->setVersion( 5 );
+ this->localWireFormatInfo->setMaxInactivityDuration( 3000 );
+ this->localWireFormatInfo->setTightEncodingEnabled( false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InactivityMonitorTest::tearDown() {
+ this->transport.reset( NULL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InactivityMonitorTest::testCreate() {
+
+ InactivityMonitor monitor( this->transport,
this->transport->getWireFormat() );
+
+ CPPUNIT_ASSERT( monitor.getInitialDelayTime() == 0 );
+ CPPUNIT_ASSERT( monitor.getReadCheckTime() == 0 );
+ CPPUNIT_ASSERT( monitor.getWriteCheckTime() == 0 );
+ CPPUNIT_ASSERT( monitor.isKeepAliveResponseRequired() == false );
+ CPPUNIT_ASSERT( monitor.isClosed() == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InactivityMonitorTest::testReadTimeout() {
+
+ MyTransportListener listener;
+ InactivityMonitor monitor( this->transport,
this->transport->getWireFormat() );
+
+ monitor.setTransportListener( &listener );
+
+ // Send the local one for the monitor to record.
+ monitor.oneway( this->localWireFormatInfo );
+
+ Thread::sleep( 2000 );
+
+ // Should not have timed out on Read yet.
+ CPPUNIT_ASSERT( listener.exceptionFired == false );
+
+ Thread::sleep( 5000 );
+
+ // Channel should have been inactive for to long.
+ CPPUNIT_ASSERT( listener.exceptionFired == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InactivityMonitorTest::testWriteMessageFail() {
+
+ this->transport->setFailOnKeepAliveSends( true );
+ this->transport->setNumSentKeepAlivesBeforeFail( 4 );
+
+ MyTransportListener listener;
+ InactivityMonitor monitor( this->transport,
this->transport->getWireFormat() );
+
+ monitor.setTransportListener( &listener );
+
+ // Send the local one for the monitor to record.
+ monitor.oneway( this->localWireFormatInfo );
+
+ Thread::sleep( 2000 );
+
+ Pointer<ActiveMQMessage> message( new ActiveMQMessage() );
+ this->transport->fireCommand( message );
+
+ // Should not have timed out on Read yet.
+ CPPUNIT_ASSERT( listener.exceptionFired == false );
+
+ Thread::sleep( 5000 );
+
+ // Channel should have been inactive for to long.
+ CPPUNIT_ASSERT( listener.exceptionFired == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InactivityMonitorTest::testNonFailureSendCase() {
+
+ MyTransportListener listener;
+ InactivityMonitor monitor( this->transport,
this->transport->getWireFormat() );
+
+ monitor.setTransportListener( &listener );
+
+ // Send the local one for the monitor to record.
+ monitor.oneway( this->localWireFormatInfo );
+
+ Pointer<ActiveMQMessage> message( new ActiveMQMessage() );
+ for( int ix = 0; ix < 20; ++ix ) {
+ monitor.oneway( message );
+ Thread::sleep( 500 );
+ this->transport->fireCommand( message );
+ Thread::sleep( 500 );
+ }
+
+ // Channel should have been inactive for to long.
+ CPPUNIT_ASSERT( listener.exceptionFired == false );
+}
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.h?rev=881015&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.h
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.h
Mon Nov 16 22:28:39 2009
@@ -0,0 +1,66 @@
+/*
+ * 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 _ACTIVEMQ_TRANSPORT_INACTIVITY_INACTIVITYMONITORTEST_H_
+#define _ACTIVEMQ_TRANSPORT_INACTIVITY_INACTIVITYMONITORTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <activemq/util/Config.h>
+#include <activemq/commands/WireFormatInfo.h>
+#include <activemq/transport/mock/MockTransport.h>
+
+#include <decaf/lang/Pointer.h>
+
+namespace activemq {
+namespace transport {
+namespace inactivity {
+
+ class InactivityMonitorTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( InactivityMonitorTest );
+ CPPUNIT_TEST( testCreate );
+ CPPUNIT_TEST( testReadTimeout );
+ CPPUNIT_TEST( testWriteMessageFail );
+ CPPUNIT_TEST( testNonFailureSendCase );
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+
+ decaf::lang::Pointer<mock::MockTransport> transport;
+
+ Pointer<activemq::commands::WireFormatInfo> localWireFormatInfo;
+
+ public:
+
+ InactivityMonitorTest();
+ virtual ~InactivityMonitorTest();
+
+ virtual void setUp();
+ virtual void tearDown();
+
+ void testCreate();
+ void testReadTimeout();
+ void testWriteMessageFail();
+ void testNonFailureSendCase();
+
+ };
+
+}}}
+
+#endif /* _ACTIVEMQ_TRANSPORT_INACTIVITY_INACTIVITYMONITORTEST_H_ */
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/inactivity/InactivityMonitorTest.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=881015&r1=881014&r2=881015&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Mon Nov
16 22:28:39 2009
@@ -102,6 +102,9 @@
#include <activemq/transport/mock/MockTransportFactoryTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(
activemq::transport::mock::MockTransportFactoryTest );
+#include <activemq/transport/inactivity/InactivityMonitorTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION(
activemq::transport::inactivity::InactivityMonitorTest );
+
#include <activemq/transport/TransportRegistryTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION( activemq::transport::TransportRegistryTest );
#include <activemq/transport/IOTransportTest.h>