Search in sources :

Example 6 with Party

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();
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) Test(org.junit.Test)

Example 7 with Party

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();
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) Test(org.junit.Test)

Example 8 with Party

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);
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) Recipient(com.quorum.tessera.partyinfo.model.Recipient) ByteBuffer(java.nio.ByteBuffer) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) HashSet(java.util.HashSet)

Example 9 with Party

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"));
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) Recipient(com.quorum.tessera.partyinfo.model.Recipient) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Test(org.junit.Test)

Example 10 with Party

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);
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) Test(org.junit.Test)

Aggregations

Party (com.quorum.tessera.partyinfo.model.Party)17 Test (org.junit.Test)13 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)7 Recipient (com.quorum.tessera.partyinfo.model.Recipient)5 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)5 PublicKey (com.quorum.tessera.encryption.PublicKey)4 Discovery (com.quorum.tessera.discovery.Discovery)3 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)3 Entity (jakarta.ws.rs.client.Entity)3 Response (jakarta.ws.rs.core.Response)3 NodeUri (com.quorum.tessera.discovery.NodeUri)2 com.quorum.tessera.enclave (com.quorum.tessera.enclave)2 GetPartyInfoResponse (com.quorum.tessera.p2p.model.GetPartyInfoResponse)2 PartyStore (com.quorum.tessera.p2p.partyinfo.PartyStore)2 NodeInfoUtil (com.quorum.tessera.partyinfo.model.NodeInfoUtil)2 Constants (com.quorum.tessera.shared.Constants)2 Operation (io.swagger.v3.oas.annotations.Operation)2 Parameter (io.swagger.v3.oas.annotations.Parameter)2 ArraySchema (io.swagger.v3.oas.annotations.media.ArraySchema)2 Content (io.swagger.v3.oas.annotations.media.Content)2