ChenSammi commented on code in PR #5847:
URL: https://github.com/apache/ozone/pull/5847#discussion_r1442440017


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/file/TestOMRecoverLeaseRequest.java:
##########
@@ -79,26 +91,230 @@ public void testRecoverHsyncFile() throws Exception {
         .thenReturn("user");
     InetSocketAddress address = new InetSocketAddress("localhost", 10000);
     when(ozoneManager.getOmRpcServerAddr()).thenReturn(address);
-    populateNamespace(true, true);
+    populateNamespace(true, true, true, true);
 
     OMClientResponse omClientResponse = validateAndUpdateCache();
+    OMResponse omResponse = omClientResponse.getOMResponse();
+    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, 
omResponse.getStatus());
+    RecoverLeaseResponse recoverLeaseResponse = 
omResponse.getRecoverLeaseResponse();
+    KeyInfo keyInfo = recoverLeaseResponse.getKeyInfo();
+    Assertions.assertNotNull(keyInfo);
+    OmKeyInfo omKeyInfo = OmKeyInfo.getFromProtobuf(keyInfo);
 
-    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK,
+    omClientResponse = 
validateAndUpdateCacheForCommit(getNewKeyArgs(omKeyInfo, 0));
+    omResponse = omClientResponse.getOMResponse();
+    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, 
omResponse.getStatus());
+
+    verifyTables(true, false);
+  }
+
+  /**
+   * Verify that RecoverLease request is idempotent.
+   * @throws Exception
+   */
+  @Test
+  public void testInitStageIdempotent() throws Exception {
+    when(ozoneManager.getAclsEnabled()).thenReturn(true);
+    when(ozoneManager.getVolumeOwner(
+        anyString(),
+        any(IAccessAuthorizer.ACLType.class), any(
+            OzoneObj.ResourceType.class)))
+        .thenReturn("user");
+    InetSocketAddress address = new InetSocketAddress("localhost", 10000);
+    when(ozoneManager.getOmRpcServerAddr()).thenReturn(address);
+    populateNamespace(true, true, true, true);
+
+    // call recovery first time
+    OMClientResponse omClientResponse = validateAndUpdateCache();
+    OMResponse omResponse = omClientResponse.getOMResponse();
+    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, 
omResponse.getStatus());
+    RecoverLeaseResponse recoverLeaseResponse = 
omResponse.getRecoverLeaseResponse();
+    KeyInfo keyInfo1 = recoverLeaseResponse.getKeyInfo();
+    Assertions.assertNotNull(keyInfo1);
+
+    // call recovery second time
+    omClientResponse = validateAndUpdateCache();
+    omResponse = omClientResponse.getOMResponse();
+    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, 
omResponse.getStatus());
+    recoverLeaseResponse = omResponse.getRecoverLeaseResponse();
+    KeyInfo keyInfo2 = recoverLeaseResponse.getKeyInfo();
+    Assertions.assertNotNull(keyInfo2);
+    Assertions.assertEquals(keyInfo1.getKeyName(), keyInfo2.getKeyName());
+  }
+
+  /**
+   * Verify that COMMIT request for recovery is not idempotent.
+   * @throws Exception
+   */
+  @Test
+  public void testCommitStageNotIdempotent() throws Exception {
+    when(ozoneManager.getAclsEnabled()).thenReturn(true);
+    when(ozoneManager.getVolumeOwner(
+        anyString(),
+        any(IAccessAuthorizer.ACLType.class), any(
+            OzoneObj.ResourceType.class)))
+        .thenReturn("user");
+    InetSocketAddress address = new InetSocketAddress("localhost", 10000);
+    when(ozoneManager.getOmRpcServerAddr()).thenReturn(address);
+    populateNamespace(true, true, true, true);
+
+    // call recovery
+    OMClientResponse omClientResponse = validateAndUpdateCache();
+    OMResponse omResponse = omClientResponse.getOMResponse();
+    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, 
omResponse.getStatus());
+    RecoverLeaseResponse recoverLeaseResponse = 
omResponse.getRecoverLeaseResponse();
+    KeyInfo keyInfo = recoverLeaseResponse.getKeyInfo();
+    Assertions.assertNotNull(keyInfo);
+    OmKeyInfo omKeyInfo = OmKeyInfo.getFromProtobuf(keyInfo);
+
+    KeyArgs newKeyArgs = getNewKeyArgs(omKeyInfo, 0);
+
+    // call commit first time
+    omClientResponse = validateAndUpdateCacheForCommit(newKeyArgs);
+    omResponse = omClientResponse.getOMResponse();
+    Assertions.assertEquals(OzoneManagerProtocolProtos.Status.OK, 
omResponse.getStatus());
+
+    // call commit second time
+    omClientResponse = validateAndUpdateCacheForCommit(newKeyArgs);
+    omResponse = omClientResponse.getOMResponse();
+    
Assertions.assertEquals(OzoneManagerProtocolProtos.Status.KEY_ALREADY_CLOSED, 
omResponse.getStatus());
+  }
+
+  /**
+   * Verify that RecoverLease COMMIT request has a new file length.
+   * @throws Exception
+   */
+  @Test
+  public void testRecoverWithNewFileLength() throws Exception {
+    when(ozoneManager.getAclsEnabled()).thenReturn(true);
+    when(ozoneManager.getVolumeOwner(
+        anyString(),
+        any(IAccessAuthorizer.ACLType.class), any(
+            OzoneObj.ResourceType.class)))
+        .thenReturn("user");
+    InetSocketAddress address = new InetSocketAddress("localhost", 10000);
+    when(ozoneManager.getOmRpcServerAddr()).thenReturn(address);

Review Comment:
   Actually not needed, removed them. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to