summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests/TimerTest.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2013-04-19 02:00:16 +0000
committerAlan Conway <aconway@apache.org>2013-04-19 02:00:16 +0000
commitd4c8ebc4ed199b257bcc74ef263ffd1ea1f770fd (patch)
treee843816907ba08e643ecd64a9b07f0b30b183b92 /qpid/cpp/src/tests/TimerTest.cpp
parentcb033e84b242f61b50a71ea65791d6bb618a6054 (diff)
downloadqpid-python-d4c8ebc4ed199b257bcc74ef263ffd1ea1f770fd.tar.gz
QPID-4748: Consistent handling of durations in broker configuration, allowing sub-second intervals.
Provides string conversion for sys::Duration, allowing intervals to be expressed like this: 10.5 - value in seconds, backward compatible. 10.5s - value in seconds 10.5ms - value in milliseconds 10.5us - value in microseconds 10.5ns - value in nanoseconds Converted the folllowing broker options to Duration: mgmtPubInterval, queueCleanInterval, linkMaintenanceInterval, linkHeartbeatInterval Did not convert: maxNegotiateTime. This is expressed in milliseconds so it would not be backward compatible to make it a Duration. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1469661 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests/TimerTest.cpp')
-rw-r--r--qpid/cpp/src/tests/TimerTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/qpid/cpp/src/tests/TimerTest.cpp b/qpid/cpp/src/tests/TimerTest.cpp
index fc5004dcb0..4a1a050390 100644
--- a/qpid/cpp/src/tests/TimerTest.cpp
+++ b/qpid/cpp/src/tests/TimerTest.cpp
@@ -21,6 +21,7 @@
*/
#include "qpid/sys/Timer.h"
#include "qpid/sys/Monitor.h"
+#include "qpid/Options.h"
#include "unit_test.h"
#include <math.h>
#include <iostream>
@@ -127,6 +128,49 @@ QPID_AUTO_TEST_CASE(testGeneral)
dynamic_pointer_cast<TestTask>(task4)->check(2);
}
+std::string toString(Duration d) { return boost::lexical_cast<std::string>(d); }
+Duration fromString(const std::string& str) { return boost::lexical_cast<Duration>(str); }
+
+QPID_AUTO_TEST_CASE(testOstreamInOut) {
+ std::string empty;
+ BOOST_CHECK_EQUAL(toString(Duration(TIME_SEC)), "1s");
+ BOOST_CHECK_EQUAL(toString(Duration(TIME_SEC*123.4)), "123.4s");
+ BOOST_CHECK_EQUAL(toString(Duration(TIME_MSEC*123.4)), "123.4ms");
+ BOOST_CHECK_EQUAL(toString(Duration(TIME_USEC*123.4)), "123.4us");
+ BOOST_CHECK_EQUAL(toString(Duration(TIME_NSEC*123)), "123ns");
+
+ BOOST_CHECK_EQUAL(fromString("123.4"), Duration(TIME_SEC*123.4));
+ BOOST_CHECK_EQUAL(fromString("123.4s"), Duration(TIME_SEC*123.4));
+ BOOST_CHECK_EQUAL(fromString("123ms"), Duration(TIME_MSEC*123));
+ BOOST_CHECK_EQUAL(fromString("123us"), Duration(TIME_USEC*123));
+ BOOST_CHECK_EQUAL(fromString("123ns"), Duration(TIME_NSEC*123));
+
+ Duration d = 0;
+ std::istringstream i;
+ std::string s;
+
+ i.str("123x");
+ i >> d;
+ BOOST_CHECK(i.fail());
+ BOOST_CHECK_EQUAL(d, 0);
+ BOOST_CHECK_EQUAL(i.str(), "123x");
+
+ i.str("xxx");
+ i >> d;
+ BOOST_CHECK(i.fail());
+ BOOST_CHECK_EQUAL(d, 0);
+ BOOST_CHECK_EQUAL(i.str(), "xxx");
+}
+
+QPID_AUTO_TEST_CASE(testOptionParse) {
+ Options opts;
+ Duration interval;
+ opts.addOptions()("interval", optValue(interval, "I"), "blah");
+ const char *args[] = { "fakeexe", "--interval", "123.4" };
+ opts.parse(sizeof(args)/sizeof(args[0]), args);
+ BOOST_CHECK_EQUAL(interval, Duration(TIME_SEC * 123.4));
+}
+
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests