-
Notifications
You must be signed in to change notification settings - Fork 130
PAN-2723: Added static nodes acceptance test #1745
Changes from all 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,44 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* 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 tech.pegasys.pantheon.tests.acceptance; | ||
|
||
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class StaticNodesAcceptanceTest extends AcceptanceTestBase { | ||
|
||
private Node otherNode; | ||
private Node node; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
otherNode = pantheon.createNodeWithNoDiscovery("other-node"); | ||
cluster.start(otherNode); | ||
} | ||
|
||
@Test | ||
public void shouldConnectToNodeAddedAsStaticNode() throws Exception { | ||
node = pantheon.createNodeWithStaticNodes("node", Arrays.asList(otherNode)); | ||
cluster.addNode(node); | ||
|
||
node.verify(net.awaitPeerCount(1)); | ||
|
||
WaitUtils.waitFor(1000000, () -> {}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* 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 tech.pegasys.pantheon.tests.acceptance.dsl; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class StaticNodesUtils { | ||
|
||
public static Path createStaticNodesFile(final Path directory, final List<String> staticNodes) { | ||
try { | ||
final Path tempFile = Files.createTempFile(directory, "", ""); | ||
tempFile.toFile().deleteOnExit(); | ||
|
||
final Path staticNodesFile = tempFile.getParent().resolve("static-nodes.json"); | ||
Files.move(tempFile, staticNodesFile); | ||
staticNodesFile.toFile().deleteOnExit(); | ||
|
||
final String json = | ||
staticNodes.stream() | ||
.map(s -> String.format("\"%s\"", s)) | ||
.collect(Collectors.joining(",", "[", "]")); | ||
Files.write(staticNodesFile, json.getBytes(UTF_8)); | ||
|
||
return staticNodesFile; | ||
} catch (final IOException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,14 +94,14 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea | |
private final boolean discoveryEnabled; | ||
private final List<URI> bootnodes = new ArrayList<>(); | ||
private final boolean bootnodeEligible; | ||
|
||
private Optional<String> genesisConfig = Optional.empty(); | ||
private NodeRequests nodeRequests; | ||
private LoginRequestFactory loginRequestFactory; | ||
private boolean useWsForJsonRpc = false; | ||
private String token = null; | ||
private final List<String> plugins = new ArrayList<>(); | ||
private final List<String> extraCLIOptions; | ||
private final List<String> staticNodes; | ||
|
||
public PantheonNode( | ||
final String name, | ||
|
@@ -120,7 +120,8 @@ public PantheonNode( | |
final boolean bootnodeEligible, | ||
final boolean revertReasonEnabled, | ||
final List<String> plugins, | ||
final List<String> extraCLIOptions) | ||
final List<String> extraCLIOptions, | ||
final List<String> staticNodes) | ||
throws IOException { | ||
this.bootnodeEligible = bootnodeEligible; | ||
this.revertReasonEnabled = revertReasonEnabled; | ||
|
@@ -159,6 +160,7 @@ public PantheonNode( | |
} | ||
}); | ||
this.extraCLIOptions = extraCLIOptions; | ||
this.staticNodes = staticNodes; | ||
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. should we check for null staticNodes and assign a new one? |
||
LOG.info("Created PantheonNode {}", this.toString()); | ||
} | ||
|
||
|
@@ -529,6 +531,15 @@ public boolean isRevertReasonEnabled() { | |
return revertReasonEnabled; | ||
} | ||
|
||
@Override | ||
public List<String> getStaticNodes() { | ||
return staticNodes; | ||
} | ||
|
||
public boolean hasStaticNodes() { | ||
return staticNodes != null && !staticNodes.isEmpty(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,10 @@ public void startNode(final PantheonNode node) { | |
.metricsConfiguration(node.metricsConfiguration()) | ||
.p2pEnabled(node.isP2pEnabled()) | ||
.graphQLConfiguration(GraphQLConfiguration.createDefault()) | ||
.staticNodes( | ||
node.getStaticNodes().stream() | ||
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 has a potential of NPE unless we make sure getStaticNodes will never return null. 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. We always initialize it in |
||
.map(EnodeURL::fromString) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
|
||
runner.start(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ public class PantheonFactoryConfigurationBuilder { | |
private boolean revertReasonEnabled = false; | ||
private List<String> plugins = new ArrayList<>(); | ||
private List<String> extraCLIOptions = new ArrayList<>(); | ||
private List<String> staticNodes = new ArrayList<>(); | ||
|
||
public PantheonFactoryConfigurationBuilder() { | ||
// Check connections more frequently during acceptance tests to cut down on | ||
|
@@ -193,6 +194,11 @@ public PantheonFactoryConfigurationBuilder revertReasonEnabled() { | |
return this; | ||
} | ||
|
||
public PantheonFactoryConfigurationBuilder staticNodes(final List<String> staticNodes) { | ||
this.staticNodes = staticNodes; | ||
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. null check? |
||
return this; | ||
} | ||
|
||
public PantheonFactoryConfiguration build() { | ||
return new PantheonFactoryConfiguration( | ||
name, | ||
|
@@ -211,6 +217,7 @@ public PantheonFactoryConfiguration build() { | |
bootnodeEligible, | ||
revertReasonEnabled, | ||
plugins, | ||
extraCLIOptions); | ||
extraCLIOptions, | ||
staticNodes); | ||
} | ||
} |
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.
can we override the file name "static-nodes.json" later on at Pantheon CLI? if we can, then we can avoid the
Files.move
.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.
The other option is to use Files.createTempDirectory(directory, ...) and then create static-nodes.json in it ...
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.
The name is hardcoded to
static-nodes.json
. The reason I'm not creating a temp directory is 'cause we already have the node home directory to use (that's where the static-nodes.json) file should be.I'll take a look and see if I can optimize this in my following PR.