Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3f6386a
Add retry for HTTP 429 and HTTP 410
anmolasrani123 Jan 4, 2023
56c6f7d
Add retry for HTTP 429 and HTTP 410
anmolasrani123 Jan 4, 2023
2c25b39
Add retry for HTTP 429 and HTTP 410
anmolasrani123 Jan 4, 2023
88e51b6
Added tests to verify retry
anmolasrani123 Jan 5, 2023
3be0b00
Removing unused imports
anmolasrani123 Jan 5, 2023
e04011c
Adding negative tests
anmolasrani123 Jan 5, 2023
6283410
Merge branch 'trunk' into HADOOP-17377
anmolanmol1234 Apr 3, 2023
cf73a70
Merge branch 'apache:trunk' into HADOOP-17377
anmolanmol1234 Aug 22, 2023
e6740a3
Resolving PR comments
anmolanmol1234 Aug 22, 2023
0688809
Mockito fix
anmolanmol1234 Aug 22, 2023
115e88a
Added in other PR
anmolanmol1234 Aug 23, 2023
fe15f44
Removed
anmolanmol1234 Aug 23, 2023
01ec633
Removed new version changes
anmolanmol1234 Aug 23, 2023
4faa92d
Merge branch 'HADOOP-17377' of https://github.com/anmolanmol1234/hado…
anmolanmol1234 Aug 23, 2023
24c0483
Reverted
anmolanmol1234 Aug 23, 2023
99e66fa
Reverted mockito changes
anmolanmol1234 Aug 23, 2023
8b5e883
Merge branch 'apache:trunk' into HADOOP-17377
anmolanmol1234 Aug 23, 2023
1472eb8
POM
anmolanmol1234 Aug 23, 2023
7ba573f
Merge branch 'apache:trunk' into HADOOP-17377
anmolanmol1234 Aug 29, 2023
3f80d00
Merge branch 'HADOOP-17377' of https://github.com/anmolanmol1234/hado…
anmolanmol1234 Aug 30, 2023
462a3b6
Checkstyle fix
anmolanmol1234 Aug 30, 2023
78329de
PR comments
anmolanmol1234 Aug 31, 2023
240965d
Correct default value for backoff interval
anmolanmol1234 Nov 15, 2023
b0563a1
Merge branch 'apache:trunk' into HADOOP-17377
anmolanmol1234 Nov 15, 2023
225541e
Merge branch 'HADOOP-17377' of https://github.com/anmolanmol1234/hado…
anmolanmol1234 Nov 15, 2023
c7d4671
Modify tests and backmerge
anmolanmol1234 Oct 23, 2025
588ffb9
Checkstyle and mockito fix
anmolanmol1234 Oct 23, 2025
fd26066
fix config value
anmolanmol1234 Oct 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Writable call(

// Nothing should be logged for a suppressed exception.
server.logException(logger, new TestException1(), dummyCall);
verifyZeroInteractions(logger);
verifyNoInteractions(logger);

// No stack trace should be logged for a terse exception.
server.logException(logger, new TestException2(), dummyCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public void testSameOrigin() throws ServletException, IOException {
CrossOriginFilter filter = new CrossOriginFilter();
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockRes);
Mockito.verifyNoInteractions(mockRes);
Mockito.verify(mockChain).doFilter(mockReq, mockRes);
}

Expand Down Expand Up @@ -224,7 +223,7 @@ public void testDisallowedOrigin() throws ServletException, IOException {
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockRes);
Mockito.verifyNoInteractions(mockRes);
Mockito.verify(mockChain).doFilter(mockReq, mockRes);
}

Expand Down Expand Up @@ -252,7 +251,7 @@ public void testDisallowedMethod() throws ServletException, IOException {
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockRes);
Mockito.verifyNoInteractions(mockRes);
Mockito.verify(mockChain).doFilter(mockReq, mockRes);
}

Expand Down Expand Up @@ -283,7 +282,7 @@ public void testDisallowedHeader() throws ServletException, IOException {
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockRes);
Mockito.verifyNoInteractions(mockRes);
Mockito.verify(mockChain).doFilter(mockReq, mockRes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testNoHeaderDefaultConfigBadRequest()

verify(mockRes, atLeastOnce()).sendError(
HttpServletResponse.SC_BAD_REQUEST, EXPECTED_MESSAGE);
Mockito.verifyZeroInteractions(mockChain);
Mockito.verifyNoInteractions(mockChain);
}

@Test
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testNoHeaderCustomAgentConfigBadRequest()

verify(mockRes, atLeastOnce()).sendError(
HttpServletResponse.SC_BAD_REQUEST, EXPECTED_MESSAGE);
Mockito.verifyZeroInteractions(mockChain);
Mockito.verifyNoInteractions(mockChain);
}

@Test
Expand Down Expand Up @@ -228,7 +228,7 @@ public void testMissingHeaderWithCustomHeaderConfigBadRequest()
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockChain);
Mockito.verifyNoInteractions(mockChain);
}

@Test
Expand Down Expand Up @@ -260,7 +260,7 @@ public void testMissingHeaderNoMethodsToIgnoreConfigBadRequest()
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockChain);
Mockito.verifyNoInteractions(mockChain);
}

@Test
Expand Down Expand Up @@ -356,6 +356,6 @@ public void testMissingHeaderMultipleIgnoreMethodsConfigBadRequest()
filter.init(filterConfig);
filter.doFilter(mockReq, mockRes, mockChain);

Mockito.verifyZeroInteractions(mockChain);
Mockito.verifyNoInteractions(mockChain);
}
}
5 changes: 5 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs-rbf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.lang.reflect.Field;
import java.security.PrivilegedExceptionAction;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -62,13 +63,13 @@
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.Time;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.FieldSetter;

/**
* The administrator interface of the {@link Router} implemented by
Expand Down Expand Up @@ -118,18 +119,19 @@ public static void globalSetUp() throws Exception {
* @throws IOException
* @throws NoSuchFieldException
*/
private static void setUpMocks() throws IOException, NoSuchFieldException {
private static void setUpMocks() throws IOException, NoSuchFieldException, IllegalAccessException {
RouterRpcServer spyRpcServer =
Mockito.spy(routerContext.getRouter().createRpcServer());
FieldSetter.setField(routerContext.getRouter(),
Router.class.getDeclaredField("rpcServer"), spyRpcServer);
Field rpcServerField = Router.class.getDeclaredField("rpcServer");
rpcServerField.setAccessible(true);
rpcServerField.set(routerContext.getRouter(), spyRpcServer);
Mockito.doReturn(null).when(spyRpcServer).getFileInfo(Mockito.anyString());

// mock rpc client for destination check when editing mount tables.
mockRpcClient = Mockito.spy(spyRpcServer.getRPCClient());
FieldSetter.setField(spyRpcServer,
RouterRpcServer.class.getDeclaredField("rpcClient"),
mockRpcClient);
Field rpcClientField = RouterRpcServer.class.getDeclaredField("rpcClient");
rpcClientField.setAccessible(true);
rpcClientField.set(spyRpcServer, mockRpcClient);
RemoteLocation remoteLocation0 =
new RemoteLocation("ns0", "/testdir", null);
RemoteLocation remoteLocation1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.apache.hadoop.test.Whitebox.getInternalState;
Expand Down Expand Up @@ -73,6 +72,7 @@
import org.apache.hadoop.ipc.StandbyException;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.event.Level;

/**
Expand Down Expand Up @@ -423,7 +423,7 @@ public void testSubclusterDown() throws Exception {
FSNamesystem ns0 = nn0.getNamesystem();
HAContext nn0haCtx = (HAContext)getInternalState(ns0, "haContext");
HAContext mockCtx = mock(HAContext.class);
doThrow(new StandbyException("Mock")).when(mockCtx).checkOperation(any());
doThrow(new StandbyException("Mock")).when(mockCtx).checkOperation(Mockito.any());
setInternalState(ns0, "haContext", mockCtx);

// router0 should throw an exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ public void testNoLookupsWhenNotUsed() throws Exception {
CacheManager cm = cluster.getNamesystem().getCacheManager();
LocatedBlocks locations = Mockito.mock(LocatedBlocks.class);
cm.setCachedLocations(locations);
Mockito.verifyZeroInteractions(locations);
Mockito.verifyNoInteractions(locations);
}

@Test(timeout=120000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,6 @@ public void testShortCircuitSnapshotSearch() throws SnapshotException {
INodesInPath iip = Mockito.mock(INodesInPath.class);
List<INodeDirectory> snapDirs = new ArrayList<>();
FSDirSnapshotOp.checkSnapshot(fsn.getFSDirectory(), iip, snapDirs);
Mockito.verifyZeroInteractions(iip);
Mockito.verifyNoInteractions(iip);
}
}
15 changes: 14 additions & 1 deletion hadoop-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,20 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.28.2</version>
<version>4.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.11.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
7 changes: 7 additions & 0 deletions hadoop-tools/hadoop-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? because its not in the base project pom.

I would rather this PR doesn't need that mockito upgrade as mockito upgrades are always a painful piece of work which never gets backported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed dependency

<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minikdc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public final class AbfsHttpConstants {
// The HTTP 100 Continue informational status response code indicates that everything so far
// is OK and that the client should continue with the request or ignore it if it is already finished.
public static final String HUNDRED_CONTINUE = "100-continue";
/**
* HTTP status code indicating that the server has received too many requests and the client should
* qualify for retrying the operation, as described in the Microsoft Azure documentation.
* {@link "https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#error-handling"}.
*/
public static final int HTTP_TOO_MANY_REQUESTS = 429;

public static final char CHAR_FORWARD_SLASH = '/';
public static final char CHAR_EXCLAMATION_POINT = '!';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,19 @@ public String getRequestId() {
return this.requestId;
}

protected HttpException(
/**
Constructs an instance of HttpException with detailed information about an HTTP error response.
This exception is designed to encapsulate details of an HTTP error response, providing context about the error
encountered during an HTTP operation. It includes the HTTP error code, the associated request ID, an error message,
the URL that triggered the error, the content type of the response, and the response body.
@param httpErrorCode The HTTP error code indicating the nature of the encountered error.
@param requestId The unique identifier associated with the corresponding HTTP request.
@param message A descriptive error message providing additional information about the encountered error.
@param url The URL that resulted in the HTTP error response.
@param contentType The content type of the HTTP response.
@param body The body of the HTTP response, containing more details about the error.
*/
public HttpException(
final int httpErrorCode,
final String requestId,
final String message,
Expand Down Expand Up @@ -341,7 +353,20 @@ private static boolean isRecoverableFailure(IOException e) {
|| e instanceof FileNotFoundException);
}

private static AzureADToken getTokenSingleCall(String authEndpoint,
/**
Retrieves an Azure OAuth token for authentication through a single API call.
This method facilitates the acquisition of an OAuth token from Azure Active Directory
to enable secure authentication for various services. It supports both Managed Service Identity (MSI)
tokens and non-MSI tokens based on the provided parameters.
@param authEndpoint The URL endpoint for OAuth token retrieval.
@param payload The payload to be included in the token request. This typically contains grant type and
any required parameters for token acquisition.
@param headers A Hashtable containing additional HTTP headers to be included in the token request.
@param httpMethod The HTTP method to be used for the token request (e.g., GET, POST).
@param isMsi A boolean flag indicating whether to request a Managed Service Identity (MSI) token or not.
@return An AzureADToken object containing the acquired OAuth token and associated metadata.
*/
public static AzureADToken getTokenSingleCall(String authEndpoint,
String payload, Hashtable<String, String> headers, String httpMethod,
boolean isMsi)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.hadoop.classification.VisibleForTesting;

import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.HTTP_CONTINUE;
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.HTTP_TOO_MANY_REQUESTS;

/**
* Retry policy used by AbfsClient.
Expand Down Expand Up @@ -123,6 +124,9 @@ public ExponentialRetryPolicy(final int retryCount, final int minBackoff, final
* and the current strategy. The valid http status code lies in the range of 1xx-5xx.
* But an invalid status code might be set due to network or timeout kind of issues.
* Such invalid status code also qualify for retry.
* HTTP status code 410 qualifies for retry based on
* https://docs.microsoft.com/en-in/azure/virtual-machines/linux/
* instance-metadata-service?tabs=windows#errors-and-debugging
*
* @param retryCount The current retry attempt count.
* @param statusCode The status code of the response, or -1 for socket error.
Expand All @@ -132,6 +136,8 @@ public boolean shouldRetry(final int retryCount, final int statusCode) {
return retryCount < this.retryCount
&& (statusCode < HTTP_CONTINUE
|| statusCode == HttpURLConnection.HTTP_CLIENT_TIMEOUT
|| statusCode == HttpURLConnection.HTTP_GONE
|| statusCode == HTTP_TOO_MANY_REQUESTS
|| (statusCode >= HttpURLConnection.HTTP_INTERNAL_ERROR
&& statusCode != HttpURLConnection.HTTP_NOT_IMPLEMENTED
&& statusCode != HttpURLConnection.HTTP_VERSION));
Expand Down
Loading