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();
}
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();
}
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);
}
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());
}
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);
}
Aggregations