Search in sources :

Example 6 with RecoveryResult

use of com.quorum.tessera.recovery.RecoveryResult in project tessera by ConsenSys.

the class RecoveryImplTest method testRequestPartialSuccess.

@Test
public void testRequestPartialSuccess() {
    when(transactionRequester.requestAllTransactionsFromLegacyNode(eq("http://party2"))).thenReturn(false);
    final RecoveryResult result = recovery.request();
    assertThat(result).isEqualTo(RecoveryResult.PARTIAL_SUCCESS);
    verify(transactionRequester, times(2)).requestAllTransactionsFromNode(anyString());
    verify(transactionRequester, times(2)).requestAllTransactionsFromLegacyNode(anyString());
    verify(discovery).getRemoteNodeInfos();
}
Also used : RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 7 with RecoveryResult

use of com.quorum.tessera.recovery.RecoveryResult in project tessera by ConsenSys.

the class RecoveryImplTest method testStagingFailed.

@Test
public void testStagingFailed() {
    when(stagingEntityDAO.updateStageForBatch(anyInt(), anyLong())).thenReturn(0);
    when(stagingEntityDAO.countAll()).thenReturn(2L);
    when(stagingEntityDAO.countStaged()).thenReturn(0L);
    RecoveryResult result = recovery.stage();
    assertThat(result).isEqualTo(RecoveryResult.FAILURE);
    verify(stagingEntityDAO).updateStageForBatch(anyInt(), anyLong());
    verify(stagingEntityDAO).countAll();
    verify(stagingEntityDAO).countStaged();
}
Also used : RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 8 with RecoveryResult

use of com.quorum.tessera.recovery.RecoveryResult in project tessera by ConsenSys.

the class RecoveryImplTest method testSyncPartialSuccess.

@Test
public void testSyncPartialSuccess() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2));
    when(stagingEntityDAO.countAll()).thenReturn(2L);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    EncodedPayload encodedPayload2 = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(encodedPayload);
    when(version2.getEncodedPayload()).thenReturn(encodedPayload2);
    when(transactionManager.storePayload(encodedPayload)).thenThrow(PrivacyViolationException.class);
    RecoveryResult result = recovery.sync();
    assertThat(result).isEqualTo(RecoveryResult.PARTIAL_SUCCESS);
    verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
    verify(stagingEntityDAO, times(2)).countAll();
    verify(transactionManager).storePayload(encodedPayload);
    verify(transactionManager).storePayload(encodedPayload2);
}
Also used : StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 9 with RecoveryResult

use of com.quorum.tessera.recovery.RecoveryResult in project tessera by ConsenSys.

the class RecoveryImplTest method testSyncFailed.

@Test
public void testSyncFailed() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    EncodedPayload encodedPayload2 = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(encodedPayload);
    when(version2.getEncodedPayload()).thenReturn(encodedPayload2);
    List<StagingTransaction> stagingTransactions = List.of(version1, version2);
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(stagingTransactions);
    when(stagingEntityDAO.countAll()).thenReturn((long) stagingTransactions.size());
    when(transactionManager.storePayload(any())).thenThrow(PrivacyViolationException.class);
    RecoveryResult result = recovery.sync();
    assertThat(result).isEqualTo(RecoveryResult.FAILURE);
    verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
    verify(stagingEntityDAO, times(2)).countAll();
    verify(transactionManager, times(2)).storePayload(any());
}
Also used : StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 10 with RecoveryResult

use of com.quorum.tessera.recovery.RecoveryResult in project tessera by ConsenSys.

the class RecoveryImplTest method testSyncSuccess.

@Test
public void testSyncSuccess() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    EncodedPayload firstPayload = mock(EncodedPayload.class);
    EncodedPayload secondPayload = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(firstPayload);
    when(version2.getEncodedPayload()).thenReturn(secondPayload);
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2));
    when(stagingEntityDAO.countAll()).thenReturn(2L);
    when(transactionManager.storePayload(any())).thenReturn(new MessageHash("hash".getBytes()));
    RecoveryResult result = recovery.sync();
    assertThat(result).isEqualTo(RecoveryResult.SUCCESS);
    verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
    verify(stagingEntityDAO, times(2)).countAll();
    verify(transactionManager).storePayload(firstPayload);
    verify(transactionManager).storePayload(secondPayload);
}
Also used : StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Aggregations

RecoveryResult (com.quorum.tessera.recovery.RecoveryResult)11 Test (org.junit.Test)10 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)4 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)4 MessageHash (com.quorum.tessera.data.MessageHash)1 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)1 PersistenceException (jakarta.persistence.PersistenceException)1