-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix OOM error when a bad api key is passed (#210)
* fix: Fix OOM error when a bad api key is passed
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/test/kotlin/com/amplitude/core/utilities/FileResponseHandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.amplitude.core.utilities | ||
|
||
import com.amplitude.core.Configuration | ||
import com.amplitude.core.events.BaseEvent | ||
import com.amplitude.core.platform.EventPipeline | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.json.JSONObject | ||
import org.junit.jupiter.api.Test | ||
|
||
class FileResponseHandlerTest { | ||
@Test | ||
fun testBadResponseHandlerForInvalidApiKey() { | ||
val response = BadRequestResponse( | ||
JSONObject("{\"error\":\"Invalid API key\"}") | ||
) | ||
val storage = mockk<EventsFileStorage>() | ||
val pipeline = mockk<EventPipeline>() | ||
val handler = | ||
FileResponseHandler(storage, pipeline, Configuration("test"), mockk(), mockk(), null) | ||
|
||
every { | ||
storage.removeFile("file_path") | ||
} returns true | ||
|
||
handler.handleBadRequestResponse( | ||
response, | ||
"file_path", | ||
JSONUtil.eventsToString( | ||
listOf(generateBaseEvent("test1"), generateBaseEvent("test2")) | ||
) | ||
) | ||
|
||
verify(exactly = 1) { | ||
storage.removeFile("file_path") | ||
} | ||
} | ||
|
||
private fun generateBaseEvent(eventType: String): BaseEvent { | ||
val baseEvent = BaseEvent() | ||
baseEvent.eventType = eventType | ||
return baseEvent | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
core/src/test/kotlin/com/amplitude/core/utilities/InMemoryResponseHandlerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.amplitude.core.utilities | ||
|
||
import com.amplitude.core.Configuration | ||
import com.amplitude.core.events.BaseEvent | ||
import com.amplitude.core.platform.EventPipeline | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import org.json.JSONObject | ||
import org.junit.jupiter.api.Test | ||
|
||
class InMemoryResponseHandlerTest { | ||
@Test | ||
fun testBadResponseHandlerForInvalidApiKey() { | ||
val response = BadRequestResponse( | ||
JSONObject("{\"error\":\"Invalid API key\"}") | ||
) | ||
val storage = mockk<EventsFileStorage>() | ||
val pipeline = mockk<EventPipeline>() | ||
val handler = | ||
InMemoryResponseHandler(pipeline, Configuration("test"), mockk(), mockk()) | ||
|
||
every { | ||
storage.removeFile("file_path") | ||
} returns true | ||
|
||
handler.handleBadRequestResponse( | ||
response, | ||
listOf(generateBaseEvent("test1"), generateBaseEvent("test2")), | ||
"" | ||
) | ||
|
||
verify(exactly = 0) { | ||
pipeline.put(any()) | ||
} | ||
} | ||
|
||
private fun generateBaseEvent(eventType: String): BaseEvent { | ||
val baseEvent = BaseEvent() | ||
baseEvent.eventType = eventType | ||
return baseEvent | ||
} | ||
} |