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 2017/02/09 21:42:40 UTC
activemq-cpp git commit:
https://issues.apache.org/jira/browse/AMQCPP-610
Repository: activemq-cpp
Updated Branches:
refs/heads/3.9.x f93fa9ea1 -> 2c99860e9
https://issues.apache.org/jira/browse/AMQCPP-610
Updates to ensure that an initial connect attempt is made even if max
reconnect attempts is zero, ensure that the task runner doesn't stall on
the close.
Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/2c99860e
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/2c99860e
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/2c99860e
Branch: refs/heads/3.9.x
Commit: 2c99860e9edf96d87f429d553fdd7d0cae861033
Parents: f93fa9e
Author: Timothy Bish <ta...@gmail.com>
Authored: Thu Feb 9 16:42:32 2017 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Thu Feb 9 16:42:32 2017 -0500
----------------------------------------------------------------------
.../transport/failover/FailoverTransport.cpp | 12 ++-
.../failover/FailoverTransportTest.cpp | 96 ++++++++++++++++++++
.../transport/failover/FailoverTransportTest.h | 6 ++
3 files changed, 111 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/2c99860e/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp b/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
index b5ea33b..9ee7a91 100644
--- a/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
+++ b/activemq-cpp/src/main/activemq/transport/failover/FailoverTransport.cpp
@@ -64,6 +64,8 @@ namespace failover {
FailoverTransportImpl(const FailoverTransportImpl&);
FailoverTransportImpl& operator= (const FailoverTransportImpl&);
+ public:
+
static const int DEFAULT_INITIAL_RECONNECT_DELAY;
static const int INFINITE_WAIT;
@@ -856,7 +858,11 @@ bool FailoverTransport::isPending() const {
int maxReconnectAttempts = this->impl->calculateReconnectAttemptLimit();
- if (maxReconnectAttempts != -1 && this->impl->connectFailures >= maxReconnectAttempts) {
+ if (impl->firstConnection && impl->connectFailures == 0) {
+ return true;
+ }
+
+ if (maxReconnectAttempts != -1 && this->impl->connectFailures > maxReconnectAttempts) {
result = false;
} else {
result = true;
@@ -1021,9 +1027,9 @@ bool FailoverTransport::iterate() {
}
}
- int reconnectAttempts = this->impl->calculateReconnectAttemptLimit();
+ int reconnectLimit = this->impl->calculateReconnectAttemptLimit();
- if (reconnectAttempts >= 0 && ++this->impl->connectFailures >= reconnectAttempts) {
+ if (reconnectLimit != impl->INFINITE_WAIT && ++this->impl->connectFailures > reconnectLimit) {
this->impl->connectionFailure = failure;
// Make sure on initial startup, that the transportListener has been initialized
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/2c99860e/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp b/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp
index bc3f04f..89307f6 100644
--- a/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp
+++ b/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.cpp
@@ -22,6 +22,7 @@
#include <activemq/transport/mock/MockTransport.h>
#include <activemq/exceptions/ActiveMQException.h>
#include <activemq/commands/ActiveMQMessage.h>
+#include <activemq/commands/WireFormatInfo.h>
#include <activemq/commands/ConnectionControl.h>
#include <activemq/mock/MockBrokerService.h>
#include <decaf/lang/Pointer.h>
@@ -700,3 +701,98 @@ void FailoverTransportTest::testConnectedToMockBroker() {
broker1.stop();
broker1.waitUntilStopped();
}
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::testMaxReconnectsZeroAttemptsOneConnect() {
+
+ std::string uri = "failover://(mock://localhost:61616)?maxReconnectAttempts=0";
+
+ DefaultTransportListener listener;
+ FailoverTransportFactory factory;
+
+ Pointer<Transport> transport(factory.create(uri));
+ CPPUNIT_ASSERT(transport != NULL);
+ transport->setTransportListener(&listener);
+
+ FailoverTransport* failover =
+ dynamic_cast<FailoverTransport*>(transport->narrow(typeid(FailoverTransport)));
+
+ CPPUNIT_ASSERT(failover != NULL);
+
+ transport->start();
+
+ Thread::sleep(1000);
+ CPPUNIT_ASSERT(failover->isConnected() == true);
+
+ transport->close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::testMaxReconnectsHonorsConfiguration() {
+
+ // max reconnect attempts of two means one connection attempt followed by
+ // two retries.
+
+ std::string uri = "failover://(mock://localhost:61616?failOnCreate=true,"
+ "mock://localhost:61617?failOnCreate=true)"
+ "?randomize=false&maxReconnectAttempts=2";
+
+ Pointer<WireFormatInfo> info(new WireFormatInfo());
+
+ DefaultTransportListener listener;
+ FailoverTransportFactory factory;
+
+ Pointer<Transport> transport(factory.create(uri));
+ CPPUNIT_ASSERT(transport != NULL);
+ transport->setTransportListener(&listener);
+
+ FailoverTransport* failover =
+ dynamic_cast<FailoverTransport*>(transport->narrow(typeid(FailoverTransport)));
+
+ CPPUNIT_ASSERT(failover != NULL);
+ CPPUNIT_ASSERT(failover->isRandomize() == false);
+
+ transport->start();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE("Send should have failed after max connect attempts of two",
+ transport->oneway(info), Exception);
+
+ CPPUNIT_ASSERT(failover->isConnected() == false);
+
+ transport->close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FailoverTransportTest::testStartupMaxReconnectsHonorsConfiguration() {
+
+ // max reconnect attempts of two means one connection attempt followed by
+ // two retries.
+
+ std::string uri = "failover://(mock://localhost:61616?failOnCreate=true,"
+ "mock://localhost:61617?failOnCreate=true)"
+ "?randomize=false&startupMaxReconnectAttempts=2";
+
+ Pointer<WireFormatInfo> info(new WireFormatInfo());
+
+ DefaultTransportListener listener;
+ FailoverTransportFactory factory;
+
+ Pointer<Transport> transport(factory.create(uri));
+ CPPUNIT_ASSERT(transport != NULL);
+ transport->setTransportListener(&listener);
+
+ FailoverTransport* failover =
+ dynamic_cast<FailoverTransport*>(transport->narrow(typeid(FailoverTransport)));
+
+ CPPUNIT_ASSERT(failover != NULL);
+ CPPUNIT_ASSERT(failover->isRandomize() == false);
+
+ transport->start();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE("Send should have failed after max connect attempts of two",
+ transport->oneway(info), Exception);
+
+ CPPUNIT_ASSERT(failover->isConnected() == false);
+
+ transport->close();
+}
http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/2c99860e/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.h b/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.h
index f0ea87b..9afd8a5 100644
--- a/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.h
+++ b/activemq-cpp/src/test/activemq/transport/failover/FailoverTransportTest.h
@@ -54,6 +54,9 @@ namespace failover {
CPPUNIT_TEST( testPriorityBackupConfig );
CPPUNIT_TEST( testUriOptionsApplied );
CPPUNIT_TEST( testConnectedToMockBroker );
+ CPPUNIT_TEST( testMaxReconnectsZeroAttemptsOneConnect );
+ CPPUNIT_TEST( testMaxReconnectsHonorsConfiguration );
+ CPPUNIT_TEST( testStartupMaxReconnectsHonorsConfiguration );
CPPUNIT_TEST_SUITE_END();
public:
@@ -75,6 +78,9 @@ namespace failover {
void testPriorityBackupConfig();
void testUriOptionsApplied();
void testConnectedToMockBroker();
+ void testMaxReconnectsZeroAttemptsOneConnect();
+ void testMaxReconnectsHonorsConfiguration();
+ void testStartupMaxReconnectsHonorsConfiguration();
private: