Polishing
This commit is contained in:
parent
0f51ff5ebc
commit
214d0d76a5
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -39,6 +39,7 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||||
super(errorHandler);
|
super(errorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context,
|
protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context,
|
||||||
CacheOperationInvoker invoker) {
|
CacheOperationInvoker invoker) {
|
||||||
|
@ -82,7 +83,6 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
|
protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
|
||||||
if (exceptionCache == null) {
|
if (exceptionCache == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -92,7 +92,6 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
|
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
|
||||||
CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
|
CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
|
||||||
if (exceptionCacheResolver != null) {
|
if (exceptionCacheResolver != null) {
|
||||||
|
@ -101,9 +100,10 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewrite the call stack of the specified {@code exception} so that it matches
|
* Rewrite the call stack of the specified {@code exception} so that it matches
|
||||||
* the current call stack up-to (included) the specified method invocation.
|
* the current call stack up to (included) the specified method invocation.
|
||||||
* <p>Clone the specified exception. If the exception is not {@code serializable},
|
* <p>Clone the specified exception. If the exception is not {@code serializable},
|
||||||
* the original exception is returned. If no common ancestor can be found, returns
|
* the original exception is returned. If no common ancestor can be found, returns
|
||||||
* the original exception.
|
* the original exception.
|
||||||
|
@ -111,8 +111,8 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor<CacheResultOper
|
||||||
* @param exception the exception to merge with the current call stack
|
* @param exception the exception to merge with the current call stack
|
||||||
* @param className the class name of the common ancestor
|
* @param className the class name of the common ancestor
|
||||||
* @param methodName the method name of the common ancestor
|
* @param methodName the method name of the common ancestor
|
||||||
* @return a clone exception with a rewritten call stack composed of the current
|
* @return a clone exception with a rewritten call stack composed of the current call
|
||||||
* call stack up to (included) the common ancestor specified by the {@code className} and
|
* stack up to (included) the common ancestor specified by the {@code className} and
|
||||||
* {@code methodName} arguments, followed by stack trace elements of the specified
|
* {@code methodName} arguments, followed by stack trace elements of the specified
|
||||||
* {@code exception} after the common ancestor.
|
* {@code exception} after the common ancestor.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -49,9 +49,6 @@ import static org.mockito.BDDMockito.*;
|
||||||
*/
|
*/
|
||||||
public class JCacheErrorHandlerTests {
|
public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private Cache cache;
|
private Cache cache;
|
||||||
|
|
||||||
private Cache errorCache;
|
private Cache errorCache;
|
||||||
|
@ -60,20 +57,23 @@ public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
private SimpleService simpleService;
|
private SimpleService simpleService;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
AnnotationConfigApplicationContext context =
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||||
new AnnotationConfigApplicationContext(Config.class);
|
|
||||||
this.cache = context.getBean("mockCache", Cache.class);
|
this.cache = context.getBean("mockCache", Cache.class);
|
||||||
this.errorCache = context.getBean("mockErrorCache", Cache.class);
|
this.errorCache = context.getBean("mockErrorCache", Cache.class);
|
||||||
this.errorHandler = context.getBean(CacheErrorHandler.class);
|
this.errorHandler = context.getBean(CacheErrorHandler.class);
|
||||||
this.simpleService = context.getBean(SimpleService.class);
|
this.simpleService = context.getBean(SimpleService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFail() {
|
public void getFail() {
|
||||||
UnsupportedOperationException exception =
|
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
|
||||||
new UnsupportedOperationException("Test exception on get");
|
|
||||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||||
willThrow(exception).given(this.cache).get(key);
|
willThrow(exception).given(this.cache).get(key);
|
||||||
|
|
||||||
|
@ -83,8 +83,7 @@ public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPutNewElementFail() {
|
public void getPutNewElementFail() {
|
||||||
UnsupportedOperationException exception =
|
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||||
new UnsupportedOperationException("Test exception on put");
|
|
||||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||||
given(this.cache.get(key)).willReturn(null);
|
given(this.cache.get(key)).willReturn(null);
|
||||||
willThrow(exception).given(this.cache).put(key, 0L);
|
willThrow(exception).given(this.cache).put(key, 0L);
|
||||||
|
@ -95,12 +94,10 @@ public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFailPutExceptionFail() {
|
public void getFailPutExceptionFail() {
|
||||||
UnsupportedOperationException exceptionOnPut =
|
UnsupportedOperationException exceptionOnPut = new UnsupportedOperationException("Test exception on put");
|
||||||
new UnsupportedOperationException("Test exception on put");
|
|
||||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||||
given(this.cache.get(key)).willReturn(null);
|
given(this.cache.get(key)).willReturn(null);
|
||||||
willThrow(exceptionOnPut).given(this.errorCache).put(key,
|
willThrow(exceptionOnPut).given(this.errorCache).put(key, SimpleService.TEST_EXCEPTION);
|
||||||
SimpleService.TEST_EXCEPTION);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.simpleService.getFail(0L);
|
this.simpleService.getFail(0L);
|
||||||
|
@ -108,14 +105,13 @@ public class JCacheErrorHandlerTests {
|
||||||
catch (IllegalStateException ex) {
|
catch (IllegalStateException ex) {
|
||||||
assertEquals("Test exception", ex.getMessage());
|
assertEquals("Test exception", ex.getMessage());
|
||||||
}
|
}
|
||||||
verify(this.errorHandler).handleCachePutError(exceptionOnPut,
|
verify(this.errorHandler).handleCachePutError(
|
||||||
this.errorCache, key, SimpleService.TEST_EXCEPTION);
|
exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void putFail() {
|
public void putFail() {
|
||||||
UnsupportedOperationException exception =
|
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
|
||||||
new UnsupportedOperationException("Test exception on put");
|
|
||||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||||
willThrow(exception).given(this.cache).put(key, 234L);
|
willThrow(exception).given(this.cache).put(key, 234L);
|
||||||
|
|
||||||
|
@ -125,8 +121,7 @@ public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void evictFail() {
|
public void evictFail() {
|
||||||
UnsupportedOperationException exception =
|
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||||
new UnsupportedOperationException("Test exception on evict");
|
|
||||||
Object key = SimpleKeyGenerator.generateKey(0L);
|
Object key = SimpleKeyGenerator.generateKey(0L);
|
||||||
willThrow(exception).given(this.cache).evict(key);
|
willThrow(exception).given(this.cache).evict(key);
|
||||||
|
|
||||||
|
@ -136,8 +131,7 @@ public class JCacheErrorHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clearFail() {
|
public void clearFail() {
|
||||||
UnsupportedOperationException exception =
|
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
|
||||||
new UnsupportedOperationException("Test exception on evict");
|
|
||||||
willThrow(exception).given(this.cache).clear();
|
willThrow(exception).given(this.cache).clear();
|
||||||
|
|
||||||
this.simpleService.clear();
|
this.simpleService.clear();
|
||||||
|
@ -181,14 +175,13 @@ public class JCacheErrorHandlerTests {
|
||||||
given(cache.getName()).willReturn("error");
|
given(cache.getName()).willReturn("error");
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@CacheDefaults(cacheName = "test")
|
@CacheDefaults(cacheName = "test")
|
||||||
public static class SimpleService {
|
public static class SimpleService {
|
||||||
|
|
||||||
private static final IllegalStateException TEST_EXCEPTION =
|
private static final IllegalStateException TEST_EXCEPTION = new IllegalStateException("Test exception");
|
||||||
new IllegalStateException("Test exception");
|
|
||||||
|
|
||||||
private AtomicLong counter = new AtomicLong();
|
private AtomicLong counter = new AtomicLong();
|
||||||
|
|
||||||
|
@ -214,4 +207,5 @@ public class JCacheErrorHandlerTests {
|
||||||
public void clear() {
|
public void clear() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
|
||||||
public class Elvis extends SpelNodeImpl {
|
public class Elvis extends SpelNodeImpl {
|
||||||
|
|
||||||
public Elvis(int pos, SpelNodeImpl... args) {
|
public Elvis(int pos, SpelNodeImpl... args) {
|
||||||
super(pos,args);
|
super(pos, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public class Elvis extends SpelNodeImpl {
|
||||||
mv.visitLdcInsn("");
|
mv.visitLdcInsn("");
|
||||||
mv.visitInsn(SWAP);
|
mv.visitInsn(SWAP);
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false);
|
||||||
mv.visitJumpInsn(IFEQ, endOfIf); // If not empty, drop through to elseTarget
|
mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget
|
||||||
mv.visitLabel(elseTarget);
|
mv.visitLabel(elseTarget);
|
||||||
mv.visitInsn(POP);
|
mv.visitInsn(POP);
|
||||||
this.children[1].generateCode(mv, cf);
|
this.children[1].generateCode(mv, cf);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -35,7 +35,7 @@ import org.springframework.expression.spel.SpelMessage;
|
||||||
public class Ternary extends SpelNodeImpl {
|
public class Ternary extends SpelNodeImpl {
|
||||||
|
|
||||||
public Ternary(int pos, SpelNodeImpl... args) {
|
public Ternary(int pos, SpelNodeImpl... args) {
|
||||||
super(pos,args);
|
super(pos, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -4787,30 +4787,6 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
assertIsCompiled(exp);
|
assertIsCompiled(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertIsCompiled(Expression ex) {
|
|
||||||
try {
|
|
||||||
Field f = SpelExpression.class.getDeclaredField("compiledAst");
|
|
||||||
f.setAccessible(true);
|
|
||||||
Object object = f.get(ex);
|
|
||||||
assertNotNull(object);
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Foo {
|
|
||||||
|
|
||||||
public String bar() {
|
|
||||||
return "BAR";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String bar(String arg) {
|
|
||||||
return arg.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// helper methods
|
// helper methods
|
||||||
|
|
||||||
|
@ -4871,6 +4847,20 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertIsCompiled(Expression expression) {
|
||||||
|
try {
|
||||||
|
Field field = SpelExpression.class.getDeclaredField("compiledAst");
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object object = field.get(expression);
|
||||||
|
assertNotNull(object);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
fail(ex.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// nested types
|
||||||
|
|
||||||
public interface Message<T> {
|
public interface Message<T> {
|
||||||
|
|
||||||
|
@ -4987,7 +4977,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
try {
|
try {
|
||||||
method = Payload2.class.getDeclaredMethod("getField", String.class);
|
method = Payload2.class.getDeclaredMethod("getField", String.class);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String descriptor = cf.lastDescriptor();
|
String descriptor = cf.lastDescriptor();
|
||||||
|
@ -5845,4 +5835,16 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Foo {
|
||||||
|
|
||||||
|
public String bar() {
|
||||||
|
return "BAR";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String bar(String arg) {
|
||||||
|
return arg.toUpperCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
|
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
|
||||||
final SettableListenableFuture<ClientHttpResponse> responseFuture =
|
final SettableListenableFuture<ClientHttpResponse> responseFuture = new SettableListenableFuture<>();
|
||||||
new SettableListenableFuture<>();
|
|
||||||
|
|
||||||
ChannelFutureListener connectionListener = new ChannelFutureListener() {
|
ChannelFutureListener connectionListener = new ChannelFutureListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -141,8 +140,7 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements
|
||||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||||
nettyRequest.headers().add(entry.getKey(), entry.getValue());
|
nettyRequest.headers().add(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH)
|
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) {
|
||||||
&& this.body.buffer().readableBytes() > 0) {
|
|
||||||
nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes());
|
nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue