diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java index a0c58bc..ae536b6 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/Optimize.java @@ -49,7 +49,7 @@ private Optimize() {} * Experience Edge network. * *

The returned decision propositions are cached in-memory in the Optimize SDK extension and - * can be retrieved using {@link #getPropositions(List, long, AdobeCallback)} API. + * can be retrieved using {@link #getPropositions(List, AdobeCallback)} API. * * @param decisionScopes {@code List} containing scopes for which offers need to * be updated. @@ -58,12 +58,13 @@ private Optimize() {} * @param data {@code Map} containing additional free-form data to be sent in * the personalization query request. */ + @Deprecated public static void updatePropositions( @NonNull final List decisionScopes, @Nullable final Map xdm, @Nullable final Map data) { - final long defaultTimeout = OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; - updatePropositions(decisionScopes, xdm, data, defaultTimeout, null); + + updatePropositions(decisionScopes, xdm, data, null); } /** @@ -88,8 +89,9 @@ public static void updatePropositions( @Nullable final Map xdm, @Nullable final Map data, @Nullable final AdobeCallback> callback) { - final long defaultTimeout = OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; - updatePropositionsInternal(decisionScopes, xdm, data, defaultTimeout, callback); + final double defaultTimeoutSeconds = + OptimizeConstants.EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT; + updatePropositionsInternal(decisionScopes, xdm, data, defaultTimeoutSeconds, callback); } /** @@ -98,7 +100,7 @@ public static void updatePropositions( * Experience Edge network. * *

The returned decision propositions are cached in-memory in the Optimize SDK extension and - * can be retrieved using {@link #getPropositions(List, long, AdobeCallback)} API. + * can be retrieved using {@link #getPropositions(List, double, AdobeCallback)} API. * * @param decisionScopes {@code List} containing scopes for which offers need to * be updated. @@ -106,8 +108,8 @@ public static void updatePropositions( * the personalization query request. * @param data {@code Map} containing additional free-form data to be sent in * the personalization query request. - * @param timeoutMillis {@code Long} containing additional configurable timeout to be sent in - * the personalization query request. + * @param timeoutSeconds {@code Double} containing additional configurable timeout(seconds) to + * be sent in the personalization query request. * @param callback {@code AdobeCallback>} which will be * invoked when decision propositions are received from the Edge network. */ @@ -115,16 +117,16 @@ public static void updatePropositions( @NonNull final List decisionScopes, @Nullable final Map xdm, @Nullable final Map data, - final long timeoutMillis, + final double timeoutSeconds, @Nullable final AdobeCallback> callback) { - updatePropositionsInternal(decisionScopes, xdm, data, timeoutMillis, callback); + updatePropositionsInternal(decisionScopes, xdm, data, timeoutSeconds, callback); } private static void updatePropositionsInternal( @NonNull final List decisionScopes, @Nullable final Map xdm, @Nullable final Map data, - final long timeoutMillis, + final double timeoutSeconds, @Nullable final AdobeCallback> callback) { if (OptimizeUtils.isNullOrEmpty(decisionScopes)) { @@ -175,6 +177,9 @@ private static void updatePropositionsInternal( if (!OptimizeUtils.isNullOrEmpty(data)) { eventData.put(OptimizeConstants.EventDataKeys.DATA, data); } + + long timeoutMillis = (long) (timeoutSeconds * OptimizeConstants.TIMEOUT_CONVERSION_FACTOR); + eventData.put(OptimizeConstants.EventDataKeys.TIMEOUT, timeoutMillis); final Event event = @@ -275,8 +280,8 @@ public void call(final Event event) { public static void getPropositions( @NonNull final List decisionScopes, @NonNull final AdobeCallback> callback) { - long defaultTimeout = OptimizeConstants.GET_RESPONSE_CALLBACK_TIMEOUT; - getPropositionsInternal(decisionScopes, defaultTimeout, callback); + final double defaultTimeoutSeconds = OptimizeConstants.GET_RESPONSE_CALLBACK_TIMEOUT; + getPropositionsInternal(decisionScopes, defaultTimeoutSeconds, callback); } /** @@ -290,14 +295,14 @@ public static void getPropositions( */ public static void getPropositions( @NonNull final List decisionScopes, - final long timeoutMillis, + final double timeoutSeconds, @NonNull final AdobeCallback> callback) { - getPropositionsInternal(decisionScopes, timeoutMillis, callback); + getPropositionsInternal(decisionScopes, timeoutSeconds, callback); } private static void getPropositionsInternal( @NonNull final List decisionScopes, - final long timeoutMillis, + final double timeoutSeconds, @NonNull final AdobeCallback> callback) { if (OptimizeUtils.isNullOrEmpty(decisionScopes)) { Log.warning( @@ -345,8 +350,8 @@ private static void getPropositionsInternal( .setEventData(eventData) .build(); - // Increased default response callback timeout to 10s to ensure prior update propositions - // requests have enough time to complete. + long timeoutMillis = (long) (timeoutSeconds * OptimizeConstants.TIMEOUT_CONVERSION_FACTOR); + MobileCore.dispatchEventWithResponseCallback( event, timeoutMillis, diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java index bb5a598..71571c4 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OptimizeConstants.java @@ -16,9 +16,9 @@ class OptimizeConstants { static final String EXTENSION_VERSION = "3.2.0"; static final String EXTENSION_NAME = "com.adobe.optimize"; static final String FRIENDLY_NAME = "Optimize"; - static final long DEFAULT_RESPONSE_CALLBACK_TIMEOUT = 500L; - static final long GET_RESPONSE_CALLBACK_TIMEOUT = 10000L; - static final long EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10000L; + static final double GET_RESPONSE_CALLBACK_TIMEOUT = 10; + static final double EDGE_CONTENT_COMPLETE_RESPONSE_TIMEOUT = 10; + static final long TIMEOUT_CONVERSION_FACTOR = 1000; static final String ACTIVITY_ID = "activityId"; static final String XDM_ACTIVITY_ID = "xdm:activityId"; diff --git a/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java b/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java index 9254413..c26255c 100644 --- a/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java +++ b/code/optimize/src/test/java/com/adobe/marketing/mobile/optimize/OptimizeTests.java @@ -11,9 +11,6 @@ package com.adobe.marketing.mobile.optimize; -import static com.adobe.marketing.mobile.optimize.Optimize.failWithOptimizeError; -import static com.adobe.marketing.mobile.optimize.Optimize.getPropositions; -import static com.adobe.marketing.mobile.optimize.Optimize.updatePropositions; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -460,7 +457,7 @@ public void testGetPropositions_validDecisionScope() throws Exception { new DecisionScope( "eyJhY3Rpdml0eUlkIjoieGNvcmU6b2ZmZXItYWN0aXZpdHk6MTExMTExMTExMTExMTExMSIsInBsYWNlbWVudElkIjoieGNvcmU6b2ZmZXItcGxhY2VtZW50OjExMTExMTExMTExMTExMTEifQ==")); - getPropositions( + Optimize.getPropositions( scopes, new AdobeCallbackWithError>() { @Override @@ -567,7 +564,7 @@ public void testGetPropositions_multipleValidDecisionScopes() { "eyJhY3Rpdml0eUlkIjoieGNvcmU6b2ZmZXItYWN0aXZpdHk6MTExMTExMTExMTExMTExMSIsInBsYWNlbWVudElkIjoieGNvcmU6b2ZmZXItcGxhY2VtZW50OjExMTExMTExMTExMTExMTEifQ==")); scopes.add(new DecisionScope("myMbox")); - getPropositions( + Optimize.getPropositions( scopes, new AdobeCallbackWithError>() { @Override @@ -637,7 +634,7 @@ public void testGetPropositions_invalidDecisionScopeInList() { new DecisionScope( "eyJhY3Rpdml0eUlkIjoiIiwicGxhY2VtZW50SWQiOiJ4Y29yZTpvZmZlci1wbGFjZW1lbnQ6MTExMTExMTExMTExMTExMSJ9")); - getPropositions( + Optimize.getPropositions( scopes, new AdobeCallbackWithError>() { @Override @@ -666,7 +663,7 @@ public void call(Map propositionsMap) { public void testGetPropositions_emptyDecisionScopesList() { try (MockedStatic logMockedStatic = Mockito.mockStatic(Log.class)) { // test - getPropositions( + Optimize.getPropositions( new ArrayList(), new AdobeCallbackWithError>() { @Override @@ -695,7 +692,7 @@ public void call(Map propositionsMap) { public void testGetPropositions_nullDecisionScopesList() { try (MockedStatic logMockedStatic = Mockito.mockStatic(Log.class)) { // test - getPropositions( + Optimize.getPropositions( null, new AdobeCallbackWithError>() { @Override @@ -906,7 +903,7 @@ public void test_clearCachedPropositions() { @Test public void testUpdatePropositions_timeoutError() { - long timeoutMillis = 100; + double timeoutSeconds = 0.1; Map xdm = new HashMap<>(); Map data = new HashMap<>(); final List scopes = new ArrayList<>(); @@ -947,13 +944,13 @@ public void testUpdatePropositions_timeoutError() { .thenAnswer( (Answer) invocation -> { - failWithOptimizeError( + Optimize.failWithOptimizeError( callbackMockEvent, AEPOptimizeError.Companion.getTimeoutError()); return null; }); - updatePropositions(scopes, xdm, data, timeoutMillis, callbackMock); + Optimize.updatePropositions(scopes, xdm, data, timeoutSeconds, callbackMock); ArgumentCaptor errorCaptor = ArgumentCaptor.forClass(AEPOptimizeError.class); verify(callbackMockEvent, times(1)).fail(errorCaptor.capture()); @@ -965,7 +962,7 @@ public void testUpdatePropositions_timeoutError() { @Test public void testGetPropositions_timeoutError() { - long timeoutMillis = 100; + double timeoutSeconds = 0.1; final List scopes = new ArrayList<>(); scopes.add( new DecisionScope( @@ -1004,13 +1001,13 @@ public void testGetPropositions_timeoutError() { .thenAnswer( (Answer) invocation -> { - failWithOptimizeError( + Optimize.failWithOptimizeError( callbackMockEvent, AEPOptimizeError.Companion.getTimeoutError()); return null; }); - getPropositions(scopes, timeoutMillis, callbackMock); + Optimize.getPropositions(scopes, timeoutSeconds, callbackMock); ArgumentCaptor errorCaptor = ArgumentCaptor.forClass(AEPOptimizeError.class); verify(callbackMockEvent, times(1)).fail(errorCaptor.capture()); diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt index 173bf29..19a9ddc 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/OffersScreen.kt @@ -182,7 +182,7 @@ fun OffersView(viewModel: MainViewModel) { decisionScopes = decisionScopeList, xdm = mapOf(Pair("xdmKey", "1234")), data = data, - timeout = 200 + timeoutSeconds = 0.2 ) }) { Text( @@ -203,7 +203,7 @@ fun OffersView(viewModel: MainViewModel) { viewModel.getPropositions( decisionScopes = decisionScopeList, - timeout = 200 + timeoutSeconds = 0.2 ) }) { Text( diff --git a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt index 3768678..2240944 100644 --- a/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt +++ b/code/testapp/src/main/java/com/adobe/marketing/optimizeapp/viewmodels/MainViewModel.kt @@ -71,9 +71,9 @@ class MainViewModel: ViewModel() { * Calls the Optimize SDK API to get the Propositions see [Optimize.getPropositions] * * @param [decisionScopes] a [List] of [DecisionScope] - * @param [timeout] a [Long] in milliseconds + * @param [timeoutSeconds] a [Double] in seconds */ - fun getPropositions(decisionScopes: List, timeout: Long? = null) { + fun getPropositions(decisionScopes: List, timeoutSeconds: Double? = null) { optimizePropositionStateMap.clear() val callback = object : AdobeCallbackWithError> { override fun call(propositions: Map?) { @@ -86,8 +86,8 @@ class MainViewModel: ViewModel() { print("Error in getting Propositions.") } } - timeout?.let { milliseconds -> - Optimize.getPropositions(decisionScopes, milliseconds, callback) + timeoutSeconds?.let { seconds -> + Optimize.getPropositions(decisionScopes, seconds, callback) } ?: Optimize.getPropositions(decisionScopes, callback) } @@ -97,13 +97,13 @@ class MainViewModel: ViewModel() { * @param decisionScopes a [List] of [DecisionScope] * @param xdm a [Map] of xdm params * @param data a [Map] of data - * @param timeout a [Long] in milliseconds + * @param timeoutSeconds a [Double] in seconds */ fun updatePropositions( decisionScopes: List, xdm: Map, data: Map, - timeout: Long? = null + timeoutSeconds: Double? = null ) { val callback = object : AdobeCallbackWithOptimizeError> { override fun call(propositions: Map?) { @@ -119,12 +119,12 @@ class MainViewModel: ViewModel() { } optimizePropositionStateMap.clear() - timeout?.let { milliseconds -> + timeoutSeconds?.let { seconds -> Optimize.updatePropositions( decisionScopes, xdm, data, - milliseconds, + seconds, callback ) } ?: Optimize.updatePropositions(decisionScopes, xdm, data, callback)