Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2577] Integration Integration test(s) on p2p of 'net_services' #1402

Merged
merged 38 commits into from
May 17, 2019

Conversation

smatthewenglish
Copy link
Contributor

@smatthewenglish smatthewenglish commented May 6, 2019

PR description

An acceptance tests for PAN‌-2577.

Fixed Issue(s)

Ensures the proper performance of the net_services endpoint.

@smatthewenglish smatthewenglish added the work in progress Work on this pull request is ongoing label May 6, 2019
@smatthewenglish smatthewenglish force-pushed the net_services branch 3 times, most recently from 9f7e06d to f8e6392 Compare May 6, 2019 10:17
@shemnon
Copy link
Contributor

shemnon commented May 6, 2019

To answer the question in the PR description, that is exactly what we are trying to fix. There was a unit tests that mocked things up differently that passed at a unit level. What we need is a non-mocked test where pantheon is stood up and we see all the ports we opened in net_services.

We need a test that fails against revision d5dd1d4e but passes after revision 105dc5b5

@smatthewenglish smatthewenglish force-pushed the net_services branch 8 times, most recently from e41902e to 64efbdc Compare May 13, 2019 11:15
@smatthewenglish smatthewenglish removed the work in progress Work on this pull request is ongoing label May 13, 2019
assertThat(expectation.get("jsonrpc").get("port")).isEqualTo(result.get("jsonrpc").get("port"));
assertThat(expectation.get("ws").get("host")).isEqualTo(result.get("ws").get("host"));
assertThat(expectation.get("ws").get("port")).isEqualTo(result.get("ws").get("port"));
assertThat(expectation.get("p2p").get("host")).isEqualTo(result.get("p2p").get("host"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not checking the p2p port value here

expectation.put("jsonrpc", constituentMap);
expectation.put("ws", constituentMap);
expectation.put("p2p", constituentMap);
assertThat(expectation.get("jsonrpc").get("host")).isEqualTo(result.get("jsonrpc").get("host"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format of assertThat should be: assertThat(actual).isEqualTo(expected) - these checks should be reformatted.

}

@Test
public void adminAddPeerForcesConnection() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be renamed

new HashMap() {
{
put("host", "127.0.0.1");
put("port", "0");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expecting a port of "0" for everything is a little confusing. Can you explicitly configure the json-rpc and ws ports to distinct values?

noDiscoveryCluster.start(nodeA, nodeB);
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case where all net services (json-rpc, ws, and p2p) are disabled?

}
return (netServicesResponse != null ? netServicesResponse.getResult() : null) != null
? netServicesResponse.getResult()
: null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've got an extra ternary operator here 😄

@@ -68,6 +71,10 @@ public AdminJsonRpcRequestFactory admin() {
return admin;
}

public NetServicesJsonRpcRequestFactory netServices() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about renaming NetServicesJsonRpcRequestFactory to something like CustomNetJsonRpcRequestFactory. Then if we end up expanding the "net_" api in the future, we can add more methods to this factory. Then this method would become customNet().

public Request<?, NetServicesResponse> netServices() {

return new Request<>(
"net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class);
"net_services", Collections.emptyList(), web3jService, NetServicesResponse.class);

If you use emptyList() here, you can remove the annotation @SuppressWarnings({"unchecked", "rawtypes"})

Request<?, NetServicesJsonRpcRequestFactory.NetServicesResponse> request =
netServicesJsonRpcRequestFactory.netServices();
netServicesResponse = request.send();
} catch (final Exception ignored) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't ignore an exception here, you should throw.

netServicesResponse = request.send();
} catch (final Exception ignored) {
}
return netServicesResponse != null ? netServicesResponse.getResult() : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to check for null. Just move the return statement into the try block and throw the exception instead of ignoring it and you can return getResult() directly.

final ClusterConfiguration clusterConfiguration =
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build();
noDiscoveryCluster = new Cluster(clusterConfiguration, net);
nodeA = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeA");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a utility for creating a node with all net services turned on?

nodeB = pantheon.createArchiveNodeNetServicesDisabled("nodeB");
noDiscoveryCluster.start(nodeA, nodeB);

nodeA.verify(net.netServicesNotActive());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could create a generic method that can be configured with expected services: net.netServices(List<String> expectedServices)

@smatthewenglish smatthewenglish force-pushed the net_services branch 3 times, most recently from 2aa359d to e71f7ab Compare May 16, 2019 22:46
CustomNetJsonRpcRequestFactory.NetServicesResponse netServicesResponse = request.send();
netServicesActive = netServicesResponse.getResult();
} catch (final Exception e) {
LOG.error("Error parsing response to 'net_services' json-rpc request.", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw, not log an error

Suggested change
LOG.error("Error parsing response to 'net_services' json-rpc request.", e);
throw new RuntimeException(e);

} catch (final Exception e) {
LOG.error("Error parsing response to 'net_services' json-rpc request.", e);
}
return netServicesActive;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the catch rethrows, you don't need this extra return statement

assertThat(NetworkUtility.isValidPort(p2pPort) || jsonRpcPort == 0).isTrue();
}

public static class ExpectNetServicesReturnsNoServicesAsActiveX implements Condition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static class ExpectNetServicesReturnsNoServicesAsActiveX implements Condition {
public static class ExpectNetServicesReturnsOnlyJsonRpcActive implements Condition {

assertThat(NetworkUtility.isValidPort(p2pPort) || jsonRpcPort == 0).isTrue();
}

public static class ExpectNetServicesReturnsNoServicesAsActiveX implements Condition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this an independent class in a separate file rather than an internal class?

@@ -68,6 +71,10 @@ public AdminJsonRpcRequestFactory admin() {
return admin;
}

public CustomNetJsonRpcRequestFactory netServices() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the naming for CustomNetJsonRpcRequestFactory-related variables and methods consistent? So this would be: customNet()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name still needs to be updated

this.web3jService = web3jService;
}

public Request<?, NetServicesResponse> customNet() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Request<?, NetServicesResponse> customNet() {
public Request<?, NetServicesResponse> netServices() {

@@ -34,13 +35,15 @@ public JsonRequestFactories(
final PermissioningJsonRpcRequestFactory perm,
final AdminJsonRpcRequestFactory admin,
final EeaJsonRpcRequestFactory eea,
final CustomNetJsonRpcRequestFactory netServices,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final CustomNetJsonRpcRequestFactory netServices,
final CustomNetJsonRpcRequestFactory customNet,

@@ -25,6 +25,7 @@
private final PermissioningJsonRpcRequestFactory perm;
private final AdminJsonRpcRequestFactory admin;
private final EeaJsonRpcRequestFactory eea;
private final CustomNetJsonRpcRequestFactory netServices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private final CustomNetJsonRpcRequestFactory netServices;
private final CustomNetJsonRpcRequestFactory customNet;

Copy link
Contributor

@mbaxter mbaxter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed one method name update, but otherwise looks good! Please update before merging.

@@ -68,6 +71,10 @@ public AdminJsonRpcRequestFactory admin() {
return admin;
}

public CustomNetJsonRpcRequestFactory netServices() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name still needs to be updated

@smatthewenglish smatthewenglish merged commit 8b26d3a into PegaSysEng:master May 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants