From 3e941b6d4751dfa8d2dba3f96392ebda4201e863 Mon Sep 17 00:00:00 2001 From: timkimadobe <95260439+timkimadobe@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:30:19 -0800 Subject: [PATCH] Revert "Update recoverable error codes (#170)" This reverts commit 408549518ba9a085ced9b01523fb31da0fe7d677. --- code/app-kotlin/build.gradle.kts | 4 +- code/app/build.gradle.kts | 4 +- code/edge/build.gradle.kts | 5 +- .../marketing/mobile/EdgeNetworkService.java | 25 +++----- .../mobile/EdgeNetworkServiceTest.java | 64 ------------------- 5 files changed, 18 insertions(+), 84 deletions(-) diff --git a/code/app-kotlin/build.gradle.kts b/code/app-kotlin/build.gradle.kts index e47b71b3..ad3891f4 100644 --- a/code/app-kotlin/build.gradle.kts +++ b/code/app-kotlin/build.gradle.kts @@ -78,7 +78,9 @@ dependencies { implementation("com.adobe.marketing.mobile:core:$mavenCoreVersion") implementation("com.adobe.marketing.mobile:edgeidentity:$mavenEdgeIdentityVersion") - implementation("com.adobe.marketing.mobile:edgeconsent:3.0.0") + implementation("com.adobe.marketing.mobile:edgeconsent:$mavenEdgeConsentVersion") { + exclude(group = "com.adobe.marketing.mobile", module = "edge") + } implementation("com.adobe.marketing.mobile:assurance:3.0.0") implementation("androidx.constraintlayout:constraintlayout:2.0.4") diff --git a/code/app/build.gradle.kts b/code/app/build.gradle.kts index 51c798ed..d4bf3fb8 100644 --- a/code/app/build.gradle.kts +++ b/code/app/build.gradle.kts @@ -75,7 +75,9 @@ dependencies { implementation("com.adobe.marketing.mobile:core:$mavenCoreVersion") implementation("com.adobe.marketing.mobile:edgeidentity:$mavenEdgeIdentityVersion") - implementation("com.adobe.marketing.mobile:edgeconsent:3.0.0") + implementation("com.adobe.marketing.mobile:edgeconsent:$mavenEdgeConsentVersion") { + exclude(group = "com.adobe.marketing.mobile", module = "edge") + } implementation("com.adobe.marketing.mobile:assurance:3.0.0") implementation("androidx.constraintlayout:constraintlayout:2.0.4") diff --git a/code/edge/build.gradle.kts b/code/edge/build.gradle.kts index 9e770124..7ea28733 100644 --- a/code/edge/build.gradle.kts +++ b/code/edge/build.gradle.kts @@ -39,5 +39,8 @@ dependencies { testImplementation("com.github.adobe:aepsdk-testutils-android:$mavenTestUtilsVersion") androidTestImplementation("com.github.adobe:aepsdk-testutils-android:$mavenTestUtilsVersion") - androidTestImplementation("com.adobe.marketing.mobile:edgeconsent:3.0.0") + androidTestImplementation("com.adobe.marketing.mobile:edgeconsent:$mavenEdgeConsentVersion") + { + exclude(group = "com.adobe.marketing.mobile", module = "edge") + } } \ No newline at end of file diff --git a/code/edge/src/main/java/com/adobe/marketing/mobile/EdgeNetworkService.java b/code/edge/src/main/java/com/adobe/marketing/mobile/EdgeNetworkService.java index 683bd46a..bc60ba45 100644 --- a/code/edge/src/main/java/com/adobe/marketing/mobile/EdgeNetworkService.java +++ b/code/edge/src/main/java/com/adobe/marketing/mobile/EdgeNetworkService.java @@ -18,20 +18,18 @@ import com.adobe.marketing.mobile.services.Log; import com.adobe.marketing.mobile.services.NetworkRequest; import com.adobe.marketing.mobile.services.Networking; -import com.adobe.marketing.mobile.services.NetworkingConstants; import com.adobe.marketing.mobile.util.StringUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Scanner; -import java.util.Set; import java.util.concurrent.CountDownLatch; import org.json.JSONException; import org.json.JSONObject; @@ -100,13 +98,14 @@ interface ResponseCallback { private static final String DEFAULT_GENERIC_ERROR_MESSAGE = "Request to Edge Network failed with an unknown exception"; - static final Set recoverableNetworkErrorCodes = mergeUnique( - NetworkingConstants.RECOVERABLE_ERROR_CODES, + static final List recoverableNetworkErrorCodes = new ArrayList<>( Arrays.asList( -1, // returned for SocketTimeoutException 429, // too many requests - The user has sent too many requests in a given amount of time ("rate limiting"). - 507, // insufficient storage - HttpURLConnection.HTTP_BAD_GATEWAY + HttpURLConnection.HTTP_CLIENT_TIMEOUT, + HttpURLConnection.HTTP_BAD_GATEWAY, + HttpURLConnection.HTTP_UNAVAILABLE, + HttpURLConnection.HTTP_GATEWAY_TIMEOUT ) ); @@ -259,10 +258,9 @@ RetryResult doRequest( private int computeRetryInterval(final HttpConnecting connection) { String header = connection.getResponsePropertyValue(EdgeConstants.NetworkKeys.HEADER_KEY_RETRY_AFTER); - int retryAfter = EdgeConstants.Defaults.RETRY_INTERVAL_SECONDS; if (header != null && header.matches("\\d+")) { try { - retryAfter = Integer.parseInt(header); + return Integer.parseInt(header); } catch (NumberFormatException e) { Log.debug( LOG_TAG, @@ -274,7 +272,7 @@ private int computeRetryInterval(final HttpConnecting connection) { } } - return retryAfter > 0 ? retryAfter : EdgeConstants.Defaults.RETRY_INTERVAL_SECONDS; + return EdgeConstants.Defaults.RETRY_INTERVAL_SECONDS; } /** @@ -579,11 +577,4 @@ private String readInputStream(final InputStream inputStream) { return composeGenericErrorAsJson(e.getMessage()); } } - - private static Set mergeUnique(final List arr1, final List arr2) { - Set merged = new HashSet<>(); - merged.addAll(arr1); - merged.addAll(arr2); - return merged; - } } diff --git a/code/edge/src/test/java/com/adobe/marketing/mobile/EdgeNetworkServiceTest.java b/code/edge/src/test/java/com/adobe/marketing/mobile/EdgeNetworkServiceTest.java index df8303a6..8370a81c 100644 --- a/code/edge/src/test/java/com/adobe/marketing/mobile/EdgeNetworkServiceTest.java +++ b/code/edge/src/test/java/com/adobe/marketing/mobile/EdgeNetworkServiceTest.java @@ -20,19 +20,15 @@ import com.adobe.marketing.mobile.services.HttpMethod; import com.adobe.marketing.mobile.services.NetworkRequest; -import com.adobe.marketing.mobile.services.NetworkingConstants; import com.adobe.marketing.mobile.util.MockConnection; import com.adobe.marketing.mobile.util.MockNetworkService; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.json.JSONException; @@ -54,7 +50,6 @@ public class EdgeNetworkServiceTest { private static final String TEST_URL = "https://test.com"; private static final String HEADER_CONTENT_TYPE = "Content-Type"; private static final String HEADER_CONTENT_TYPE_JSON_VALUE = "application/json"; - private static final String HEADER_RETRY_AFTER = "Retry-After"; private final Map requestHeaders = new HashMap() { { put("key1", "value1"); @@ -365,65 +360,6 @@ public void testDoRequest_whenConnection_RecoverableResponseCode_504_ReturnsRetr testRecoverableNetworkResponse(504, "Gateway Timeout"); } - @Test - public void testDoRequest_whenConnection_RecoverableResponseCode_507_ReturnsRetryYes_AndNoResponseCallback_AndNoErrorCallback() { - testRecoverableNetworkResponse(507, "Insufficient Storage"); - } - - @Test - public void testDoRequest_whenConnection_RecoverableResponseCodeAndRetryAfter_ReturnsRetryTimeout() { - Set recoverableNetworkErrorCodes = new HashSet<>(); - recoverableNetworkErrorCodes.addAll(NetworkingConstants.RECOVERABLE_ERROR_CODES); - recoverableNetworkErrorCodes.addAll(Arrays.asList(429, 502, 507, -1)); - - for (int responseCode : recoverableNetworkErrorCodes) { - testRecoverableWithRetryAfter(responseCode, "30", 30); - } - } - - @Test - public void testDoRequest_whenConnection_InvalidRetryAfter_ReturnsDefaultRetryTimeout() { - testRecoverableNetworkResponse(507, "Insufficient Storage"); - String[] invalidRetryAfter = { "InvalidRetryAfter", "A", "", "-1", "0", " " }; - - for (String retryAfter : invalidRetryAfter) { - testRecoverableWithRetryAfter(503, retryAfter, 5); // expecting default timeout - } - } - - @Test - public void testDoRequest_whenConnection_ValidRetryAfter_ReturnsCorrectRetryTimeout() { - testRecoverableNetworkResponse(507, "Insufficient Storage"); - String[] invalidRetryAfter = { "1", "5", "30", "60", "180", "300" }; - - for (String retryAfter : invalidRetryAfter) { - testRecoverableWithRetryAfter(503, retryAfter, Integer.parseInt(retryAfter)); // expecting provided timeout - } - } - - private void testRecoverableWithRetryAfter( - final int responseCode, - final String retryAfter, - final int expectedRetryAfter - ) { - // setup - final String url = "https://test.com"; - final String jsonRequest = "{}"; - final Map headers = new HashMap<>(); - headers.put(HEADER_RETRY_AFTER, retryAfter); - MockConnection mockConnection = new MockConnection(responseCode, null, "error", headers); - mockNetworkService.reset(); - mockNetworkService.setMockResponseFor(url, mockConnection); - networkService = new EdgeNetworkService(mockNetworkService); - - // test - DoRequestResult result = doRequestSync(url, jsonRequest); - - // verify - assertEquals(EdgeNetworkService.Retry.YES, result.retryResult.getShouldRetry()); - assertEquals(expectedRetryAfter, result.retryResult.getRetryIntervalSeconds()); - } - private void testRecoverableNetworkResponse(final int responseCode, final String errorString) { // setup final String url = "https://test.com";