ChunksManifestVerifier { public Results verifyAllChunks(String spaceId, ChunksManifest manifest) { Results results = new Results(); for (ManifestEntry entry : manifest.getEntries()) { String chunkId = entry.getChunkId(); String checksum = entry.getChunkMD5(); long byteSize = entry.getByteSize(); try { Map<String, String> props = this.contentStore.getContentProperties(spaceId, entry.getChunkId()); String remoteChecksum = props.get(ContentStore.CONTENT_CHECKSUM); long remoteByteSize = Long.valueOf(props.get(ContentStore.CONTENT_SIZE)); if (!checksum.equals(remoteChecksum)) { results.add(chunkId, "manifest checksum (" + checksum + ") does not match DuraCloud checksum (" + remoteChecksum + ")", false); } else if (byteSize != remoteByteSize) { results.add(chunkId, "manifest byte size (" + byteSize + ") does not match DuraCloud byte size (" + remoteByteSize + ")", false); } else { results.add(chunkId, null, true); } } catch (Exception ex) { results.add(chunkId, ex.getMessage(), false); } } if (CollectionUtils.isNullOrEmpty(results.get())) { throw new DuraCloudRuntimeException("failed to retrieve any chunks at list in chunk manifest: " + spaceId + "/" + manifest.getManifestId()); } else { return results; } } ChunksManifestVerifier(ContentStore contentStore); Results verifyAllChunks(String spaceId, ChunksManifest manifest);  }
@Test public void testSuccess() throws ContentStoreException { ChunksManifestVerifier verifier = new ChunksManifestVerifier(contentStore); for (ManifestEntry entry : manifest.getEntries()) { expectGetContentProps(spaceId, entry, entry.getByteSize(), entry.getChunkMD5()); } replayAll(); Results results = verifier.verifyAllChunks(spaceId, manifest); assertTrue(results.isSuccess()); assertResultSizeIsEqual(results); }
@Test public void testFailureDueToChecksumMismatch() throws ContentStoreException { ChunksManifestVerifier verifier = new ChunksManifestVerifier(contentStore); for (ManifestEntry entry : manifest.getEntries()) { expectGetContentProps(spaceId, entry, entry.getByteSize(), "badChecksum"); } replayAll(); Results results = verifier.verifyAllChunks(spaceId, manifest); assertTrue(!results.isSuccess()); assertResultSizeIsEqual(results); }
@Test public void testFailureDueToSizeMismatch() throws ContentStoreException { ChunksManifestVerifier verifier = new ChunksManifestVerifier(contentStore); for (ManifestEntry entry : manifest.getEntries()) { long byteSize = entry.getByteSize(); expectGetContentProps(spaceId, entry, byteSize + 1, entry.getChunkMD5()); } replayAll(); Results results = verifier.verifyAllChunks(spaceId, manifest); assertTrue(!results.isSuccess()); assertResultSizeIsEqual(results); }
@Test public void testFailureDueToMissingChunk() throws ContentStoreException { ChunksManifestVerifier verifier = new ChunksManifestVerifier(contentStore); for (ManifestEntry entry : manifest.getEntries()) { expect(contentStore.getContentProperties(spaceId, entry.getChunkId())) .andThrow(new ContentStoreException("chunk not found!")); } replayAll(); Results results = verifier.verifyAllChunks(spaceId, manifest); assertTrue(!results.isSuccess()); assertResultSizeIsEqual(results); }