### Question:
OMKeyRenameResponse extends OMClientResponse { @Override public void addToDBBatch(OMMetadataManager omMetadataManager, BatchOperation batchOperation) throws IOException { String volumeName = renameKeyInfo.getVolumeName(); String bucketName = renameKeyInfo.getBucketName(); omMetadataManager.getKeyTable().deleteWithBatch(batchOperation, omMetadataManager.getOzoneKey(volumeName, bucketName, fromKeyName)); omMetadataManager.getKeyTable().putWithBatch(batchOperation, omMetadataManager.getOzoneKey(volumeName, bucketName, toKeyName), renameKeyInfo); } OMKeyRenameResponse(@Nonnull OMResponse omResponse,
      String fromKeyName, String toKeyName, @Nonnull OmKeyInfo renameKeyInfo);  OMKeyRenameResponse(@Nonnull OMResponse omResponse); @Override void addToDBBatch(OMMetadataManager omMetadataManager,
      BatchOperation batchOperation);  }### Answer:
@Test public void testAddToDBBatch() throws Exception { OmKeyInfo omKeyInfo = TestOMRequestUtils.createOmKeyInfo(volumeName, bucketName, keyName, replicationType, replicationFactor); OzoneManagerProtocolProtos.OMResponse omResponse = OzoneManagerProtocolProtos.OMResponse.newBuilder().setRenameKeyResponse( OzoneManagerProtocolProtos.RenameKeyResponse.getDefaultInstance()) .setStatus(OzoneManagerProtocolProtos.Status.OK) .setCmdType(OzoneManagerProtocolProtos.Type.RenameKey) .build(); String toKeyName = UUID.randomUUID().toString(); OMKeyRenameResponse omKeyRenameResponse = new OMKeyRenameResponse( omResponse, keyName, toKeyName, omKeyInfo); String ozoneFromKey = omMetadataManager.getOzoneKey(volumeName, bucketName, keyName); String ozoneToKey = omMetadataManager.getOzoneKey(volumeName, bucketName, toKeyName); TestOMRequestUtils.addKeyToTable(false, volumeName, bucketName, keyName, clientID, replicationType, replicationFactor, omMetadataManager); Assert.assertTrue(omMetadataManager.getKeyTable().isExist(ozoneFromKey)); Assert.assertFalse(omMetadataManager.getKeyTable().isExist(ozoneToKey)); omKeyRenameResponse.addToDBBatch(omMetadataManager, batchOperation); omMetadataManager.getStore().commitBatchOperation(batchOperation); Assert.assertFalse(omMetadataManager.getKeyTable().isExist(ozoneFromKey)); Assert.assertTrue(omMetadataManager.getKeyTable().isExist(ozoneToKey)); }
@Test public void testAddToDBBatchWithSameKeyName() throws Exception { OmKeyInfo omKeyInfo = TestOMRequestUtils.createOmKeyInfo(volumeName, bucketName, keyName, replicationType, replicationFactor); OzoneManagerProtocolProtos.OMResponse omResponse = OzoneManagerProtocolProtos.OMResponse.newBuilder().setRenameKeyResponse( OzoneManagerProtocolProtos.RenameKeyResponse.getDefaultInstance()) .setStatus(OzoneManagerProtocolProtos.Status.KEY_NOT_FOUND) .setCmdType(OzoneManagerProtocolProtos.Type.RenameKey) .build(); OMKeyRenameResponse omKeyRenameResponse = new OMKeyRenameResponse( omResponse, keyName, keyName, omKeyInfo); String ozoneFromKey = omMetadataManager.getOzoneKey(volumeName, bucketName, keyName); TestOMRequestUtils.addKeyToTable(false, volumeName, bucketName, keyName, clientID, replicationType, replicationFactor, omMetadataManager); Assert.assertTrue(omMetadataManager.getKeyTable().isExist(ozoneFromKey)); omKeyRenameResponse.addToDBBatch(omMetadataManager, batchOperation); omMetadataManager.getStore().commitBatchOperation(batchOperation); Assert.assertTrue(omMetadataManager.getKeyTable().isExist(ozoneFromKey)); }