Skip to content

Commit

Permalink
fix dependencies, test and more
Browse files Browse the repository at this point in the history
  • Loading branch information
aatarasoff committed May 26, 2022
1 parent 0e6d1ff commit ae1a7a2
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 32 deletions.
2 changes: 1 addition & 1 deletion autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
compileOnly "org.springframework.boot:spring-boot-starter-web", optional
compileOnly "org.springframework.boot:spring-boot-starter-actuator", optional
compileOnly "org.springframework.cloud:spring-cloud-starter-loadbalancer", optional
compileOnly "org.springframework.cloud:spring-cloud-sleuth-zipkin", optional
compileOnly "org.springframework.cloud:spring-cloud-starter-sleuth", optional

compileOnly 'org.apache.commons:commons-pool2', optional
compileOnly 'org.apache.commons:commons-lang3', optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import org.apache.thrift.protocol.TProtocolFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.propagation.Propagator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.PropertyResolver;
Expand All @@ -23,7 +23,6 @@
* Created on 2016-06-14
*/
@Configuration
@ConditionalOnBean(Tracer.class)
public class PoolConfiguration {

@Autowired
Expand All @@ -47,6 +46,9 @@ public class PoolConfiguration {
@Autowired
private Tracer tracer;

@Autowired
private Propagator propagator;

@Bean
@ConditionalOnMissingBean(name = "thriftClientsPool")
public KeyedObjectPool<ThriftClientKey, TServiceClient> thriftClientsPool() {
Expand All @@ -65,6 +67,7 @@ private KeyedPooledObjectFactory<ThriftClientKey, TServiceClient> thriftClientPo
.propertyResolver(propertyResolver)
.loadBalancerClient(loadBalancerClient)
.tracer(tracer)
.propagator(propagator)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,6 @@ public void flush() throws TTransportException {
}
}

@Override
public TConfiguration getConfiguration() {
return null;
}

@Override
public void updateKnownMessageSize(long size) throws TTransportException {

}

@Override
public void checkReadBytesAvailable(long numBytes) throws TTransportException {

}

private void doFlush(byte[] data) throws TTransportException, IOException {
ServiceInstance serviceInstance = this.loadBalancerClient.choose(serviceName);

Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ allprojects {
subprojects {
apply plugin: 'java'


sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand All @@ -52,6 +53,8 @@ subprojects {
junitXml.enabled = true
html.enabled = true
}

useJUnitPlatform()
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package info.developerblog.examples.thirft.simpleclient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureAfter({ SimpleDiscoveryClientAutoConfiguration.class })
public class DiscoveryClientAutoConfiguration implements ApplicationListener<WebServerInitializedEvent> {

@Autowired
private DiscoveryClient simpleDiscoveryClient;

@Override
public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) {
int port = webServerInitializedEvent.getWebServer().getPort();
for (String serviceId : simpleDiscoveryClient.getServices()) {
for (ServiceInstance instance : simpleDiscoveryClient.getInstances(serviceId)) {
((DefaultServiceInstance) instance).setPort(port);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
import info.developerblog.spring.thrift.annotation.ThriftClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.EnableAsync;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.annotation.PostConstruct;

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

/**
Expand Down
35 changes: 26 additions & 9 deletions examples/simple-client/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
greeting-service:
ribbon:
listOfServers: localhost:${local.server.port}
spring:
cloud:
discovery:
client:
simple:
instances:
greeting-service:
- instanceId: server1
serviceId: greeting-service
host: localhost
port: 0
greeting-service-with-timeouts:
- instanceId: server1
serviceId: greeting-service-with-timeouts
host: localhost
port: 0
greeting-service-with-timeouts-oneoff:
- instanceId: server1
serviceId: greeting-service-with-timeouts-oneoff
host: localhost
port: 0
greeting-service-with-timeouts-retriable:
- instanceId: server1
serviceId: greeting-service-with-timeouts-retriable
host: localhost
port: 0
greeting-service-with-timeouts:
connectTimeout: 10
readTimeout: 100
ribbon:
listOfServers: localhost:${local.server.port}
greeting-service-with-timeouts-oneoff:
connectTimeout: 10
readTimeout: 100
ribbon:
listOfServers: localhost:${local.server.port}
greeting-service-with-timeouts-retriable:
connectTimeout: 10
readTimeout: 100
maxRetries: 3
ribbon:
listOfServers: localhost:${local.server.port}

thrift.client.max.threads: 10
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -26,7 +25,6 @@
webEnvironment = RANDOM_PORT
)
public class TGreetingServiceHandlerTests {

@LocalServerPort
int port;

Expand All @@ -38,7 +36,7 @@ public class TGreetingServiceHandlerTests {

TGreetingService.Iface client;

@BeforeAll
@BeforeEach
public void setUp() throws Exception {
TTransport transport = new THttpClient("http://localhost:" + port + "/api");

Expand Down
2 changes: 1 addition & 1 deletion starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
compileApi 'org.springframework.boot:spring-boot-starter-web'
compileApi 'org.springframework.boot:spring-boot-starter-actuator'
compileApi 'org.springframework.cloud:spring-cloud-starter-loadbalancer'
compileApi 'org.springframework.cloud:spring-cloud-sleuth-zipkin'
compileApi 'org.springframework.cloud:spring-cloud-starter-sleuth'

compileApi 'org.apache.commons:commons-pool2'
compileApi 'org.apache.commons:commons-lang3'
Expand Down

0 comments on commit ae1a7a2

Please sign in to comment.