GH-2699: Make expressions cache concurrent
Fixes spring-projects/spring-integration#2699
* [GH-2699] Match style
* [GH-2699] Shorten test line length
**Cherry-pick to 5.0.x**
(cherry picked from commit cd8cbaa99c)
This commit is contained in:
committed by
Artem Bilan
parent
c64524b163
commit
d803e75647
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||
@@ -42,6 +43,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Gareth Chapman
|
||||
* @author Cameron Mayfield
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -49,11 +51,11 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
|
||||
private final ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
|
||||
|
||||
private final Map<Method, String> channels = new HashMap<>();
|
||||
private final Map<Method, String> channels = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<Method, Expression> payloadExpressions = new HashMap<>();
|
||||
private final Map<Method, Expression> payloadExpressions = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<Method, Map<String, Expression>> headersExpressions = new HashMap<>();
|
||||
private final Map<Method, Map<String, Expression>> headersExpressions = new ConcurrentHashMap<>();
|
||||
|
||||
private final Set<Class<? extends Annotation>> annotationTypes;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -16,13 +16,16 @@
|
||||
|
||||
package org.springframework.integration.aop;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -31,10 +34,12 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.messaging.handler.annotation.Header;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Cameron Mayfield
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
@@ -42,7 +47,6 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
|
||||
private final MethodAnnotationPublisherMetadataSource source = new MethodAnnotationPublisherMetadataSource();
|
||||
|
||||
|
||||
@Test
|
||||
public void channelNameAndExplicitReturnValuePayload() {
|
||||
Method method = getMethod("methodWithChannelAndExplicitReturnAsPayload");
|
||||
@@ -83,6 +87,16 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
assertEquals("#args[2]", headerMap.get("bar").getExpressionString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionsAreConcurrentHashMap() {
|
||||
assertThat("Expressions should be concurrent to allow startup",
|
||||
ReflectionTestUtils.getField(source, "channels"), instanceOf(ConcurrentHashMap.class));
|
||||
assertThat("Expressions should be concurrent to allow startup",
|
||||
ReflectionTestUtils.getField(source, "payloadExpressions"), instanceOf(ConcurrentHashMap.class));
|
||||
assertThat("Expressions should be concurrent to allow startup",
|
||||
ReflectionTestUtils.getField(source, "headersExpressions"), instanceOf(ConcurrentHashMap.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voidReturnWithValidPayloadExpression() {
|
||||
Method method = getMethod("methodWithVoidReturnAndMethodNameAsPayload");
|
||||
@@ -142,7 +156,6 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Publisher
|
||||
@Payload("testExpression1")
|
||||
public void methodWithPayloadAnnotation(String arg1, int arg2) {
|
||||
@@ -160,7 +173,6 @@ public class MethodAnnotationPublisherMetadataSourceTests {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
|
||||
@Publisher(channel = "foo")
|
||||
@Payload("#method")
|
||||
public void methodWithVoidReturnAndMethodNameAsPayload() {
|
||||
|
||||
Reference in New Issue
Block a user