Skip to content

Commit

Permalink
Merge pull request #78 from chanchiem/testjdk
Browse files Browse the repository at this point in the history
Add testing for JDK11 (#77)
  • Loading branch information
luluzhao authored Jul 2, 2019
2 parents 8f92459 + 46774ac commit 4970455
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ addons:

jdk:
- openjdk8
- openjdk11
- oraclejdk8

install:
- mvn install -DskipTests -Dgpg.skip -Dmaven.javadoc.skip -B -V

sudo: false
dist: trusty
dist: trusty
10 changes: 5 additions & 5 deletions aws-xray-recorder-sdk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.6</version>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<version>3.0.1</version>
<configuration>
<footer> <![CDATA[
<script src="/SdkStatic/sdk-priv.js" async="true"></script>
Expand Down

0 comments on commit 4970455

Please sign in to comment.