adwetojha commented on code in PR #11752:
URL: https://github.com/apache/ozone/pull/11752#discussion_r4493449569
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMAllocateBlockRequest.java:
##########
@@ -75,6 +77,51 @@
*/
public class TestOMAllocateBlockRequest extends OMKeyRequestTests {
+ @Test
+ public void testMissingPipelineMapsToRetryableError() throws Exception {
+ String message = "Waited pipeline disappeared";
+ when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(),
+ anyString(), any(ExcludeList.class), anyString()))
+ .thenThrow(new SCMException(message,
SCMException.ResultCodes.PIPELINE_NOT_FOUND));
+
+ OMAllocateBlockRequest request =
getOmAllocateBlockRequest(createAllocateBlockRequest());
+ OMException error = assertThrows(OMException.class,
+ () -> request.allocateBlock(replicationConfig, new ExcludeList(),
scmBlockSize, false,
+ UserInfo.newBuilder().build(), ozoneManager));
+
+ assertEquals(OMException.ResultCodes.KEY_ALLOCATION_ERROR,
error.getResult());
+ assertEquals(message, error.getMessage());
+ }
+
+ @Test
+ public void testScmSafeModeMappingIsPreserved() throws Exception {
+ when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(),
+ anyString(), any(ExcludeList.class), anyString()))
+ .thenThrow(new SCMException("SCM is in safe mode",
SCMException.ResultCodes.SAFE_MODE_EXCEPTION));
+
+ OMAllocateBlockRequest request =
getOmAllocateBlockRequest(createAllocateBlockRequest());
+ OMException error = assertThrows(OMException.class,
+ () -> request.allocateBlock(replicationConfig, new ExcludeList(),
scmBlockSize, false,
+ UserInfo.newBuilder().build(), ozoneManager));
+
+ assertEquals(OMException.ResultCodes.SCM_IN_SAFE_MODE, error.getResult());
+ }
+
+ @Test
+ public void testOtherScmAllocationFailureIsNotReclassified() throws
Exception {
+ SCMException cause = new SCMException("No suitable datanode",
+ SCMException.ResultCodes.FAILED_TO_FIND_SUITABLE_NODE);
+ when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(),
+ anyString(), any(ExcludeList.class), anyString())).thenThrow(cause);
+
+ OMAllocateBlockRequest request =
getOmAllocateBlockRequest(createAllocateBlockRequest());
+ SCMException error = assertThrows(SCMException.class,
+ () -> request.allocateBlock(replicationConfig, new ExcludeList(),
scmBlockSize, false,
+ UserInfo.newBuilder().build(), ozoneManager));
+
+ assertSame(cause, error);
Review Comment:
Thanks for the suggestion! I've extracted a small
`allocateBlockWithScmFailure()` helper that takes an `SCMException`, configures
the SCM mock, invokes `allocateBlock()`, and returns the thrown exception.
All three tests now reuse this helper while preserving their individual
assertions.
--
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]