Search in sources :

Example 1 with RecoveryResult

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

the class RecoveryImplTest method testSyncPsvTransactionOnlySentOnce.

@Test
public void testSyncPsvTransactionOnlySentOnce() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    StagingTransaction anotherTx = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    when(anotherTx.getHash()).thenReturn("TXN2");
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    EncodedPayload encodedPayload2 = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(encodedPayload);
    when(version2.getEncodedPayload()).thenReturn(encodedPayload);
    when(anotherTx.getEncodedPayload()).thenReturn(encodedPayload2);
    when(version1.getPrivacyMode()).thenReturn(PrivacyMode.PRIVATE_STATE_VALIDATION);
    when(version2.getPrivacyMode()).thenReturn(PrivacyMode.PRIVATE_STATE_VALIDATION);
    when(anotherTx.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2, anotherTx));
    when(stagingEntityDAO.countAll()).thenReturn(3L);
    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).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 2 with RecoveryResult

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

the class RecoveryImplTest method testRequestFailed.

@Test
public void testRequestFailed() {
    when(transactionRequester.requestAllTransactionsFromNode(anyString())).thenReturn(false);
    when(transactionRequester.requestAllTransactionsFromLegacyNode(anyString())).thenReturn(false);
    final RecoveryResult result = recovery.request();
    assertThat(result).isEqualTo(RecoveryResult.FAILURE);
    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 3 with RecoveryResult

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

the class RecoveryImplTest method testStagingPartialSuccess.

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

Example 4 with RecoveryResult

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

the class RecoveryImplTest method testStagingSuccess.

@Test
public void testStagingSuccess() {
    // Staging loop run 3 times until there is no record left
    when(stagingEntityDAO.updateStageForBatch(anyInt(), eq(1L))).thenReturn(1);
    when(stagingEntityDAO.updateStageForBatch(anyInt(), eq(2L))).thenReturn(1);
    when(stagingEntityDAO.updateStageForBatch(anyInt(), eq(3L))).thenReturn(0);
    when(stagingEntityDAO.countAll()).thenReturn(2L);
    when(stagingEntityDAO.countStaged()).thenReturn(2L);
    RecoveryResult result = recovery.stage();
    assertThat(result).isEqualTo(RecoveryResult.SUCCESS);
    verify(stagingEntityDAO, times(3)).updateStageForBatch(anyInt(), anyLong());
    verify(stagingEntityDAO).countAll();
    verify(stagingEntityDAO).countStaged();
}
Also used : RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 5 with RecoveryResult

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

the class RecoveryImpl method recover.

@Override
public int recover() {
    try {
        if (stagingEntityDAO.countAll() != 0 || stagingEntityDAO.countAllAffected() != 0) {
            LOGGER.error("Staging tables are not empty. Please ensure database has been setup correctly for recovery process");
            return RecoveryResult.FAILURE.getCode();
        }
    } catch (Exception ex) {
        LOGGER.error("Attempt to query failed. Please ensure database has been setup correctly for recovery process");
        return RecoveryResult.FAILURE.getCode();
    }
    final long startTime = System.nanoTime();
    LOGGER.debug("Requesting transactions from other nodes");
    final RecoveryResult resendResult = request();
    final long resendFinished = System.nanoTime();
    LOGGER.debug("Perform staging of transactions");
    final RecoveryResult stageResult = stage();
    final long stagingFinished = System.nanoTime();
    LOGGER.debug("Perform synchronisation of transactions");
    final RecoveryResult syncResult = sync();
    final long syncFinished = System.nanoTime();
    LOGGER.info("Resend Stage: {} (duration = {} ms). Staging Stage: {} (duration = {} ms). Sync Stage: {} (duration = {} ms)", resendResult, (resendFinished - startTime) / 1000000, stageResult, (stagingFinished - resendFinished) / 1000000, syncResult, (syncFinished - stagingFinished) / 1000000);
    final long endTime = System.nanoTime();
    LOGGER.info("Recovery process took {} ms", (endTime - startTime) / 1000000);
    return Stream.of(resendResult, stageResult, syncResult).map(RecoveryResult::getCode).reduce(Integer::max).get();
}
Also used : PrivacyViolationException(com.quorum.tessera.transaction.exception.PrivacyViolationException) PersistenceException(jakarta.persistence.PersistenceException) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult)

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