Formatting
This commit is contained in:
@@ -30,8 +30,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(
|
@SpringBootTest(properties = { "spring.jmx.enabled=true", "endpoints.default.jmx.enabled=true" })
|
||||||
properties = { "spring.jmx.enabled=true", "endpoints.default.jmx.enabled=true" })
|
|
||||||
public class BusJmxEndpointTests {
|
public class BusJmxEndpointTests {
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(
|
@SpringBootTest(properties = "spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS:true",
|
||||||
properties = "spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS:true",
|
|
||||||
webEnvironment = RANDOM_PORT)
|
webEnvironment = RANDOM_PORT)
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class BusJacksonIntegrationTests {
|
public class BusJacksonIntegrationTests {
|
||||||
@@ -75,16 +74,14 @@ public class BusJacksonIntegrationTests {
|
|||||||
assertThat(this.converter.getMapper().getSerializationConfig()
|
assertThat(this.converter.getMapper().getSerializationConfig()
|
||||||
.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).isTrue();
|
.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).isTrue();
|
||||||
|
|
||||||
Map map = this.rest.getForObject("http://localhost:" + this.port + "/date",
|
Map map = this.rest.getForObject("http://localhost:" + this.port + "/date", Map.class);
|
||||||
Map.class);
|
|
||||||
assertThat(map).containsOnlyKeys("date");
|
assertThat(map).containsOnlyKeys("date");
|
||||||
assertThat(map.get("date")).isInstanceOf(Long.class);
|
assertThat(map.get("date")).isInstanceOf(Long.class);
|
||||||
|
|
||||||
this.rest.put("http://localhost:" + this.port + "/names" + "/foo", null);
|
this.rest.put("http://localhost:" + this.port + "/names" + "/foo", null);
|
||||||
this.rest.put("http://localhost:" + this.port + "/names" + "/bar", null);
|
this.rest.put("http://localhost:" + this.port + "/names" + "/bar", null);
|
||||||
|
|
||||||
ResponseEntity<List> response = this.rest
|
ResponseEntity<List> response = this.rest.getForEntity("http://localhost:" + this.port + "/names", List.class);
|
||||||
.getForEntity("http://localhost:" + this.port + "/names", List.class);
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
assertThat(response.getBody()).contains("foo", "bar");
|
assertThat(response.getBody()).contains("foo", "bar");
|
||||||
}
|
}
|
||||||
@@ -133,8 +130,7 @@ public class BusJacksonIntegrationTests {
|
|||||||
@PutMapping("/names/{name}")
|
@PutMapping("/names/{name}")
|
||||||
public void sayName(@PathVariable String name) {
|
public void sayName(@PathVariable String name) {
|
||||||
this.names.add(name);
|
this.names.add(name);
|
||||||
this.publisher.publishEvent(
|
this.publisher.publishEvent(new NameEvent(this, this.busServiceMatcher.getServiceId(), name));
|
||||||
new NameEvent(this, this.busServiceMatcher.getServiceId(), name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/date")
|
@GetMapping("/date")
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
|||||||
@EnableConfigurationProperties(BusProperties.class)
|
@EnableConfigurationProperties(BusProperties.class)
|
||||||
@AutoConfigureBefore(BindingServiceConfiguration.class)
|
@AutoConfigureBefore(BindingServiceConfiguration.class)
|
||||||
// so stream bindings work properly
|
// so stream bindings work properly
|
||||||
@AutoConfigureAfter({ LifecycleMvcEndpointAutoConfiguration.class,
|
@AutoConfigureAfter({ LifecycleMvcEndpointAutoConfiguration.class, ServiceMatcherAutoConfiguration.class })
|
||||||
ServiceMatcherAutoConfiguration.class })
|
|
||||||
// so actuator endpoints have needed dependencies
|
// so actuator endpoints have needed dependencies
|
||||||
public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
||||||
|
|
||||||
@@ -92,8 +91,7 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
|||||||
|
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
public BusAutoConfiguration(ServiceMatcher serviceMatcher,
|
public BusAutoConfiguration(ServiceMatcher serviceMatcher, BindingServiceProperties bindings, BusProperties bus) {
|
||||||
BindingServiceProperties bindings, BusProperties bus) {
|
|
||||||
this.serviceMatcher = serviceMatcher;
|
this.serviceMatcher = serviceMatcher;
|
||||||
this.bindings = bindings;
|
this.bindings = bindings;
|
||||||
this.bus = bus;
|
this.bus = bus;
|
||||||
@@ -101,35 +99,26 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
BindingProperties inputBinding = this.bindings.getBindings()
|
BindingProperties inputBinding = this.bindings.getBindings().get(SpringCloudBusClient.INPUT);
|
||||||
.get(SpringCloudBusClient.INPUT);
|
|
||||||
if (inputBinding == null) {
|
if (inputBinding == null) {
|
||||||
this.bindings.getBindings().put(SpringCloudBusClient.INPUT,
|
this.bindings.getBindings().put(SpringCloudBusClient.INPUT, new BindingProperties());
|
||||||
new BindingProperties());
|
|
||||||
}
|
}
|
||||||
BindingProperties input = this.bindings.getBindings()
|
BindingProperties input = this.bindings.getBindings().get(SpringCloudBusClient.INPUT);
|
||||||
.get(SpringCloudBusClient.INPUT);
|
if (input.getDestination() == null || input.getDestination().equals(SpringCloudBusClient.INPUT)) {
|
||||||
if (input.getDestination() == null
|
|
||||||
|| input.getDestination().equals(SpringCloudBusClient.INPUT)) {
|
|
||||||
input.setDestination(this.bus.getDestination());
|
input.setDestination(this.bus.getDestination());
|
||||||
}
|
}
|
||||||
BindingProperties outputBinding = this.bindings.getBindings()
|
BindingProperties outputBinding = this.bindings.getBindings().get(SpringCloudBusClient.OUTPUT);
|
||||||
.get(SpringCloudBusClient.OUTPUT);
|
|
||||||
if (outputBinding == null) {
|
if (outputBinding == null) {
|
||||||
this.bindings.getBindings().put(SpringCloudBusClient.OUTPUT,
|
this.bindings.getBindings().put(SpringCloudBusClient.OUTPUT, new BindingProperties());
|
||||||
new BindingProperties());
|
|
||||||
}
|
}
|
||||||
BindingProperties output = this.bindings.getBindings()
|
BindingProperties output = this.bindings.getBindings().get(SpringCloudBusClient.OUTPUT);
|
||||||
.get(SpringCloudBusClient.OUTPUT);
|
if (output.getDestination() == null || output.getDestination().equals(SpringCloudBusClient.OUTPUT)) {
|
||||||
if (output.getDestination() == null
|
|
||||||
|| output.getDestination().equals(SpringCloudBusClient.OUTPUT)) {
|
|
||||||
output.setDestination(this.bus.getDestination());
|
output.setDestination(this.bus.getDestination());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationEventPublisher(
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||||
ApplicationEventPublisher applicationEventPublisher) {
|
|
||||||
this.applicationEventPublisher = applicationEventPublisher;
|
this.applicationEventPublisher = applicationEventPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,8 +130,7 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
|||||||
|
|
||||||
@EventListener(classes = RemoteApplicationEvent.class)
|
@EventListener(classes = RemoteApplicationEvent.class)
|
||||||
public void acceptLocal(RemoteApplicationEvent event) {
|
public void acceptLocal(RemoteApplicationEvent event) {
|
||||||
if (this.serviceMatcher.isFromSelf(event)
|
if (this.serviceMatcher.isFromSelf(event) && !(event instanceof AckRemoteApplicationEvent)) {
|
||||||
&& !(event instanceof AckRemoteApplicationEvent)) {
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Sending remote event on bus: " + event);
|
log.debug("Sending remote event on bus: " + event);
|
||||||
}
|
}
|
||||||
@@ -165,35 +153,30 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
|||||||
log.debug("Received remote event from bus: " + event);
|
log.debug("Received remote event from bus: " + event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.serviceMatcher.isForSelf(event)
|
if (this.serviceMatcher.isForSelf(event) && this.applicationEventPublisher != null) {
|
||||||
&& this.applicationEventPublisher != null) {
|
|
||||||
if (!this.serviceMatcher.isFromSelf(event)) {
|
if (!this.serviceMatcher.isFromSelf(event)) {
|
||||||
this.applicationEventPublisher.publishEvent(event);
|
this.applicationEventPublisher.publishEvent(event);
|
||||||
}
|
}
|
||||||
if (this.bus.getAck().isEnabled()) {
|
if (this.bus.getAck().isEnabled()) {
|
||||||
AckRemoteApplicationEvent ack = new AckRemoteApplicationEvent(this,
|
AckRemoteApplicationEvent ack = new AckRemoteApplicationEvent(this, this.serviceMatcher.getServiceId(),
|
||||||
this.serviceMatcher.getServiceId(),
|
this.bus.getAck().getDestinationService(), event.getDestinationService(), event.getId(),
|
||||||
this.bus.getAck().getDestinationService(),
|
event.getClass());
|
||||||
event.getDestinationService(), event.getId(), event.getClass());
|
this.cloudBusOutboundChannel.send(MessageBuilder.withPayload(ack).build());
|
||||||
this.cloudBusOutboundChannel
|
|
||||||
.send(MessageBuilder.withPayload(ack).build());
|
|
||||||
this.applicationEventPublisher.publishEvent(ack);
|
this.applicationEventPublisher.publishEvent(ack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.bus.getTrace().isEnabled() && this.applicationEventPublisher != null) {
|
if (this.bus.getTrace().isEnabled() && this.applicationEventPublisher != null) {
|
||||||
// We are set to register sent events so publish it for local consumption,
|
// We are set to register sent events so publish it for local consumption,
|
||||||
// irrespective of the origin
|
// irrespective of the origin
|
||||||
this.applicationEventPublisher.publishEvent(new SentApplicationEvent(this,
|
this.applicationEventPublisher.publishEvent(new SentApplicationEvent(this, event.getOriginService(),
|
||||||
event.getOriginService(), event.getDestinationService(),
|
event.getDestinationService(), event.getId(), event.getClass()));
|
||||||
event.getId(), event.getClass()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({ Endpoint.class })
|
@ConditionalOnClass({ Endpoint.class })
|
||||||
@ConditionalOnBean(HttpTraceRepository.class)
|
@ConditionalOnBean(HttpTraceRepository.class)
|
||||||
@ConditionalOnProperty(value = "spring.cloud.bus.trace.enabled",
|
@ConditionalOnProperty(value = "spring.cloud.bus.trace.enabled", matchIfMissing = false)
|
||||||
matchIfMissing = false)
|
|
||||||
protected static class BusAckTraceConfiguration {
|
protected static class BusAckTraceConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -210,8 +193,7 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
|||||||
protected static class BusEnvironmentConfiguration {
|
protected static class BusEnvironmentConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(value = "spring.cloud.bus.env.enabled",
|
@ConditionalOnProperty(value = "spring.cloud.bus.env.enabled", matchIfMissing = true)
|
||||||
matchIfMissing = true)
|
|
||||||
public EnvironmentChangeListener environmentChangeListener() {
|
public EnvironmentChangeListener environmentChangeListener() {
|
||||||
return new EnvironmentChangeListener();
|
return new EnvironmentChangeListener();
|
||||||
}
|
}
|
||||||
@@ -222,8 +204,7 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnAvailableEndpoint
|
@ConditionalOnAvailableEndpoint
|
||||||
public EnvironmentBusEndpoint environmentBusEndpoint(
|
public EnvironmentBusEndpoint environmentBusEndpoint(ApplicationContext context, BusProperties bus) {
|
||||||
ApplicationContext context, BusProperties bus) {
|
|
||||||
return new EnvironmentBusEndpoint(context, bus.getId());
|
return new EnvironmentBusEndpoint(context, bus.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,19 +38,15 @@ public class BusEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
|||||||
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
|
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||||
SpringApplication application) {
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("spring.cloud.stream.bindings." + SpringCloudBusClient.OUTPUT
|
map.put("spring.cloud.stream.bindings." + SpringCloudBusClient.OUTPUT + ".content-type",
|
||||||
+ ".content-type",
|
environment.getProperty("spring.cloud.bus.content-type", "application/json"));
|
||||||
environment.getProperty("spring.cloud.bus.content-type",
|
|
||||||
"application/json"));
|
|
||||||
map.put("spring.cloud.bus.id", IdUtils.getUnresolvedServiceId());
|
map.put("spring.cloud.bus.id", IdUtils.getUnresolvedServiceId());
|
||||||
addOrReplace(environment.getPropertySources(), map);
|
addOrReplace(environment.getPropertySources(), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addOrReplace(MutablePropertySources propertySources,
|
private void addOrReplace(MutablePropertySources propertySources, Map<String, Object> map) {
|
||||||
Map<String, Object> map) {
|
|
||||||
MapPropertySource target = null;
|
MapPropertySource target = null;
|
||||||
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
||||||
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
|
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Qualifier
|
@Qualifier
|
||||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE,
|
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER })
|
||||||
ElementType.PARAMETER })
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Inherited
|
@Inherited
|
||||||
@Documented
|
@Documented
|
||||||
|
|||||||
@@ -33,29 +33,24 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnBusEnabled
|
@ConditionalOnBusEnabled
|
||||||
@AutoConfigureAfter(
|
@AutoConfigureAfter(name = { "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration" })
|
||||||
name = { "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration" })
|
|
||||||
public class BusRefreshAutoConfiguration {
|
public class BusRefreshAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled",
|
@ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true)
|
||||||
matchIfMissing = true)
|
|
||||||
@ConditionalOnBean(ContextRefresher.class)
|
@ConditionalOnBean(ContextRefresher.class)
|
||||||
public RefreshListener refreshListener(ContextRefresher contextRefresher,
|
public RefreshListener refreshListener(ContextRefresher contextRefresher, ServiceMatcher serviceMatcher) {
|
||||||
ServiceMatcher serviceMatcher) {
|
|
||||||
return new RefreshListener(contextRefresher, serviceMatcher);
|
return new RefreshListener(contextRefresher, serviceMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(
|
@ConditionalOnClass(name = { "org.springframework.boot.actuate.endpoint.annotation.Endpoint",
|
||||||
name = { "org.springframework.boot.actuate.endpoint.annotation.Endpoint",
|
"org.springframework.cloud.context.scope.refresh.RefreshScope" })
|
||||||
"org.springframework.cloud.context.scope.refresh.RefreshScope" })
|
|
||||||
protected static class BusRefreshEndpointConfiguration {
|
protected static class BusRefreshEndpointConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnAvailableEndpoint
|
@ConditionalOnAvailableEndpoint
|
||||||
public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context,
|
public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context, BusProperties bus) {
|
||||||
BusProperties bus) {
|
|
||||||
return new RefreshBusEndpoint(context, bus.getId());
|
return new RefreshBusEndpoint(context, bus.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@ConditionalOnProperty(value = ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED,
|
@ConditionalOnProperty(value = ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED, matchIfMissing = true)
|
||||||
matchIfMissing = true)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||||
public @interface ConditionalOnBusEnabled {
|
public @interface ConditionalOnBusEnabled {
|
||||||
|
|||||||
@@ -43,12 +43,10 @@ public class ServiceMatcherAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ServiceMatcher serviceMatcher(@BusPathMatcher PathMatcher pathMatcher,
|
public ServiceMatcher serviceMatcher(@BusPathMatcher PathMatcher pathMatcher, BusProperties properties,
|
||||||
BusProperties properties, Environment environment) {
|
Environment environment) {
|
||||||
String[] configNames = environment.getProperty(CLOUD_CONFIG_NAME_PROPERTY,
|
String[] configNames = environment.getProperty(CLOUD_CONFIG_NAME_PROPERTY, String[].class, new String[] {});
|
||||||
String[].class, new String[] {});
|
ServiceMatcher serviceMatcher = new ServiceMatcher(pathMatcher, properties.getId(), configNames);
|
||||||
ServiceMatcher serviceMatcher = new ServiceMatcher(pathMatcher,
|
|
||||||
properties.getId(), configNames);
|
|
||||||
return serviceMatcher;
|
return serviceMatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,18 +36,16 @@ public class EnvironmentBusEndpoint extends AbstractBusEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@WriteOperation
|
@WriteOperation
|
||||||
public void busEnvWithDestination(String name, String value,
|
// TODO: document params
|
||||||
@Selector String destination) { // TODO: document params
|
public void busEnvWithDestination(String name, String value, @Selector String destination) {
|
||||||
Map<String, String> params = Collections.singletonMap(name, value);
|
Map<String, String> params = Collections.singletonMap(name, value);
|
||||||
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(),
|
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), destination, params));
|
||||||
destination, params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteOperation
|
@WriteOperation
|
||||||
public void busEnv(String name, String value) { // TODO: document params
|
public void busEnv(String name, String value) { // TODO: document params
|
||||||
Map<String, String> params = Collections.singletonMap(name, value);
|
Map<String, String> params = Collections.singletonMap(name, value);
|
||||||
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), null,
|
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), null, params));
|
||||||
params));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ public class AckRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
this.event = null;
|
this.event = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AckRemoteApplicationEvent(Object source, String originService,
|
public AckRemoteApplicationEvent(Object source, String originService, String destinationService,
|
||||||
String destinationService, String ackDestinationService, String ackId,
|
String ackDestinationService, String ackId, Class<? extends RemoteApplicationEvent> type) {
|
||||||
Class<? extends RemoteApplicationEvent> type) {
|
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
this.ackDestinationService = ackDestinationService;
|
this.ackDestinationService = ackDestinationService;
|
||||||
this.ackId = ackId;
|
this.ackId = ackId;
|
||||||
@@ -74,8 +73,7 @@ public class AckRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
@JsonProperty("event")
|
@JsonProperty("event")
|
||||||
public void setEventName(String eventName) {
|
public void setEventName(String eventName) {
|
||||||
try {
|
try {
|
||||||
this.event = (Class<? extends RemoteApplicationEvent>) Class
|
this.event = (Class<? extends RemoteApplicationEvent>) Class.forName(eventName);
|
||||||
.forName(eventName);
|
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e) {
|
catch (ClassNotFoundException e) {
|
||||||
this.event = UnknownRemoteApplicationEvent.class;
|
this.event = UnknownRemoteApplicationEvent.class;
|
||||||
@@ -86,8 +84,7 @@ public class AckRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = super.hashCode();
|
int result = super.hashCode();
|
||||||
result = prime * result + ((this.ackDestinationService == null) ? 0
|
result = prime * result + ((this.ackDestinationService == null) ? 0 : this.ackDestinationService.hashCode());
|
||||||
: this.ackDestinationService.hashCode());
|
|
||||||
result = prime * result + ((this.ackId == null) ? 0 : this.ackId.hashCode());
|
result = prime * result + ((this.ackId == null) ? 0 : this.ackId.hashCode());
|
||||||
result = prime * result + ((this.event == null) ? 0 : this.event.hashCode());
|
result = prime * result + ((this.event == null) ? 0 : this.event.hashCode());
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ import org.springframework.context.ApplicationListener;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
public class EnvironmentChangeListener
|
public class EnvironmentChangeListener implements ApplicationListener<EnvironmentChangeRemoteApplicationEvent> {
|
||||||
implements ApplicationListener<EnvironmentChangeRemoteApplicationEvent> {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(EnvironmentChangeListener.class);
|
private static Log log = LogFactory.getLog(EnvironmentChangeListener.class);
|
||||||
|
|
||||||
@@ -39,8 +38,7 @@ public class EnvironmentChangeListener
|
|||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(EnvironmentChangeRemoteApplicationEvent event) {
|
public void onApplicationEvent(EnvironmentChangeRemoteApplicationEvent event) {
|
||||||
Map<String, String> values = event.getValues();
|
Map<String, String> values = event.getValues();
|
||||||
log.info("Received remote environment change request. Keys/values to update "
|
log.info("Received remote environment change request. Keys/values to update " + values);
|
||||||
+ values);
|
|
||||||
for (Map.Entry<String, String> entry : values.entrySet()) {
|
for (Map.Entry<String, String> entry : values.entrySet()) {
|
||||||
this.env.setProperty(entry.getKey(), entry.getValue());
|
this.env.setProperty(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv
|
|||||||
this.values = null;
|
this.values = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnvironmentChangeRemoteApplicationEvent(Object source, String originService,
|
public EnvironmentChangeRemoteApplicationEvent(Object source, String originService, String destinationService,
|
||||||
String destinationService, Map<String, String> values) {
|
Map<String, String> values) {
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
@@ -77,10 +77,8 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringCreator(this).append("id", getId())
|
return new ToStringCreator(this).append("id", getId()).append("originService", getOriginService())
|
||||||
.append("originService", getOriginService())
|
.append("destinationService", getDestinationService()).append("values", values).toString();
|
||||||
.append("destinationService", getDestinationService())
|
|
||||||
.append("values", values).toString();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ import org.springframework.context.ApplicationListener;
|
|||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
*/
|
*/
|
||||||
public class RefreshListener
|
public class RefreshListener implements ApplicationListener<RefreshRemoteApplicationEvent> {
|
||||||
implements ApplicationListener<RefreshRemoteApplicationEvent> {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(RefreshListener.class);
|
private static Log log = LogFactory.getLog(RefreshListener.class);
|
||||||
|
|
||||||
@@ -38,8 +37,7 @@ public class RefreshListener
|
|||||||
|
|
||||||
private ServiceMatcher serviceMatcher;
|
private ServiceMatcher serviceMatcher;
|
||||||
|
|
||||||
public RefreshListener(ContextRefresher contextRefresher,
|
public RefreshListener(ContextRefresher contextRefresher, ServiceMatcher serviceMatcher) {
|
||||||
ServiceMatcher serviceMatcher) {
|
|
||||||
this.contextRefresher = contextRefresher;
|
this.contextRefresher = contextRefresher;
|
||||||
this.serviceMatcher = serviceMatcher;
|
this.serviceMatcher = serviceMatcher;
|
||||||
}
|
}
|
||||||
@@ -52,8 +50,7 @@ public class RefreshListener
|
|||||||
log.info("Keys refreshed " + keys);
|
log.info("Keys refreshed " + keys);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.info("Refresh not performed, the event was targetting "
|
log.info("Refresh not performed, the event was targetting " + event.getDestinationService());
|
||||||
+ event.getDestinationService());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ public class RefreshRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
// for serializers
|
// for serializers
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefreshRemoteApplicationEvent(Object source, String originService,
|
public RefreshRemoteApplicationEvent(Object source, String originService, String destinationService) {
|
||||||
String destinationService) {
|
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent {
|
|||||||
this(TRANSIENT_SOURCE, null, null);
|
this(TRANSIENT_SOURCE, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RemoteApplicationEvent(Object source, String originService,
|
protected RemoteApplicationEvent(Object source, String originService, String destinationService) {
|
||||||
String destinationService) {
|
|
||||||
super(source);
|
super(source);
|
||||||
this.originService = originService;
|
this.originService = originService;
|
||||||
if (destinationService == null) {
|
if (destinationService == null) {
|
||||||
@@ -88,11 +87,9 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((this.destinationService == null) ? 0
|
result = prime * result + ((this.destinationService == null) ? 0 : this.destinationService.hashCode());
|
||||||
: this.destinationService.hashCode());
|
|
||||||
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
|
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((this.originService == null) ? 0 : this.originService.hashCode());
|
||||||
+ ((this.originService == null) ? 0 : this.originService.hashCode());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,8 +134,7 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringCreator(this).append("id", id)
|
return new ToStringCreator(this).append("id", id).append("originService", originService)
|
||||||
.append("originService", originService)
|
|
||||||
.append("destinationService", destinationService).toString();
|
.append("destinationService", destinationService).toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ public class SentApplicationEvent extends ApplicationEvent {
|
|||||||
this(TRANSIENT_SOURCE, null, null, null, RemoteApplicationEvent.class);
|
this(TRANSIENT_SOURCE, null, null, null, RemoteApplicationEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SentApplicationEvent(Object source, String originService,
|
public SentApplicationEvent(Object source, String originService, String destinationService, String id,
|
||||||
String destinationService, String id,
|
|
||||||
Class<? extends RemoteApplicationEvent> type) {
|
Class<? extends RemoteApplicationEvent> type) {
|
||||||
super(source);
|
super(source);
|
||||||
this.originService = originService;
|
this.originService = originService;
|
||||||
@@ -92,11 +91,9 @@ public class SentApplicationEvent extends ApplicationEvent {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((this.destinationService == null) ? 0
|
result = prime * result + ((this.destinationService == null) ? 0 : this.destinationService.hashCode());
|
||||||
: this.destinationService.hashCode());
|
|
||||||
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
|
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((this.originService == null) ? 0 : this.originService.hashCode());
|
||||||
+ ((this.originService == null) ? 0 : this.originService.hashCode());
|
|
||||||
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
|
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,11 +59,9 @@ public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringCreator(this).append("id", getId())
|
return new ToStringCreator(this).append("id", getId()).append("originService", getOriginService())
|
||||||
.append("originService", getOriginService())
|
.append("destinationService", getDestinationService()).append("typeInfo", typeInfo)
|
||||||
.append("destinationService", getDestinationService())
|
.append("payload", getPayloadAsString()).toString();
|
||||||
.append("typeInfo", typeInfo).append("payload", getPayloadAsString())
|
|
||||||
.toString();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,20 +66,17 @@ public class BusJacksonAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(name = "busJsonConverter")
|
@ConditionalOnMissingBean(name = "busJsonConverter")
|
||||||
@StreamMessageConverter
|
@StreamMessageConverter
|
||||||
public AbstractMessageConverter busJsonConverter(
|
public AbstractMessageConverter busJsonConverter(@Autowired(required = false) ObjectMapper objectMapper) {
|
||||||
@Autowired(required = false) ObjectMapper objectMapper) {
|
|
||||||
return new BusJacksonMessageConverter(objectMapper);
|
return new BusJacksonMessageConverter(objectMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class BusJacksonMessageConverter extends AbstractMessageConverter
|
class BusJacksonMessageConverter extends AbstractMessageConverter implements InitializingBean {
|
||||||
implements InitializingBean {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(BusJacksonMessageConverter.class);
|
private static final Log log = LogFactory.getLog(BusJacksonMessageConverter.class);
|
||||||
|
|
||||||
private static final String DEFAULT_PACKAGE = ClassUtils
|
private static final String DEFAULT_PACKAGE = ClassUtils.getPackageName(RemoteApplicationEvent.class);
|
||||||
.getPackageName(RemoteApplicationEvent.class);
|
|
||||||
|
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
@@ -127,8 +124,7 @@ class BusJacksonMessageConverter extends AbstractMessageConverter
|
|||||||
for (String pkg : this.packagesToScan) {
|
for (String pkg : this.packagesToScan) {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
|
||||||
false);
|
false);
|
||||||
provider.addIncludeFilter(
|
provider.addIncludeFilter(new AssignableTypeFilter(RemoteApplicationEvent.class));
|
||||||
new AssignableTypeFilter(RemoteApplicationEvent.class));
|
|
||||||
|
|
||||||
Set<BeanDefinition> components = provider.findCandidateComponents(pkg);
|
Set<BeanDefinition> components = provider.findCandidateComponents(pkg);
|
||||||
for (BeanDefinition component : components) {
|
for (BeanDefinition component : components) {
|
||||||
@@ -136,8 +132,7 @@ class BusJacksonMessageConverter extends AbstractMessageConverter
|
|||||||
types.add(Class.forName(component.getBeanClassName()));
|
types.add(Class.forName(component.getBeanClassName()));
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e) {
|
catch (ClassNotFoundException e) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException("Failed to scan classpath for remote event classes", e);
|
||||||
"Failed to scan classpath for remote event classes", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,8 +150,7 @@ class BusJacksonMessageConverter extends AbstractMessageConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object convertFromInternal(Message<?> message, Class<?> targetClass,
|
public Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) {
|
||||||
Object conversionHint) {
|
|
||||||
Object result = null;
|
Object result = null;
|
||||||
try {
|
try {
|
||||||
Object payload = message.getPayload();
|
Object payload = message.getPayload();
|
||||||
@@ -166,8 +160,7 @@ class BusJacksonMessageConverter extends AbstractMessageConverter
|
|||||||
result = this.mapper.readValue((byte[]) payload, targetClass);
|
result = this.mapper.readValue((byte[]) payload, targetClass);
|
||||||
}
|
}
|
||||||
catch (InvalidTypeIdException e) {
|
catch (InvalidTypeIdException e) {
|
||||||
return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(),
|
return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), (byte[]) payload);
|
||||||
(byte[]) payload);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (payload instanceof String) {
|
else if (payload instanceof String) {
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegi
|
|||||||
final BeanDefinitionRegistry registry) {
|
final BeanDefinitionRegistry registry) {
|
||||||
|
|
||||||
Map<String, Object> componentScan = importingClassMetadata
|
Map<String, Object> componentScan = importingClassMetadata
|
||||||
.getAnnotationAttributes(RemoteApplicationEventScan.class.getName(),
|
.getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), false);
|
||||||
false);
|
|
||||||
|
|
||||||
Set<String> basePackages = new HashSet<>();
|
Set<String> basePackages = new HashSet<>();
|
||||||
for (String pkg : (String[]) componentScan.get("value")) {
|
for (String pkg : (String[]) componentScan.get("value")) {
|
||||||
@@ -66,8 +65,7 @@ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (basePackages.isEmpty()) {
|
if (basePackages.isEmpty()) {
|
||||||
basePackages.add(
|
basePackages.add(ClassUtils.getPackageName(importingClassMetadata.getClassName()));
|
||||||
ClassUtils.getPackageName(importingClassMetadata.getClassName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!registry.containsBeanDefinition(BUS_JSON_CONVERTER)) {
|
if (!registry.containsBeanDefinition(BUS_JSON_CONVERTER)) {
|
||||||
@@ -75,27 +73,22 @@ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegi
|
|||||||
.genericBeanDefinition(BusJacksonMessageConverter.class);
|
.genericBeanDefinition(BusJacksonMessageConverter.class);
|
||||||
beanDefinitionBuilder.addPropertyValue(PACKAGES_TO_SCAN,
|
beanDefinitionBuilder.addPropertyValue(PACKAGES_TO_SCAN,
|
||||||
basePackages.toArray(new String[basePackages.size()]));
|
basePackages.toArray(new String[basePackages.size()]));
|
||||||
AbstractBeanDefinition beanDefinition = beanDefinitionBuilder
|
AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
|
||||||
.getBeanDefinition();
|
|
||||||
|
|
||||||
BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition,
|
BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, BUS_JSON_CONVERTER);
|
||||||
BUS_JSON_CONVERTER);
|
|
||||||
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
|
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
basePackages.addAll(getEarlierPackagesToScan(registry));
|
basePackages.addAll(getEarlierPackagesToScan(registry));
|
||||||
registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues()
|
registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues().addPropertyValue(PACKAGES_TO_SCAN,
|
||||||
.addPropertyValue(PACKAGES_TO_SCAN,
|
basePackages.toArray(new String[basePackages.size()]));
|
||||||
basePackages.toArray(new String[basePackages.size()]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getEarlierPackagesToScan(final BeanDefinitionRegistry registry) {
|
private Set<String> getEarlierPackagesToScan(final BeanDefinitionRegistry registry) {
|
||||||
if (registry.containsBeanDefinition(BUS_JSON_CONVERTER)
|
if (registry.containsBeanDefinition(BUS_JSON_CONVERTER)
|
||||||
&& registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues()
|
&& registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues().get(PACKAGES_TO_SCAN) != null) {
|
||||||
.get(PACKAGES_TO_SCAN) != null) {
|
String[] earlierValues = (String[]) registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues()
|
||||||
String[] earlierValues = (String[]) registry
|
|
||||||
.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues()
|
|
||||||
.get(PACKAGES_TO_SCAN);
|
.get(PACKAGES_TO_SCAN);
|
||||||
return new HashSet<>(Arrays.asList(earlierValues));
|
return new HashSet<>(Arrays.asList(earlierValues));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,16 +30,14 @@ import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
@RunWith(ModifiedClassPathRunner.class)
|
||||||
@ClassPathExclusions({ "spring-boot-actuator-*.jar",
|
@ClassPathExclusions({ "spring-boot-actuator-*.jar", "spring-boot-starter-actuator-*.jar" })
|
||||||
"spring-boot-starter-actuator-*.jar" })
|
|
||||||
public class BusAutoConfigurationClassPathTests {
|
public class BusAutoConfigurationClassPathTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void refreshListenerCreatedWithoutActuator() {
|
public void refreshListenerCreatedWithoutActuator() {
|
||||||
new ApplicationContextRunner()
|
new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class,
|
||||||
ServiceMatcherAutoConfiguration.class,
|
ServiceMatcherAutoConfiguration.class, BusRefreshAutoConfiguration.class))
|
||||||
BusRefreshAutoConfiguration.class))
|
|
||||||
.run(context -> assertThat(context).hasSingleBean(RefreshListener.class)
|
.run(context -> assertThat(context).hasSingleBean(RefreshListener.class)
|
||||||
.doesNotHaveBean(RefreshBusEndpoint.class));
|
.doesNotHaveBean(RefreshBusEndpoint.class));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,84 +69,66 @@ public class BusAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultId() {
|
public void defaultId() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--server.port=0");
|
||||||
"--server.port=0");
|
assertThat(this.context.getBean(BusProperties.class).getId().startsWith("application:0:"))
|
||||||
assertThat(this.context.getBean(BusProperties.class).getId()
|
.as("Wrong ID: " + this.context.getBean(BusProperties.class).getId()).isTrue();
|
||||||
.startsWith("application:0:")).as(
|
|
||||||
"Wrong ID: " + this.context.getBean(BusProperties.class).getId())
|
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotForSelf() {
|
public void inboundNotForSelf() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=foo",
|
||||||
"--spring.cloud.bus.id=foo", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "bar", "bar")));
|
||||||
new RefreshRemoteApplicationEvent(this, "bar", "bar")));
|
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNull();
|
||||||
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
|
|
||||||
.isNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundFromSelf() {
|
public void inboundFromSelf() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=foo",
|
||||||
"--spring.cloud.bus.id=foo", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", null)));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", null)));
|
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNull();
|
||||||
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
|
|
||||||
.isNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotFromSelf() {
|
public void inboundNotFromSelf() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
|
||||||
"--spring.cloud.bus.id=bar", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", null)));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", null)));
|
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
|
||||||
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
|
|
||||||
.isNotNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotFromSelfWithAck() throws Exception {
|
public void inboundNotFromSelfWithAck() throws Exception {
|
||||||
this.context = SpringApplication.run(
|
this.context = SpringApplication.run(
|
||||||
new Class[] { InboundMessageHandlerConfiguration.class,
|
new Class[] { InboundMessageHandlerConfiguration.class, OutboundMessageHandlerConfiguration.class,
|
||||||
OutboundMessageHandlerConfiguration.class,
|
|
||||||
SentMessageConfiguration.class },
|
SentMessageConfiguration.class },
|
||||||
new String[] { "--spring.cloud.bus.id=bar", "--server.port=0" });
|
new String[] { "--spring.cloud.bus.id=bar", "--server.port=0" });
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", null)));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", null)));
|
RefreshRemoteApplicationEvent refresh = this.context.getBean(InboundMessageHandlerConfiguration.class).refresh;
|
||||||
RefreshRemoteApplicationEvent refresh = this.context
|
|
||||||
.getBean(InboundMessageHandlerConfiguration.class).refresh;
|
|
||||||
assertThat(refresh).isNotNull();
|
assertThat(refresh).isNotNull();
|
||||||
OutboundMessageHandlerConfiguration outbound = this.context
|
OutboundMessageHandlerConfiguration outbound = this.context.getBean(OutboundMessageHandlerConfiguration.class);
|
||||||
.getBean(OutboundMessageHandlerConfiguration.class);
|
|
||||||
outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
|
outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
|
||||||
String message = (String) outbound.message.getPayload();
|
String message = (String) outbound.message.getPayload();
|
||||||
assertThat(message.contains("\"ackId\":\"" + refresh.getId()))
|
assertThat(message.contains("\"ackId\":\"" + refresh.getId())).as("Wrong ackId: " + message).isTrue();
|
||||||
.as("Wrong ackId: " + message).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotFromSelfWithTrace() throws Exception {
|
public void inboundNotFromSelfWithTrace() throws Exception {
|
||||||
this.context = SpringApplication.run(
|
this.context = SpringApplication.run(
|
||||||
new Class[] { InboundMessageHandlerConfiguration.class,
|
new Class[] { InboundMessageHandlerConfiguration.class, OutboundMessageHandlerConfiguration.class,
|
||||||
OutboundMessageHandlerConfiguration.class,
|
|
||||||
SentMessageConfiguration.class },
|
SentMessageConfiguration.class },
|
||||||
new String[] { "--spring.cloud.bus.trace.enabled=true",
|
new String[] { "--spring.cloud.bus.trace.enabled=true", "--spring.cloud.bus.id=bar",
|
||||||
"--spring.cloud.bus.id=bar", "--server.port=0" });
|
"--server.port=0" });
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", null)));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", null)));
|
RefreshRemoteApplicationEvent refresh = this.context.getBean(InboundMessageHandlerConfiguration.class).refresh;
|
||||||
RefreshRemoteApplicationEvent refresh = this.context
|
|
||||||
.getBean(InboundMessageHandlerConfiguration.class).refresh;
|
|
||||||
assertThat(refresh).isNotNull();
|
assertThat(refresh).isNotNull();
|
||||||
SentMessageConfiguration sent = this.context
|
SentMessageConfiguration sent = this.context.getBean(SentMessageConfiguration.class);
|
||||||
.getBean(SentMessageConfiguration.class);
|
|
||||||
assertThat(sent.event).isNotNull();
|
assertThat(sent.event).isNotNull();
|
||||||
assertThat(sent.count).isEqualTo(1);
|
assertThat(sent.count).isEqualTo(1);
|
||||||
}
|
}
|
||||||
@@ -154,51 +136,43 @@ public class BusAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void inboundAckWithTrace() throws Exception {
|
public void inboundAckWithTrace() throws Exception {
|
||||||
this.context = SpringApplication.run(
|
this.context = SpringApplication.run(
|
||||||
new Class[] { InboundMessageHandlerConfiguration.class,
|
new Class[] { InboundMessageHandlerConfiguration.class, OutboundMessageHandlerConfiguration.class,
|
||||||
OutboundMessageHandlerConfiguration.class,
|
|
||||||
AckMessageConfiguration.class },
|
AckMessageConfiguration.class },
|
||||||
new String[] { "--spring.cloud.bus.trace.enabled=true",
|
new String[] { "--spring.cloud.bus.trace.enabled=true", "--spring.cloud.bus.id=bar",
|
||||||
"--spring.cloud.bus.id=bar", "--server.port=0" });
|
"--server.port=0" });
|
||||||
this.context.getBean(BusProperties.class).setId("bar");
|
this.context.getBean(BusProperties.class).setId("bar");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class).send(new GenericMessage<>(
|
||||||
.send(new GenericMessage<>(new AckRemoteApplicationEvent(this, "foo",
|
new AckRemoteApplicationEvent(this, "foo", null, "ID", "bar", RefreshRemoteApplicationEvent.class)));
|
||||||
null, "ID", "bar", RefreshRemoteApplicationEvent.class)));
|
AckMessageConfiguration sent = this.context.getBean(AckMessageConfiguration.class);
|
||||||
AckMessageConfiguration sent = this.context
|
|
||||||
.getBean(AckMessageConfiguration.class);
|
|
||||||
assertThat(sent.event).isNotNull();
|
assertThat(sent.event).isNotNull();
|
||||||
assertThat(sent.count).isEqualTo(1);
|
assertThat(sent.count).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outboundFromSelf() throws Exception {
|
public void outboundFromSelf() throws Exception {
|
||||||
this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class, "--debug=true",
|
||||||
"--debug=true", "--spring.cloud.bus.id=foo", "--server.port=0");
|
"--spring.cloud.bus.id=foo", "--server.port=0");
|
||||||
this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null));
|
this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null));
|
||||||
OutboundMessageHandlerConfiguration outbound = this.context
|
OutboundMessageHandlerConfiguration outbound = this.context.getBean(OutboundMessageHandlerConfiguration.class);
|
||||||
.getBean(OutboundMessageHandlerConfiguration.class);
|
|
||||||
outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
|
outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
|
||||||
assertThat(outbound.message).as("message was null").isNotNull();
|
assertThat(outbound.message).as("message was null").isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outboundNotFromSelf() {
|
public void outboundNotFromSelf() {
|
||||||
this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
|
||||||
"--spring.cloud.bus.id=bar", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null));
|
this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", null));
|
||||||
assertThat(
|
assertThat(this.context.getBean(OutboundMessageHandlerConfiguration.class).message).isNull();
|
||||||
this.context.getBean(OutboundMessageHandlerConfiguration.class).message)
|
|
||||||
.isNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotFromSelfPathPattern() {
|
public void inboundNotFromSelfPathPattern() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar:1000",
|
||||||
"--spring.cloud.bus.id=bar:1000", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:*")));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", "bar:*")));
|
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
|
||||||
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
|
|
||||||
.isNotNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -206,31 +180,26 @@ public class BusAutoConfigurationTests {
|
|||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
||||||
"--spring.cloud.bus.id=bar:test:1000", "--server.port=0");
|
"--spring.cloud.bus.id=bar:test:1000", "--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:**")));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", "bar:**")));
|
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
|
||||||
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
|
|
||||||
.isNotNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotFromSelfFlatPattern() {
|
public void inboundNotFromSelfFlatPattern() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
|
||||||
"--spring.cloud.bus.id=bar", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(
|
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar*")));
|
||||||
new RefreshRemoteApplicationEvent(this, "foo", "bar*")));
|
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
|
||||||
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh)
|
|
||||||
.isNotNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// see https://github.com/spring-cloud/spring-cloud-bus/issues/74
|
// see https://github.com/spring-cloud/spring-cloud-bus/issues/74
|
||||||
@Test
|
@Test
|
||||||
public void inboundNotFromSelfUnknown() {
|
public void inboundNotFromSelfUnknown() {
|
||||||
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
|
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
|
||||||
"--spring.cloud.bus.id=bar", "--server.port=0");
|
"--server.port=0");
|
||||||
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
this.context.getBean(SpringCloudBusClient.INPUT, MessageChannel.class)
|
||||||
.send(new GenericMessage<>(new UnknownRemoteApplicationEvent(this,
|
.send(new GenericMessage<>(new UnknownRemoteApplicationEvent(this, "UnknownEvent", "yada".getBytes())));
|
||||||
"UnknownEvent", "yada".getBytes())));
|
|
||||||
// No Exception expected
|
// No Exception expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,14 +254,13 @@ public class BusAutoConfigurationTests {
|
|||||||
assertThat(output.getDestination()).isEqualTo(bus.getDestination());
|
assertThat(output.getDestination()).isEqualTo(bus.getDestination());
|
||||||
}
|
}
|
||||||
|
|
||||||
private BusProperties setupBusAutoConfig(
|
private BusProperties setupBusAutoConfig(HashMap<String, BindingProperties> properties) {
|
||||||
HashMap<String, BindingProperties> properties) {
|
|
||||||
BindingServiceProperties serviceProperties = mock(BindingServiceProperties.class);
|
BindingServiceProperties serviceProperties = mock(BindingServiceProperties.class);
|
||||||
when(serviceProperties.getBindings()).thenReturn(properties);
|
when(serviceProperties.getBindings()).thenReturn(properties);
|
||||||
|
|
||||||
BusProperties bus = new BusProperties();
|
BusProperties bus = new BusProperties();
|
||||||
BusAutoConfiguration configuration = new BusAutoConfiguration(
|
BusAutoConfiguration configuration = new BusAutoConfiguration(mock(ServiceMatcher.class), serviceProperties,
|
||||||
mock(ServiceMatcher.class), serviceProperties, bus);
|
bus);
|
||||||
configuration.init();
|
configuration.init();
|
||||||
return bus;
|
return bus;
|
||||||
}
|
}
|
||||||
@@ -303,8 +271,7 @@ public class BusAutoConfigurationTests {
|
|||||||
public void serviceMatcherIdIsConstantAfterRefresh() {
|
public void serviceMatcherIdIsConstantAfterRefresh() {
|
||||||
this.context = SpringApplication.run(new Class[] { RefreshConfig.class, },
|
this.context = SpringApplication.run(new Class[] { RefreshConfig.class, },
|
||||||
new String[] { "--spring.main.allow-bean-definition-overriding=true" });
|
new String[] { "--spring.main.allow-bean-definition-overriding=true" });
|
||||||
String originalServiceId = this.context.getBean(ServiceMatcher.class)
|
String originalServiceId = this.context.getBean(ServiceMatcher.class).getServiceId();
|
||||||
.getServiceId();
|
|
||||||
this.context.getBean(ContextRefresher.class).refresh();
|
this.context.getBean(ContextRefresher.class).refresh();
|
||||||
String newServiceId = this.context.getBean(ServiceMatcher.class).getServiceId();
|
String newServiceId = this.context.getBean(ServiceMatcher.class).getServiceId();
|
||||||
assertThat(newServiceId).isEqualTo(originalServiceId);
|
assertThat(newServiceId).isEqualTo(originalServiceId);
|
||||||
@@ -318,8 +285,7 @@ public class BusAutoConfigurationTests {
|
|||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@Import({ MessageConsumer.class, BusAutoConfiguration.class,
|
@Import({ MessageConsumer.class, BusAutoConfiguration.class, TestSupportBinderAutoConfiguration.class,
|
||||||
TestSupportBinderAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class })
|
PropertyPlaceholderAutoConfiguration.class })
|
||||||
protected static class OutboundMessageHandlerConfiguration {
|
protected static class OutboundMessageHandlerConfiguration {
|
||||||
|
|
||||||
@@ -339,8 +305,7 @@ public class BusAutoConfigurationTests {
|
|||||||
private ChannelInterceptor interceptor() {
|
private ChannelInterceptor interceptor() {
|
||||||
return new ChannelInterceptorAdapter() {
|
return new ChannelInterceptorAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void postSend(Message<?> message, MessageChannel channel,
|
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
|
||||||
boolean sent) {
|
|
||||||
OutboundMessageHandlerConfiguration.this.message = message;
|
OutboundMessageHandlerConfiguration.this.message = message;
|
||||||
OutboundMessageHandlerConfiguration.this.latch.countDown();
|
OutboundMessageHandlerConfiguration.this.latch.countDown();
|
||||||
}
|
}
|
||||||
@@ -361,8 +326,7 @@ public class BusAutoConfigurationTests {
|
|||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@Import({ MessageConsumer.class, BusAutoConfiguration.class,
|
@Import({ MessageConsumer.class, BusAutoConfiguration.class, TestSupportBinderAutoConfiguration.class,
|
||||||
TestSupportBinderAutoConfiguration.class,
|
|
||||||
PropertyPlaceholderAutoConfiguration.class })
|
PropertyPlaceholderAutoConfiguration.class })
|
||||||
protected static class InboundMessageHandlerConfiguration
|
protected static class InboundMessageHandlerConfiguration
|
||||||
implements ApplicationListener<RefreshRemoteApplicationEvent> {
|
implements ApplicationListener<RefreshRemoteApplicationEvent> {
|
||||||
@@ -377,8 +341,7 @@ public class BusAutoConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
protected static class SentMessageConfiguration
|
protected static class SentMessageConfiguration implements ApplicationListener<SentApplicationEvent> {
|
||||||
implements ApplicationListener<SentApplicationEvent> {
|
|
||||||
|
|
||||||
private SentApplicationEvent event;
|
private SentApplicationEvent event;
|
||||||
|
|
||||||
@@ -393,8 +356,7 @@ public class BusAutoConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
protected static class AckMessageConfiguration
|
protected static class AckMessageConfiguration implements ApplicationListener<AckRemoteApplicationEvent> {
|
||||||
implements ApplicationListener<AckRemoteApplicationEvent> {
|
|
||||||
|
|
||||||
private AckRemoteApplicationEvent event;
|
private AckRemoteApplicationEvent event;
|
||||||
|
|
||||||
|
|||||||
@@ -47,25 +47,20 @@ public class ConditionalOnBusEnabledTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void busEnabledTrue() {
|
public void busEnabledTrue() {
|
||||||
load(MyBusEnabledConfig.class,
|
load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":true");
|
||||||
ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":true");
|
assertThat(this.context.containsBean("foo")).as("missing bean from @ConditionalOnBusEnabled config").isTrue();
|
||||||
assertThat(this.context.containsBean("foo"))
|
|
||||||
.as("missing bean from @ConditionalOnBusEnabled config").isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void busEnabledMissing() {
|
public void busEnabledMissing() {
|
||||||
load(MyBusEnabledConfig.class);
|
load(MyBusEnabledConfig.class);
|
||||||
assertThat(this.context.containsBean("foo"))
|
assertThat(this.context.containsBean("foo")).as("missing bean from @ConditionalOnBusEnabled config").isTrue();
|
||||||
.as("missing bean from @ConditionalOnBusEnabled config").isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void busDisabled() {
|
public void busDisabled() {
|
||||||
load(MyBusEnabledConfig.class,
|
load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":false");
|
||||||
ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":false");
|
assertThat(this.context.containsBean("foo")).as("bean exists from disabled @ConditionalOnBusEnabled config")
|
||||||
assertThat(this.context.containsBean("foo"))
|
|
||||||
.as("bean exists from disabled @ConditionalOnBusEnabled config")
|
|
||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
classes = RefreshListenerIntegrationTests.MyApp.class,
|
classes = RefreshListenerIntegrationTests.MyApp.class,
|
||||||
properties = { "management.endpoints.web.exposure.include=*",
|
properties = { "management.endpoints.web.exposure.include=*", "spring.application.name=foobar" })
|
||||||
"spring.application.name=foobar" })
|
|
||||||
public class RefreshListenerIntegrationTests {
|
public class RefreshListenerIntegrationTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -57,10 +56,10 @@ public class RefreshListenerIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testEndpoint() {
|
public void testEndpoint() {
|
||||||
System.out.println(rest.getForObject("/actuator", String.class));
|
System.out.println(rest.getForObject("/actuator", String.class));
|
||||||
assertThat(rest.postForEntity("/actuator/bus-refresh/demoapp", new HashMap<>(),
|
assertThat(rest.postForEntity("/actuator/bus-refresh/demoapp", new HashMap<>(), String.class).getStatusCode())
|
||||||
String.class).getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
.isEqualTo(HttpStatus.NO_CONTENT);
|
||||||
assertThat(rest.postForEntity("/actuator/bus-refresh/foobar", new HashMap<>(),
|
assertThat(rest.postForEntity("/actuator/bus-refresh/foobar", new HashMap<>(), String.class).getStatusCode())
|
||||||
String.class).getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
.isEqualTo(HttpStatus.NO_CONTENT);
|
||||||
verify(contextRefresher, times(1)).refresh();
|
verify(contextRefresher, times(1)).refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,87 +45,97 @@ public class ServiceMatcherTests {
|
|||||||
private void initMatcher(String id) {
|
private void initMatcher(String id) {
|
||||||
BusProperties properties = new BusProperties();
|
BusProperties properties = new BusProperties();
|
||||||
properties.setId(id);
|
properties.setId(id);
|
||||||
DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(
|
DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(new AntPathMatcher(":"));
|
||||||
new AntPathMatcher(":"));
|
|
||||||
this.matcher = new ServiceMatcher(pathMatcher, properties.getId());
|
this.matcher = new ServiceMatcher(pathMatcher, properties.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromSelf() {
|
public void fromSelf() {
|
||||||
assertThat(this.matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isFromSelf(
|
||||||
this, "one:two:8888", "foo:bar:spam", EMPTY_MAP))).isTrue();
|
new EnvironmentChangeRemoteApplicationEvent(this, "one:two:8888", "foo:bar:spam", EMPTY_MAP))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelf() {
|
public void forSelf() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isForSelf(
|
||||||
this, "foo:bar:spam", "one:two:8888", EMPTY_MAP))).isTrue();
|
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:8888", EMPTY_MAP))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcard() {
|
public void forSelfWithWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:two:*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithGlobalWildcard() {
|
public void forSelfWithGlobalWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "**", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardName() {
|
public void forSelfWithWildcardName() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardNameAndProfile() {
|
public void forSelfWithWildcardNameAndProfile() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*:t*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardString() {
|
public void forSelfWithWildcardString() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notForSelfWithWildCardNameAndMismatchingProfile() {
|
public void notForSelfWithWildCardNameAndMismatchingProfile() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*:f*", EMPTY_MAP))).isFalse();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithDoubleWildcard() {
|
public void forSelfWithDoubleWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:**", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithNoWildcard() {
|
public void forSelfWithNoWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithProfileNoWildcard() {
|
public void forSelfWithProfileNoWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:two", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notForSelf() {
|
public void notForSelf() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isForSelf(
|
||||||
this, "foo:bar:spam", "one:two:9999", EMPTY_MAP))).isFalse();
|
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFromSelf() {
|
public void notFromSelf() {
|
||||||
assertThat(this.matcher.isFromSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isFromSelf(
|
||||||
this, "one:two:9999", "foo:bar:spam", EMPTY_MAP))).isFalse();
|
new EnvironmentChangeRemoteApplicationEvent(this, "one:two:9999", "foo:bar:spam", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,8 +144,9 @@ public class ServiceMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void forSelfWithMultipleProfiles() {
|
public void forSelfWithMultipleProfiles() {
|
||||||
initMatcher("customerportal:dev,cloud:80");
|
initMatcher("customerportal:dev,cloud:80");
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isForSelf(
|
||||||
this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP))).isTrue();
|
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,8 +155,9 @@ public class ServiceMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void notForSelfWithMultipleProfiles() {
|
public void notForSelfWithMultipleProfiles() {
|
||||||
initMatcher("customerportal:dev,cloud:80");
|
initMatcher("customerportal:dev,cloud:80");
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP))).isFalse();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,8 +166,8 @@ public class ServiceMatcherTests {
|
|||||||
@Test
|
@Test
|
||||||
public void notForSelfWithMultipleProfilesDifferentPort() {
|
public void notForSelfWithMultipleProfilesDifferentPort() {
|
||||||
initMatcher("customerportal:dev,cloud:80");
|
initMatcher("customerportal:dev,cloud:80");
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam",
|
||||||
this, "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP))).isFalse();
|
"customerportal:cloud:8008", EMPTY_MAP))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,96 +45,108 @@ public class ServiceMatcherWithConfigNamesTests {
|
|||||||
private void initMatcher(String id, String[] configNames) {
|
private void initMatcher(String id, String[] configNames) {
|
||||||
BusProperties properties = new BusProperties();
|
BusProperties properties = new BusProperties();
|
||||||
properties.setId(id);
|
properties.setId(id);
|
||||||
DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(
|
DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(new AntPathMatcher(":"));
|
||||||
new AntPathMatcher(":"));
|
|
||||||
this.matcher = new ServiceMatcher(pathMatcher, properties.getId(), configNames);
|
this.matcher = new ServiceMatcher(pathMatcher, properties.getId(), configNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcard() {
|
public void forSelfWithWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:two:*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardAndOtherConfigName() {
|
public void forSelfWithWildcardAndOtherConfigName() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "three:two:*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "three:two:*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithGlobalWildcard() {
|
public void forSelfWithGlobalWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "**", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardName() {
|
public void forSelfWithWildcardName() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardNameAndProfile() {
|
public void forSelfWithWildcardNameAndProfile() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*:t*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithWildcardString() {
|
public void forSelfWithWildcardString() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notForSelfWithWildCardNameAndMismatchingProfile() {
|
public void notForSelfWithWildCardNameAndMismatchingProfile() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "o*:f*", EMPTY_MAP))).isFalse();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithDoubleWildcard() {
|
public void forSelfWithDoubleWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:**", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithNoWildcard() {
|
public void forSelfWithNoWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithProfileNoWildcard() {
|
public void forSelfWithProfileNoWildcard() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:two", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notForSelf() {
|
public void notForSelf() {
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isForSelf(
|
||||||
this, "foo:bar:spam", "one:two:9999", EMPTY_MAP))).isFalse();
|
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forSelfWithMultipleProfiles() {
|
public void forSelfWithMultipleProfiles() {
|
||||||
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
|
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP))).isTrue();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP)))
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notForSelfWithMultipleProfiles() {
|
public void notForSelfWithMultipleProfiles() {
|
||||||
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
|
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher
|
||||||
this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP))).isFalse();
|
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)))
|
||||||
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notForSelfWithMultipleProfilesDifferentPort() {
|
public void notForSelfWithMultipleProfilesDifferentPort() {
|
||||||
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
|
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
|
||||||
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(
|
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam",
|
||||||
this, "foo:bar:spam", "customerportal:cloud:8008", EMPTY_MAP))).isFalse();
|
"customerportal:cloud:8008", EMPTY_MAP))).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ public class TestRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
private TestRemoteApplicationEvent() {
|
private TestRemoteApplicationEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TestRemoteApplicationEvent(Object source, String originService,
|
protected TestRemoteApplicationEvent(Object source, String originService, String destinationService) {
|
||||||
String destinationService) {
|
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ public class TypedRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
private TypedRemoteApplicationEvent() {
|
private TypedRemoteApplicationEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TypedRemoteApplicationEvent(Object source, String originService,
|
protected TypedRemoteApplicationEvent(Object source, String originService, String destinationService) {
|
||||||
String destinationService) {
|
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,87 +50,72 @@ public class RemoteApplicationEventScanTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void importingClassMetadataPackageRegistered() {
|
public void importingClassMetadataPackageRegistered() {
|
||||||
this.converter = createTestContext(DefaultConfig.class)
|
this.converter = createTestContext(DefaultConfig.class).getBean(BusJacksonMessageConverter.class);
|
||||||
.getBean(BusJacksonMessageConverter.class);
|
|
||||||
|
|
||||||
assertConverterBeanAfterPropertiesSet(
|
assertConverterBeanAfterPropertiesSet(
|
||||||
new String[] { "org.springframework.cloud.bus.jackson",
|
new String[] { "org.springframework.cloud.bus.jackson", "org.springframework.cloud.bus.event" },
|
||||||
"org.springframework.cloud.bus.event" },
|
AnotherRemoteApplicationEvent.class, MyRemoteApplicationEvent.class, TestRemoteApplicationEvent.class,
|
||||||
AnotherRemoteApplicationEvent.class, MyRemoteApplicationEvent.class,
|
TypedRemoteApplicationEvent.class);
|
||||||
TestRemoteApplicationEvent.class, TypedRemoteApplicationEvent.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void annotationValuePackagesRegistered() {
|
public void annotationValuePackagesRegistered() {
|
||||||
this.converter = createTestContext(ValueConfig.class)
|
this.converter = createTestContext(ValueConfig.class).getBean(BusJacksonMessageConverter.class);
|
||||||
.getBean(BusJacksonMessageConverter.class);
|
|
||||||
|
|
||||||
assertConverterBeanAfterPropertiesSet(
|
assertConverterBeanAfterPropertiesSet(
|
||||||
new String[] { "test.foo.bar", "com.acme",
|
new String[] { "test.foo.bar", "com.acme", "org.springframework.cloud.bus.event" },
|
||||||
"org.springframework.cloud.bus.event" },
|
|
||||||
FooBarTestRemoteApplicationEvent.class, TestRemoteApplicationEvent.class,
|
FooBarTestRemoteApplicationEvent.class, TestRemoteApplicationEvent.class,
|
||||||
TypedRemoteApplicationEvent.class);
|
TypedRemoteApplicationEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void annotationValueBasePackagesRegistered() {
|
public void annotationValueBasePackagesRegistered() {
|
||||||
this.converter = createTestContext(BasePackagesConfig.class)
|
this.converter = createTestContext(BasePackagesConfig.class).getBean(BusJacksonMessageConverter.class);
|
||||||
.getBean(BusJacksonMessageConverter.class);
|
|
||||||
|
|
||||||
assertConverterBeanAfterPropertiesSet(
|
assertConverterBeanAfterPropertiesSet(
|
||||||
new String[] { "test.foo.bar", "fizz.buzz", "com.acme",
|
new String[] { "test.foo.bar", "fizz.buzz", "com.acme", "org.springframework.cloud.bus.event" },
|
||||||
"org.springframework.cloud.bus.event" },
|
|
||||||
FooBarTestRemoteApplicationEvent.class, TestRemoteApplicationEvent.class,
|
FooBarTestRemoteApplicationEvent.class, TestRemoteApplicationEvent.class,
|
||||||
TypedRemoteApplicationEvent.class);
|
TypedRemoteApplicationEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void annotationBasePackagesRegistered() {
|
public void annotationBasePackagesRegistered() {
|
||||||
this.converter = createTestContext(BasePackageClassesConfig.class)
|
this.converter = createTestContext(BasePackageClassesConfig.class).getBean(BusJacksonMessageConverter.class);
|
||||||
.getBean(BusJacksonMessageConverter.class);
|
|
||||||
|
|
||||||
assertConverterBeanAfterPropertiesSet(
|
assertConverterBeanAfterPropertiesSet(
|
||||||
new String[] { "org.springframework.cloud.bus.event.test",
|
new String[] { "org.springframework.cloud.bus.event.test", "org.springframework.cloud.bus.event" },
|
||||||
"org.springframework.cloud.bus.event" },
|
|
||||||
TestRemoteApplicationEvent.class, TypedRemoteApplicationEvent.class);
|
TestRemoteApplicationEvent.class, TypedRemoteApplicationEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConfigurableApplicationContext createTestContext(Class<?> configuration) {
|
private ConfigurableApplicationContext createTestContext(Class<?> configuration) {
|
||||||
return new SpringApplicationBuilder(configuration).web(WebApplicationType.NONE)
|
return new SpringApplicationBuilder(configuration).web(WebApplicationType.NONE).bannerMode(Banner.Mode.OFF)
|
||||||
.bannerMode(Banner.Mode.OFF).run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertConverterBeanAfterPropertiesSet(
|
private void assertConverterBeanAfterPropertiesSet(final String[] expectedPackageToScan,
|
||||||
final String[] expectedPackageToScan,
|
|
||||||
final Class<?>... expectedRegisterdClasses) {
|
final Class<?>... expectedRegisterdClasses) {
|
||||||
final ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils
|
final ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(this.converter, "mapper");
|
||||||
.getField(this.converter, "mapper");
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final LinkedHashSet<NamedType> registeredSubtypes = (LinkedHashSet<NamedType>) ReflectionTestUtils
|
final LinkedHashSet<NamedType> registeredSubtypes = (LinkedHashSet<NamedType>) ReflectionTestUtils
|
||||||
.getField(mapper.getSubtypeResolver(), "_registeredSubtypes");
|
.getField(mapper.getSubtypeResolver(), "_registeredSubtypes");
|
||||||
|
|
||||||
final List<Class<?>> expectedRegisterdClassesAsList = new ArrayList<>(
|
final List<Class<?>> expectedRegisterdClassesAsList = new ArrayList<>(Arrays.asList(expectedRegisterdClasses));
|
||||||
Arrays.asList(expectedRegisterdClasses));
|
|
||||||
addStandardSpringCloudEventBusEvents(expectedRegisterdClassesAsList);
|
addStandardSpringCloudEventBusEvents(expectedRegisterdClassesAsList);
|
||||||
|
|
||||||
assertThat(expectedRegisterdClassesAsList.size() == registeredSubtypes.size())
|
assertThat(expectedRegisterdClassesAsList.size() == registeredSubtypes.size())
|
||||||
.as("Wrong RemoteApplicationEvent classes are registerd in object mapper")
|
.as("Wrong RemoteApplicationEvent classes are registerd in object mapper").isTrue();
|
||||||
.isTrue();
|
|
||||||
|
|
||||||
for (final NamedType namedType : registeredSubtypes) {
|
for (final NamedType namedType : registeredSubtypes) {
|
||||||
assertThat(expectedRegisterdClassesAsList.contains(namedType.getType()))
|
assertThat(expectedRegisterdClassesAsList.contains(namedType.getType())).isTrue();
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter,
|
assertThat(Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter, "packagesToScan")))
|
||||||
"packagesToScan"))).as("RemoteApplicationEvent packages not registered")
|
.as("RemoteApplicationEvent packages not registered").contains(expectedPackageToScan);
|
||||||
.contains(expectedPackageToScan);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStandardSpringCloudEventBusEvents(
|
private void addStandardSpringCloudEventBusEvents(final List<Class<?>> expectedRegisterdClassesAsList) {
|
||||||
final List<Class<?>> expectedRegisterdClassesAsList) {
|
|
||||||
expectedRegisterdClassesAsList.add(AckRemoteApplicationEvent.class);
|
expectedRegisterdClassesAsList.add(AckRemoteApplicationEvent.class);
|
||||||
expectedRegisterdClassesAsList.add(EnvironmentChangeRemoteApplicationEvent.class);
|
expectedRegisterdClassesAsList.add(EnvironmentChangeRemoteApplicationEvent.class);
|
||||||
expectedRegisterdClassesAsList.add(RefreshRemoteApplicationEvent.class);
|
expectedRegisterdClassesAsList.add(RefreshRemoteApplicationEvent.class);
|
||||||
|
|||||||
@@ -37,13 +37,12 @@ public class SerializationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void vanillaDeserialize() throws Exception {
|
public void vanillaDeserialize() throws Exception {
|
||||||
this.mapper.registerModule(new SubtypeModule(RefreshRemoteApplicationEvent.class,
|
this.mapper.registerModule(
|
||||||
EnvironmentChangeRemoteApplicationEvent.class));
|
new SubtypeModule(RefreshRemoteApplicationEvent.class, EnvironmentChangeRemoteApplicationEvent.class));
|
||||||
EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent(
|
EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent(this, "foo", "bar",
|
||||||
this, "foo", "bar", Collections.<String, String>emptyMap());
|
Collections.<String, String>emptyMap());
|
||||||
String value = this.mapper.writeValueAsString(source);
|
String value = this.mapper.writeValueAsString(source);
|
||||||
RemoteApplicationEvent event = this.mapper.readValue(value,
|
RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class);
|
||||||
RemoteApplicationEvent.class);
|
|
||||||
assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue();
|
assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue();
|
||||||
assertThat(event.getId()).isNotNull();
|
assertThat(event.getId()).isNotNull();
|
||||||
assertThat(event.getId().equals(source.getId())).isTrue();
|
assertThat(event.getId().equals(source.getId())).isTrue();
|
||||||
@@ -51,14 +50,13 @@ public class SerializationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void deserializeOldValueWithNoId() throws Exception {
|
public void deserializeOldValueWithNoId() throws Exception {
|
||||||
this.mapper.registerModule(new SubtypeModule(RefreshRemoteApplicationEvent.class,
|
this.mapper.registerModule(
|
||||||
EnvironmentChangeRemoteApplicationEvent.class));
|
new SubtypeModule(RefreshRemoteApplicationEvent.class, EnvironmentChangeRemoteApplicationEvent.class));
|
||||||
EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent(
|
EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent(this, "foo", "bar",
|
||||||
this, "foo", "bar", Collections.<String, String>emptyMap());
|
Collections.<String, String>emptyMap());
|
||||||
String value = this.mapper.writeValueAsString(source);
|
String value = this.mapper.writeValueAsString(source);
|
||||||
value = value.replaceAll(",\"id\":\"[a-f0-9-]*\"", "");
|
value = value.replaceAll(",\"id\":\"[a-f0-9-]*\"", "");
|
||||||
RemoteApplicationEvent event = this.mapper.readValue(value,
|
RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class);
|
||||||
RemoteApplicationEvent.class);
|
|
||||||
assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue();
|
assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue();
|
||||||
assertThat(event.getId()).isNotNull();
|
assertThat(event.getId()).isNotNull();
|
||||||
assertThat(event.getId().equals(source.getId())).isFalse();
|
assertThat(event.getId().equals(source.getId())).isFalse();
|
||||||
|
|||||||
@@ -44,23 +44,18 @@ public class SubtypeModuleTests {
|
|||||||
RemoteApplicationEvent event = mapper.readValue(
|
RemoteApplicationEvent event = mapper.readValue(
|
||||||
"{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}",
|
"{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}",
|
||||||
RemoteApplicationEvent.class);
|
RemoteApplicationEvent.class);
|
||||||
assertThat(event instanceof MyRemoteApplicationEvent).as("event is wrong type")
|
assertThat(event instanceof MyRemoteApplicationEvent).as("event is wrong type").isTrue();
|
||||||
.isTrue();
|
|
||||||
MyRemoteApplicationEvent myEvent = MyRemoteApplicationEvent.class.cast(event);
|
MyRemoteApplicationEvent myEvent = MyRemoteApplicationEvent.class.cast(event);
|
||||||
assertThat(myEvent.getOriginService()).as("originService was wrong")
|
assertThat(myEvent.getOriginService()).as("originService was wrong").isEqualTo("myorigin");
|
||||||
.isEqualTo("myorigin");
|
assertThat(myEvent.getDestinationService()).as("destinationService was wrong").isEqualTo("myservice");
|
||||||
assertThat(myEvent.getDestinationService()).as("destinationService was wrong")
|
|
||||||
.isEqualTo("myservice");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeWhenTypeIsKnown() throws Exception {
|
public void testDeserializeWhenTypeIsKnown() throws Exception {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
RemoteApplicationEvent event = mapper.readValue("{\"type\":\"another\"}",
|
RemoteApplicationEvent event = mapper.readValue("{\"type\":\"another\"}", AnotherRemoteApplicationEvent.class);
|
||||||
AnotherRemoteApplicationEvent.class);
|
assertThat(event instanceof AnotherRemoteApplicationEvent).as("event is wrong type").isTrue();
|
||||||
assertThat(event instanceof AnotherRemoteApplicationEvent)
|
|
||||||
.as("event is wrong type").isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -70,39 +65,34 @@ public class SubtypeModuleTests {
|
|||||||
|
|
||||||
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(mapper);
|
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(mapper);
|
||||||
converter.afterPropertiesSet();
|
converter.afterPropertiesSet();
|
||||||
Object event = converter.fromMessage(MessageBuilder.withPayload(
|
Object event = converter.fromMessage(MessageBuilder
|
||||||
"{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}")
|
.withPayload("{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}").build(),
|
||||||
.build(), RemoteApplicationEvent.class);
|
RemoteApplicationEvent.class);
|
||||||
assertThat(event).isNotNull().isInstanceOf(TestRemoteApplicationEvent.class);
|
assertThat(event).isNotNull().isInstanceOf(TestRemoteApplicationEvent.class);
|
||||||
assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService())
|
assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService()).isEqualTo("myorigin");
|
||||||
.isEqualTo("myorigin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeWithMessageConverter() throws Exception {
|
public void testDeserializeWithMessageConverter() throws Exception {
|
||||||
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
||||||
converter.afterPropertiesSet();
|
converter.afterPropertiesSet();
|
||||||
Object event = converter.fromMessage(MessageBuilder
|
Object event = converter.fromMessage(
|
||||||
.withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(),
|
MessageBuilder.withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(),
|
||||||
RemoteApplicationEvent.class);
|
RemoteApplicationEvent.class);
|
||||||
assertThat(event instanceof TestRemoteApplicationEvent).as("event is wrong type")
|
assertThat(event instanceof TestRemoteApplicationEvent).as("event is wrong type").isTrue();
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeUnknownTypeWithMessageConverter() throws Exception {
|
public void testDeserializeUnknownTypeWithMessageConverter() throws Exception {
|
||||||
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
||||||
converter.afterPropertiesSet();
|
converter.afterPropertiesSet();
|
||||||
Object event = converter.fromMessage(MessageBuilder
|
Object event = converter.fromMessage(
|
||||||
.withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}")
|
MessageBuilder.withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}").build(),
|
||||||
.build(), RemoteApplicationEvent.class);
|
RemoteApplicationEvent.class);
|
||||||
assertThat(event instanceof UnknownRemoteApplicationEvent)
|
assertThat(event instanceof UnknownRemoteApplicationEvent).as("event is wrong type").isTrue();
|
||||||
.as("event is wrong type").isTrue();
|
assertThat(((UnknownRemoteApplicationEvent) event).getTypeInfo()).as("type information is wrong")
|
||||||
assertThat(((UnknownRemoteApplicationEvent) event).getTypeInfo())
|
|
||||||
.as("type information is wrong")
|
|
||||||
.isEqualTo("NotDefinedTestRemoteApplicationEvent");
|
.isEqualTo("NotDefinedTestRemoteApplicationEvent");
|
||||||
assertThat(((UnknownRemoteApplicationEvent) event).getPayloadAsString())
|
assertThat(((UnknownRemoteApplicationEvent) event).getPayloadAsString()).as("payload is wrong")
|
||||||
.as("payload is wrong")
|
|
||||||
.isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}");
|
.isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,11 +100,9 @@ public class SubtypeModuleTests {
|
|||||||
public void testDeserializeJsonTypeWithMessageConverter() throws Exception {
|
public void testDeserializeJsonTypeWithMessageConverter() throws Exception {
|
||||||
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
||||||
converter.afterPropertiesSet();
|
converter.afterPropertiesSet();
|
||||||
Object event = converter.fromMessage(
|
Object event = converter.fromMessage(MessageBuilder.withPayload("{\"type\":\"typed\"}").build(),
|
||||||
MessageBuilder.withPayload("{\"type\":\"typed\"}").build(),
|
|
||||||
RemoteApplicationEvent.class);
|
RemoteApplicationEvent.class);
|
||||||
assertThat(event instanceof TypedRemoteApplicationEvent).as("event is wrong type")
|
assertThat(event instanceof TypedRemoteApplicationEvent).as("event is wrong type").isTrue();
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,12 +112,12 @@ public class SubtypeModuleTests {
|
|||||||
public void testDeserializeAckRemoteApplicationEventWithKnownType() throws Exception {
|
public void testDeserializeAckRemoteApplicationEventWithKnownType() throws Exception {
|
||||||
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
||||||
converter.afterPropertiesSet();
|
converter.afterPropertiesSet();
|
||||||
Object event = converter.fromMessage(MessageBuilder
|
Object event = converter
|
||||||
.withPayload("{\"type\":\"AckRemoteApplicationEvent\", "
|
.fromMessage(MessageBuilder
|
||||||
+ "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}")
|
.withPayload("{\"type\":\"AckRemoteApplicationEvent\", "
|
||||||
.build(), RemoteApplicationEvent.class);
|
+ "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}")
|
||||||
assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack")
|
.build(), RemoteApplicationEvent.class);
|
||||||
.isTrue();
|
assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack").isTrue();
|
||||||
AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event);
|
AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event);
|
||||||
assertThat(ackEvent.getEvent()).as("inner ack event has wrong type")
|
assertThat(ackEvent.getEvent()).as("inner ack event has wrong type")
|
||||||
.isEqualTo(TestRemoteApplicationEvent.class);
|
.isEqualTo(TestRemoteApplicationEvent.class);
|
||||||
@@ -139,15 +127,14 @@ public class SubtypeModuleTests {
|
|||||||
* see https://github.com/spring-cloud/spring-cloud-bus/issues/74
|
* see https://github.com/spring-cloud/spring-cloud-bus/issues/74
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeAckRemoteApplicationEventWithUnknownType()
|
public void testDeserializeAckRemoteApplicationEventWithUnknownType() throws Exception {
|
||||||
throws Exception {
|
|
||||||
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
|
||||||
converter.afterPropertiesSet();
|
converter.afterPropertiesSet();
|
||||||
Object event = converter.fromMessage(MessageBuilder.withPayload(
|
Object event = converter.fromMessage(MessageBuilder
|
||||||
"{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}")
|
.withPayload(
|
||||||
|
"{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}")
|
||||||
.build(), RemoteApplicationEvent.class);
|
.build(), RemoteApplicationEvent.class);
|
||||||
assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack")
|
assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack").isTrue();
|
||||||
.isTrue();
|
|
||||||
AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event);
|
AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event);
|
||||||
assertThat(ackEvent.getEvent()).as("inner ack event has wrong type")
|
assertThat(ackEvent.getEvent()).as("inner ack event has wrong type")
|
||||||
.isEqualTo(UnknownRemoteApplicationEvent.class);
|
.isEqualTo(UnknownRemoteApplicationEvent.class);
|
||||||
@@ -161,8 +148,7 @@ public class SubtypeModuleTests {
|
|||||||
private MyRemoteApplicationEvent() {
|
private MyRemoteApplicationEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MyRemoteApplicationEvent(Object source, String originService,
|
protected MyRemoteApplicationEvent(Object source, String originService, String destinationService) {
|
||||||
String destinationService) {
|
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,8 +166,7 @@ public class SubtypeModuleTests {
|
|||||||
private AnotherRemoteApplicationEvent() {
|
private AnotherRemoteApplicationEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AnotherRemoteApplicationEvent(Object source, String originService,
|
protected AnotherRemoteApplicationEvent(Object source, String originService, String destinationService) {
|
||||||
String destinationService) {
|
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,12 @@ public class FooBarTestRemoteApplicationEvent extends RemoteApplicationEvent {
|
|||||||
private FooBarTestRemoteApplicationEvent() {
|
private FooBarTestRemoteApplicationEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FooBarTestRemoteApplicationEvent(final Object source,
|
protected FooBarTestRemoteApplicationEvent(final Object source, final String originService,
|
||||||
final String originService, final String destinationService) {
|
final String destinationService) {
|
||||||
super(source, originService, destinationService);
|
super(source, originService, destinationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected FooBarTestRemoteApplicationEvent(final Object source,
|
protected FooBarTestRemoteApplicationEvent(final Object source, final String originService) {
|
||||||
final String originService) {
|
|
||||||
super(source, originService);
|
super(source, originService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user