Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SQDSDKS-5914 - Pod redirection #447

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
29 changes: 28 additions & 1 deletion .github/workflows/cross-platform-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,48 @@ jobs:
uses: actions/checkout@v3
with:
repository: mParticle/crossplatform-sdk-tests

- name: "Checkout Android SDK Branch"
uses: actions/checkout@v3
with:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{github.head_ref}}
path: .sdks/android

- name: Gradle cache
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a #v2.9.0

- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-cache

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b #v2.28.0
with:
api-level: 29
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: "Install JDK 11"
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
- name: "Run Crossplatform Tests"
uses: reactivecircus/android-emulator-runner@b35b1c6e6921ebfd3f980c2236ac298f019df53a #v2.28.0
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b #v2.28.0
with:
api-level: 29
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew runAndroid
- name: "Archive Test Results"
if: ${{ always() }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ jobs:

delete-regression-branch:
name: "Delete regression branch"
if: ${{ always() }}
needs: [semantic-release-dryrun, create-regression-branch]
needs: semantic-release-dryrun
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.MP_SEMANTIC_RELEASE_BOT }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class MParticleOptionsTest : BaseAbstractTest() {
Assert.assertTrue(
com.mparticle.networking.AccessUtils.equals(
options.networkOptions,
com.mparticle.networking.AccessUtils.defaultNetworkOptions
com.mparticle.networking.AccessUtils.getDefaultNetworkOptions()
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.mparticle.networking

object AccessUtils {
val defaultNetworkOptions: NetworkOptions
get() = NetworkOptionsManager.defaultNetworkOptions()
private var defaultNetworkOptions: NetworkOptions? = null

fun getDefaultNetworkOptions(): NetworkOptions {
defaultNetworkOptions =
NetworkOptionsManager.defaultNetworkOptions()
return defaultNetworkOptions!!
}

fun equals(networkOptions1: NetworkOptions, networkOptions2: NetworkOptions): Boolean {
if (networkOptions1 === networkOptions2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.mparticle.networking

import com.mparticle.MParticle
import com.mparticle.MParticleOptions
import com.mparticle.NetworkUtilities
import com.mparticle.internal.AccessUtils
import com.mparticle.testutils.BaseCleanInstallEachTest
import junit.framework.TestCase
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.net.MalformedURLException
import kotlin.test.assertEquals

class MParticleBaseClientImplTest : BaseCleanInstallEachTest() {
var defaultUrls = HashMap<MParticleBaseClientImpl.Endpoint, MPUrl>()
Expand All @@ -20,11 +22,72 @@ class MParticleBaseClientImplTest : BaseCleanInstallEachTest() {
startMParticle(MParticleOptions.builder(mContext).credentials(apiKey, "secret"))
val baseClientImpl = AccessUtils.getApiClient() as MParticleBaseClientImpl
for (endpoint in MParticleBaseClientImpl.Endpoint.values()) {
defaultUrls[endpoint] = baseClientImpl.getUrl(endpoint, endpoint.name)
defaultUrls[endpoint] = baseClientImpl.getUrl(endpoint, endpoint.name, false)
}
MParticle.setInstance(null)
}

@Test
markvdouw marked this conversation as resolved.
Show resolved Hide resolved
fun testUrlPrefixWithPodRedirection() {
val prefix = "eu1"
val url =
NetworkUtilities.getUrlWithPrefix(NetworkOptionsManager.MP_URL_PREFIX, prefix, true)
Assert.assertEquals("${NetworkOptionsManager.MP_URL_PREFIX}.$prefix.mparticle.com", url)
}

@Test
fun testUrlPrefixWithoutPodRedirection() {
val prefix = "eu1"
val url =
NetworkUtilities.getUrlWithPrefix(NetworkOptionsManager.MP_URL_PREFIX, prefix, false)
Assert.assertEquals("${NetworkOptionsManager.MP_URL_PREFIX}.mparticle.com", url)
}

@Test
fun testAllPrefixes() {
val map = mapOf<String, String>(
Pair("us1-1vc4gbp24cdtx6e31s58icnymzy83f1uf", "us1"),
Pair("us2-v2p8lr3w2g90vtpaumbq21zy05cl50qm3", "us2"),
Pair("eu1-bkabfno0b8zpv5bwi2zm2mfa1kfml19al", "eu1"),
Pair("au1-iermuj83dbeoshm0n32f10feotclq6i4a", "au1"),
Pair("st1-k77ivhkbbqf4ce0s3y12zpcthyn1ixfyu", "st1"),
Pair("us3-w1y2y8yj8q58d5bx9u2dvtxzl4cpa7cuf", "us3")
)
map.forEach { key, value ->
val prefix = NetworkUtilities.getPodPrefix(key) ?: ""
assertEquals(value, prefix)
assertEquals(
"${NetworkOptionsManager.MP_URL_PREFIX}.$prefix.mparticle.com",
NetworkUtilities.getUrlWithPrefix(NetworkOptionsManager.MP_URL_PREFIX, prefix, true)
)
assertEquals(
"${NetworkOptionsManager.MP_IDENTITY_URL_PREFIX}.$prefix.mparticle.com",
NetworkUtilities.getUrlWithPrefix(
NetworkOptionsManager.MP_IDENTITY_URL_PREFIX,
prefix,
true
)
)

assertEquals(
"${NetworkOptionsManager.MP_URL_PREFIX}.mparticle.com",
NetworkUtilities.getUrlWithPrefix(
NetworkOptionsManager.MP_URL_PREFIX,
prefix,
false
)
)
assertEquals(
"${NetworkOptionsManager.MP_IDENTITY_URL_PREFIX}.mparticle.com",
NetworkUtilities.getUrlWithPrefix(
NetworkOptionsManager.MP_IDENTITY_URL_PREFIX,
prefix,
false
)
)
}
}

@Test
@Throws(MalformedURLException::class)
fun testGetUrlForceDefaultOption() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mparticle.networking

import com.mparticle.MParticle
import com.mparticle.MParticleOptions
import com.mparticle.NetworkUtilities
import com.mparticle.internal.AccessUtils
import com.mparticle.testutils.BaseCleanInstallEachTest
import org.junit.After
Expand Down Expand Up @@ -38,19 +39,19 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
MParticle.start(MParticleOptions.builder(mContext).credentials(apiKey, "s").build())
setClients()
Assert.assertEquals(
NetworkOptionsManager.MP_URL,
NetworkUtilities.getUrlWithPrefix(url = NetworkOptionsManager.MP_URL_PREFIX, "", false),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.AUDIENCE).authority
)
Assert.assertEquals(
NetworkOptionsManager.MP_CONFIG_URL,
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.CONFIG).authority
)
Assert.assertEquals(
NetworkOptionsManager.MP_URL,
NetworkUtilities.getUrlWithPrefix(url = NetworkOptionsManager.MP_URL_PREFIX, "", false),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
NetworkOptionsManager.MP_IDENTITY_URL,
NetworkUtilities.getUrlWithPrefix(url = NetworkOptionsManager.MP_IDENTITY_URL_PREFIX, "", false),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.IDENTITY).authority
)
var randIdentityPath = mRandomUtils.getAlphaString(10)
Expand All @@ -71,7 +72,7 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
identityClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
NetworkOptionsManager.MP_IDENTITY_URL,
NetworkOptionsManager.MP_IDENTITY_URL_PREFIX.addSuffix(),
identityClient.getUrl(MParticleBaseClientImpl.Endpoint.IDENTITY).authority
)
randIdentityPath = mRandomUtils.getAlphaString(10)
Expand All @@ -84,10 +85,12 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
)
}

private fun String.addSuffix(suffix: String = ".mparticle.com") = "$this$suffix"

@Test
@Throws(MalformedURLException::class)
fun testRandomEndpoint() {
val identityUrl = mRandomUtils.getAlphaString(20)
val identityUrl = "${mRandomUtils.getAlphaString(20)}"
val configUrl = mRandomUtils.getAlphaString(20)
val audienceUrl = mRandomUtils.getAlphaString(20)
val eventsUrl = mRandomUtils.getAlphaString(20)
Expand All @@ -114,19 +117,19 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
MParticle.start(options)
setClients()
Assert.assertEquals(
audienceUrl,
audienceUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.AUDIENCE).authority
)
Assert.assertEquals(
configUrl,
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.CONFIG).authority
)
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
identityUrl,
identityUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.IDENTITY).authority
)
var randIdentityPath = mRandomUtils.getAlphaString(10)
Expand All @@ -135,19 +138,19 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.IDENTITY, randIdentityPath).path
)
Assert.assertEquals(
audienceUrl,
audienceUrl.addSuffix(),
identityClient.getUrl(MParticleBaseClientImpl.Endpoint.AUDIENCE).authority
)
Assert.assertEquals(
configUrl,
identityClient.getUrl(MParticleBaseClientImpl.Endpoint.CONFIG).authority
)
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
identityClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
identityUrl,
identityUrl.addSuffix(),
identityClient.getUrl(MParticleBaseClientImpl.Endpoint.IDENTITY).authority
)
randIdentityPath = mRandomUtils.getAlphaString(10)
Expand Down Expand Up @@ -211,19 +214,19 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
MParticle.start(options)
setClients()
Assert.assertEquals(
audienceUrl,
audienceUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.AUDIENCE).authority
)
Assert.assertEquals(
configUrl,
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.CONFIG).authority
)
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
identityUrl,
identityUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.IDENTITY).authority
)
val randIdentityPath = mRandomUtils.getAlphaString(10)
Expand Down Expand Up @@ -285,11 +288,11 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
MParticle.start(options)
setClients()
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.ALIAS).authority
)
}
Expand All @@ -311,11 +314,11 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
MParticle.start(options)
setClients()
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
aliasUrl,
aliasUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.ALIAS).authority
)
}
Expand All @@ -335,7 +338,7 @@ class NetworkOptionsTest : BaseCleanInstallEachTest() {
MParticle.start(options)
setClients()
Assert.assertEquals(
eventsUrl,
eventsUrl.addSuffix(),
mpClient.getUrl(MParticleBaseClientImpl.Endpoint.EVENTS).authority
)
Assert.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ConfigManager {
static final String KEY_OPT_OUT = "oo";
public static final String KEY_UNHANDLED_EXCEPTIONS = "cue";
public static final String KEY_PUSH_MESSAGES = "pmk";
public static final String DIRECT_URL_ROUTING = "dur";
markvdouw marked this conversation as resolved.
Show resolved Hide resolved
public static final String KEY_EMBEDDED_KITS = "eks";
static final String KEY_UPLOAD_INTERVAL = "uitl";
static final String KEY_SESSION_TIMEOUT = "stl";
Expand Down Expand Up @@ -83,6 +84,7 @@ public class ConfigManager {
static SharedPreferences sPreferences;

private static JSONArray sPushKeys;
private boolean directUrlRouting = false;
private UserStorage mUserStorage;
private String mLogUnhandledExceptions = VALUE_APP_DEFINED;

Expand Down Expand Up @@ -405,6 +407,8 @@ private synchronized void updateCoreConfig(JSONObject responseJSON, boolean newC
sPushKeys = responseJSON.getJSONArray(KEY_PUSH_MESSAGES);
editor.putString(KEY_PUSH_MESSAGES, sPushKeys.toString());
}
directUrlRouting = responseJSON.optBoolean(DIRECT_URL_ROUTING, false);
editor.putBoolean(DIRECT_URL_ROUTING, directUrlRouting);

mRampValue = responseJSON.optInt(KEY_RAMP, -1);

Expand Down Expand Up @@ -1276,6 +1280,20 @@ public ConsentState getConsentState(long mpid) {
return ConsentState.withConsentState(serializedConsent).build();
}

public boolean podRedirectionEnabled() {
return directUrlRouting;
}

public String getPodPrefix() {
String prefix = "us1";
try {
markvdouw marked this conversation as resolved.
Show resolved Hide resolved
prefix = getApiKey().split("-")[0];
} catch (Exception e) {
prefix = "us1";
}
return prefix;
}

public void setConsentState(ConsentState state, long mpid) {
String serializedConsent = null;
if (state != null) {
Expand Down
Loading
Loading