[go: nahoru, domu]

Skip to content

Commit

Permalink
load tests (in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
skarpenko committed Mar 7, 2018
1 parent 4a4b5bb commit 8d3d757
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import feign.reactive.ReactiveMethodHandlerFactory;
import feign.reactive.HystrixMethodHandler;
import feign.reactive.client.ReactiveClient;
import feign.reactive.client.ReactiveClientFactory;
import feign.reactive.client.RibbonReactiveClient;
Expand All @@ -18,7 +19,7 @@

/**
* Allows to specify ribbon {@link LoadBalancerCommand}
* and HystrixObservableCommand.Setter.
* and HystrixObservableCommand.Setter with fallback factory.
*
* @author Sergii Karpenko
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package feign;
package feign.reactive;

import com.netflix.hystrix.HystrixObservableCommand;
import feign.reactive.ReactiveMethodHandlerFactory;
import feign.CloudReactiveFeign;
import feign.MethodMetadata;
import feign.Target;
import org.reactivestreams.Publisher;
import org.springframework.lang.Nullable;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -36,16 +38,17 @@ private HystrixMethodHandler(
@Nullable
Function<Throwable, Object> fallbackFactory) {
checkNotNull(target, "target must be not null");
;

checkNotNull(methodMetadata, "methodMetadata must be not null");
method = Arrays.stream(target.type().getMethods())
.filter(method -> configKey(target.type(), method).equals(methodMetadata.configKey()))
.findFirst().orElseThrow(() -> new IllegalArgumentException());
method.setAccessible(true);

returnPublisherType = ((ParameterizedType) methodMetadata.returnType()).getRawType();
this.methodHandler = checkNotNull(methodHandler, "methodHandler must be not null");
this.fallbackFactory = fallbackFactory;
checkNotNull(setterFactory, "hystrixObservableCommandSetter must be not null");
checkNotNull(setterFactory, "setterFactory must be not null");
hystrixObservableCommandSetter = setterFactory.create(target, methodMetadata);
}

Expand All @@ -64,10 +67,9 @@ protected Observable<Object> resumeWithFallback() {
if (fallbackFactory != null) {
Object fallback = fallbackFactory.apply(getExecutionException());
try {
method.setAccessible(true);
Object fallbackValue = method.invoke(fallback, argv);
Object fallbackValue = getFallbackValue(fallback, method, argv);
return RxReactiveStreams.toObservable((Publisher<Object>) fallbackValue);
} catch (Exception e) {
} catch (Throwable e) {
return Observable.error(e);
}

Expand All @@ -82,12 +84,16 @@ protected Observable<Object> resumeWithFallback() {
return returnPublisherType == Mono.class ? Mono.from(publisher) : Flux.from(publisher);
}

static class Factory implements ReactiveMethodHandlerFactory {
protected Object getFallbackValue(Object target, Method method, Object[] argv) throws Throwable {
return method.invoke(target, argv);
}

public static class Factory implements ReactiveMethodHandlerFactory {
private final ReactiveMethodHandlerFactory methodHandlerFactory;
private final CloudReactiveFeign.SetterFactory commandSetterFactory;
private final Function<Throwable, Object> fallbackFactory;

Factory(ReactiveMethodHandlerFactory methodHandlerFactory,
public Factory(ReactiveMethodHandlerFactory methodHandlerFactory,
CloudReactiveFeign.SetterFactory commandSetterFactory,
@Nullable
Function<Throwable, Object> fallbackFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;


/**
* @author Sergii Karpenko
*/
public class HystrixReactiveHttpClientTest {

@ClassRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.isA;


/**
* @author Sergii Karpenko
*/
public class LoadBalancingReactiveHttpClientTest {

@ClassRule
Expand Down
5 changes: 1 addition & 4 deletions feign-reactive-core/src/main/java/feign/ReactiveFeign.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import feign.reactive.ReactiveClientMethodHandler;
import feign.reactive.ReactiveDelegatingContract;
import feign.reactive.ReactiveMethodHandlerFactory;
import feign.reactive.ReactiveOptions;
import feign.reactive.*;
import feign.reactive.client.ReactiveClientFactory;
import feign.reactive.client.WebReactiveClient;
import io.netty.channel.ChannelOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
Expand Down Expand Up @@ -32,10 +33,7 @@ public List<MethodMetadata> parseAndValidatateMetadata(

for (final MethodMetadata metadata : metadatas) {
final Type type = metadata.returnType();

if (!(type instanceof ParameterizedType)
|| !((ParameterizedType) type).getRawType().equals(Mono.class)
&& !((ParameterizedType) type).getRawType().equals(Flux.class)) {
if (!isMonoOrFlux(type)) {
throw new IllegalArgumentException(String.format(
"Method %s of contract %s doesn't returns reactor.core.publisher.Mono or reactor.core.publisher.Flux",
metadata.configKey(), targetType.getSimpleName()));
Expand All @@ -44,4 +42,10 @@ public List<MethodMetadata> parseAndValidatateMetadata(

return metadatas;
}

private boolean isMonoOrFlux(final Type type) {
return (type instanceof ParameterizedType)
&& (((ParameterizedType) type).getRawType().equals(Mono.class)
|| ((ParameterizedType) type).getRawType().equals(Flux.class));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package feign;
package feign.reactive;

import feign.InvocationHandlerFactory;
import feign.InvocationHandlerFactory.MethodHandler;
import feign.Target;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -18,7 +20,7 @@
*
* @author Sergii Karpenko
*/
final class ReactiveInvocationHandler implements InvocationHandler {
public final class ReactiveInvocationHandler implements InvocationHandler {
private final Target<?> target;
private final Map<Method, MethodHandler> dispatch;

Expand All @@ -43,13 +45,7 @@ public Object invoke(final Object proxy,
case "toString":
return toString();
default:
if (isReturnsMonoOrFlux(method)) {
return invokeRequestMethod(method, args);
} else {
throw new FeignException(String.format(
"Method %s of contract %s doesn't return reactor.core.publisher.Mono or reactor.core.publisher.Flux",
method.getName(), method.getDeclaringClass().getSimpleName()));
}
return invokeRequestMethod(method, args);
}
}

Expand Down Expand Up @@ -103,7 +99,7 @@ public String toString() {
/**
* Factory for ReactiveInvocationHandler.
*/
static final class Factory implements InvocationHandlerFactory {
public static final class Factory implements InvocationHandlerFactory {

@Override
public InvocationHandler create(final Target target,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package feign;
package feign.reactive;

import feign.InvocationHandlerFactory;
import org.reactivestreams.Publisher;

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


import feign.MethodMetadata;
import feign.ReactiveMethodHandler;
import feign.Target;

public interface ReactiveMethodHandlerFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;

/**
* @author Sergii Karpenko
*/

@RunWith(SpringRunner.class)
@SpringBootTest(
classes = {IcecreamController.class},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
/**
* Test the new capability of Reactive Feign client to support both Feign
* Request.Options (regression) and the new ReactiveOptions configuration.
*
* @author Sergii Karpenko
*/
@RunWith(SpringRunner.class)
@SpringBootTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;

/**
* @author Sergii Karpenko
*/
public class RetryingTest {

@ClassRule
Expand Down
75 changes: 75 additions & 0 deletions feign-reactive-load-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-reactive</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>feign-reactive-load-tests</artifactId>

<properties>
</properties>

<dependencies>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-reactive-core</artifactId>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-reactive-cloud</artifactId>
</dependency>

<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>${hystrix.version}</version>
</dependency>

<dependency>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius-core</artifactId>
<version>${archaius.version}</version>
</dependency>

<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-core</artifactId>
<version>${ribbon-version}</version>
</dependency>

<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
<version>${ribbon-version}</version>
</dependency>

<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Loading

0 comments on commit 8d3d757

Please sign in to comment.