Skip to content

Commit

Permalink
[FSSDK-10587] chore: rollback to 4.0.0 (#491)
Browse files Browse the repository at this point in the history
* Rollback to 4.0.0
  • Loading branch information
muzahidul-opti committed Aug 23, 2024
1 parent 049ec0a commit d1aabb8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 242 deletions.
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 @@ -68,45 +68,45 @@ class ODPSegmentClientTest {
verify(urlConnection).disconnect()
}

// @Test
// fun fetchQualifiedSegments_400() {
// `when`(urlConnection.responseCode).thenReturn(400)
//
// segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
//
// verify(client).execute(captor.capture(), eq(0), eq(0))
// val received = captor.value.execute()
//
// assertNull(received)
// verify(logger).error("Unexpected response from ODP segment endpoint, status: 400")
// verify(urlConnection).disconnect()
// }

// @Test
// fun fetchQualifiedSegments_500() {
// `when`(urlConnection.responseCode).thenReturn(500)
//
// segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)
//
// verify(client).execute(captor.capture(), eq(0), eq(0))
// val received = captor.value.execute()
//
// assertNull(received)
// verify(logger).error("Unexpected response from ODP segment endpoint, status: 500")
// 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_400() {
`when`(urlConnection.responseCode).thenReturn(400)

segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)

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

assertNull(received)
verify(logger).error("Unexpected response from ODP segment endpoint, status: 400")
verify(urlConnection).disconnect()
}

@Test
fun fetchQualifiedSegments_500() {
`when`(urlConnection.responseCode).thenReturn(500)

segmentClient.fetchQualifiedSegments(apiKey, apiEndpoint, payload)

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

assertNull(received)
verify(logger).error("Unexpected response from ODP segment endpoint, status: 500")
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())
}
}
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 @@ -62,13 +62,11 @@ open class ODPSegmentClient(private val client: ClientForODPOnly, private val lo
} else {
var errMsg = "Unexpected response from ODP segment endpoint, status: $status"
logger.error(errMsg)
// return@Request null
throw Exception(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 d1aabb8

Please sign in to comment.