Skip to content

Commit

Permalink
Pull request #263: Feature/RUM-20521 openkit java .net native should …
Browse files Browse the repository at this point in the history
…use long instead of int for bytessent and

Merge in OP/openkit-java from feature/RUM-20521-openkit-java-.net-native-should-use-long-instead-of-int-for-bytessent-and to main

* commit 'a4e498097bf5c8e628a498c4aa8a86ee3a882821':
  RUM-20521 PR Fixes
  RUM-20521 Updating Tests and Changelog
  RUM-20521 Adding API and changing tests

GitOrigin-RevId: a03e010c1f0e915fb7026a951a5b4643f339ab02
  • Loading branch information
TheHighriser authored and openkitdt committed Jul 17, 2024
1 parent b8d0a4e commit 6b5c8f0
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 56 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased](https://github.com/Dynatrace/openkit-java/compare/v3.2.0...HEAD)

### Added
- `WebRequestTracer.setBytesSent(long bytes)` to increase the size range
- `WebRequestTracer.setBytesReceived(long bytes)` to increase the size range

### Changed
- Deprecated `WebRequestTracer.setBytesSent(int bytes)` due to datatype limitations
- Deprecated `WebRequestTracer.setBytesReceived(int bytes)` due to datatype limitations

## 3.2.0 [Release date: 2023-12-06]
[GitHub Releases](https://github.com/Dynatrace/openkit-java/releases/tag/v3.2.0)

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/dynatrace/openkit/api/WebRequestTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,39 @@ public interface WebRequestTracer extends Closeable {
/**
* Sets the amount of sent data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}.
*
* @deprecated
* This method should no longer be used due its datatype limitation. Use {@link WebRequestTracer#setBytesSent(long)} instead.
*
* @param bytesSent number of bytes
*/
@Deprecated
WebRequestTracer setBytesSent(int bytesSent);

/**
* Sets the amount of sent data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}.
*
* @param bytesSent number of bytes
*/
WebRequestTracer setBytesSent(long bytesSent);

/**
* Sets the amount of received data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}.
*
* @deprecated
* This method should no longer be used due its datatype limitation. Use {@link WebRequestTracer#setBytesReceived(long)} instead.
*
* @param bytesReceived number of bytes
*/
@Deprecated
WebRequestTracer setBytesReceived(int bytesReceived);

/**
* Sets the amount of received data of this web request. Has to be called before {@link WebRequestTracer#stop(int)}.
*
* @param bytesReceived number of bytes
*/
WebRequestTracer setBytesReceived(long bytesReceived);

/**
* Starts the web request timing. Should be called when the web request is initiated.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ public WebRequestTracer setBytesSent(int bytesSent) {
return this;
}

@Override
public WebRequestTracer setBytesSent(long bytesSent) {
return this;
}

@Override
public WebRequestTracer setBytesReceived(int bytesReceived) {
return this;
}

@Override
public WebRequestTracer setBytesReceived(long bytesReceived) {
return this;
}

@Override
public WebRequestTracer start() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public abstract class WebRequestTracerBaseImpl implements WebRequestTracer, Canc
/** The response code received from the request */
private int responseCode = -1;
/** The number of bytes sent */
private int bytesSent = -1;
private long bytesSent = -1;
/** The number of bytes received */
private int bytesReceived = -1;
private long bytesReceived = -1;

/** Start time of the web request, set in {@link #start()} */
private long startTime;
Expand Down Expand Up @@ -103,6 +103,11 @@ public String getTag() {

@Override
public WebRequestTracer setBytesSent(int bytesSent) {
return setBytesSent((long) bytesSent);
}

@Override
public WebRequestTracer setBytesSent(long bytesSent) {
synchronized (lockObject) {
if (!isStopped()) {
this.bytesSent = bytesSent;
Expand All @@ -113,6 +118,11 @@ public WebRequestTracer setBytesSent(int bytesSent) {

@Override
public WebRequestTracer setBytesReceived(int bytesReceived) {
return setBytesReceived((long) bytesReceived);
}

@Override
public WebRequestTracer setBytesReceived(long bytesReceived) {
synchronized (lockObject) {
if (!isStopped()) {
this.bytesReceived = bytesReceived;
Expand Down Expand Up @@ -201,11 +211,11 @@ public int getEndSequenceNo() {
return endSequenceNo;
}

public int getBytesSent() {
public long getBytesSent() {
return bytesSent;
}

public int getBytesReceived() {
public long getBytesReceived() {
return bytesReceived;
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/dynatrace/openkit/protocol/Beacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,20 @@ private void addKeyValuePairIfNotNegative(StringBuilder builder, String key, int
}
}

/**
* Serialization helper method for adding key/value pairs with int values
*
* the key value pair is only added to the string builder when the int is not negative
*
* @param builder The string builder storing serialized data.
* @param key The key to add.
* @param longValue The value to add.
*/
private void addKeyValuePairIfNotNegative(StringBuilder builder, String key, long longValue) {
if (longValue >= 0) {
addKeyValuePair(builder, key, longValue);
}
}

/**
* Serialization helper method for adding key/value pairs with double values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public void setBytesSentReturnsSelf() {
assertThat((NullWebRequestTracer)obtained, is(sameInstance(target)));
}

@Test
public void setBytesSentLongReturnsSelf() {
// given
NullWebRequestTracer target = NullWebRequestTracer.INSTANCE;

// when
WebRequestTracer obtained = target.setBytesSent(37L);

// then
assertThat(obtained, instanceOf(NullWebRequestTracer.class));
assertThat((NullWebRequestTracer)obtained, is(sameInstance(target)));
}

@Test
public void setBytesReceivedReturnsSelf() {
// given
Expand All @@ -64,6 +77,19 @@ public void setBytesReceivedReturnsSelf() {
assertThat((NullWebRequestTracer)obtained, is(sameInstance(target)));
}

@Test
public void setBytesReceivedLongReturnsSelf() {
// given
NullWebRequestTracer target = NullWebRequestTracer.INSTANCE;

// when
WebRequestTracer obtained = target.setBytesReceived(73L);

// then
assertThat(obtained, instanceOf(NullWebRequestTracer.class));
assertThat((NullWebRequestTracer)obtained, is(sameInstance(target)));
}

@Test
public void startReturnsSelf() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public void defaultValues() {
assertThat(target.getEndTime(), is(-1L));
assertThat(target.getStartSequenceNo(), is(SEQUENCE_NUMBER));
assertThat(target.getEndSequenceNo(), is(-1));
assertThat(target.getBytesSent(), is(-1));
assertThat(target.getBytesReceived(), is(-1));
assertThat(target.getBytesSent(), is(-1L));
assertThat(target.getBytesReceived(), is(-1L));
assertThat(target.getParent(), is(sameInstance(parentOpenKitObject)));

// and verify that the sequence number was retrieved from beacon, as well as the tag
Expand Down Expand Up @@ -158,7 +158,21 @@ public void setBytesSentSetsTheNumberOfSentBytes() {
WebRequestTracer obtained = target.setBytesSent(1234);

// then
assertThat(target.getBytesSent(), is(1234));
assertThat(target.getBytesSent(), is(1234L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

@Test
public void setBytesSentLongSetsTheNumberOfSentBytes() {

// given
WebRequestTracerBaseImpl target = new TestWebRequestTracerBaseImpl(logger, parentOpenKitObject, mockBeacon);

// when setting the sent bytes
WebRequestTracer obtained = target.setBytesSent(1234L);

// then
assertThat(target.getBytesSent(), is(1234L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

Expand All @@ -173,7 +187,22 @@ public void setBytesSentDoesNotSetAnythingIfStoppedWithResponseCode() {
WebRequestTracer obtained = target.setBytesSent(1234);

// then
assertThat(target.getBytesSent(), is(-1));
assertThat(target.getBytesSent(), is(-1L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

@Test
public void setBytesSentLongDoesNotSetAnythingIfStoppedWithResponseCode() {

// given
WebRequestTracerBaseImpl target = new TestWebRequestTracerBaseImpl(logger, parentOpenKitObject, mockBeacon);
target.stop(200);

// when setting the sent bytes
WebRequestTracer obtained = target.setBytesSent(1234L);

// then
assertThat(target.getBytesSent(), is(-1L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

Expand All @@ -187,7 +216,21 @@ public void setBytesReceivedSetsTheNumberOfReceivedBytes() {
WebRequestTracer obtained = target.setBytesReceived(4321);

// then
assertThat(target.getBytesReceived(), is(4321));
assertThat(target.getBytesReceived(), is(4321L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

@Test
public void setBytesReceivedLongSetsTheNumberOfReceivedBytes() {

// given
WebRequestTracerBaseImpl target = new TestWebRequestTracerBaseImpl(logger, parentOpenKitObject, mockBeacon);

// when setting the received bytes
WebRequestTracer obtained = target.setBytesReceived(4321L);

// then
assertThat(target.getBytesReceived(), is(4321L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

Expand All @@ -201,7 +244,21 @@ public void setBytesReceivedDoesNotSetAnythingIfStoppedWithResponseCode() {
WebRequestTracer obtained = target.setBytesReceived(4321);

// then
assertThat(target.getBytesReceived(), is(-1));
assertThat(target.getBytesReceived(), is(-1L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

@Test
public void setBytesReceivedLongDoesNotSetAnythingIfStoppedWithResponseCode() {
// given
WebRequestTracerBaseImpl target = new TestWebRequestTracerBaseImpl(logger, parentOpenKitObject, mockBeacon);
target.stop(200);

// when setting the received bytes
WebRequestTracer obtained = target.setBytesReceived(4321L);

// then
assertThat(target.getBytesReceived(), is(-1L));
assertThat(obtained, is(sameInstance((WebRequestTracer)target)));
}

Expand Down
Loading

0 comments on commit 6b5c8f0

Please sign in to comment.