} catch(VoldemortException e) {}
metadataFile.delete();
// Missing metadata checksum type
metadataFile = new File(testSourceDirectory, ".metadata");
ReadOnlyStorageMetadata metadata = new ReadOnlyStorageMetadata();
metadata.add(ReadOnlyStorageMetadata.FORMAT, ReadOnlyStorageFormat.READONLY_V2.getCode());
FileUtils.writeStringToFile(metadataFile, metadata.toJsonString());
fetchedFile = fetcher.fetch(testSourceDirectory.getAbsolutePath(),
testDestinationDirectory.getAbsolutePath() + "3");
assertNotNull(fetchedFile);
assertEquals(fetchedFile.getAbsolutePath(), testDestinationDirectory.getAbsolutePath()
+ "3");
metadataFile.delete();
// Incorrect checksum type + missing checksum
metadata.add(ReadOnlyStorageMetadata.CHECKSUM_TYPE, "blah");
FileUtils.writeStringToFile(metadataFile, metadata.toJsonString());
fetchedFile = fetcher.fetch(testSourceDirectory.getAbsolutePath(),
testDestinationDirectory.getAbsolutePath() + "4");
assertNotNull(fetchedFile);
assertEquals(fetchedFile.getAbsolutePath(), testDestinationDirectory.getAbsolutePath()
+ "4");
metadataFile.delete();
// Incorrect metadata checksum
metadata.add(ReadOnlyStorageMetadata.CHECKSUM_TYPE, CheckSum.toString(CheckSumType.MD5));
metadata.add(ReadOnlyStorageMetadata.CHECKSUM, "1234");
FileUtils.writeStringToFile(metadataFile, metadata.toJsonString());
fetchedFile = fetcher.fetch(testSourceDirectory.getAbsolutePath(),
testDestinationDirectory.getAbsolutePath() + "5");
assertNull(fetchedFile);
metadataFile.delete();
// Correct metadata checksum - MD5
metadata.add(ReadOnlyStorageMetadata.CHECKSUM,
new String(Hex.encodeHex(CheckSumTests.calculateCheckSum(testSourceDirectory.listFiles(),
CheckSumType.MD5))));
FileUtils.writeStringToFile(metadataFile, metadata.toJsonString());
fetchedFile = fetcher.fetch(testSourceDirectory.getAbsolutePath(),
testDestinationDirectory.getAbsolutePath() + "6");
assertNotNull(fetchedFile);
assertEquals(fetchedFile.getAbsolutePath(), testDestinationDirectory.getAbsolutePath()
+ "6");
// Correct metadata checksum - ADLER32
metadata.add(ReadOnlyStorageMetadata.CHECKSUM_TYPE, CheckSum.toString(CheckSumType.ADLER32));
metadata.add(ReadOnlyStorageMetadata.CHECKSUM,
new String(Hex.encodeHex(CheckSumTests.calculateCheckSum(testSourceDirectory.listFiles(),
CheckSumType.ADLER32))));
FileUtils.writeStringToFile(metadataFile, metadata.toJsonString());
fetchedFile = fetcher.fetch(testSourceDirectory.getAbsolutePath(),
testDestinationDirectory.getAbsolutePath() + "7");
assertNotNull(fetchedFile);
assertEquals(fetchedFile.getAbsolutePath(), testDestinationDirectory.getAbsolutePath()
+ "7");
// Correct metadata checksum - CRC32
metadata.add(ReadOnlyStorageMetadata.CHECKSUM_TYPE, CheckSum.toString(CheckSumType.CRC32));
metadata.add(ReadOnlyStorageMetadata.CHECKSUM,
new String(Hex.encodeHex(CheckSumTests.calculateCheckSum(testSourceDirectory.listFiles(),
CheckSumType.CRC32))));
FileUtils.writeStringToFile(metadataFile, metadata.toJsonString());
fetchedFile = fetcher.fetch(testSourceDirectory.getAbsolutePath(),
testDestinationDirectory.getAbsolutePath() + "8");
assertNotNull(fetchedFile);
assertEquals(fetchedFile.getAbsolutePath(), testDestinationDirectory.getAbsolutePath()
+ "8");