-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
begin populating new session payload
- Loading branch information
1 parent
b943585
commit c555f57
Showing
7 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...ndroid-sdk/src/main/java/io/embrace/android/embracesdk/capture/envelope/EnvelopeSource.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package io.embrace.android.embracesdk.capture.envelope | ||
|
||
import io.embrace.android.embracesdk.internal.payload.Envelope | ||
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType | ||
|
||
internal fun interface EnvelopeSource<T> { | ||
fun getEnvelope(): Envelope<T> | ||
fun getEnvelope(endType: SessionSnapshotType): Envelope<T> | ||
} |
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
3 changes: 2 additions & 1 deletion
3
.../main/java/io/embrace/android/embracesdk/capture/envelope/session/SessionPayloadSource.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package io.embrace.android.embracesdk.capture.envelope.session | ||
|
||
import io.embrace.android.embracesdk.internal.payload.SessionPayload | ||
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType | ||
|
||
/** | ||
* Creates a [SessionPayload] object. | ||
*/ | ||
internal fun interface SessionPayloadSource { | ||
fun getSessionPayload(): SessionPayload | ||
fun getSessionPayload(endType: SessionSnapshotType): SessionPayload | ||
} |
18 changes: 14 additions & 4 deletions
18
...n/java/io/embrace/android/embracesdk/capture/envelope/session/SessionPayloadSourceImpl.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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
package io.embrace.android.embracesdk.capture.envelope.session | ||
|
||
import io.embrace.android.embracesdk.anr.ndk.NativeThreadSamplerService | ||
import io.embrace.android.embracesdk.internal.payload.SessionPayload | ||
import io.embrace.android.embracesdk.logging.InternalErrorService | ||
import io.embrace.android.embracesdk.session.captureDataSafely | ||
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType | ||
|
||
internal class SessionPayloadSourceImpl : SessionPayloadSource { | ||
internal class SessionPayloadSourceImpl( | ||
private val internalErrorService: InternalErrorService, | ||
private val nativeThreadSamplerService: NativeThreadSamplerService?, | ||
) : SessionPayloadSource { | ||
|
||
override fun getSessionPayload(): SessionPayload { | ||
throw NotImplementedError("Not yet implemented") | ||
} | ||
override fun getSessionPayload(endType: SessionSnapshotType) = SessionPayload( | ||
spans = null, | ||
spanSnapshots = null, | ||
internalError = captureDataSafely { internalErrorService.currentExceptionError?.toNewPayload() }, | ||
sharedLibSymbolMapping = captureDataSafely { nativeThreadSamplerService?.getNativeSymbols() } | ||
) | ||
} |
10 changes: 9 additions & 1 deletion
10
...src/test/java/io/embrace/android/embracesdk/capture/envelope/SessionEnvelopeSourceTest.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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package io.embrace.android.embracesdk.capture.envelope | ||
|
||
import io.embrace.android.embracesdk.capture.envelope.session.SessionPayloadSourceImpl | ||
import io.embrace.android.embracesdk.fakes.FakeInternalErrorService | ||
import io.embrace.android.embracesdk.fakes.FakeNativeThreadSamplerService | ||
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType | ||
import org.junit.Test | ||
|
||
internal class SessionEnvelopeSourceTest { | ||
|
||
@Test(expected = NotImplementedError::class) | ||
fun getEnvelope() { | ||
SessionEnvelopeSource(SessionPayloadSourceImpl()).getEnvelope() | ||
SessionEnvelopeSource( | ||
SessionPayloadSourceImpl( | ||
FakeInternalErrorService(), | ||
FakeNativeThreadSamplerService() | ||
) | ||
).getEnvelope(SessionSnapshotType.NORMAL_END) | ||
} | ||
} |
48 changes: 45 additions & 3 deletions
48
...va/io/embrace/android/embracesdk/capture/envelope/session/SessionPayloadSourceImplTest.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 |
---|---|---|
@@ -1,11 +1,53 @@ | ||
package io.embrace.android.embracesdk.capture.envelope.session | ||
|
||
import io.embrace.android.embracesdk.fakes.FakeClock | ||
import io.embrace.android.embracesdk.fakes.FakeInternalErrorService | ||
import io.embrace.android.embracesdk.fakes.FakeNativeThreadSamplerService | ||
import io.embrace.android.embracesdk.internal.payload.SessionPayload | ||
import io.embrace.android.embracesdk.payload.LegacyExceptionError | ||
import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
internal class SessionPayloadSourceImplTest { | ||
|
||
@Test(expected = NotImplementedError::class) | ||
fun getSessionPayload() { | ||
SessionPayloadSourceImpl().getSessionPayload() | ||
private lateinit var impl: SessionPayloadSourceImpl | ||
|
||
@Before | ||
fun setUp() { | ||
val errorService = FakeInternalErrorService().apply { | ||
currentExceptionError = LegacyExceptionError().apply { | ||
addException(RuntimeException(), "test", FakeClock()) | ||
} | ||
} | ||
impl = SessionPayloadSourceImpl( | ||
errorService, | ||
FakeNativeThreadSamplerService() | ||
) | ||
} | ||
|
||
@Test | ||
fun `session crash`() { | ||
val payload = impl.getSessionPayload(SessionSnapshotType.JVM_CRASH) | ||
assertPayloadPopulated(payload) | ||
} | ||
|
||
@Test | ||
fun `session cache`() { | ||
val payload = impl.getSessionPayload(SessionSnapshotType.PERIODIC_CACHE) | ||
assertPayloadPopulated(payload) | ||
} | ||
|
||
@Test | ||
fun `session lifecycle change`() { | ||
val payload = impl.getSessionPayload(SessionSnapshotType.NORMAL_END) | ||
assertPayloadPopulated(payload) | ||
} | ||
|
||
private fun assertPayloadPopulated(payload: SessionPayload) { | ||
val err = checkNotNull(payload.internalError) | ||
assertEquals(1, err.count) | ||
assertEquals(mapOf("armeabi-v7a" to "my-symbols"), payload.sharedLibSymbolMapping) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...d-sdk/src/test/java/io/embrace/android/embracesdk/fakes/FakeNativeThreadSamplerService.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,39 @@ | ||
package io.embrace.android.embracesdk.fakes | ||
|
||
import io.embrace.android.embracesdk.anr.ndk.NativeThreadSamplerService | ||
import io.embrace.android.embracesdk.payload.NativeThreadAnrInterval | ||
|
||
internal class FakeNativeThreadSamplerService : NativeThreadSamplerService { | ||
|
||
var symbols: Map<String, String>? = mapOf("armeabi-v7a" to "my-symbols") | ||
|
||
override fun onThreadBlocked(thread: Thread, timestamp: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun onThreadBlockedInterval(thread: Thread, timestamp: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun onThreadUnblocked(thread: Thread, timestamp: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun setupNativeSampler(): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun monitorCurrentThread(): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getNativeSymbols(): Map<String, String>? = symbols | ||
|
||
override fun getCapturedIntervals(receivedTermination: Boolean?): List<NativeThreadAnrInterval>? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun cleanCollections() { | ||
TODO("Not yet implemented") | ||
} | ||
} |