-
Couldn't load subscription status.
- Fork 30
[ECR-2906] LC: Implemented System API endpoints support #716
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
Changes from 6 commits
0ebdd95
7b33137
7c6d080
c5fd9f6
80334bc
411a1a6
c7746a4
0aae6e6
e0db8ff
688f924
a97222c
e4a4969
515bc2c
6d819b2
8ab36f1
0e5dc5c
826c351
809be09
6562719
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 |
|---|---|---|
|
|
@@ -40,6 +40,29 @@ public interface ExonumClient { | |
| */ | ||
| HashCode submitTransaction(TransactionMessage tx); | ||
|
|
||
| /** | ||
| * Returns a number of unconfirmed transactions those are currently located in | ||
| * the memory pool and are waiting for acceptance to a block. | ||
|
||
| * @throws RuntimeException if the client is unable to complete a request | ||
| * (e.g., in case of connectivity problems) | ||
| */ | ||
| int getUnconfirmedTransactions(); | ||
|
||
|
|
||
| /** | ||
| * Returns <b>true</b> if the node is connected to the other peers. | ||
|
||
| * And <b>false</b> otherwise. | ||
|
||
| * @throws RuntimeException if the client is unable to complete a request | ||
bullet-tooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * (e.g., in case of connectivity problems) | ||
| */ | ||
| boolean healthCheck(); | ||
|
||
|
|
||
| /** | ||
| * Returns string containing information about Exonum, Rust and OS version. | ||
| * @throws RuntimeException if the client is unable to complete a request | ||
| * (e.g., in case of connectivity problems) | ||
| */ | ||
| String getUserAgentInfo(); | ||
bullet-tooth marked this conversation as resolved.
Show resolved
Hide resolved
bullet-tooth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Returns Exonum client builder. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright 2019 The Exonum Team | ||
| * | ||
| * 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.exonum.client; | ||
|
|
||
| import com.google.common.base.MoreObjects; | ||
|
|
||
| /** | ||
| * Json object wrapper for health check response. | ||
| */ | ||
| class HealthCheckResponse { | ||
| boolean connectivity; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
bullet-tooth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return MoreObjects.toStringHelper(this) | ||
| .add("connectivity", connectivity) | ||
| .toString(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright 2019 The Exonum Team | ||
| * | ||
| * 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.exonum.client; | ||
|
|
||
| import com.google.common.base.MoreObjects; | ||
|
|
||
| /** | ||
| * Json object wrapper for memory pool response. | ||
| */ | ||
| class MemoryPoolResponse { | ||
| int size; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return MoreObjects.toStringHelper(this) | ||
| .add("size", size) | ||
| .toString(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,10 @@ | |
| import static com.exonum.binding.common.crypto.CryptoFunctions.ed25519; | ||
| import static com.exonum.binding.common.serialization.json.JsonSerializer.json; | ||
| import static com.exonum.client.ExonumHttpClient.HEX_ENCODER; | ||
| import static com.exonum.client.ExonumUrls.HEALTH_CHECK; | ||
| import static com.exonum.client.ExonumUrls.MEMORY_POOL; | ||
| import static com.exonum.client.ExonumUrls.SUBMIT_TRANSACTION; | ||
| import static com.exonum.client.ExonumUrls.USER_AGENT; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
|
|
@@ -89,4 +92,59 @@ void submitTransactionTest() throws InterruptedException { | |
| assertThat(actualTxMessage, is(txMessage)); | ||
| } | ||
|
|
||
| @Test | ||
| void getUnconfirmedTransactions() throws InterruptedException { | ||
| // Mock response | ||
| int mockCount = 10; | ||
| String mockResponse = "{\"size\": " + mockCount + " }"; | ||
| server.enqueue(new MockResponse().setBody(mockResponse)); | ||
|
|
||
| // Call | ||
| int actualCount = exonumClient.getUnconfirmedTransactions(); | ||
|
|
||
| // Assert response | ||
| assertThat(actualCount, is(mockCount)); | ||
|
|
||
| // Assert request params | ||
| RecordedRequest recordedRequest = server.takeRequest(); | ||
| assertThat(recordedRequest.getMethod(), is("GET")); | ||
| assertThat(recordedRequest.getPath(), is(MEMORY_POOL)); | ||
| } | ||
|
|
||
| @Test | ||
| void healthCheck() throws InterruptedException { | ||
| // Mock response | ||
| boolean mockConnectivity = true; | ||
| String mockResponse = "{\"connectivity\": " + mockConnectivity + " }"; | ||
| server.enqueue(new MockResponse().setBody(mockResponse)); | ||
|
|
||
| // Call | ||
| boolean actualConnectivity = exonumClient.healthCheck(); | ||
|
|
||
| // Assert response | ||
| assertThat(actualConnectivity, is(mockConnectivity)); | ||
|
|
||
| // Assert request params | ||
| RecordedRequest recordedRequest = server.takeRequest(); | ||
| assertThat(recordedRequest.getMethod(), is("GET")); | ||
| assertThat(recordedRequest.getPath(), is(HEALTH_CHECK)); | ||
| } | ||
|
|
||
| @Test | ||
| void getUserAgentInfo() throws InterruptedException { | ||
| // Mock response | ||
| String mockResponse = "exonum 0.6.0/rustc 1.26.0 (2789b067d 2018-03-06)\n\n/Mac OS10.13.3"; | ||
|
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. I see — a String will do 🙃 |
||
| server.enqueue(new MockResponse().setBody(mockResponse)); | ||
|
|
||
| // Call | ||
| String actualResponse = exonumClient.getUserAgentInfo(); | ||
|
|
||
| // Assert response | ||
| assertThat(actualResponse, is(mockResponse)); | ||
|
|
||
| // Assert request params | ||
| RecordedRequest recordedRequest = server.takeRequest(); | ||
| assertThat(recordedRequest.getMethod(), is("GET")); | ||
| assertThat(recordedRequest.getPath(), is(USER_AGENT)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that/which are currently …