-
Notifications
You must be signed in to change notification settings - Fork 88
Upgrade to Spring Boot 2.0.4 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.web3j.spring.actuate; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; | ||
| import org.springframework.boot.actuate.endpoint.web.annotation.EndpointWebExtension; | ||
| import org.springframework.boot.actuate.health.Health; | ||
| import org.springframework.boot.actuate.health.Health.Builder; | ||
| import org.springframework.boot.actuate.health.HealthEndpoint; | ||
| import org.springframework.util.Assert; | ||
| import org.web3j.protocol.Web3j; | ||
| import org.web3j.protocol.core.methods.response.EthBlockNumber; | ||
| import org.web3j.protocol.core.methods.response.EthProtocolVersion; | ||
| import org.web3j.protocol.core.methods.response.NetPeerCount; | ||
| import org.web3j.protocol.core.methods.response.NetVersion; | ||
| import org.web3j.protocol.core.methods.response.Web3ClientVersion; | ||
|
|
||
| /** | ||
| * Health endpoint extension for Web3j | ||
| */ | ||
|
|
||
| @EndpointWebExtension(endpoint = HealthEndpoint.class) | ||
| public class Web3jHealthEndpointWebExtension { | ||
|
|
||
| private Web3j web3j; | ||
|
|
||
| public Web3jHealthEndpointWebExtension(Web3j web3j) { | ||
| Assert.notNull(web3j, "Web3j must not be null"); | ||
| this.web3j = web3j; | ||
| } | ||
|
|
||
| @ReadOperation | ||
| public Health health() { | ||
| Builder builder = Health.up(); | ||
|
|
||
| try { | ||
| boolean listening = web3j.netListening().send().isListening(); | ||
| if (!listening) { | ||
| builder = builder.down(); | ||
| } else { | ||
| CompletableFuture<NetVersion> netVersion = web3j.netVersion().sendAsync(); | ||
| CompletableFuture<Web3ClientVersion> clientVersion = web3j.web3ClientVersion().sendAsync(); | ||
| CompletableFuture<EthBlockNumber> ethBlockNumber = web3j.ethBlockNumber().sendAsync(); | ||
| CompletableFuture<EthProtocolVersion> ethProtocolVersion = web3j.ethProtocolVersion().sendAsync(); | ||
| CompletableFuture<NetPeerCount> netPeerCount = web3j.netPeerCount().sendAsync(); | ||
| CompletableFuture.allOf(netVersion, clientVersion, ethBlockNumber, ethProtocolVersion, netPeerCount) | ||
| .join(); | ||
|
|
||
| builder.withDetail("netVersion", netVersion.get().getNetVersion()); | ||
| builder.withDetail("clientVersion", clientVersion.get().getWeb3ClientVersion()); | ||
| builder.withDetail("blockNumber", ethBlockNumber.get().getBlockNumber()); | ||
| builder.withDetail("protocolVersion", ethProtocolVersion.get().getProtocolVersion()); | ||
| builder.withDetail("netPeerCount", netPeerCount.get().getQuantity()); | ||
| } | ||
| } catch (Exception e) { | ||
| builder = builder.down(e); | ||
| } | ||
|
|
||
| return builder.build(); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| package org.web3j.spring.autoconfigure; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.startsWith; | ||
| import static org.hamcrest.core.IsEqual.equalTo; | ||
| import static org.junit.Assert.assertThat; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.reflect.Field; | ||
| import java.nio.file.Files; | ||
|
|
@@ -9,24 +15,17 @@ | |
| import org.junit.Test; | ||
| import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
| import org.springframework.boot.actuate.health.Health; | ||
| import org.springframework.boot.actuate.health.HealthIndicator; | ||
| import org.springframework.boot.actuate.health.Status; | ||
| import org.springframework.boot.test.util.EnvironmentTestUtils; | ||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import org.web3j.protocol.Service; | ||
| import org.web3j.protocol.Web3j; | ||
| import org.web3j.protocol.Web3jService; | ||
| import org.web3j.protocol.admin.Admin; | ||
| import org.web3j.protocol.core.JsonRpc2_0Web3j; | ||
| import org.web3j.protocol.http.HttpService; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.startsWith; | ||
| import static org.hamcrest.core.IsEqual.equalTo; | ||
| import static org.junit.Assert.assertThat; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
| import org.web3j.spring.actuate.Web3jHealthEndpointWebExtension; | ||
|
|
||
| public class Web3jAutoConfigurationTest { | ||
|
|
||
|
|
@@ -98,8 +97,8 @@ public void testNoAdminClient() { | |
| public void testHealthCheckIndicatorDown() { | ||
| load(EmptyConfiguration.class, "web3j.client-address="); | ||
|
|
||
| HealthIndicator web3jHealthIndicator = this.context.getBean(HealthIndicator.class); | ||
| Health health = web3jHealthIndicator.health(); | ||
| Web3jHealthEndpointWebExtension healthEndpoint = this.context.getBean(Web3jHealthEndpointWebExtension.class); | ||
| Health health = healthEndpoint.health(); | ||
| assertThat(health.getStatus(), equalTo(Status.DOWN)); | ||
| assertThat(health.getDetails().get("error").toString(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails, the error being returned is "org.web3j.exceptions.MessageDecodingException: Value must be in format 0x[1-9]+[0-9]* or 0x0".
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me all tests are green. Could you post the full stacktrace of the exception?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests seem to work for me, could it be a conflict in your env? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests work fine, I had an instance of Test-RPC running on port 8545. |
||
| startsWith("java.net.ConnectException: Failed to connect to localhost/")); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.