|
56 | 56 | import static org.junit.jupiter.api.Assertions.assertEquals; |
57 | 57 | import static org.junit.jupiter.api.Assertions.assertFalse; |
58 | 58 | import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 59 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
59 | 60 | import static org.junit.jupiter.api.Assertions.assertNull; |
60 | 61 | import static org.junit.jupiter.api.Assertions.assertTrue; |
61 | 62 | import static org.mockito.Mockito.anyString; |
@@ -186,6 +187,42 @@ public void testValidateAndUpdateCache() throws Exception { |
186 | 187 | assertEquals(initialSnapshotPurgeFailCount, getOmMetrics().getNumSnapshotPurgeFails()); |
187 | 188 | } |
188 | 189 |
|
| 190 | + @Test |
| 191 | + public void testDuplicateSnapshotPurge() throws Exception { |
| 192 | + List<String> snapshotDbKeysToPurge = createSnapshots(1); |
| 193 | + assertFalse(getOmMetadataManager().getSnapshotInfoTable().isEmpty()); |
| 194 | + OMRequest snapshotPurgeRequest = createPurgeKeysRequest( |
| 195 | + snapshotDbKeysToPurge); |
| 196 | + |
| 197 | + OMSnapshotPurgeRequest omSnapshotPurgeRequest = preExecute(snapshotPurgeRequest); |
| 198 | + |
| 199 | + OMSnapshotPurgeResponse omSnapshotPurgeResponse = (OMSnapshotPurgeResponse) |
| 200 | + omSnapshotPurgeRequest.validateAndUpdateCache(getOzoneManager(), 200L); |
| 201 | + |
| 202 | + try (BatchOperation batchOperation = getOmMetadataManager().getStore().initBatchOperation()) { |
| 203 | + omSnapshotPurgeResponse.checkAndUpdateDB(getOmMetadataManager(), batchOperation); |
| 204 | + getOmMetadataManager().getStore().commitBatchOperation(batchOperation); |
| 205 | + } |
| 206 | + |
| 207 | + // Check if the entries are deleted. |
| 208 | + assertTrue(getOmMetadataManager().getSnapshotInfoTable().isEmpty()); |
| 209 | + |
| 210 | + OMSnapshotPurgeResponse omSnapshotPurgeResponse1 = (OMSnapshotPurgeResponse) |
| 211 | + omSnapshotPurgeRequest.validateAndUpdateCache(getOzoneManager(), 201L); |
| 212 | + |
| 213 | + for (Map.Entry<String, SnapshotInfo> purgedSnapshot : omSnapshotPurgeResponse1.getUpdatedSnapInfos().entrySet()) { |
| 214 | + assertNotNull(purgedSnapshot.getValue()); |
| 215 | + } |
| 216 | + for (String snapshotTableKey: snapshotDbKeysToPurge) { |
| 217 | + assertNull(getOmMetadataManager().getSnapshotInfoTable().get(snapshotTableKey)); |
| 218 | + } |
| 219 | + |
| 220 | + try (BatchOperation batchOperation = getOmMetadataManager().getStore().initBatchOperation()) { |
| 221 | + omSnapshotPurgeResponse1.checkAndUpdateDB(getOmMetadataManager(), batchOperation); |
| 222 | + getOmMetadataManager().getStore().commitBatchOperation(batchOperation); |
| 223 | + } |
| 224 | + } |
| 225 | + |
189 | 226 | /** |
190 | 227 | * This test is mainly to validate metrics and error code. |
191 | 228 | */ |
|
0 commit comments