From a08d10a628833cc87491f33bf472887b7fb5cc89 Mon Sep 17 00:00:00 2001 From: "Hochrieser, Matthias" Date: Thu, 18 Jul 2024 11:28:41 +0200 Subject: [PATCH] Pull request #210: RUM-20521 Adding int64_t for WebTracer bytesSent and bytesReceived Merge in OP/openkit-native from feature/RUM-20521-openkit-java-.net-native-should-use-long-instead-of-int-for-bytessent-and to main * commit '88c6ec9571953c39b090f16a2375d4167d912f22': RUM-20521 Forgot to update header for sample RUM-20521 Sample Fix RUM-20521 Adding int64_t for WebTracer bytesSent and bytesReceived GitOrigin-RevId: dda941a86175fb2885fbe4614720905184d113be --- CHANGELOG.md | 14 +++++ docs/example.md | 8 +-- include/OpenKit/IWebRequestTracer.h | 20 ++++++ include/OpenKit/OpenKit-c.h | 20 ++++++ samples/sample1/src/openkit-sample.cxx | 4 +- samples/sample2/src/openkit-sample.c | 4 +- src/api-c/OpenKit-c.cxx | 10 +++ src/core/objects/IWebRequestTracerInternals.h | 8 ++- src/core/objects/NullWebRequestTracer.cxx | 10 +++ src/core/objects/NullWebRequestTracer.h | 4 ++ src/core/objects/WebRequestTracer.cxx | 14 ++++- src/core/objects/WebRequestTracer.h | 12 ++-- test/api/mock/MockIWebRequestTracer.h | 4 ++ .../core/objects/NullWebRequestTracerTest.cxx | 28 +++++++++ test/core/objects/WebRequestTracerTest.cxx | 62 +++++++++++++++++-- .../mock/MockIWebRequestTracerInternals.h | 29 +++++++-- 16 files changed, 226 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d797404c..b1329651 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ ## [Unreleased](https://github.com/Dynatrace/openkit-native/compare/v3.2.0...HEAD) +### Added + +- `IWebRequestTracer::setBytesSent(int64_t bytes)` to increase the size range +- `IWebRequestTracer::setBytesReceived(int64_t bytes)` to increase the size range +- `setBytesSentLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytes)` to increase the size range +- `setBytesReceivedLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytes)` to increase the size range + +### Changed + +- Deprecated `IWebRequestTracer::setBytesSent(int32_t bytes)` due to datatype limitations +- Deprecated `IWebRequestTracer::setBytesReceived(int32_t bytes)` due to datatype limitations +- Deprecated `setBytesSent(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytes)` due to datatype limitations +- Deprecated `setBytesReceived(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytes)` due to datatype limitations + ## 3.2.0 [Release date: 2023-12-06] [GitHub Releases](https://github.com/Dynatrace/openkit-native/releases/tag/v3.2.0) diff --git a/docs/example.md b/docs/example.md index a9dad8b9..fa96a2d4 100644 --- a/docs/example.md +++ b/docs/example.md @@ -722,8 +722,8 @@ webRequestTracer->start(); // perform the request here & do not forget to add the HTTP header -webRequestTracer->setBytesSent(12345); // 12345 bytes sent -webRequestTracer->setBytesReceived(67890); // 67890 bytes received +webRequestTracer->setBytesSent(12345L); // 12345 bytes sent +webRequestTracer->setBytesReceived(67890L); // 67890 bytes received webRequestTracer->stop(200); // 200 was the response code // also reset the shared pointer after stop() method has been called @@ -752,8 +752,8 @@ startWebRequest(webRequestTracer); // perform the request here & do not forget to add the HTTP header -setBytesSent(webRequestTracer, 12345); // 12345 bytes sent -setBytesReceived(webRequestTracer, 67890); // 67890 bytes received +setBytesSent(webRequestTracer, 12345L); // 12345 bytes sent +setBytesReceived(webRequestTracer, 67890L); // 67890 bytes received stopWebRequestWithResponseCode(webRequestTracer, 200); // 200 was the response code // since webRequestTracer now points to an invalid memory diff --git a/include/OpenKit/IWebRequestTracer.h b/include/OpenKit/IWebRequestTracer.h index 1c040b00..54374f68 100644 --- a/include/OpenKit/IWebRequestTracer.h +++ b/include/OpenKit/IWebRequestTracer.h @@ -47,17 +47,37 @@ namespace openkit /// /// @param[in] bytesSent number of bytes sent /// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call + /// @deprecated This method should no longer be used due its datatype limitation. Use IWebRequestTracer::setBytesSent(int64_t) instead. /// + OPENKIT_DEPRECATED virtual std::shared_ptr setBytesSent(int32_t bytesSent) = 0; + /// + /// Sets the amount of sent data of this web request. Has to be called before @ref openkit::IWebRequestTracer::stop(int). + /// + /// @param[in] bytesSent number of bytes sent + /// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call + /// + virtual std::shared_ptr setBytesSent(int64_t bytesSent) = 0; + /// /// Sets the amount of received data of this web request. Has to be called before @ref openkit::IWebRequestTracer::stop(int). /// /// @param[in] bytesReceived number of bytes received /// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call + /// @deprecated This method should no longer be used due its datatype limitation. Use IWebRequestTracer::setBytesReceived(int64_t) instead. /// + OPENKIT_DEPRECATED virtual std::shared_ptr setBytesReceived(int32_t bytesReceived) = 0; + /// + /// Sets the amount of received data of this web request. Has to be called before @ref openkit::IWebRequestTracer::stop(int). + /// + /// @param[in] bytesReceived number of bytes received + /// @returns pointer to this WebRequestTracer instance that can be used for a fluent-API call + /// + virtual std::shared_ptr setBytesReceived(int64_t bytesReceived) = 0; + /// /// Starts the web request timing. Should be called when the web request is initiated. /// diff --git a/include/OpenKit/OpenKit-c.h b/include/OpenKit/OpenKit-c.h index 7958cd33..43df9356 100644 --- a/include/OpenKit/OpenKit-c.h +++ b/include/OpenKit/OpenKit-c.h @@ -969,7 +969,9 @@ extern "C" { /// /// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction /// @param[in] bytesSent number of bytes sent + /// @deprecated This method should no longer be used due its datatype limitation. Use setBytesSent(struct WebRequestTracerHandle*, int64_t) instead. /// + OPENKIT_DEPRECATED OPENKIT_EXPORT void setBytesSent(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesSent); /// @@ -977,9 +979,27 @@ extern "C" { /// /// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction /// @param[in] bytesReceived number of bytes received + /// @deprecated This method should no longer be used due its datatype limitation. Use setBytesSent(struct WebRequestTracerHandle*, int64_t) instead. /// + OPENKIT_DEPRECATED OPENKIT_EXPORT void setBytesReceived(struct WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesReceived); + /// + /// Sets the amount of sent data of this web request. Has to be called before @ref stopWebRequest(). + /// + /// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction + /// @param[in] bytesSent number of bytes sent + /// + OPENKIT_EXPORT void setBytesSentLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesSent); + + /// + /// Sets the amount of received data of this web request. Has to be called before @ref stopWebRequest(). + /// + /// @param[in] webRequestTracerHandle the handle returned by @ref traceWebRequestOnRootAction or @ref traceWebRequestOnAction + /// @param[in] bytesReceived number of bytes received + /// + OPENKIT_EXPORT void setBytesReceivedLong(struct WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesReceived); + #ifdef __cplusplus } // extern "C" diff --git a/samples/sample1/src/openkit-sample.cxx b/samples/sample1/src/openkit-sample.cxx index 854e070e..80ba1caa 100644 --- a/samples/sample1/src/openkit-sample.cxx +++ b/samples/sample1/src/openkit-sample.cxx @@ -105,8 +105,8 @@ int32_t main(int32_t argc, char** argv) std::this_thread::sleep_for(std::chrono::milliseconds(144)); - webRequest->setBytesSent(123); - webRequest->setBytesReceived(45); + webRequest->setBytesSent(123L); + webRequest->setBytesReceived(45L); webRequest->stop(200); childAction1->leaveAction(); diff --git a/samples/sample2/src/openkit-sample.c b/samples/sample2/src/openkit-sample.c index 96f34ce1..28b1512f 100644 --- a/samples/sample2/src/openkit-sample.c +++ b/samples/sample2/src/openkit-sample.c @@ -205,8 +205,8 @@ int32_t main(int32_t argc, char** argv) #else usleep(144 * 1000); #endif - setBytesSent(webRequest, 123); - setBytesReceived(webRequest, 45); + setBytesSent(webRequest, 123L); + setBytesReceived(webRequest, 45L); stopWebRequestWithResponseCode(webRequest, 200); leaveAction(actionHandle); diff --git a/src/api-c/OpenKit-c.cxx b/src/api-c/OpenKit-c.cxx index b775e178..9ffd4ca8 100644 --- a/src/api-c/OpenKit-c.cxx +++ b/src/api-c/OpenKit-c.cxx @@ -1730,6 +1730,11 @@ extern "C" { } void setBytesSent(WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesSent) + { + setBytesSentLong(webRequestTracerHandle, bytesSent); + } + + void setBytesSentLong(WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesSent) { TRY { @@ -1744,6 +1749,11 @@ extern "C" { } void setBytesReceived(WebRequestTracerHandle* webRequestTracerHandle, int32_t bytesReceived) + { + setBytesReceivedLong(webRequestTracerHandle, bytesReceived); + } + + void setBytesReceivedLong(WebRequestTracerHandle* webRequestTracerHandle, int64_t bytesReceived) { TRY { diff --git a/src/core/objects/IWebRequestTracerInternals.h b/src/core/objects/IWebRequestTracerInternals.h index ecaf6ad3..e81c402d 100644 --- a/src/core/objects/IWebRequestTracerInternals.h +++ b/src/core/objects/IWebRequestTracerInternals.h @@ -39,6 +39,10 @@ namespace core std::shared_ptr setBytesReceived(int32_t bytesReceived) override = 0; + std::shared_ptr setBytesSent(int64_t bytesSent) override = 0; + + std::shared_ptr setBytesReceived(int64_t bytesReceived) override = 0; + std::shared_ptr start() override = 0; void stop(int32_t responseCode) override = 0; @@ -87,13 +91,13 @@ namespace core /// Returns the number of bytes sent /// @returns amount of bytes sent /// - virtual int32_t getBytesSent() const = 0; + virtual int64_t getBytesSent() const = 0; /// /// Returns the number of bytes received /// @returns amount of bytes received /// - virtual int32_t getBytesReceived() const = 0; + virtual int64_t getBytesReceived() const = 0; /// /// Returns a flag if stop() has already been called diff --git a/src/core/objects/NullWebRequestTracer.cxx b/src/core/objects/NullWebRequestTracer.cxx index ef0be969..18624174 100644 --- a/src/core/objects/NullWebRequestTracer.cxx +++ b/src/core/objects/NullWebRequestTracer.cxx @@ -40,6 +40,16 @@ std::shared_ptr NullWebRequestTracer::setBytesReceiv return shared_from_this(); } +std::shared_ptr NullWebRequestTracer::setBytesSent(int64_t /*bytesSent*/) +{ + return shared_from_this(); +} + +std::shared_ptr NullWebRequestTracer::setBytesReceived(int64_t /*bytesReceived*/) +{ + return shared_from_this(); +} + std::shared_ptr NullWebRequestTracer::start() { return shared_from_this(); diff --git a/src/core/objects/NullWebRequestTracer.h b/src/core/objects/NullWebRequestTracer.h index d14cc35e..ffd77a8e 100644 --- a/src/core/objects/NullWebRequestTracer.h +++ b/src/core/objects/NullWebRequestTracer.h @@ -47,6 +47,10 @@ namespace core std::shared_ptr setBytesReceived(int32_t /*bytesReceived*/) override; + std::shared_ptr setBytesSent(int64_t /*bytesSent*/) override; + + std::shared_ptr setBytesReceived(int64_t /*bytesReceived*/) override; + std::shared_ptr start() override; void stop(int32_t /*responseCode*/) override; diff --git a/src/core/objects/WebRequestTracer.cxx b/src/core/objects/WebRequestTracer.cxx index cec1ec39..89226603 100644 --- a/src/core/objects/WebRequestTracer.cxx +++ b/src/core/objects/WebRequestTracer.cxx @@ -82,6 +82,11 @@ const char* WebRequestTracer::getTag() const } std::shared_ptr WebRequestTracer::setBytesSent(int32_t bytesSent) +{ + return this->setBytesSent((int64_t) bytesSent); +} + +std::shared_ptr WebRequestTracer::setBytesSent(int64_t bytesSent) { // synchronized scope { @@ -96,6 +101,11 @@ std::shared_ptr WebRequestTracer::setBytesSent(int32 } std::shared_ptr WebRequestTracer::setBytesReceived(int32_t bytesReceived) +{ + return this->setBytesReceived((int64_t) bytesReceived); +} + +std::shared_ptr WebRequestTracer::setBytesReceived(int64_t bytesReceived) { // synchronized scope { @@ -208,12 +218,12 @@ int32_t WebRequestTracer::getEndSequenceNo() const return mEndSequenceNo; } -int32_t WebRequestTracer::getBytesSent() const +int64_t WebRequestTracer::getBytesSent() const { return mBytesSent; } -int32_t WebRequestTracer::getBytesReceived() const +int64_t WebRequestTracer::getBytesReceived() const { return mBytesReceived; } diff --git a/src/core/objects/WebRequestTracer.h b/src/core/objects/WebRequestTracer.h index 418b2f3e..65bfa277 100644 --- a/src/core/objects/WebRequestTracer.h +++ b/src/core/objects/WebRequestTracer.h @@ -85,6 +85,10 @@ namespace core std::shared_ptr setBytesReceived(int32_t bytesReceived) override; + std::shared_ptr setBytesSent(int64_t bytesSent) override; + + std::shared_ptr setBytesReceived(int64_t bytesReceived) override; + std::shared_ptr start() override; void stop(int32_t responseCode) override; @@ -133,13 +137,13 @@ namespace core /// Returns the number of bytes sent /// @returns amount of bytes sent /// - int32_t getBytesSent() const override; + int64_t getBytesSent() const override; /// /// Returns the number of bytes received /// @returns amount of bytes received /// - int32_t getBytesReceived() const override; + int64_t getBytesReceived() const override; /// /// Returns a flag if stop() has already been called @@ -190,10 +194,10 @@ namespace core int32_t mResponseCode; /// Number of bytes sent for the web request - int32_t mBytesSent; + int64_t mBytesSent; /// Number of bytes received for the web request - int32_t mBytesReceived; + int64_t mBytesReceived; /// web request start time int64_t mStartTime; diff --git a/test/api/mock/MockIWebRequestTracer.h b/test/api/mock/MockIWebRequestTracer.h index ef7c665b..08a7cb8d 100644 --- a/test/api/mock/MockIWebRequestTracer.h +++ b/test/api/mock/MockIWebRequestTracer.h @@ -48,6 +48,10 @@ namespace test MOCK_METHOD(std::shared_ptr, setBytesReceived, (int32_t), (override)); + MOCK_METHOD(std::shared_ptr, setBytesSent, (int64_t), (override)); + + MOCK_METHOD(std::shared_ptr, setBytesReceived, (int64_t), (override)); + MOCK_METHOD(std::shared_ptr, start, (), (override)); MOCK_METHOD(void, stop, (int32_t), (override)); diff --git a/test/core/objects/NullWebRequestTracerTest.cxx b/test/core/objects/NullWebRequestTracerTest.cxx index cfcf0983..e591bd0a 100644 --- a/test/core/objects/NullWebRequestTracerTest.cxx +++ b/test/core/objects/NullWebRequestTracerTest.cxx @@ -65,6 +65,34 @@ TEST_F(NullWebRequestTracerTest, setBytesReceivedReturnsSelf) ASSERT_THAT(nullTracer, testing::Eq(target)); } +TEST_F(NullWebRequestTracerTest, setBytesSentLongReturnsSelf) +{ + // given + auto target = NullWebRequestTracer_t::instance(); + + // when + auto obtained = target->setBytesSent(37L); + + // then + auto nullTracer = std::dynamic_pointer_cast(obtained); + ASSERT_THAT(nullTracer, testing::NotNull()); + ASSERT_THAT(nullTracer, testing::Eq(target)); +} + +TEST_F(NullWebRequestTracerTest, setBytesReceivedLongReturnsSelf) +{ + // given + auto target = NullWebRequestTracer_t::instance(); + + // when + auto obtained = target->setBytesReceived(73L); + + // then + auto nullTracer = std::dynamic_pointer_cast(obtained); + ASSERT_THAT(nullTracer, testing::NotNull()); + ASSERT_THAT(nullTracer, testing::Eq(target)); +} + TEST_F(NullWebRequestTracerTest, startReturnsSelf) { // given diff --git a/test/core/objects/WebRequestTracerTest.cxx b/test/core/objects/WebRequestTracerTest.cxx index 9b866ef6..9b7a15be 100644 --- a/test/core/objects/WebRequestTracerTest.cxx +++ b/test/core/objects/WebRequestTracerTest.cxx @@ -179,7 +179,7 @@ TEST_F(WebRequestTracerTest, setBytesSentSetsTheNumberOfSentBytes) // verify ASSERT_EQ(obtained, testWebRequestTracer); - ASSERT_EQ(testWebRequestTracer->getBytesSent(), 1234); + ASSERT_EQ(testWebRequestTracer->getBytesSent(), 1234L); } TEST_F(WebRequestTracerTest, setBytesSentDoesNotSetAnythingIfStoppedWithResponseCode) @@ -193,7 +193,7 @@ TEST_F(WebRequestTracerTest, setBytesSentDoesNotSetAnythingIfStoppedWithResponse // verify ASSERT_EQ(obtained, testWebRequestTracer); - ASSERT_EQ(testWebRequestTracer->getBytesSent(), -1); + ASSERT_EQ(testWebRequestTracer->getBytesSent(), -1L); } TEST_F(WebRequestTracerTest, setBytesReceivedSetsTheNumberOfReceivedBytes) @@ -206,7 +206,7 @@ TEST_F(WebRequestTracerTest, setBytesReceivedSetsTheNumberOfReceivedBytes) // verify ASSERT_EQ(obtained, testWebRequestTracer); - ASSERT_EQ(testWebRequestTracer->getBytesReceived(), 1234); + ASSERT_EQ(testWebRequestTracer->getBytesReceived(), 1234L); } TEST_F(WebRequestTracerTest, setBytesReceivedDoesNotSetAnythingIfStoppedWithResponseCode) @@ -220,7 +220,61 @@ TEST_F(WebRequestTracerTest, setBytesReceivedDoesNotSetAnythingIfStoppedWithResp // verify ASSERT_EQ(obtained, testWebRequestTracer); - ASSERT_EQ(testWebRequestTracer->getBytesReceived(), -1); + ASSERT_EQ(testWebRequestTracer->getBytesReceived(), -1L); +} + +TEST_F(WebRequestTracerTest, setBytesSentLongSetsTheNumberOfSentBytes) +{ + // given + auto testWebRequestTracer = createTracer()->build(); + + // when + auto obtained = testWebRequestTracer->setBytesSent(1234L); + + // verify + ASSERT_EQ(obtained, testWebRequestTracer); + ASSERT_EQ(testWebRequestTracer->getBytesSent(), 1234L); +} + +TEST_F(WebRequestTracerTest, setBytesSentLongDoesNotSetAnythingIfStoppedWithResponseCode) +{ + // given + auto testWebRequestTracer = createTracer()->build(); + + // when + testWebRequestTracer->stop(200); + auto obtained = testWebRequestTracer->setBytesSent(1234L); + + // verify + ASSERT_EQ(obtained, testWebRequestTracer); + ASSERT_EQ(testWebRequestTracer->getBytesSent(), -1L); +} + +TEST_F(WebRequestTracerTest, setBytesReceivedLongSetsTheNumberOfReceivedBytes) +{ + // given + auto testWebRequestTracer = createTracer()->build(); + + // when + auto obtained = testWebRequestTracer->setBytesReceived(1234L); + + // verify + ASSERT_EQ(obtained, testWebRequestTracer); + ASSERT_EQ(testWebRequestTracer->getBytesReceived(), 1234L); +} + +TEST_F(WebRequestTracerTest, setBytesReceivedLongDoesNotSetAnythingIfStoppedWithResponseCode) +{ + // given + auto testWebRequestTracer = createTracer()->build(); + + // when + testWebRequestTracer->stop(200); + auto obtained = testWebRequestTracer->setBytesReceived(1234L); + + // verify + ASSERT_EQ(obtained, testWebRequestTracer); + ASSERT_EQ(testWebRequestTracer->getBytesReceived(), -1L); } TEST_F(WebRequestTracerTest, startSetsTheStartTime) diff --git a/test/core/objects/mock/MockIWebRequestTracerInternals.h b/test/core/objects/mock/MockIWebRequestTracerInternals.h index 795ee8cc..60eac0c0 100644 --- a/test/core/objects/mock/MockIWebRequestTracerInternals.h +++ b/test/core/objects/mock/MockIWebRequestTracerInternals.h @@ -38,9 +38,10 @@ namespace test { { ON_CALL(*this, getTag()).WillByDefault(testing::Return(DefaultValues::EMPTY_CHAR_STRING)); ON_CALL(*this, getURL()).WillByDefault(testing::ReturnRef(DefaultValues::UTF8_EMPTY_STRING)); - - ON_CALL(*this, setBytesSent(testing::_)).WillByDefault(testing::Return(nullptr)); - ON_CALL(*this, setBytesReceived(testing::_)).WillByDefault(testing::Return(nullptr)); + ON_CALL(*this, setBytesSent(testing::An())).WillByDefault(testing::Return(nullptr)); + ON_CALL(*this, setBytesReceived(testing::An())).WillByDefault(testing::Return(nullptr)); + ON_CALL(*this, setBytesSent(testing::An())).WillByDefault(testing::Return(nullptr)); + ON_CALL(*this, setBytesReceived(testing::An())).WillByDefault(testing::Return(nullptr)); ON_CALL(*this, start()).WillByDefault(testing::Return(nullptr)); } @@ -76,6 +77,24 @@ namespace test { (override) ); + MOCK_METHOD( + std::shared_ptr, + setBytesSent, + ( + int64_t /* bytesSent */ + ), + (override) + ); + + MOCK_METHOD( + std::shared_ptr, + setBytesReceived, + ( + int64_t /* bytes/received */ + ), + (override) + ); + MOCK_METHOD(std::shared_ptr, start, (), (override)); MOCK_METHOD(void, stop, (int32_t), (override)); @@ -96,9 +115,9 @@ namespace test { MOCK_METHOD(int32_t, getEndSequenceNo, (), (const, override)); - MOCK_METHOD(int32_t, getBytesSent, (), (const, override)); + MOCK_METHOD(int64_t, getBytesSent, (), (const, override)); - MOCK_METHOD(int32_t, getBytesReceived, (), (const, override)); + MOCK_METHOD(int64_t, getBytesReceived, (), (const, override)); MOCK_METHOD(bool, isStopped, (), (const, override)); };