-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle logger creation failures #52
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6bc265f
Handle logger creation failure
Augustyniak a62783f
move interface to a separate file
Augustyniak 6b47e30
Merge branch 'main' into handle-logger-creation-error
Augustyniak 9249964
format fix
Augustyniak b4fd016
fix
Augustyniak cfb7b4c
add ? when working with optional
Augustyniak cc59881
add missing license headers
Augustyniak 33ed31d
suppress warning
Augustyniak b27514c
Merge branch 'main' into handle-logger-creation-error
Augustyniak bda5381
use getAndSet instead of getAndUpdate
Augustyniak 5407f34
remove resetShared
Augustyniak b46bcf7
add docs
Augustyniak 03c3811
fix flaky test
Augustyniak f817a9f
add empty line
Augustyniak 675d77e
Update platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/Captu…
Augustyniak 9fd7a77
remove suppress
Augustyniak ae82127
fix teardown
Augustyniak dbb6426
format fix
Augustyniak 3a533d4
fix test
Augustyniak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do you use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nowhere, leftover that I thought I removed. Removing for real time time...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, re-added it to fix flakiness of
CaptureTest.kt
tests