Use modern java constructs
This commit is contained in:
@@ -44,7 +44,7 @@ public class PatternMatcher<S> {
|
||||
this.map = map;
|
||||
// Sort keys to start with the most specific
|
||||
this.sorted = new ArrayList<>(map.keySet());
|
||||
Collections.sort(this.sorted, (o1, o2) -> {
|
||||
this.sorted.sort((o1, o2) -> {
|
||||
String s1 = o1; // .replace('?', '{');
|
||||
String s2 = o2; // .replace('*', '}');
|
||||
return s2.compareTo(s1);
|
||||
|
||||
@@ -112,10 +112,7 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
|
||||
try {
|
||||
return proxy.getClass().getMethod(method.getName(), method.getParameterTypes());
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
catch (NoSuchMethodException | SecurityException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.retry.interceptor;
|
||||
@@ -96,10 +99,7 @@ public class RetryOperationsInterceptor implements MethodInterceptor {
|
||||
try {
|
||||
return ((ProxyMethodInvocation) this.invocation).invocableClone().proceed();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Error e) {
|
||||
catch (Exception | Error e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2019 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -208,10 +208,7 @@ public class StatefulRetryOperationsInterceptor implements MethodInterceptor {
|
||||
try {
|
||||
return this.invocation.proceed();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Error e) {
|
||||
catch (Exception | Error e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
||||
@@ -41,8 +41,7 @@ public class DummySleeper implements Sleeper {
|
||||
public long[] getBackOffs() {
|
||||
long[] result = new long[backOffs.size()];
|
||||
int i = 0;
|
||||
for (Iterator<Long> iterator = backOffs.iterator(); iterator.hasNext();) {
|
||||
Long value = iterator.next();
|
||||
for (Long value : backOffs) {
|
||||
result[i++] = value;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,28 +33,28 @@ public class ExponentialBackOffPolicyTests {
|
||||
public void testSetMaxInterval() throws Exception {
|
||||
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
|
||||
strategy.setMaxInterval(1000);
|
||||
assertTrue(strategy.toString().indexOf("maxInterval=1000") >= 0);
|
||||
assertTrue(strategy.toString().contains("maxInterval=1000"));
|
||||
strategy.setMaxInterval(0);
|
||||
// The minimum value for the max interval is 1
|
||||
assertTrue(strategy.toString().indexOf("maxInterval=1") >= 0);
|
||||
assertTrue(strategy.toString().contains("maxInterval=1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInitialInterval() throws Exception {
|
||||
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
|
||||
strategy.setInitialInterval(10000);
|
||||
assertTrue(strategy.toString().indexOf("initialInterval=10000,") >= 0);
|
||||
assertTrue(strategy.toString().contains("initialInterval=10000,"));
|
||||
strategy.setInitialInterval(0);
|
||||
assertTrue(strategy.toString().indexOf("initialInterval=1,") >= 0);
|
||||
assertTrue(strategy.toString().contains("initialInterval=1,"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMultiplier() throws Exception {
|
||||
ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy();
|
||||
strategy.setMultiplier(3.);
|
||||
assertTrue(strategy.toString().indexOf("multiplier=3.") >= 0);
|
||||
assertTrue(strategy.toString().contains("multiplier=3."));
|
||||
strategy.setMultiplier(.5);
|
||||
assertTrue(strategy.toString().indexOf("multiplier=1.") >= 0);
|
||||
assertTrue(strategy.toString().contains("multiplier=1."));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -247,7 +247,7 @@ public class RetryOperationsInterceptorTests {
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertTrue("Exception message should contain MethodInvocation: " + e.getMessage(),
|
||||
e.getMessage().indexOf("MethodInvocation") >= 0);
|
||||
e.getMessage().contains("MethodInvocation"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2019 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.retry.listener;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.retry.RetryCallback;
|
||||
import org.springframework.retry.RetryContext;
|
||||
import org.springframework.retry.interceptor.MethodInvocationRetryCallback;
|
||||
@@ -51,8 +53,7 @@ public class MethodInvocationRetryListenerSupportTests {
|
||||
}
|
||||
};
|
||||
RetryContext context = mock(RetryContext.class);
|
||||
MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
|
||||
support.close(context, callback, null);
|
||||
support.close(context, mockMethodInvocationRetryCallback(), null);
|
||||
|
||||
assertEquals(1, callsOnDoCloseMethod.get());
|
||||
}
|
||||
@@ -68,7 +69,7 @@ public class MethodInvocationRetryListenerSupportTests {
|
||||
}
|
||||
};
|
||||
RetryContext context = mock(RetryContext.class);
|
||||
RetryCallback callback = mock(RetryCallback.class);
|
||||
RetryCallback<?, ?> callback = mock(RetryCallback.class);
|
||||
support.close(context, callback, null);
|
||||
|
||||
assertEquals(0, callsOnDoCloseMethod.get());
|
||||
@@ -96,8 +97,7 @@ public class MethodInvocationRetryListenerSupportTests {
|
||||
}
|
||||
};
|
||||
RetryContext context = mock(RetryContext.class);
|
||||
MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
|
||||
support.onError(context, callback, null);
|
||||
support.onError(context, mockMethodInvocationRetryCallback(), null);
|
||||
|
||||
assertEquals(1, callsOnDoOnErrorMethod.get());
|
||||
}
|
||||
@@ -120,10 +120,13 @@ public class MethodInvocationRetryListenerSupportTests {
|
||||
}
|
||||
};
|
||||
RetryContext context = mock(RetryContext.class);
|
||||
MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
|
||||
assertTrue(support.open(context, callback));
|
||||
|
||||
assertTrue(support.open(context, mockMethodInvocationRetryCallback()));
|
||||
assertEquals(1, callsOnDoOpenMethod.get());
|
||||
}
|
||||
|
||||
private MethodInvocationRetryCallback<?, ?> mockMethodInvocationRetryCallback() {
|
||||
return mock(MethodInvocationRetryCallback.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class StatefulRecoveryRetryTests {
|
||||
}
|
||||
catch (RetryException e) {
|
||||
String message = e.getMessage();
|
||||
assertTrue("Message does not contain 'capacity': " + message, message.indexOf("capacity") >= 0);
|
||||
assertTrue("Message does not contain 'capacity': " + message, message.contains("capacity"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user