From bf787ce18c4734ca2ceb71962853db58e49bfc22 Mon Sep 17 00:00:00 2001 From: Jeffery Saeteurn Date: Wed, 26 Jun 2019 11:49:00 -0700 Subject: [PATCH 1/4] Add testing for JDK11 (#77) --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 38f14fa8..aecbb431 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,12 @@ addons: jdk: - openjdk8 + - openjdk11 - oraclejdk8 + - oraclejdk11 install: - mvn install -DskipTests -Dgpg.skip -Dmaven.javadoc.skip -B -V sudo: false -dist: trusty \ No newline at end of file +dist: trusty From c7cb8e5ad86f8c39c28ad08342917e957f868c65 Mon Sep 17 00:00:00 2001 From: Jeffery Saeteurn Date: Wed, 26 Jun 2019 12:02:33 -0700 Subject: [PATCH 2/4] Remove OracleJDK11, can only use OpenJDK11 (#77) --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aecbb431..9e20bbf0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ jdk: - openjdk8 - openjdk11 - oraclejdk8 - - oraclejdk11 install: - mvn install -DskipTests -Dgpg.skip -Dmaven.javadoc.skip -B -V From 13df1263e32698928289b53b723ae05c88e947c9 Mon Sep 17 00:00:00 2001 From: Jeffery Saeteurn Date: Thu, 27 Jun 2019 12:49:03 -0700 Subject: [PATCH 3/4] Removing dependency on J2EE class DataTypeConverter; added custom hex to string parser. (#77) This change should allow test to pass for JDK11 --- .../sampling/CentralizedSamplingStrategy.java | 4 +- .../com/amazonaws/xray/utils/ByteUtils.java | 24 +++++++++++ .../amazonaws/xray/utils/ByteUtilsTest.java | 43 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/ByteUtils.java create mode 100644 aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/ByteUtilsTest.java diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/CentralizedSamplingStrategy.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/CentralizedSamplingStrategy.java index a0f9609f..bd2faea5 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/CentralizedSamplingStrategy.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/strategy/sampling/CentralizedSamplingStrategy.java @@ -6,10 +6,10 @@ import com.amazonaws.xray.strategy.sampling.pollers.RulePoller; import com.amazonaws.xray.strategy.sampling.pollers.TargetPoller; import com.amazonaws.xray.strategy.sampling.rule.CentralizedRule; +import com.amazonaws.xray.utils.ByteUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.xml.bind.DatatypeConverter; import java.net.URL; import java.security.SecureRandom; import java.time.Clock; @@ -24,7 +24,7 @@ public class CentralizedSamplingStrategy implements SamplingStrategy { SecureRandom rand = new SecureRandom(); byte[] bytes = new byte[12]; rand.nextBytes(bytes); - clientID = DatatypeConverter.printHexBinary(bytes); + clientID = ByteUtils.byteArrayToHexString(bytes); } private boolean isStarted = false; diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/ByteUtils.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/ByteUtils.java new file mode 100644 index 00000000..67ff2ad2 --- /dev/null +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/ByteUtils.java @@ -0,0 +1,24 @@ +package com.amazonaws.xray.utils; + +public class ByteUtils { + static final String HEXES = "0123456789ABCDEF"; + + /** + * ref: https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java + * + * Converts the input byte array into a hexadecimal string. + * @param raw - Byte array + * @return String - Hexadecimal representation of the byte array. + */ + public static String byteArrayToHexString( byte [] raw ) { + if ( raw == null ) { + return null; + } + final StringBuilder hex = new StringBuilder( 2 * raw.length ); + for ( final byte b : raw ) { + hex.append(HEXES.charAt((b & 0xF0) >> 4)) + .append(HEXES.charAt((b & 0x0F))); + } + return hex.toString(); + } +} diff --git a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/ByteUtilsTest.java b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/ByteUtilsTest.java new file mode 100644 index 00000000..44871ead --- /dev/null +++ b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/ByteUtilsTest.java @@ -0,0 +1,43 @@ +package com.amazonaws.xray.utils; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class ByteUtilsTest { + + @Test + public void testHexString() { + byte[] zeroArray = new byte[16]; + assert ByteUtils.byteArrayToHexString(zeroArray).contentEquals("00000000000000000000000000000000"); + + byte[] emptyArray = {}; + assert ByteUtils.byteArrayToHexString(emptyArray).contentEquals(""); + + byte[] zeroByte = {(byte) 0x00}; + assert ByteUtils.byteArrayToHexString(zeroByte).contentEquals("00"); + + byte[] fullByte = {(byte) 0xFF}; + assert ByteUtils.byteArrayToHexString(fullByte).contentEquals("FF"); + + byte[] leadingZero = {(byte) 0x0F}; + assert ByteUtils.byteArrayToHexString(leadingZero).contentEquals("0F"); + + byte[] longLeadingZero = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x11}; + assert ByteUtils.byteArrayToHexString(longLeadingZero).contentEquals("00000000000011"); + + byte[] trailingZero = {(byte) 0x11, (byte) 0x00}; + assert ByteUtils.byteArrayToHexString(trailingZero).contentEquals("1100"); + + byte[] longTrailingZero = new byte[16]; + longTrailingZero[0] = (byte) 0xFF; + assert ByteUtils.byteArrayToHexString(longTrailingZero).contentEquals("FF000000000000000000000000000000"); + + byte[] basicArray = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xF0, (byte) 0x0F, (byte) 0xFF}; + assert ByteUtils.byteArrayToHexString(basicArray).contentEquals("FFFFFF00FFF00FFF"); + + byte[] basicVariedArray = {(byte) 0x82, (byte) 0xF2, (byte) 0xAB, (byte) 0xA4, (byte) 0xDE, (byte) 0x15, (byte) 0x19, (byte) 0x11}; + assert ByteUtils.byteArrayToHexString(basicVariedArray).contentEquals("82F2ABA4DE151911"); + } +} From 46774ac4b647e473beb215a87dcae97f2fceb01b Mon Sep 17 00:00:00 2001 From: Lulu Zhao Date: Mon, 1 Jul 2019 16:39:43 -0700 Subject: [PATCH 4/4] fix unit test after updating mockito and powermock version --- aws-xray-recorder-sdk-core/pom.xml | 10 +++++----- .../xray/javax/servlet/AWSXRayServletFilterTest.java | 2 +- .../sampling/LocalizedSamplingStrategyTest.java | 2 +- .../xray/strategy/sampling/pollers/RulePollerTest.java | 2 +- .../strategy/sampling/pollers/TargetPollerTest.java | 2 +- .../strategy/sampling/rule/CentralizedRuleTest.java | 2 +- pom.xml | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/aws-xray-recorder-sdk-core/pom.xml b/aws-xray-recorder-sdk-core/pom.xml index 5ce85620..adb96322 100644 --- a/aws-xray-recorder-sdk-core/pom.xml +++ b/aws-xray-recorder-sdk-core/pom.xml @@ -60,20 +60,20 @@ org.mockito - mockito-all - 1.10.19 + mockito-core + 2.23.4 test org.powermock powermock-module-junit4 - 1.6.6 + 2.0.2 test org.powermock - powermock-api-mockito - 1.6.6 + powermock-api-mockito2 + 2.0.2 test diff --git a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/javax/servlet/AWSXRayServletFilterTest.java b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/javax/servlet/AWSXRayServletFilterTest.java index 27b27d7a..75cddc58 100644 --- a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/javax/servlet/AWSXRayServletFilterTest.java +++ b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/javax/servlet/AWSXRayServletFilterTest.java @@ -24,7 +24,7 @@ import org.junit.runners.MethodSorters; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; +import org.powermock.reflect.Whitebox; import com.amazonaws.xray.AWSXRay; import com.amazonaws.xray.AWSXRayRecorderBuilder; diff --git a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/LocalizedSamplingStrategyTest.java b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/LocalizedSamplingStrategyTest.java index 9d20d043..4f297948 100644 --- a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/LocalizedSamplingStrategyTest.java +++ b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/LocalizedSamplingStrategyTest.java @@ -8,7 +8,7 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import org.mockito.internal.util.reflection.Whitebox; +import org.powermock.reflect.Whitebox; @FixMethodOrder(MethodSorters.JVM) public class LocalizedSamplingStrategyTest { diff --git a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/RulePollerTest.java b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/RulePollerTest.java index ad106941..a35c1257 100644 --- a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/RulePollerTest.java +++ b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/RulePollerTest.java @@ -5,7 +5,7 @@ import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; +import org.powermock.reflect.Whitebox; import java.time.Clock; import java.util.concurrent.ScheduledExecutorService; diff --git a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/TargetPollerTest.java b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/TargetPollerTest.java index c9cf6f9a..93cbefab 100644 --- a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/TargetPollerTest.java +++ b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/pollers/TargetPollerTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import org.junit.Assert; import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; +import org.powermock.reflect.Whitebox; import java.time.Clock; import java.util.concurrent.ScheduledExecutorService; diff --git a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRuleTest.java b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRuleTest.java index eae7aa1f..8f1cd8b4 100644 --- a/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRuleTest.java +++ b/aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/strategy/sampling/rule/CentralizedRuleTest.java @@ -12,7 +12,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.powermock.reflect.Whitebox; import java.time.Clock; diff --git a/pom.xml b/pom.xml index e7cfce93..033fc584 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ maven-javadoc-plugin - 2.10.4 + 3.0.1