Fix Java 17 compilation and test issues (#12353)
* Adds --add-opens to the surefire-maven-plugin config required for deserialization using Gson/XStream * Upgrades plugin dependencies to JDK 17 compatible versions * Replaces some reflection that no longer works on JDK 17 * Fixes issues when mocking Random * Run Nashorn dependant tests only on JDK < 15 Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -53,7 +53,6 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet {
|
||||
|
||||
private static final String DEFAULT_LOCALE = "en";
|
||||
|
||||
private static final long ONLINE_WAIT_TIMEOUT_IN_MILLISECONDS = 5000;
|
||||
private static final long DISCOVERY_COMPLETION_TIMEOUT_IN_MILLISECONDS = 5000;
|
||||
private static final long CHECK_INTERVAL_IN_MILLISECONDS = 100;
|
||||
|
||||
@@ -62,6 +61,8 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet {
|
||||
private final Inbox inbox;
|
||||
private final ThingRegistry thingRegistry;
|
||||
|
||||
private long onlineWaitTimeoutInMilliseconds = 5000;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CreateBridgeServlet}.
|
||||
*
|
||||
@@ -73,6 +74,10 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet {
|
||||
this.thingRegistry = thingRegistry;
|
||||
}
|
||||
|
||||
public void setOnlineWaitTimeoutInMilliseconds(long onlineWaitTimeoutInMilliseconds) {
|
||||
this.onlineWaitTimeoutInMilliseconds = onlineWaitTimeoutInMilliseconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRedirectionDestination(HttpServletRequest request) {
|
||||
String bridgeUidString = request.getParameter(BRIDGE_UID_PARAMETER_NAME);
|
||||
@@ -175,7 +180,7 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet {
|
||||
private void waitForBridgeToComeOnline(Thing bridge) {
|
||||
try {
|
||||
waitForConditionWithTimeout(() -> bridge.getStatus() == ThingStatus.ONLINE,
|
||||
ONLINE_WAIT_TIMEOUT_IN_MILLISECONDS);
|
||||
onlineWaitTimeoutInMilliseconds);
|
||||
waitForConditionWithTimeout(new DiscoveryResultCountDoesNotChangeCondition(),
|
||||
DISCOVERY_COMPLETION_TIMEOUT_IN_MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -75,7 +75,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenTheNumberOfFailedAttemptsIsNegativeThenZeroIsAssumedInstead() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(RETRY_INTERVAL);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME,
|
||||
@@ -91,7 +91,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenThereIsNoFailedAttemptThenTheMaximalResultIsMinimumWaitTimePlusRetryInterval() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(RETRY_INTERVAL);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME,
|
||||
@@ -107,7 +107,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenThereIsOneFailedAttemptThenTheMaximalResultIsMinimumWaitTimePlusTwiceTheRetryInterval() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(RETRY_INTERVAL * 2);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME,
|
||||
@@ -123,7 +123,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenThereAreTwoFailedAttemptsThenTheMaximalResultIsMinimumWaitTimePlusFourTimesTheRetryInterval() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(RETRY_INTERVAL * 4);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME,
|
||||
@@ -139,7 +139,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenThereAreTwoFailedAttemptsThenTheMinimalResultIsTheMinimumWaitTime() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(0L);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME,
|
||||
@@ -155,7 +155,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenTheDrawnRandomValueIsNegativeThenItIsProjectedToAPositiveValue() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(-RETRY_INTERVAL * 4 - 1);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME,
|
||||
@@ -171,7 +171,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenTheResultWouldBeLargerThanTheMaximumThenItIsCappedToTheMaximum() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(MAXIMUM_WAIT_TIME - ALTERNATIVE_MINIMUM_WAIT_TIME);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(ALTERNATIVE_MINIMUM_WAIT_TIME,
|
||||
@@ -187,7 +187,7 @@ public class ExponentialBackoffWithJitterTest {
|
||||
@Test
|
||||
public void whenTheResultWouldBeLargerThanTheAlternativeMaximumThenItIsCappedToTheAlternativeMaximum() {
|
||||
// given:
|
||||
Random random = mock(Random.class);
|
||||
Random random = mock(Random.class, withSettings().withoutAnnotations());
|
||||
when(random.nextLong()).thenReturn(ALTERNATIVE_MAXIMUM_WAIT_TIME - ALTERNATIVE_MINIMUM_WAIT_TIME);
|
||||
|
||||
ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(ALTERNATIVE_MINIMUM_WAIT_TIME,
|
||||
|
||||
Reference in New Issue
Block a user