Last active
April 22, 2020 15:06
-
-
Save Feder1co5oave/8d70b3383fd6c2011619f38e17d19d46 to your computer and use it in GitHub Desktop.
Vert.x circuit breaker bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.api.test; | |
import io.vertx.circuitbreaker.CircuitBreaker; | |
import io.vertx.circuitbreaker.CircuitBreakerOptions; | |
import io.vertx.core.Promise; | |
import io.vertx.core.Vertx; | |
public class CBTest { | |
static Vertx vertx = Vertx.vertx(); | |
static CircuitBreaker breaker = CircuitBreaker.create("breakerName", vertx, new CircuitBreakerOptions() | |
.setMaxRetries(0) | |
.setTimeout(500) | |
.setFallbackOnFailure(false) | |
.setResetTimeout(500) | |
.setMaxFailures(1)) | |
.closeHandler(CBTest::state) | |
.openHandler(CBTest::state) | |
.halfOpenHandler(CBTest::state); | |
public static void main(String[] args) { | |
vertx.getOrCreateContext() | |
.exceptionHandler(ex -> ex.printStackTrace()) //intercept exceptions in the context | |
.runOnContext(v -> { | |
state(null); | |
breaker.execute(CBTest::pingSuccess).onComplete(v1 -> { | |
breaker.execute(CBTest::pingDelay).onComplete(v2 -> { | |
System.out.println("wait for half-open..."); | |
vertx.setTimer(1000, l -> { | |
breaker.execute(CBTest::pingSuccess).onComplete(v3 -> { | |
breaker.execute(CBTest::pingSuccess).onComplete(v4 -> { | |
vertx.close(); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} | |
public static void pingFail(Promise<Void> p) { | |
System.out.println("fail"); | |
p.fail("ping fail"); | |
} | |
public static void pingDelay(Promise<Void> p) { | |
System.out.println("timeout"); | |
vertx.setTimer(500, l -> p.complete()); | |
} | |
public static void pingSuccess(Promise<Void> p) { | |
System.out.println("success"); | |
p.complete(); | |
} | |
public static void state(Object o) { | |
System.out.println(breaker.state()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
~ Copyright (c) 2011-2016 The original author or authors | |
~ | |
~ All rights reserved. This program and the accompanying materials | |
~ are made available under the terms of the Eclipse Public License v1.0 | |
~ and Apache License v2.0 which accompanies this distribution. | |
~ | |
~ The Eclipse Public License is available at | |
~ http://www.eclipse.org/legal/epl-v10.html | |
~ | |
~ The Apache License v2.0 is available at | |
~ http://www.opensource.org/licenses/apache2.0.php | |
~ | |
~ You may elect to redistribute this code under either of these licenses. | |
--><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.vertx</groupId> | |
<artifactId>vertx-ext-parent</artifactId> | |
<version>34</version> | |
</parent> | |
<artifactId>vertx-circuit-breaker</artifactId> | |
<version>4.0.0-SNAPSHOT</version> | |
<properties> | |
<hystrix.version>1.5.2</hystrix.version> | |
<codegen.rxjava.deprecated>true</codegen.rxjava.deprecated> | |
</properties> | |
<dependencyManagement> | |
<dependencies> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-dependencies</artifactId> | |
<version>${project.version}</version> | |
<type>pom</type> | |
<scope>import</scope> | |
</dependency> | |
</dependencies> | |
</dependencyManagement> | |
<dependencies> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-hazelcast</artifactId> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-web</artifactId> | |
<optional>true</optional> | |
</dependency> | |
<dependency> | |
<!-- for metrics --> | |
<groupId>org.hdrhistogram</groupId> | |
<artifactId>HdrHistogram</artifactId> | |
<version>2.1.10</version> | |
</dependency> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-core</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-codegen</artifactId> | |
<optional>true</optional> | |
</dependency> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-docgen</artifactId> | |
<optional>true</optional> | |
</dependency> | |
<!-- For tests and examples --> | |
<dependency> | |
<groupId>com.netflix.hystrix</groupId> | |
<artifactId>hystrix-core</artifactId> | |
<version>${hystrix.version}</version> | |
<scope>provided</scope> | |
<optional>true</optional> | |
</dependency> | |
<dependency> | |
<groupId>com.jayway.restassured</groupId> | |
<artifactId>rest-assured</artifactId> | |
<version>2.8.0</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.12</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.assertj</groupId> | |
<artifactId>assertj-core</artifactId> | |
<version>3.3.0</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.jayway.awaitility</groupId> | |
<artifactId>awaitility</artifactId> | |
<version>1.7.0</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>com.github.tomakehurst</groupId> | |
<artifactId>wiremock</artifactId> | |
<version>2.2.1</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>io.vertx</groupId> | |
<artifactId>vertx-unit</artifactId> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-jdk14</artifactId> | |
<version>1.7.30</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment