use of com.quorum.tessera.partyinfo.model.Party in project tessera by ConsenSys.
the class SyncPollerTest method singlePartyTaskFailsAndNotifiesStore.
@Test
public void singlePartyTaskFailsAndNotifiesStore() {
final String targetUrl = "fakeurl.com";
final SyncableParty syncableParty = new SyncableParty(new Party(targetUrl), 0);
doReturn(false).when(transactionRequester).requestAllTransactionsFromNode(targetUrl);
doReturn(Optional.of(syncableParty), Optional.empty()).when(resendPartyStore).getNextParty();
syncPoller.run();
final ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
verify(executorService).submit(captor.capture());
verify(resendPartyStore, times(2)).getNextParty();
final Runnable task = captor.getValue();
task.run();
verify(transactionRequester).requestAllTransactionsFromNode(targetUrl);
verify(resendPartyStore).incrementFailedAttempt(syncableParty);
verify(resendPartyStore).addUnseenParties(emptySet());
verify(partyInfoService, times(2)).getCurrent();
}
use of com.quorum.tessera.partyinfo.model.Party in project tessera by ConsenSys.
the class SyncPollerTest method singlePartyTaskUpdatePartyInfoThrowsAndNotifiesStore.
@Test
public void singlePartyTaskUpdatePartyInfoThrowsAndNotifiesStore() {
final String targetUrl = "fakeurl.com";
final SyncableParty syncableParty = new SyncableParty(new Party(targetUrl), 0);
doThrow(new RuntimeException("Unable to connect")).when(p2pClient).sendPartyInfo(anyString(), any());
doReturn(Optional.of(syncableParty), Optional.empty()).when(resendPartyStore).getNextParty();
syncPoller.run();
final ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
verify(executorService).submit(captor.capture());
verify(resendPartyStore, times(2)).getNextParty();
final Runnable task = captor.getValue();
task.run();
verify(transactionRequester, times(0)).requestAllTransactionsFromNode(targetUrl);
verify(resendPartyStore).incrementFailedAttempt(syncableParty);
verify(resendPartyStore).addUnseenParties(emptySet());
verify(partyInfoService, times(2)).getCurrent();
}
use of com.quorum.tessera.partyinfo.model.Party in project tessera by ConsenSys.
the class PartyInfoParser method from.
/**
* Decodes a set of PartyInfo to the format that is shared between nodes
*
* @param encoded the encoded information that needs to be read
* @return the decoded {@link PartyInfo} which contains the other nodes information
*/
default PartyInfo from(final byte[] encoded) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(encoded);
final int urlLength = toIntExact(byteBuffer.getLong());
checkLength(urlLength);
final byte[] urlBytes = new byte[urlLength];
byteBuffer.get(urlBytes);
final String url = new String(urlBytes, UTF_8);
final int numberOfRecipients = toIntExact(byteBuffer.getLong());
checkLength(numberOfRecipients);
final Set<Recipient> recipients = new HashSet<>();
for (int i = 0; i < numberOfRecipients; i++) {
final int recipientKeyLength = toIntExact(byteBuffer.getLong());
checkLength(recipientKeyLength);
final byte[] recipientKeyBytes = new byte[recipientKeyLength];
byteBuffer.get(recipientKeyBytes);
final int recipientUrlValueLength = toIntExact(byteBuffer.getLong());
checkLength(recipientUrlValueLength);
final byte[] urlValueData = new byte[recipientUrlValueLength];
byteBuffer.get(urlValueData);
final String recipientUrl = new String(urlValueData, UTF_8);
recipients.add(Recipient.of(PublicKey.from(recipientKeyBytes), recipientUrl));
}
final int partyCount = toIntExact(byteBuffer.getLong());
checkLength(partyCount);
final Set<Party> parties = new HashSet<>();
for (int i = 0; i < partyCount; i++) {
long partyElementLength = byteBuffer.getLong();
checkLength(partyElementLength);
byte[] ptyData = new byte[toIntExact(partyElementLength)];
byteBuffer.get(ptyData);
parties.add(new Party(new String(ptyData, UTF_8)));
}
return new PartyInfo(url, recipients, parties);
}
use of com.quorum.tessera.partyinfo.model.Party in project tessera by ConsenSys.
the class PartyInfoParserTest method from.
@Test
public void from() {
PartyInfo result = partyInfoParser.from(dataOne);
assertThat(result).isNotNull();
assertThat(result.getUrl()).isEqualTo("http://localhost:8000");
assertThat(result.getRecipients()).hasSize(1);
final Recipient recipient = result.getRecipients().iterator().next();
assertThat(recipient.getUrl()).isEqualTo("http://localhost:8001");
assertThat(recipient.getKey()).isNotNull();
assertThat(result.getParties()).hasSize(1);
assertThat(result.getParties()).containsExactly(new Party("http://localhost:8001"));
}
use of com.quorum.tessera.partyinfo.model.Party in project tessera by ConsenSys.
the class ResendPartyStoreTest method failedRequestMakesPartyAvailableForUseIfBelowThreeshold.
@Test
public void failedRequestMakesPartyAvailableForUseIfBelowThreeshold() {
final int presetAttempts = 10;
final Party party = new Party("badurl.com");
final SyncableParty failedReq = new SyncableParty(party, presetAttempts);
this.resendPartyStore.incrementFailedAttempt(failedReq);
final Optional<SyncableParty> partyOne = resendPartyStore.getNextParty();
assertThat(partyOne).isPresent();
assertThat(partyOne.get().getParty()).isEqualTo(party);
assertThat(partyOne.get().getAttempts()).isEqualTo(presetAttempts + 1);
}
Aggregations