-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle logger creation failures (#52)
- Loading branch information
1 parent
a9faf8f
commit 751653c
Showing
22 changed files
with
449 additions
and
146 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
28 changes: 28 additions & 0 deletions
28
platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/IBridge.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,28 @@ | ||
// capture-sdk - bitdrift's client SDK | ||
// Copyright Bitdrift, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by a source available license that can be found in the | ||
// LICENSE file or at: | ||
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt | ||
|
||
package io.bitdrift.capture | ||
|
||
import io.bitdrift.capture.error.IErrorReporter | ||
import io.bitdrift.capture.network.ICaptureNetwork | ||
import io.bitdrift.capture.providers.session.SessionStrategyConfiguration | ||
|
||
internal interface IBridge { | ||
fun createLogger( | ||
sdkDirectory: String, | ||
apiKey: String, | ||
sessionStrategy: SessionStrategyConfiguration, | ||
metadataProvider: IMetadataProvider, | ||
resourceUtilizationTarget: IResourceUtilizationTarget, | ||
eventsListenerTarget: IEventsListenerTarget, | ||
applicationId: String, | ||
applicationVersion: String, | ||
network: ICaptureNetwork, | ||
preferences: IPreferences, | ||
errorReporter: IErrorReporter, | ||
): Long | ||
} |
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
108 changes: 108 additions & 0 deletions
108
platform/jvm/capture/src/test/kotlin/io/bitdrift/capture/ConfigurationTest.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,108 @@ | ||
// capture-sdk - bitdrift's client SDK | ||
// Copyright Bitdrift, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by a source available license that can be found in the | ||
// LICENSE file or at: | ||
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt | ||
|
||
package io.bitdrift.capture | ||
|
||
import androidx.test.core.app.ApplicationProvider | ||
import com.nhaarman.mockitokotlin2.anyOrNull | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.times | ||
import com.nhaarman.mockitokotlin2.verify | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import io.bitdrift.capture.providers.session.SessionStrategy | ||
import org.assertj.core.api.Assertions | ||
import org.junit.After | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(sdk = [21]) | ||
class ConfigurationTest { | ||
@Test | ||
fun configurationFailure() { | ||
val initializer = ContextHolder() | ||
initializer.create(ApplicationProvider.getApplicationContext()) | ||
|
||
val bridge: IBridge = mock {} | ||
whenever( | ||
bridge.createLogger( | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
), | ||
).thenReturn(-1L) | ||
|
||
// We start without configured logger. | ||
Assertions.assertThat(Capture.logger()).isNull() | ||
|
||
Capture.Logger.configure( | ||
apiKey = "test1", | ||
sessionStrategy = SessionStrategy.Fixed(), | ||
dateProvider = null, | ||
bridge = bridge, | ||
) | ||
|
||
// The configuration failed so the logger is still `null`. | ||
Assertions.assertThat(Capture.logger()).isNull() | ||
|
||
// We confirm that we actually tried to configure the logger. | ||
verify(bridge, times(1)).createLogger( | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
) | ||
|
||
// We perform another attempt to configure the logger to verify that | ||
// consecutive configure calls are no-ops. | ||
Capture.Logger.configure( | ||
apiKey = "test1", | ||
sessionStrategy = SessionStrategy.Fixed(), | ||
dateProvider = null, | ||
bridge = bridge, | ||
) | ||
|
||
Assertions.assertThat(Capture.logger()).isNull() | ||
|
||
// We verify that the second configure call was a no-op. | ||
verify(bridge, times(1)).createLogger( | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
anyOrNull(), | ||
) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
Capture.Logger.resetShared() | ||
} | ||
} |
Oops, something went wrong.