Skip to content
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

fix: sdk 189 deduplication for metrics android #361

Open
wants to merge 5 commits into
base: develop-v2
Choose a base branch
from

Conversation

itsdebs
Copy link
Contributor

@itsdebs itsdebs commented Nov 14, 2023

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • Version upgraded (project, README, gradle, podspec etc)
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added unit tests for the code
  • I have made corresponding changes to the documentation

Supports Deduplication for metrics.
Snapshots are saved periodically in separate database.
Snapshots are synced with server at intervals.

Copy link

sonarcloud bot commented Nov 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@ChryssaAliferi ChryssaAliferi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we are not proceeding with this at the moment, finalised some comments for later use. Thanks!

// companion object{
// internal fun JsonAdapter.manipulate(): JsonAdapter {
companion object {
// internal fun JsonAdapter.manipulate(): JsonAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this commented-out code?


fun getMetricsFirst(limit: Long, callback: (List<MetricModelWithId<out Number>>) -> Unit)

// fun getMetricsAndErrorFirst(limit : Long, callback : (List<MetricModel<Number>>, List<ErrorModel>) -> Unit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, do we need this commented out part?

init {
jsonAdapter = MoshiAdapter()
override fun shutdown(shutdownExecutor: Boolean) {
TODO("Not yet implemented")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably comment this out, this part of the code is prone to crash if executed

endpoint: String,
responseClass: Class<T>
): Future<HttpResponse<T>> {
TODO("Not yet implemented")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO markups should be commented out, this part of the code is prone to crash if executed.

endpoint: String,
responseTypeAdapter: RudderTypeAdapter<T>
): Future<HttpResponse<T>> {
TODO("Not yet implemented")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

responseTypeAdapter: RudderTypeAdapter<T>,
isGzipEnabled: Boolean
): Future<HttpResponse<T>> {
TODO("Not yet implemented")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️

}

override fun setInterceptor(httpInterceptor: HttpInterceptor) {
TODO("Not yet implemented")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

jsonAdapter, TestExecutor()
)
@Test
fun `test uploadWithSuccessfulUpload`() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Kotlin tests it would be nice to start applying Given-When-Then naming 😃 .

    @Test
    fun `given some test data, when the service is successful, upload is successful`() {
        val mockSnapshot = TestDataGenerator.mockSnapshot()
        val callbackMock = mock<(Boolean) -> Unit>()
        val mockWebService = MockPostWebService(200)
        val uploadMediator = DefaultUploadMediator("https://api.example.com", mock(), mock(), true, mockWebService)

        uploadMediator.upload(mockSnapshot, callbackMock)

        verify(callbackMock, times(1)).invoke(true)
    }
    @Test
    fun `given some test data, when the service is unsuccessful, upload is not successful`() {
        val mockSnapshot = TestDataGenerator.mockSnapshot()
        val callbackMock = mock<(Boolean) -> Unit>()
        val mockWebService = MockPostWebService(400)
        val uploadMediator = DefaultUploadMediator("https://api.example.com", mock(), mock(), true, mockWebService)

        uploadMediator.upload(mockSnapshot, callbackMock)

        verify(callbackMock, times(1)).invoke(false)
    }

internal class DefaultSnapshotCreator(private val libraryMetadata: LibraryMetadata,
private val apiVersion: Int, private val jsonAdapter:
JsonAdapter): SnapshotCreator {
companion object {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Kotlin, files and classes are completely decoupled. You can also declare private top-level functions and variables and they'll be accessible only to the classes within the same file. Top-level declarations instead of companion objects for such cases of private static data can be preferred and are more Kotlin-like. If however, for whatever reason, you have to produce a Java class with Kotlin code such that the class has a static member, you must resort to a companion object and a special annotation.

private const val SOURCE_KEY = "source"
private const val METRICS_KEY = "metrics"
private const val ERROR_KEY = "errors"
private const val VERSION_KEY = "version"
private const val MESSAGE_ID_KEY = "message_id"

internal class DefaultSnapshotCreator(
    private val libraryMetadata: LibraryMetadata,
    private val apiVersion: Int, private val jsonAdapter:
    JsonAdapter
) : SnapshotCreator {

uploadedErrorModel: ErrorModel,
success: Boolean) -> Unit)? = null
private val snapshotCapturer: SnapshotCapturer,
// private val libraryMetadata: LibraryMetadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commented-out code needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants