use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class PartyInfoResourceTest method partyInfoGet.
@Test
public void partyInfoGet() {
final String partyInfoJson = "{\"url\":\"http://localhost:9001/\",\"peers\":[{\"url\":\"http://localhost:9006/\"},{\"url\":\"http://localhost:9005/\"}],\"keys\":[{\"key\":\"BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=\",\"url\":\"http://localhost:9001/\"},{\"key\":\"QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=\",\"url\":\"http://localhost:9002/\"}]}";
NodeInfo partyInfo = NodeInfo.Builder.create().withUrl("http://localhost:9001/").withRecipients(List.of(com.quorum.tessera.partyinfo.node.Recipient.of(PublicKey.from(Base64.getDecoder().decode("BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=")), "http://localhost:9001/"), com.quorum.tessera.partyinfo.node.Recipient.of(PublicKey.from(Base64.getDecoder().decode("QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=")), "http://localhost:9002/"))).build();
when(discovery.getCurrent()).thenReturn(partyInfo);
when(partyStore.getParties()).thenReturn(Set.of(URI.create("http://localhost:9006/"), URI.create("http://localhost:9005/")));
final Response response = partyInfoResource.getPartyInfo();
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
final String output = response.getEntity().toString();
final JsonReader expected = Json.createReader(new StringReader(partyInfoJson));
final JsonReader actual = Json.createReader(new StringReader(output));
JsonObject expectedJsonObject = expected.readObject();
JsonObject actualJsonObject = actual.readObject();
assertThat(actualJsonObject.getJsonArray("keys")).containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("keys"));
assertThat(actualJsonObject.getJsonArray("peers")).containsExactlyInAnyOrderElementsOf(expectedJsonObject.getJsonArray("peers"));
assertThat(actualJsonObject.getString("url")).isEqualTo(expectedJsonObject.getString("url"));
verify(discovery).getCurrent();
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class PartyInfoBroadcasterTest method testWhenURLIsOwn.
@Test
public void testWhenURLIsOwn() {
final NodeInfo partyInfo = NodeInfo.Builder.create().withUrl(OWN_URL).build();
when(partyStore.getParties()).thenReturn(Set.of(URI.create(OWN_URL)));
when(discovery.getCurrent()).thenReturn(partyInfo);
when(partyInfoParser.to(any(PartyInfo.class))).thenReturn(DATA);
when(p2pClient.sendPartyInfo(OWN_URL, DATA)).thenReturn(true);
partyInfoBroadcaster.run();
verify(partyStore).loadFromConfigIfEmpty();
verify(partyStore).getParties();
verify(partyInfoParser).to(any(PartyInfo.class));
verify(discovery).getCurrent();
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class PartyInfoBroadcasterTest method run.
@Test
public void run() {
final NodeInfo partyInfo = NodeInfo.Builder.create().withUrl(OWN_URL).build();
when(partyStore.getParties()).thenReturn(Set.of(URI.create(OWN_URL), URI.create(TARGET_URL)));
when(discovery.getCurrent()).thenReturn(partyInfo);
when(p2pClient.sendPartyInfo(TARGET_URL, DATA)).thenReturn(true);
partyInfoBroadcaster.run();
verify(partyStore).loadFromConfigIfEmpty();
verify(partyStore).getParties();
verify(discovery).getCurrent();
verify(partyInfoParser).to(any(PartyInfo.class));
verify(p2pClient).sendPartyInfo(TARGET_URL, DATA);
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class PartyInfoResource method getPartyInfo.
@Operation(summary = "/partyinfo", description = "fetch network/peer information")
@ApiResponse(responseCode = "200", description = "server's partyinfo data", content = @Content(schema = @Schema(implementation = GetPartyInfoResponse.class)))
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getPartyInfo() {
final NodeInfo current = this.discovery.getCurrent();
final JsonArrayBuilder peersBuilder = Json.createArrayBuilder();
partyStore.getParties().stream().map(party -> Json.createObjectBuilder().add("url", party.toString()).build()).forEach(peersBuilder::add);
final JsonArrayBuilder recipientBuilder = Json.createArrayBuilder();
current.getRecipients().stream().map(recipient -> Json.createObjectBuilder().add("key", recipient.getKey().encodeToBase64()).add("url", recipient.getUrl()).build()).forEach(recipientBuilder::add);
final String output = Json.createObjectBuilder().add("url", current.getUrl()).add("peers", peersBuilder.build()).add("keys", recipientBuilder.build()).build().toString();
LOGGER.debug("Sending json {} from {}", output, current);
return Response.status(Response.Status.OK).entity(output).build();
}
use of com.quorum.tessera.partyinfo.node.NodeInfo in project tessera by ConsenSys.
the class SyncPollerTest method localUrlIsExcludedFromPoll.
@Test
public void localUrlIsExcludedFromPoll() {
final String targetUrl = "localurl.com";
final String syncableUrl = "syncable.com";
final com.quorum.tessera.partyinfo.node.Recipient localKey = com.quorum.tessera.partyinfo.node.Recipient.of(mock(PublicKey.class), targetUrl);
final com.quorum.tessera.partyinfo.node.Recipient anotherKey = com.quorum.tessera.partyinfo.node.Recipient.of(mock(PublicKey.class), syncableUrl);
final Party syncableParty = new Party(syncableUrl);
final Set<Recipient> recipients = Set.of(localKey, anotherKey);
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("localurl.com").withRecipients(recipients).build();
// partyStore.store(URI.create(syncableUrl));
when(partyInfoService.getCurrent()).thenReturn(nodeInfo);
doReturn(Optional.empty()).when(resendPartyStore).getNextParty();
syncPoller.run();
verify(resendPartyStore, times(1)).addUnseenParties(Set.of(syncableParty));
verify(resendPartyStore, times(1)).getNextParty();
}
Aggregations