HDFS-11913. Ozone: TestKeySpaceManager#testDeleteVolume fails. Contributed by Weiwei Yang.

This commit is contained in:
Anu Engineer 2017-06-02 00:48:39 -07:00 committed by Owen O'Malley
parent 4893692972
commit aa5722dc44
2 changed files with 38 additions and 19 deletions

View File

@ -201,10 +201,14 @@ public class MetadataManagerImpl implements MetadataManager {
byte[] dbVolumeRootKey = DFSUtil.string2Bytes(dbVolumeRootName); byte[] dbVolumeRootKey = DFSUtil.string2Bytes(dbVolumeRootName);
// Seek to the root of the volume and look for the next key // Seek to the root of the volume and look for the next key
iterator.seek(dbVolumeRootKey); iterator.seek(dbVolumeRootKey);
String firstBucketKey = DFSUtil.bytes2String(iterator.next().getKey()); if (iterator.hasNext()) {
// if the key starts with /<volume name> String firstBucketKey = DFSUtil.bytes2String(iterator.next().getKey());
// then there is at least one bucket // if the key starts with /<volume name>/
return !firstBucketKey.startsWith(OzoneConsts.KSM_VOLUME_PREFIX + volume); // then there is at least one bucket
return !firstBucketKey.startsWith(dbVolumeRootName);
} else {
return true;
}
} }
} }
} }

View File

@ -187,26 +187,41 @@ public class TestKeySpaceManager {
String userName = "user" + RandomStringUtils.randomNumeric(5); String userName = "user" + RandomStringUtils.randomNumeric(5);
String adminName = "admin" + RandomStringUtils.randomNumeric(5); String adminName = "admin" + RandomStringUtils.randomNumeric(5);
String volumeName = "volume" + RandomStringUtils.randomNumeric(5); String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
String volumeName1 = volumeName + "_A";
String volumeName2 = volumeName + "_AA";
VolumeArgs volumeArgs = null;
VolumeInfo volumeInfo = null;
VolumeArgs createVolumeArgs = new VolumeArgs(volumeName, userArgs); // Create 2 empty volumes with same prefix.
createVolumeArgs.setUserName(userName); volumeArgs = new VolumeArgs(volumeName1, userArgs);
createVolumeArgs.setAdminName(adminName); volumeArgs.setUserName(userName);
storageHandler.createVolume(createVolumeArgs); volumeArgs.setAdminName(adminName);
storageHandler.createVolume(volumeArgs);
VolumeArgs getVolumeArgs = new VolumeArgs(volumeName, userArgs); volumeArgs = new VolumeArgs(volumeName2, userArgs);
VolumeInfo retVolumeInfo = storageHandler.getVolumeInfo(getVolumeArgs); volumeArgs.setUserName(userName);
Assert.assertTrue(retVolumeInfo.getVolumeName().equals(volumeName)); volumeArgs.setAdminName(adminName);
Assert.assertTrue(retVolumeInfo.getOwner().getName().equals(userName)); storageHandler.createVolume(volumeArgs);
volumeArgs = new VolumeArgs(volumeName1, userArgs);
volumeInfo = storageHandler.getVolumeInfo(volumeArgs);
Assert.assertTrue(volumeInfo.getVolumeName().equals(volumeName1));
Assert.assertTrue(volumeInfo.getOwner().getName().equals(userName));
Assert.assertEquals(0, ksmMetrics.getNumVolumeCreateFails()); Assert.assertEquals(0, ksmMetrics.getNumVolumeCreateFails());
storageHandler.deleteVolume(createVolumeArgs); // Volume with _A should be able to delete as it is empty.
storageHandler.deleteVolume(volumeArgs);
try { // Make sure volume with _AA suffix still exists.
retVolumeInfo = storageHandler.getVolumeInfo(getVolumeArgs); volumeArgs = new VolumeArgs(volumeName2, userArgs);
} catch (IOException ex) { volumeInfo = storageHandler.getVolumeInfo(volumeArgs);
Assert.assertEquals(ex.getMessage(), Assert.assertTrue(volumeInfo.getVolumeName().equals(volumeName2));
"Info Volume failed, error:VOLUME_NOT_FOUND");
} // Make sure volume with _A suffix is successfully deleted.
exception.expect(IOException.class);
exception.expectMessage("Info Volume failed, error:VOLUME_NOT_FOUND");
volumeArgs = new VolumeArgs(volumeName1, userArgs);
storageHandler.getVolumeInfo(volumeArgs);
} }
// Create a volume and a bucket inside the volume, // Create a volume and a bucket inside the volume,