Skip to content

Commit

Permalink
provides tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegDokuka committed Jan 8, 2020
1 parent 6b3b267 commit a5e7612
Show file tree
Hide file tree
Showing 24 changed files with 307 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,12 @@ public Builder tags(Iterable<Tag> tags) {

DestinationInfoConfig build() {
Tags tags;
if (destination != null && !destination.isEmpty()) {
tags = this.tags.and("com.netifi.destination", destination);
} else {
tags = this.tags;
if (destination == null || destination.isEmpty()) {
destination = defaultDestination();
}

tags = this.tags.and("com.netifi.destination", destination);

return new DestinationInfoConfig() {
@Override
public String group() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import java.util.stream.Stream;

/**
* Gets current default configuration for {@link BrokerFactory}. Can be overridden with
* System
* Gets current default configuration for {@link BrokerFactory}. Can be overridden with System
* properties, or if the application provides a config file. The builder will over-ride these values
* if they are based directly in to the builder. Otherwise it will these values a default.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import com.netifi.broker.BrokerFactory;
import com.netifi.broker.BrokerService;
import com.netifi.broker.RoutingBrokerService;
import com.netifi.broker.discovery.*;
import com.netifi.broker.discovery.ConsulDiscoveryConfig;
import com.netifi.broker.discovery.DiscoveryStrategy;
import com.netifi.broker.discovery.EC2TagsDiscoveryConfig;
import com.netifi.broker.discovery.KubernetesDiscoveryConfig;
import com.netifi.broker.discovery.StaticListDiscoveryConfig;
import com.netifi.broker.discovery.StaticListDiscoveryStrategy;
import com.netifi.broker.micrometer.BrokerMeterRegistrySupplier;
import com.netifi.broker.tracing.BrokerTracerSupplier;
import com.netifi.common.tags.Tag;
Expand All @@ -30,12 +35,9 @@
import io.micrometer.core.instrument.MeterRegistry;
import io.opentracing.Tracer;
import io.rsocket.ipc.MutableRouter;
import io.rsocket.ipc.Router;
import io.rsocket.ipc.routing.SimpleRouter;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -58,8 +60,8 @@
@AutoConfigureBefore(BrokerClientConfiguration.class)
public class BrokerClientAutoConfiguration {

static RoutingBrokerService configureBrokerClient(
MutableRouter router, List<? extends BrokerServiceConfigurer> configurers) {
static RoutingBrokerService<?> configureBrokerClient(
MutableRouter<?> router, List<? extends BrokerServiceConfigurer> configurers) {
BrokerFactory.ClientBuilder clientBuilder = BrokerFactory.connect();

AnnotationAwareOrderComparator.sort(configurers);
Expand All @@ -72,13 +74,14 @@ static RoutingBrokerService configureBrokerClient(
}

@Bean(name = "internalScanClassPathBeanDefinitionRegistryPostProcessor")
public BeanDefinitionRegistryPostProcessor scanClassPathBeanDefinitionRegistryPostProcessor() {
public ScanClassPathBeanDefinitionRegistryPostProcessor
scanClassPathBeanDefinitionRegistryPostProcessor() {
return new ScanClassPathBeanDefinitionRegistryPostProcessor();
}

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public BrokerServiceConfigurer propertiesBasedBrokerClientConfigurer(
public BrokerServiceConfigurer propertiesBasedBrokerServiceConfigurer(
BrokerClientTagSupplier brokerClientTagSupplier,
BrokerClientProperties brokerClientProperties) {
return builder -> {
Expand Down Expand Up @@ -227,15 +230,6 @@ public BrokerClientTagSupplier brokerClientTagSupplier() {
}
}

@Configuration
@ConditionalOnMissingBean(Router.class)
public static class RouterConfiguration {
@Bean
public MutableRouter mutableRouter() {
return new SimpleRouter();
}
}

@Configuration
@ConditionalOnMissingBean(MeterRegistry.class)
@ConditionalOnClass(BrokerMeterRegistrySupplier.class)
Expand Down Expand Up @@ -267,15 +261,15 @@ public Tracer tracer(BrokerService brokerClient, BrokerClientProperties properti

@Configuration
@ConditionalOnNotWebApplication
@ConditionalOnMissingBean({BrokerService.class})
@ConditionalOnMissingBean(BrokerService.class)
public static class NonWebBrokerClientConfiguration {

@Bean
public RoutingBrokerService routingBrokerService(
MutableRouter router,
public RoutingBrokerService<?> routingBrokerService(
MutableRouter<?> mutableRouter,
List<? extends BrokerServiceConfigurer> configurers,
ConfigurableApplicationContext context) {
RoutingBrokerService brokerClient = configureBrokerClient(router, configurers);
RoutingBrokerService<?> brokerClient = configureBrokerClient(mutableRouter, configurers);

startDaemonAwaitThread(brokerClient);

Expand Down Expand Up @@ -306,24 +300,24 @@ public void run() {
}

@Bean
public BrokerClient routingBrokerService(RoutingBrokerService routingBrokerService) {
public BrokerClient brokerClient(RoutingBrokerService<?> routingBrokerService) {
return BrokerClient.from(routingBrokerService);
}
}

@Configuration
@ConditionalOnWebApplication
@ConditionalOnMissingBean({BrokerService.class})
@ConditionalOnMissingBean(BrokerService.class)
public static class WebBrokerClientConfiguration {

@Bean
public RoutingBrokerService routingBrokerService(
MutableRouter router, List<? extends BrokerServiceConfigurer> configurers) {
public RoutingBrokerService<?> routingBrokerService(
MutableRouter<?> router, List<? extends BrokerServiceConfigurer> configurers) {
return configureBrokerClient(router, configurers);
}

@Bean
public BrokerClient routingBrokerService(RoutingBrokerService routingBrokerService) {
public BrokerClient brokerClient(RoutingBrokerService<?> routingBrokerService) {
return BrokerClient.from(routingBrokerService);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2019 The Netifi Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netifi.spring.boot;

import io.rsocket.ipc.Router;
import io.rsocket.ipc.routing.SimpleRouter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureBefore(BrokerClientAutoConfiguration.class)
public class DefaultRoutingAutoConfiguration {

@Bean
@ConditionalOnMissingBean(Router.class)
public SimpleRouter mutableRouter() {
return new SimpleRouter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netifi.spring.boot;
package com.netifi.spring.boot.messaging;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,31 @@
* limitations under the License.
*/

package com.netifi.spring.boot;
package com.netifi.spring.boot.messaging;

import com.netifi.broker.BrokerService;
import com.netifi.spring.boot.BrokerClientAutoConfiguration;
import com.netifi.spring.messaging.BrokerClientRequesterMethodArgumentResolver;
import com.netifi.spring.messaging.MessagingRSocketRequesterClientFactory;
import com.netifi.spring.messaging.MessagingRouter;
import io.micrometer.core.instrument.MeterRegistry;
import io.opentracing.Tracer;
import io.rsocket.AbstractRSocket;
import io.rsocket.RSocket;
import io.rsocket.RSocketFactory;
import io.rsocket.ipc.MutableRouter;
import io.rsocket.transport.netty.server.TcpServerTransport;
import java.util.Optional;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.rsocket.RSocketProperties;
import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.rsocket.context.RSocketServerBootstrap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.messaging.rsocket.annotation.support.RSocketRequesterMethodArgumentResolver;
import org.springframework.util.MimeTypeUtils;

/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring RSocket support in Spring
Expand All @@ -52,42 +47,23 @@
* @author Oleh Dokuka
* @since 1.7.0
*/
@Configuration(proxyBeanMethods = false)
@Configuration
@ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class})
@AutoConfigureAfter({RSocketStrategiesAutoConfiguration.class, BrokerClientAutoConfiguration.class})
@EnableConfigurationProperties(BrokerClientMessagingProperties.class)
public class BrokerClientMessagingAutoConfiguration {
public class BrokerMessagingAutoConfiguration {

private static final RSocket STUB_RSOCKET = new AbstractRSocket() {};

@Bean
public MutableRouter messagingCustomizer(
RSocketProperties rSocketProperties,
BrokerClientProperties brokerClientProperties,
BrokerClientMessagingProperties properties,
DefaultListableBeanFactory factory,
RSocketStrategies rSocketStrategies,
RSocketMessageHandler handler) {
return new MessagingRouter(
MimeTypeUtils.ALL,
MimeTypeUtils.ALL,
rSocketStrategies.metadataExtractor(),
handler,
rSocketStrategies.routeMatcher(),
rSocketStrategies);
}

@Bean
@ConditionalOnMissingBean
public RSocketServerBootstrap messageHandlerAcceptor(
BrokerClientMessagingProperties properties,
public NetifiBootstrap netifiBootstrap(
DefaultListableBeanFactory factory,
RSocketStrategies rSocketStrategies,
RSocketMessageHandler handler,
BrokerService brokerClient,
BrokerService brokerService,
Optional<MeterRegistry> registry,
Optional<Tracer> tracer) {
RSocketServerBootstrap bootstrap = new NetifiBootstrap(brokerClient);
NetifiBootstrap bootstrap = new NetifiBootstrap(brokerService);

handler
.getArgumentResolverConfigurer()
Expand All @@ -98,7 +74,7 @@ public RSocketServerBootstrap messageHandlerAcceptor(
.getArgumentResolverConfigurer()
.addCustomResolver(
new BrokerClientRequesterMethodArgumentResolver(
brokerClient,
brokerService,
factory,
rSocketStrategies,
registry.orElse(null),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2019 The Netifi Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netifi.spring.boot.messaging;

import com.netifi.spring.boot.BrokerClientAutoConfiguration;
import com.netifi.spring.boot.DefaultRoutingAutoConfiguration;
import com.netifi.spring.messaging.MessagingRouter;
import io.rsocket.RSocketFactory;
import io.rsocket.transport.netty.server.TcpServerTransport;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.util.MimeTypeUtils;

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({RSocketRequester.class, RSocketFactory.class, TcpServerTransport.class})
@AutoConfigureBefore({BrokerClientAutoConfiguration.class, DefaultRoutingAutoConfiguration.class})
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
public class MessagingRoutingAutoConfiguration {

@Bean
public MessagingRouter messagingRouter(
RSocketStrategies rSocketStrategies, RSocketMessageHandler handler) {
return new MessagingRouter(
MimeTypeUtils.ALL,
MimeTypeUtils.ALL,
rSocketStrategies.metadataExtractor(),
handler,
rSocketStrategies.routeMatcher(),
rSocketStrategies);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netifi.spring.boot;
package com.netifi.spring.boot.messaging;

import com.netifi.broker.BrokerService;
import java.net.InetSocketAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.netifi.spring.boot.DefaultRoutingAutoConfiguration,\
com.netifi.spring.boot.BrokerClientAutoConfiguration,\
com.netifi.spring.boot.BrokerClientMessagingAutoConfiguration,\
com.netifi.spring.boot.messaging.MessagingRoutingAutoConfiguration,\
com.netifi.spring.boot.messaging.BrokerMessagingAutoConfiguration,\
com.netifi.spring.core.config.BrokerClientConfiguration
Loading

0 comments on commit a5e7612

Please sign in to comment.