mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
[TESTS] Allow remove() verification to be more flexible
Now that we have introduced remove-before-add, we need a way to validate that the SequenceNumberMap was written, but nothing else. Add this feature to the validation path.
This commit is contained in:
parent
372c26de74
commit
931c1f47b4
@ -188,7 +188,7 @@ public class P2PDataStorageClientAPITest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry);
|
||||
Assert.assertFalse(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress(), true));
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, false, true, true, true);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, false, false, false, true, true);
|
||||
}
|
||||
|
||||
// TESTCASE: Adding, then removing a mailbox message from the getMailboxDataWithSignedSeqNr API
|
||||
@ -210,7 +210,7 @@ public class P2PDataStorageClientAPITest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry);
|
||||
Assert.assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress(), true));
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true,true);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true, true,true);
|
||||
}
|
||||
|
||||
// TESTCASE: Removing a mailbox message that was added from the onMessage handler
|
||||
@ -237,6 +237,6 @@ public class P2PDataStorageClientAPITest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedMailboxStorageEntry);
|
||||
Assert.assertTrue(this.testState.mockedStorage.remove(protectedMailboxStorageEntry, TestState.getTestNodeAddress(), true));
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true,true);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedMailboxStorageEntry, true, true, true, true,true);
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ public class P2PDataStorageProtectedStorageEntryTest {
|
||||
if (!this.useMessageHandler)
|
||||
Assert.assertEquals(expectedReturnValue, addResult);
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, entry, expectInternalStateChange, true, expectSeqNrWrite, this.expectIsDataOwner());
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, entry, expectInternalStateChange, expectInternalStateChange, expectInternalStateChange, expectSeqNrWrite, this.expectIsDataOwner());
|
||||
}
|
||||
|
||||
/// Valid Add Tests (isValidForAdd() and matchesRelevantPubKey() return true)
|
||||
|
@ -67,7 +67,7 @@ public class P2PDataStorageRemoveExpiredTest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
this.testState.mockedStorage.removeExpiredEntries();
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, false, false, false, false);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, false, false, false, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Correctly skips all PersistableNetworkPayloads since they are not expirable
|
||||
@ -93,7 +93,7 @@ public class P2PDataStorageRemoveExpiredTest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
this.testState.mockedStorage.removeExpiredEntries();
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, false, false, false, false);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, false, false, false, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Correctly expires non-persistable entries that are expired
|
||||
@ -110,7 +110,7 @@ public class P2PDataStorageRemoveExpiredTest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
this.testState.mockedStorage.removeExpiredEntries();
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, true, false, false, false);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, true, true, false, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Correctly skips persistable entries that are not expired
|
||||
@ -124,7 +124,7 @@ public class P2PDataStorageRemoveExpiredTest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
this.testState.mockedStorage.removeExpiredEntries();
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, false, false, false, false);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, false, false, false, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Correctly expires persistable entries that are expired
|
||||
@ -141,7 +141,7 @@ public class P2PDataStorageRemoveExpiredTest {
|
||||
SavedTestState beforeState = this.testState.saveTestState(protectedStorageEntry);
|
||||
this.testState.mockedStorage.removeExpiredEntries();
|
||||
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, true, false, false, false);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry, true, true, false, false, false);
|
||||
}
|
||||
|
||||
// TESTCASE: Ensure we try to purge old entries sequence number map when size exceeds the maximum size
|
||||
@ -187,7 +187,7 @@ public class P2PDataStorageRemoveExpiredTest {
|
||||
// The first 4 entries (11 days old) should be purged from the SequenceNumberMap
|
||||
SavedTestState beforeState = this.testState.saveTestState(purgedProtectedStorageEntry);
|
||||
this.testState.mockedStorage.removeExpiredEntries();
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, expectedRemoves, true, false, false, false);
|
||||
this.testState.verifyProtectedStorageRemove(beforeState, expectedRemoves, true, true, false, false, false);
|
||||
|
||||
// Which means that an addition of a purged entry should succeed.
|
||||
beforeState = this.testState.saveTestState(purgedProtectedStorageEntry);
|
||||
|
@ -69,7 +69,7 @@ public class P2PDataStoreDisconnectTest {
|
||||
ProtectedStorageEntry protectedStorageEntry = beforeState.protectedStorageEntryBeforeOp;
|
||||
|
||||
currentState.verifyProtectedStorageRemove(beforeState, protectedStorageEntry,
|
||||
wasRemoved, false, false, false);
|
||||
wasRemoved, wasRemoved, false, false, false);
|
||||
|
||||
if (wasTTLReduced)
|
||||
Assert.assertTrue(protectedStorageEntry.getCreationTimeStamp() < beforeState.creationTimestampBeforeUpdate);
|
||||
|
@ -257,26 +257,28 @@ public class TestState {
|
||||
|
||||
void verifyProtectedStorageRemove(SavedTestState beforeState,
|
||||
ProtectedStorageEntry protectedStorageEntry,
|
||||
boolean expectedStateChange,
|
||||
boolean expectedBroadcastOnStateChange,
|
||||
boolean expectedHashMapAndDataStoreUpdated,
|
||||
boolean expectedListenersSignaled,
|
||||
boolean expectedBroadcast,
|
||||
boolean expectedSeqNrWrite,
|
||||
boolean expectedIsDataOwner) {
|
||||
|
||||
verifyProtectedStorageRemove(beforeState, Collections.singletonList(protectedStorageEntry),
|
||||
expectedStateChange, expectedBroadcastOnStateChange,
|
||||
expectedHashMapAndDataStoreUpdated, expectedListenersSignaled, expectedBroadcast,
|
||||
expectedSeqNrWrite, expectedIsDataOwner);
|
||||
}
|
||||
|
||||
void verifyProtectedStorageRemove(SavedTestState beforeState,
|
||||
Collection<ProtectedStorageEntry> protectedStorageEntries,
|
||||
boolean expectedStateChange,
|
||||
boolean expectedBroadcastOnStateChange,
|
||||
boolean expectedHashMapAndDataStoreUpdated,
|
||||
boolean expectedListenersSignaled,
|
||||
boolean expectedBroadcast,
|
||||
boolean expectedSeqNrWrite,
|
||||
boolean expectedIsDataOwner) {
|
||||
|
||||
// The default matcher expects orders to stay the same. So, create a custom matcher function since
|
||||
// we don't care about the order.
|
||||
if (expectedStateChange) {
|
||||
if (expectedListenersSignaled) {
|
||||
final ArgumentCaptor<Collection<ProtectedStorageEntry>> argument = ArgumentCaptor.forClass(Collection.class);
|
||||
verify(this.hashMapChangedListener).onRemoved(argument.capture());
|
||||
|
||||
@ -289,20 +291,32 @@ public class TestState {
|
||||
Assert.assertEquals(expected, actual);
|
||||
} else {
|
||||
verify(this.hashMapChangedListener, never()).onRemoved(any());
|
||||
verify(this.protectedDataStoreListener, never()).onAdded(any());
|
||||
}
|
||||
|
||||
if (!expectedSeqNrWrite)
|
||||
verify(this.mockSeqNrStorage, never()).queueUpForSave(any(SequenceNumberMap.class), anyLong());
|
||||
|
||||
if (!expectedBroadcast)
|
||||
verify(this.mockBroadcaster, never()).broadcast(any(BroadcastMessage.class), any(NodeAddress.class), any(BroadcastHandler.Listener.class), anyBoolean());
|
||||
|
||||
|
||||
protectedStorageEntries.forEach(protectedStorageEntry -> {
|
||||
P2PDataStorage.ByteArray hashMapHash = P2PDataStorage.get32ByteHashAsByteArray(protectedStorageEntry.getProtectedStoragePayload());
|
||||
|
||||
if (expectedSeqNrWrite) {
|
||||
if (expectedSeqNrWrite)
|
||||
this.verifySequenceNumberMapWriteContains(P2PDataStorage.get32ByteHashAsByteArray(
|
||||
protectedStorageEntry.getProtectedStoragePayload()), protectedStorageEntry.getSequenceNumber());
|
||||
} else {
|
||||
verify(this.mockSeqNrStorage, never()).queueUpForSave(any(SequenceNumberMap.class), anyLong());
|
||||
|
||||
if (expectedBroadcast) {
|
||||
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
|
||||
verify(this.mockBroadcaster).broadcast(any(RemoveMailboxDataMessage.class), any(NodeAddress.class), eq(null), eq(expectedIsDataOwner));
|
||||
else
|
||||
verify(this.mockBroadcaster).broadcast(any(RemoveDataMessage.class), any(NodeAddress.class), eq(null), eq(expectedIsDataOwner));
|
||||
}
|
||||
|
||||
|
||||
if (expectedStateChange) {
|
||||
if (expectedHashMapAndDataStoreUpdated) {
|
||||
Assert.assertNull(this.mockedStorage.getMap().get(hashMapHash));
|
||||
|
||||
if (protectedStorageEntry.getProtectedStoragePayload() instanceof PersistablePayload) {
|
||||
@ -310,20 +324,8 @@ public class TestState {
|
||||
|
||||
verify(this.protectedDataStoreListener).onRemoved(protectedStorageEntry);
|
||||
}
|
||||
|
||||
if (expectedBroadcastOnStateChange) {
|
||||
if (protectedStorageEntry instanceof ProtectedMailboxStorageEntry)
|
||||
verify(this.mockBroadcaster).broadcast(any(RemoveMailboxDataMessage.class), any(NodeAddress.class), eq(null), eq(expectedIsDataOwner));
|
||||
else
|
||||
verify(this.mockBroadcaster).broadcast(any(RemoveDataMessage.class), any(NodeAddress.class), eq(null), eq(expectedIsDataOwner));
|
||||
}
|
||||
|
||||
} else {
|
||||
Assert.assertEquals(beforeState.protectedStorageEntryBeforeOp, this.mockedStorage.getMap().get(hashMapHash));
|
||||
|
||||
verify(this.mockBroadcaster, never()).broadcast(any(BroadcastMessage.class), any(NodeAddress.class), any(BroadcastHandler.Listener.class), anyBoolean());
|
||||
verify(this.hashMapChangedListener, never()).onAdded(Collections.singletonList(protectedStorageEntry));
|
||||
verify(this.protectedDataStoreListener, never()).onAdded(protectedStorageEntry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user