From dd508dac1475c9c3677f2b27b00249a8f10709eb Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Tue, 22 Mar 2022 14:14:11 +0100 Subject: [PATCH] Update usage of time in armem/server --- .../armem/server/MemoryToIceAdapter.cpp | 2 +- .../filter/equalityFilter/EqualityFilter.cpp | 2 +- .../frequencyFilter/FrequencyFilter.cpp | 4 +- .../armem/server/ltm/disk/Entity.cpp | 38 ++++++---- .../armem/server/ltm/disk/EntitySnapshot.cpp | 7 +- .../ltm/disk/detail/util/filesystem_util.cpp | 3 + .../ltm/disk/detail/util/filesystem_util.h | 5 +- .../base/EntityQueryProcessorBase.cpp | 2 +- .../base/EntityQueryProcessorBase.h | 6 +- .../armem/server/test/ArMemLTMBenchmark.cpp | 2 +- .../armem/server/test/ArMemLTMTest.cpp | 2 +- .../armem/server/test/ArMemMemoryTest.cpp | 73 +++++++++---------- .../armem/server/test/ArMemQueryTest.cpp | 56 ++++++++------ 13 files changed, 112 insertions(+), 90 deletions(-) diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp index d5318d3f7..82376eaa5 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp @@ -147,7 +147,7 @@ namespace armarx::armem::server MemoryToIceAdapter::commit(const data::Commit& commitIce) { ARMARX_TRACE; - return commit(commitIce, armem::Time::now()); + return commit(commitIce, armem::Time::Now()); } diff --git a/source/RobotAPI/libraries/armem/server/ltm/base/filter/equalityFilter/EqualityFilter.cpp b/source/RobotAPI/libraries/armem/server/ltm/base/filter/equalityFilter/EqualityFilter.cpp index ec52015e2..6ca0a944c 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/base/filter/equalityFilter/EqualityFilter.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/base/filter/equalityFilter/EqualityFilter.cpp @@ -7,7 +7,7 @@ namespace armarx::armem::server::ltm::filter bool SnapshotEqualityFilter::accept(const armem::wm::EntitySnapshot& e) { auto entityID = e.id().getEntityID(); - auto genMs = e.time().toMilliSeconds(); + auto genMs = e.time().toMilliSecondsSinceEpoch(); long lastMs = 0; std::vector<aron::data::DictPtr> lastData; diff --git a/source/RobotAPI/libraries/armem/server/ltm/base/filter/frequencyFilter/FrequencyFilter.cpp b/source/RobotAPI/libraries/armem/server/ltm/base/filter/frequencyFilter/FrequencyFilter.cpp index 5650c8365..a98aab7f7 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/base/filter/frequencyFilter/FrequencyFilter.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/base/filter/frequencyFilter/FrequencyFilter.cpp @@ -6,7 +6,7 @@ namespace armarx::armem::server::ltm::filter { bool MemoryFrequencyFilter::accept(const armem::wm::Memory& e) { - auto now = armem::Time::now().toMilliSeconds(); + auto now = armem::Time::Now().toMilliSecondsSinceEpoch(); if (waitingTimeInMs < 0 || (now - timestampLastCommitInMs) > waitingTimeInMs) { timestampLastCommitInMs = now; @@ -18,7 +18,7 @@ namespace armarx::armem::server::ltm::filter bool SnapshotFrequencyFilter::accept(const armem::wm::EntitySnapshot& e) { auto entityID = e.id().getEntityID(); - auto genMs = e.time().toMilliSeconds(); + auto genMs = e.time().toMilliSecondsSinceEpoch(); long lastMs = 0; if (timestampLastCommitInMs.count(entityID) > 0) diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp b/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp index ac1703ac9..b64531211 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp @@ -81,7 +81,8 @@ namespace armarx::armem::server::ltm::disk bool Entity::forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshot&)>&& func) const { - auto f = [&](EntitySnapshot& e) { + auto f = [&](EntitySnapshot& e) + { auto ts = e.id().timestamp; if (ts >= min && ts <= max) { @@ -94,7 +95,8 @@ namespace armarx::armem::server::ltm::disk bool Entity::forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshot&)>&& func) const { - auto f = [&](EntitySnapshot& e) { + auto f = [&](EntitySnapshot& e) + { auto ts = e.id().timestamp; if (ts <= time) { @@ -107,7 +109,8 @@ namespace armarx::armem::server::ltm::disk bool Entity::forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshot&)>&& func) const { - auto f = [&](EntitySnapshot& e) { + auto f = [&](EntitySnapshot& e) + { auto ts = e.id().timestamp; if (ts < time) { @@ -138,7 +141,7 @@ namespace armarx::armem::server::ltm::disk std::shared_ptr<EntitySnapshot> Entity::findLatestSnapshot() const { - Time bestMatch = Time::microSeconds(-1); + Time bestMatch = Time::Invalid(); auto f = [&](EntitySnapshot& e) { auto ts = e.id().timestamp; if (ts > bestMatch) @@ -149,7 +152,7 @@ namespace armarx::armem::server::ltm::disk forEachSnapshot(std::move(f)); - if (bestMatch == Time::microSeconds(-1)) + if (bestMatch == Time::Invalid()) { return nullptr; } @@ -159,7 +162,7 @@ namespace armarx::armem::server::ltm::disk std::shared_ptr<EntitySnapshot> Entity::findLatestSnapshotBefore(const Time& time) const { - Time bestMatch = Time::microSeconds(-1); + Time bestMatch = Time::Invalid(); auto f = [&](EntitySnapshot& e) { auto ts = e.id().timestamp; if (ts < time && ts > bestMatch) @@ -170,7 +173,7 @@ namespace armarx::armem::server::ltm::disk forEachSnapshot(std::move(f)); - if (bestMatch == Time::microSeconds(-1)) + if (bestMatch == Time::Invalid()) { return nullptr; } @@ -180,7 +183,7 @@ namespace armarx::armem::server::ltm::disk std::shared_ptr<EntitySnapshot> Entity::findLatestSnapshotBeforeOrAt(const Time& time) const { - Time bestMatch = Time::microSeconds(-1); + Time bestMatch = Time::Invalid(); auto f = [&](EntitySnapshot& e) { auto ts = e.id().timestamp; if (ts <= time && ts > bestMatch) @@ -191,7 +194,7 @@ namespace armarx::armem::server::ltm::disk forEachSnapshot(std::move(f)); - if (bestMatch == Time::microSeconds(-1)) + if (bestMatch == Time::Invalid()) { return nullptr; } @@ -201,8 +204,9 @@ namespace armarx::armem::server::ltm::disk std::shared_ptr<EntitySnapshot> Entity::findFirstSnapshotAfter(const Time& time) const { - Time bestMatch = Time::microSeconds(std::numeric_limits<long>::max()); - auto f = [&](EntitySnapshot& e) { + Time bestMatch { Duration::MicroSeconds(std::numeric_limits<long>::max()) }; + auto f = [&](EntitySnapshot& e) + { auto ts = e.id().timestamp; if (ts > time && ts < bestMatch) { @@ -212,7 +216,7 @@ namespace armarx::armem::server::ltm::disk forEachSnapshot(std::move(f)); - if (bestMatch == Time::microSeconds(std::numeric_limits<long>::max())) + if (bestMatch == Time(Duration::MicroSeconds(std::numeric_limits<long>::max()))) { return nullptr; } @@ -222,8 +226,9 @@ namespace armarx::armem::server::ltm::disk std::shared_ptr<EntitySnapshot> Entity::findFirstSnapshotAfterOrAt(const Time& time) const { - Time bestMatch = Time::microSeconds(std::numeric_limits<long>::max()); - auto f = [&](EntitySnapshot& e) { + Time bestMatch { Duration::MicroSeconds(std::numeric_limits<long>::max()) }; + auto f = [&](EntitySnapshot& e) + { auto ts = e.id().timestamp; if (ts >= time && ts < bestMatch) { @@ -233,7 +238,7 @@ namespace armarx::armem::server::ltm::disk forEachSnapshot(std::move(f)); - if (bestMatch == Time::microSeconds(std::numeric_limits<long>::max())) + if (bestMatch == Time(Duration::MicroSeconds(std::numeric_limits<long>::max()))) { return nullptr; } @@ -252,7 +257,8 @@ namespace armarx::armem::server::ltm::disk e.id() = id(); - forEachSnapshot([&e](auto& x) { + forEachSnapshot([&e](auto& x) + { if (!e.hasSnapshot(x.id().timestamp)) // we only load the references if the snapshot is not existant { armem::wm::EntitySnapshot s; diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/server/ltm/disk/EntitySnapshot.cpp index a4aece1fd..3d43ea8a0 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/EntitySnapshot.cpp @@ -14,7 +14,12 @@ namespace armarx::armem::server::ltm::disk { EntitySnapshot::EntitySnapshot(const std::filesystem::path& p, const MemoryID& id, const std::shared_ptr<Processors>& filters, const DiskMemoryItem::MemoryEncodingMode mode, const unsigned long e) : EntitySnapshotBase(id, filters), - DiskMemoryItem(p, EscapeSegmentName(id.memoryName), std::filesystem::path(EscapeSegmentName(id.coreSegmentName)) / EscapeSegmentName(id.providerSegmentName) / EscapeSegmentName(id.entityName) / std::to_string(id.timestamp.toSeconds() / 3600 /* hours */) / std::to_string(id.timestamp.toSeconds()) / id.timestampStr()), + DiskMemoryItem(p, EscapeSegmentName(id.memoryName), + std::filesystem::path(EscapeSegmentName(id.coreSegmentName)) + / EscapeSegmentName(id.providerSegmentName) + / EscapeSegmentName(id.entityName) + / std::to_string(id.timestamp.toSecondsSinceEpoch() / 3600 /* hours */) + / std::to_string(id.timestamp.toSecondsSinceEpoch()) / id.timestampStr()), currentMode(mode), currentExport(e) { diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.cpp b/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.cpp index eceff8d47..daea3fcfc 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.cpp @@ -1,5 +1,8 @@ #include "filesystem_util.h" +#include <RobotAPI/libraries/armem/core/error/ArMemError.h> + + namespace armarx::armem::server::ltm::disk { namespace filesystem::util diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.h b/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.h index b229a7b7f..78a8f4b13 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.h +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/detail/util/filesystem_util.h @@ -1,11 +1,10 @@ #pragma once -// STD / STL #include <filesystem> -#include <iostream> #include <fstream> +#include <iostream> +#include <vector> -#include "../../../../../core/error.h" namespace armarx::armem::server::ltm::disk { diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.cpp b/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.cpp index d9df52884..645b8aaa3 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.cpp +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.cpp @@ -7,6 +7,6 @@ namespace armarx::armem::server::query_proc::base { void detail::checkReferenceTimestampNonNegative(const Time& timestamp) { - ARMARX_CHECK_NONNEGATIVE(timestamp.toMicroSeconds()) << "Reference timestamp must be non-negative."; + ARMARX_CHECK_NONNEGATIVE(timestamp.toMicroSecondsSinceEpoch()) << "Reference timestamp must be non-negative."; } } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h index 6179467a7..59581cf0d 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/EntityQueryProcessorBase.h @@ -224,8 +224,8 @@ namespace armarx::armem::server::query_proc::base const Time referenceTimestamp = fromIce<Time>(query.timestamp); base::detail::checkReferenceTimestampNonNegative(referenceTimestamp); - const float referenceTimestampMicroSeconds = referenceTimestamp.toMicroSeconds(); - const float epsDuration = fromIce<Time>(query.eps).toMicroSeconds(); + const float referenceTimestampMicroSeconds = referenceTimestamp.toMicroSecondsSinceEpoch(); + const float epsDuration = fromIce<Time>(query.eps).toMicroSecondsSinceEpoch(); // elements have to be in range [t_ref - eps, t_ref + eps] if eps is positive const auto isInRange = [&](const Time & t) -> bool @@ -235,7 +235,7 @@ namespace armarx::armem::server::query_proc::base return true; } - return std::abs(t.toMicroSeconds() - referenceTimestampMicroSeconds) <= epsDuration; + return std::abs(t.toMicroSecondsSinceEpoch() - referenceTimestampMicroSeconds) <= epsDuration; }; // last element before or at timestamp diff --git a/source/RobotAPI/libraries/armem/server/test/ArMemLTMBenchmark.cpp b/source/RobotAPI/libraries/armem/server/test/ArMemLTMBenchmark.cpp index 8aded460e..ecf13ddc3 100644 --- a/source/RobotAPI/libraries/armem/server/test/ArMemLTMBenchmark.cpp +++ b/source/RobotAPI/libraries/armem/server/test/ArMemLTMBenchmark.cpp @@ -80,7 +80,7 @@ namespace ArMemLTMBenchmark std::cout << "Store instance " << i << " of memory " << memoryName << std::endl; en.clear(); - auto& snap = en.addSnapshot(IceUtil::Time::now()); + auto& snap = en.addSnapshot(armem::Time::Now()); auto& ins = snap.addInstance(); auto cloned = aron::data::Dict::DynamicCastAndCheck(dict->clone()); ins.data() = cloned; diff --git a/source/RobotAPI/libraries/armem/server/test/ArMemLTMTest.cpp b/source/RobotAPI/libraries/armem/server/test/ArMemLTMTest.cpp index 85096741e..7999a6a57 100644 --- a/source/RobotAPI/libraries/armem/server/test/ArMemLTMTest.cpp +++ b/source/RobotAPI/libraries/armem/server/test/ArMemLTMTest.cpp @@ -116,7 +116,7 @@ namespace ArMemLTMTest } update.entityID = armem::MemoryID::fromString(memoryName + "/TestCoreSegment/TestProvider/TestEntity"); update.instancesData = q; - update.timeCreated = armem::Time::now(); + update.timeCreated = armem::Time::Now(); BOOST_CHECK_NO_THROW(providerSegment.update(update)); BOOST_CHECK_EQUAL(providerSegment.size(), 1); } diff --git a/source/RobotAPI/libraries/armem/server/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/server/test/ArMemMemoryTest.cpp index 3ec604f35..8c3052e7d 100644 --- a/source/RobotAPI/libraries/armem/server/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/server/test/ArMemMemoryTest.cpp @@ -45,7 +45,7 @@ namespace wm = armarx::armem::wm; BOOST_AUTO_TEST_CASE(test_time_to_string) { // 111111: seconds, 345: milliseconds, 789: microseconds - armem::Time time = armem::Time::microSeconds(111111345789); + armem::Time time { armem::Duration::MicroSeconds(111111345789) }; BOOST_CHECK_EQUAL(armem::toStringMilliSeconds(time), "111111345.789 ms"); BOOST_CHECK_EQUAL(armem::toStringMilliSeconds(time, 0), "111111345 ms"); @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(test_time_to_string) BOOST_CHECK_EQUAL(armem::toDateTimeMilliSeconds(time, 6), "1970-01-02 07:51:51.345789"); // 111111: seconds, 000: milliseconds, 789: microseconds - time = armem::Time::microSeconds(111111000789); + time = armem::Time(armem::Duration::MicroSeconds(111111000789)); BOOST_CHECK_EQUAL(armem::toStringMilliSeconds(time), "111111000.789 ms"); BOOST_CHECK_EQUAL(armem::toStringMicroSeconds(time), "111111000789 " "\u03BC" "s"); BOOST_CHECK_EQUAL(armem::toDateTimeMilliSeconds(time), "1970-01-02 07:51:51.000789"); @@ -69,9 +69,8 @@ BOOST_AUTO_TEST_CASE(test_time_to_string) BOOST_CHECK_EQUAL(armem::toDateTimeMilliSeconds(time, 3), "1970-01-02 07:51:51.000"); BOOST_CHECK_EQUAL(armem::toDateTimeMilliSeconds(time, 6), "1970-01-02 07:51:51.000789"); - // 111111: seconds, 345: milliseconds, 000: microseconds - time = armem::Time::microSeconds(111111345000); + time = armem::Time(armem::Duration::MicroSeconds(111111345000)); BOOST_CHECK_EQUAL(armem::toStringMilliSeconds(time), "111111345.000 ms"); BOOST_CHECK_EQUAL(armem::toStringMicroSeconds(time), "111111345000 " "\u03BC" "s"); BOOST_CHECK_EQUAL(armem::toDateTimeMilliSeconds(time), "1970-01-02 07:51:51.345000"); @@ -89,7 +88,7 @@ namespace ArMemMemoryTest struct APITestFixture { wm::EntityInstance instance { 0 }; - wm::EntitySnapshot snapshot { armem::Time::microSeconds(1000) }; + wm::EntitySnapshot snapshot { armem::Time(armem::Duration::MicroSeconds(1000)) }; wm::Entity entity { "entity" }; wm::ProviderSegment provSeg { "provider" }; wm::CoreSegment coreSeg { "core" }; @@ -111,7 +110,7 @@ namespace ArMemMemoryTest { BOOST_TEST_CONTEXT("Added: " << armem::print(added) << "\n Parent: " << armem::print(parent)) { - const armem::Time time = armem::Time::microSeconds(1000); + const armem::Time time = armem::Time(armem::Duration::MicroSeconds(1000)); BOOST_CHECK_EQUAL(added.time(), time); BOOST_CHECK_EQUAL(parent.size(), 1); BOOST_CHECK(parent.hasSnapshot(time)); @@ -174,7 +173,7 @@ BOOST_AUTO_TEST_CASE(test_add_instance_move) BOOST_AUTO_TEST_CASE(test_add_snapshot_time) { - test_add_snapshot(entity.addSnapshot(armem::Time::microSeconds(1000)), entity); + test_add_snapshot(entity.addSnapshot(armem::Time(armem::Duration::MicroSeconds(1000))), entity); } BOOST_AUTO_TEST_CASE(test_add_snapshot_copy) { @@ -386,8 +385,8 @@ BOOST_AUTO_TEST_CASE(test_key_ctors) wm::EntityInstance instance(10); BOOST_CHECK_EQUAL(instance.index(), 10); - wm::EntitySnapshot snapshot(armem::Time::milliSeconds(100)); - BOOST_CHECK_EQUAL(snapshot.time(), armem::Time::milliSeconds(100)); + wm::EntitySnapshot snapshot(armem::Time(armem::Duration::MilliSeconds(100))); + BOOST_CHECK_EQUAL(snapshot.time(), armem::Time(armem::Duration::MilliSeconds(100))); wm::Entity entity("entity"); BOOST_CHECK_EQUAL(entity.name(), "entity"); @@ -518,8 +517,8 @@ struct CustomChecks<armem::d_ltm::Memory> struct CopyMoveCtorsOpsTestBase { - const armem::MemoryID id {"M", "C", "P", "E", armem::Time::microSeconds(123000), 1}; - //const armem::MemoryID idMoved {"", "", "", "", armem::Time::microSeconds(123000), 1}; + const armem::MemoryID id {"M", "C", "P", "E", armem::Time(armem::Duration::MicroSeconds(123000)), 1}; + //const armem::MemoryID idMoved {"", "", "", "", armem::Time(armem::Duration::MicroSeconds(123000), 1}; armem::MemoryID idMoved = id; std::string typeName; @@ -653,7 +652,7 @@ struct CopyMoveCtorsOpsTest : public CopyMoveCtorsOpsTestBase } { armem::EntityUpdate update; - update.entityID = armem::MemoryID("M", "C", "P", "E", armem::Time::microSeconds(123000), 0); + update.entityID = armem::MemoryID("M", "C", "P", "E", armem::Time(armem::Duration::MicroSeconds(123000)), 0); update.timeCreated = update.entityID.timestamp; update.instancesData.emplace_back(); in.update(update); @@ -815,7 +814,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) std::make_shared<aron::data::Dict>(), std::make_shared<aron::data::Dict>() }; - update.timeCreated = armem::Time::milliSeconds(1000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(1000)); BOOST_CHECK_NO_THROW(providerSegment.update(update)); BOOST_CHECK_EQUAL(providerSegment.size(), 1); @@ -834,7 +833,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) // Another update (on memory). update.instancesData = { std::make_shared<aron::data::Dict>() }; - update.timeCreated = armem::Time::milliSeconds(2000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(2000)); memory.update(update); BOOST_CHECK_EQUAL(entity.size(), 2); BOOST_CHECK(entity.hasSnapshot(update.timeCreated)); @@ -843,7 +842,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) // A third update (on entity). update.instancesData = { std::make_shared<aron::data::Dict>() }; - update.timeCreated = armem::Time::milliSeconds(3000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(3000)); entity.update(update); BOOST_CHECK_EQUAL(entity.size(), 3); @@ -859,38 +858,38 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_entity) update.entityID.entityName = entity.name(); // With unlimited history. - update.timeCreated = armem::Time::milliSeconds(1000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(1000)); entity.update(update); - update.timeCreated = armem::Time::milliSeconds(2000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(2000)); entity.update(update); - update.timeCreated = armem::Time::milliSeconds(3000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(3000)); entity.update(update); BOOST_CHECK_EQUAL(entity.size(), 3); // Now with maximum history size. entity.setMaxHistorySize(2); BOOST_CHECK_EQUAL(entity.size(), 2); - BOOST_CHECK(not entity.hasSnapshot(armem::Time::milliSeconds(1000))); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(2000))); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(3000))); + BOOST_CHECK(not entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(1000)))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(2000)))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(3000)))); - update.timeCreated = armem::Time::milliSeconds(4000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(4000)); entity.update(update); BOOST_CHECK_EQUAL(entity.size(), 2); - BOOST_CHECK(not entity.hasSnapshot(armem::Time::milliSeconds(2000))); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(3000))); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(4000))); + BOOST_CHECK(not entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(2000)))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(3000)))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(4000)))); // Disable maximum history size. entity.setMaxHistorySize(-1); - update.timeCreated = armem::Time::milliSeconds(5000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(5000)); entity.update(update); BOOST_CHECK_EQUAL(entity.size(), 3); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(3000))); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(4000))); - BOOST_CHECK(entity.hasSnapshot(armem::Time::milliSeconds(5000))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(3000)))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(4000)))); + BOOST_CHECK(entity.hasSnapshot(armem::Time(armem::Duration::MilliSeconds(5000)))); } @@ -908,15 +907,15 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) { update.entityID.entityName = name; - update.timeCreated = armem::Time::milliSeconds(1000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(1000)); providerSegment.update(update); - update.timeCreated = armem::Time::milliSeconds(2000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(2000)); providerSegment.update(update); - update.timeCreated = armem::Time::milliSeconds(3000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(3000)); providerSegment.update(update); } update.entityID.entityName = entityNames.back(); - update.timeCreated = armem::Time::milliSeconds(4000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(4000)); providerSegment.update(update); BOOST_CHECK_EQUAL(providerSegment.getEntity("A").size(), 3); @@ -940,11 +939,11 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) providerSegment.setMaxHistorySize(2); update.entityID.entityName = "C"; - update.timeCreated = armem::Time::milliSeconds(1000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(1000)); providerSegment.update(update); - update.timeCreated = armem::Time::milliSeconds(2000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(2000)); providerSegment.update(update); - update.timeCreated = armem::Time::milliSeconds(3000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(3000)); providerSegment.update(update); // Check correctly inherited history size. @@ -959,7 +958,7 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) for (const std::string& name : entityNames) { update.entityID.entityName = name; - update.timeCreated = armem::Time::milliSeconds(5000); + update.timeCreated = armem::Time(armem::Duration::MilliSeconds(5000)); providerSegment.update(update); BOOST_CHECK_EQUAL(providerSegment.getEntity(name).getMaxHistorySize(), -1); BOOST_CHECK_EQUAL(providerSegment.getEntity(name).size(), 3); diff --git a/source/RobotAPI/libraries/armem/server/test/ArMemQueryTest.cpp b/source/RobotAPI/libraries/armem/server/test/ArMemQueryTest.cpp index 191cfb625..0b1bf1419 100644 --- a/source/RobotAPI/libraries/armem/server/test/ArMemQueryTest.cpp +++ b/source/RobotAPI/libraries/armem/server/test/ArMemQueryTest.cpp @@ -65,15 +65,15 @@ namespace ArMemQueryTest entity = armem::wm::Entity("entity"); armem::wm::EntitySnapshot snapshot; - snapshot.time() = armem::Time::microSeconds(1000); + snapshot.time() = armem::Time(armem::Duration::MicroSeconds(1000)); entity.addSnapshot(snapshot); - snapshot.time() = armem::Time::microSeconds(2000); + snapshot.time() = armem::Time(armem::Duration::MicroSeconds(2000)); entity.addSnapshot(snapshot); - snapshot.time() = armem::Time::microSeconds(3000); + snapshot.time() = armem::Time(armem::Duration::MicroSeconds(3000)); entity.addSnapshot(snapshot); - snapshot.time() = armem::Time::microSeconds(4000); + snapshot.time() = armem::Time(armem::Duration::MicroSeconds(4000)); entity.addSnapshot(snapshot); - snapshot.time() = armem::Time::microSeconds(5000); + snapshot.time() = armem::Time(armem::Duration::MicroSeconds(5000)); entity.addSnapshot(snapshot); } ~Fixture() @@ -125,9 +125,9 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_latest) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_CHECK_EQUAL(result.size(), 1); - const armem::wm::EntitySnapshot* first = result.findFirstSnapshotAfterOrAt(armem::Time::microSeconds(0)); + const armem::wm::EntitySnapshot* first = result.findFirstSnapshotAfterOrAt(armem::Time(armem::Duration::MicroSeconds(0))); BOOST_REQUIRE_NE(first, nullptr); - BOOST_CHECK_EQUAL(first->time(), armem::Time::microSeconds(5000)); + BOOST_CHECK_EQUAL(first->time(), armem::Time(armem::Duration::MicroSeconds(5000))); } } @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_existing) { BOOST_CHECK_EQUAL(result.name(), entity.name()); BOOST_REQUIRE_EQUAL(result.size(), 1); - BOOST_CHECK_EQUAL(result.getFirstSnapshot().time(), armem::Time::microSeconds(3000)); + BOOST_CHECK_EQUAL(result.getFirstSnapshot().time(), armem::Time(armem::Duration::MicroSeconds(3000))); } } @@ -195,7 +195,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_slice) std::vector<armem::Time> times = result.getTimestamps(); std::vector<armem::Time> expected { - armem::Time::microSeconds(2000), armem::Time::microSeconds(3000) + armem::Time(armem::Duration::MicroSeconds(2000)), armem::Time(armem::Duration::MicroSeconds(3000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } @@ -216,7 +216,9 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_exact) std::vector<armem::Time> times = result.getTimestamps(); std::vector<armem::Time> expected { - armem::Time::microSeconds(2000), armem::Time::microSeconds(3000), armem::Time::microSeconds(4000) + armem::Time(armem::Duration::MicroSeconds(2000)), + armem::Time(armem::Duration::MicroSeconds(3000)), + armem::Time(armem::Duration::MicroSeconds(4000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } @@ -270,7 +272,8 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_from_start) const std::vector<armem::Time> times = result.getTimestamps(); std::vector<armem::Time> expected { - armem::Time::microSeconds(1000), armem::Time::microSeconds(2000) + armem::Time(armem::Duration::MicroSeconds(1000)), + armem::Time(armem::Duration::MicroSeconds(2000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } @@ -290,7 +293,9 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_to_end) const std::vector<armem::Time> times = result.getTimestamps(); std::vector<armem::Time> expected { - armem::Time::microSeconds(3000), armem::Time::microSeconds(4000), armem::Time::microSeconds(5000) + armem::Time(armem::Duration::MicroSeconds(3000)), + armem::Time(armem::Duration::MicroSeconds(4000)), + armem::Time(armem::Duration::MicroSeconds(5000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } @@ -310,7 +315,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeTime_1) const std::vector<armem::Time> times = result.getTimestamps(); BOOST_REQUIRE_EQUAL(times.size(), 1); - BOOST_CHECK_EQUAL(times.front(), armem::Time::microSeconds(3000)); + BOOST_CHECK_EQUAL(times.front(), armem::Time(armem::Duration::MicroSeconds(3000))); } } @@ -327,7 +332,8 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeTime_2) std::vector<armem::Time> expected { - armem::Time::microSeconds(2000), armem::Time::microSeconds(3000) + armem::Time(armem::Duration::MicroSeconds(2000)), + armem::Time(armem::Duration::MicroSeconds(3000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -350,7 +356,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_before) std::vector<armem::Time> times = result.getTimestamps(); BOOST_REQUIRE_EQUAL(times.size(), 1); - BOOST_REQUIRE_EQUAL(times.front(), armem::Time::microSeconds(3000)); + BOOST_REQUIRE_EQUAL(times.front(), armem::Time(armem::Duration::MicroSeconds(3000))); } } @@ -365,7 +371,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_at) std::vector<armem::Time> times = result.getTimestamps(); BOOST_REQUIRE_EQUAL(times.size(), 1); - BOOST_REQUIRE_EQUAL(times.front(), armem::Time::microSeconds(3000)); + BOOST_REQUIRE_EQUAL(times.front(), armem::Time(armem::Duration::MicroSeconds(3000))); } } @@ -402,7 +408,8 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_no_limit) std::vector<armem::Time> expected { - armem::Time::microSeconds(3000), armem::Time::microSeconds(4000) + armem::Time(armem::Duration::MicroSeconds(3000)), + armem::Time(armem::Duration::MicroSeconds(4000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -428,7 +435,8 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_600) std::vector<armem::Time> expected { - armem::Time::microSeconds(3000), armem::Time::microSeconds(4000) + armem::Time(armem::Duration::MicroSeconds(3000)), + armem::Time(armem::Duration::MicroSeconds(4000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -473,7 +481,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_only_next) std::vector<armem::Time> expected { - armem::Time::microSeconds(4000) + armem::Time(armem::Duration::MicroSeconds(4000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -498,7 +506,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_only_previous) std::vector<armem::Time> expected { - armem::Time::microSeconds(3000) + armem::Time(armem::Duration::MicroSeconds(3000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -523,7 +531,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_perfect_match) std::vector<armem::Time> expected { - armem::Time::microSeconds(3000) + armem::Time(armem::Duration::MicroSeconds(3000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -584,7 +592,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_future_valid) std::vector<armem::Time> expected { - armem::Time::microSeconds(5'000) + armem::Time(armem::Duration::MicroSeconds(5'000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); @@ -668,7 +676,9 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) std::vector<armem::Time> times = result.getTimestamps(); std::vector<armem::Time> expected { - armem::Time::microSeconds(2000), armem::Time::microSeconds(3000), armem::Time::microSeconds(4000) + armem::Time(armem::Duration::MicroSeconds(2000)), + armem::Time(armem::Duration::MicroSeconds(3000)), + armem::Time(armem::Duration::MicroSeconds(4000)) }; BOOST_CHECK_EQUAL_COLLECTIONS(times.begin(), times.end(), expected.begin(), expected.end()); } -- GitLab