Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bharatviswa504 committed Feb 22, 2019
1 parent f90741c commit 2882fbb
Showing 1 changed file with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -770,39 +770,12 @@ public void testPutKeyRatisThreeNodesParallel() throws IOException,
public void testReadKeyWithVerifyChecksumFlagEnable() throws Exception {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();

String value = "sample value";
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
volume.createBucket(bucketName);
OzoneBucket bucket = volume.getBucket(bucketName);
String keyName = UUID.randomUUID().toString();

// Write data into a key
OzoneOutputStream out = bucket.createKey(keyName,
value.getBytes().length, ReplicationType.RATIS,
ReplicationFactor.ONE, new HashMap<>());
out.write(value.getBytes());
out.close();

// We need to find the location of the chunk file corresponding to the
// data we just wrote.
OzoneKey key = bucket.getKey(keyName);
long containerID = ((OzoneKeyDetails) key).getOzoneKeyLocations().get(0)
.getContainerID();
// Create and corrupt key
createAndCorruptKey(volumeName, bucketName, keyName);

// Get the container by traversing the datanodes. Atleast one of the
// datanode must have this container.
Container container = null;
for (HddsDatanodeService hddsDatanode : cluster.getHddsDatanodes()) {
container = hddsDatanode.getDatanodeStateMachine().getContainer()
.getContainerSet().getContainer(containerID);
if (container != null) {
break;
}
}
Assert.assertNotNull("Container not found", container);
corruptData(container, key);
// read corrupt key with verify checksum enabled
readCorruptedKey(volumeName, bucketName, keyName, true);

}
Expand All @@ -812,13 +785,23 @@ public void testReadKeyWithVerifyChecksumFlagEnable() throws Exception {
public void testReadKeyWithVerifyChecksumFlagDisable() throws Exception {
String volumeName = UUID.randomUUID().toString();
String bucketName = UUID.randomUUID().toString();
String keyName = UUID.randomUUID().toString();

// Create and corrupt key
createAndCorruptKey(volumeName, bucketName, keyName);

// read corrupt key with verify checksum enabled
readCorruptedKey(volumeName, bucketName, keyName, false);

}

private void createAndCorruptKey(String volumeName, String bucketName,
String keyName) throws IOException {
String value = "sample value";
store.createVolume(volumeName);
OzoneVolume volume = store.getVolume(volumeName);
volume.createBucket(bucketName);
OzoneBucket bucket = volume.getBucket(bucketName);
String keyName = UUID.randomUUID().toString();

// Write data into a key
OzoneOutputStream out = bucket.createKey(keyName,
Expand All @@ -845,8 +828,6 @@ public void testReadKeyWithVerifyChecksumFlagDisable() throws Exception {
}
Assert.assertNotNull("Container not found", container);
corruptData(container, key);
readCorruptedKey(volumeName, bucketName, keyName, false);

}


Expand Down

0 comments on commit 2882fbb

Please sign in to comment.