Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
muzahidul-opti authored Sep 9, 2024
2 parents 1b64dcb + 70d50b9 commit 6a2c519
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 216 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
action: build
test:
if: ${{ startsWith(github.ref, 'refs/tags/') != true && github.event.inputs.SNAPSHOT != 'true' }}
runs-on: macos-latest
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -89,7 +89,13 @@ jobs:
- name: set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 11
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Gradle cache
Expand All @@ -114,6 +120,7 @@ jobs:
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
# arch: arm64-v8a # Specify ARM architecture
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ License (Public Domain): [https://github.com/noveogroup/android-logger/blob/mast

- Ruby - https://github.com/optimizely/ruby-sdk

- Swift - https://github.com/optimizely/swift-sdk
- Swift - https://github.com/optimizely/swift-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package com.optimizely.ab.android.odp

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.optimizely.ab.android.shared.ClientForODPOnly
import com.optimizely.ab.android.shared.Client
import java.io.OutputStream
import java.net.HttpURLConnection
import org.junit.Assert.assertNull
Expand All @@ -34,9 +34,9 @@ import org.slf4j.Logger
@RunWith(AndroidJUnit4::class)
class ODPSegmentClientTest {
private val logger = mock(Logger::class.java)
private val client = mock(ClientForODPOnly::class.java)
private val client = mock(Client::class.java)
private val urlConnection = mock(HttpURLConnection::class.java)
private val captor = ArgumentCaptor.forClass(ClientForODPOnly.Request::class.java)
private val captor = ArgumentCaptor.forClass(Client.Request::class.java)
private lateinit var segmentClient: ODPSegmentClient

private val apiKey = "valid-key"
Expand Down Expand Up @@ -96,17 +96,17 @@ class ODPSegmentClientTest {
verify(urlConnection).disconnect()
}

// @Test
// fun fetchQualifiedSegments_connectionFailed() {
// `when`(urlConnection.responseCode).thenReturn(200)
//
// apiEndpoint = "invalid-url"
// segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
//
// verify(client).execute(captor.capture(), eq(0), eq(0))
// val received = captor.value.execute()
//
// assertNull(received)
// verify(logger).error(contains("Error making ODP segment request"), any())
// }
@Test
fun fetchQualifiedSegments_connectionFailed() {
`when`(urlConnection.responseCode).thenReturn(200)

apiEndpoint = "invalid-url"
segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)

verify(client).execute(captor.capture(), eq(0), eq(0))
val received = captor.value.execute()

assertNull(received)
verify(logger).error(contains("Error making ODP segment request"), any())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package com.optimizely.ab.android.odp

import android.content.Context
import androidx.annotation.VisibleForTesting
import com.optimizely.ab.android.shared.ClientForODPOnly
import com.optimizely.ab.android.shared.Client
import com.optimizely.ab.android.shared.OptlyStorage
import com.optimizely.ab.android.shared.WorkerScheduler
import com.optimizely.ab.odp.ODPApiManager
Expand All @@ -33,7 +33,7 @@ open class DefaultODPApiManager(private val context: Context, timeoutForSegmentF

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
var segmentClient = ODPSegmentClient(
ClientForODPOnly(OptlyStorage(context), LoggerFactory.getLogger(ClientForODPOnly::class.java)),
Client(OptlyStorage(context), LoggerFactory.getLogger(Client::class.java)),
LoggerFactory.getLogger(ODPSegmentClient::class.java)
)
private val logger = LoggerFactory.getLogger(DefaultODPApiManager::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
package com.optimizely.ab.android.odp

import androidx.annotation.VisibleForTesting
import com.optimizely.ab.android.shared.ClientForODPOnly
import com.optimizely.ab.android.shared.Client
import com.optimizely.ab.odp.parser.ResponseJsonParser
import com.optimizely.ab.odp.parser.ResponseJsonParserFactory
import org.slf4j.Logger
import java.net.HttpURLConnection
import java.net.URL

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
open class ODPSegmentClient(private val client: ClientForODPOnly, private val logger: Logger) {
open class ODPSegmentClient(private val client: Client, private val logger: Logger) {

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
open fun fetchQualifiedSegments(
Expand All @@ -32,7 +32,7 @@ open class ODPSegmentClient(private val client: ClientForODPOnly, private val lo
payload: String
): List<String>? {

val request: ClientForODPOnly.Request<String> = ClientForODPOnly.Request {
val request: Client.Request<String> = Client.Request {
var urlConnection: HttpURLConnection? = null
try {
val url = URL(apiEndpoint)
Expand Down Expand Up @@ -60,13 +60,13 @@ open class ODPSegmentClient(private val client: ClientForODPOnly, private val lo
logger.debug("Successfully fetched ODP segments: {}", json)
return@Request json
} else {
logger.error("Unexpected response from ODP segment endpoint, status: $status")
var errMsg = "Unexpected response from ODP segment endpoint, status: $status"
logger.error(errMsg)
return@Request null
}
} catch (e: Exception) {
logger.error("Error making ODP segment request", e)
// return@Request null
throw e
return@Request null
} finally {
if (urlConnection != null) {
try {
Expand Down

This file was deleted.

0 comments on commit 6a2c519

Please sign in to comment.