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

RUN integration tests on API 35 in testing pyramid #2272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include:
# SETUP

variables:
CURRENT_CI_IMAGE: "10"
CURRENT_CI_IMAGE: "11"
CI_IMAGE_DOCKER: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/dd-sdk-android:$CURRENT_CI_IMAGE
GIT_DEPTH: 5

Expand All @@ -19,7 +19,7 @@ variables:

EMULATOR_NAME: "android_emulator"
ANDROID_ARCH: "arm64-v8a"
ANDROID_API: "34"
ANDROID_API: "35"
ANDROID_SDK_VERSION: "commandlinetools-mac-11076708_latest"

stages:
Expand Down Expand Up @@ -249,7 +249,7 @@ test-pyramid:core-it-latest-api:
stage: test-pyramid
timeout: 1h
variables:
ANDROID_API: "34"
ANDROID_API: "35"
ANDROID_EMULATOR_IMAGE: "system-images;android-$ANDROID_API;google_apis;${ANDROID_ARCH}"
ANDROID_PLATFORM: "platforms;android-$ANDROID_API"
ANDROID_BUILD_TOOLS: "build-tools;$ANDROID_API.0.0"
Expand Down Expand Up @@ -353,7 +353,7 @@ test-pyramid:legacy-integration-instrumented-latest-api:
stage: test-pyramid
timeout: 1h
variables:
ANDROID_API: "34"
ANDROID_API: "35"
ANDROID_EMULATOR_IMAGE: "system-images;android-$ANDROID_API;google_apis;${ANDROID_ARCH}"
ANDROID_PLATFORM: "platforms;android-$ANDROID_API"
ANDROID_BUILD_TOOLS: "build-tools;$ANDROID_API.0.0"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.gitlab
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ RUN set -x \
&& rm -rf /var/lib/apt/lists/*

ENV GRADLE_VERSION 8.9
ENV ANDROID_COMPILE_SDK 34
ENV ANDROID_BUILD_TOOLS 34.0.0
ENV ANDROID_COMPILE_SDK 35
ENV ANDROID_BUILD_TOOLS 35.0.0
ENV ANDROID_SDK_TOOLS 11076708
ENV NDK_VERSION 25.1.8937393
ENV CMAKE_VERSION 3.22.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import org.gradle.api.Project

object AndroidConfig {

const val TARGET_SDK = 34
const val TARGET_SDK = 35
const val MIN_SDK = 21
const val MIN_SDK_FOR_WEAR = 23
const val BUILD_TOOLS_VERSION = "34.0.0"
const val BUILD_TOOLS_VERSION = "35.0.0"

val VERSION = Version(2, 14, 0, Version.Type.Snapshot)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal class DataStoreFileReaderTest {
@Test
fun `M log error W read() { invalid number of blocks }`() {
// Given
blocksReturned.removeLast()
blocksReturned.removeAt(blocksReturned.lastIndex)

val foundBlocks = blocksReturned.size
val expectedBlocks = TLVBlockType.values().size
Expand Down Expand Up @@ -213,7 +213,7 @@ internal class DataStoreFileReaderTest {
@Test
fun `M return onFailure W read() { invalid number of blocks }`() {
// Given
blocksReturned.removeLast()
blocksReturned.removeAt(blocksReturned.lastIndex)
val expectedMessage =
INVALID_NUMBER_OF_BLOCKS_ERROR.format(Locale.US, blocksReturned.size, TLVBlockType.values().size)
val mockCallback = mock<DataStoreReadCallback<ByteArray>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal class BitmapPool(
cacheUtils.handleTrimMemory(level, cache)
}

internal fun getBitmapByProperties(width: Int, height: Int, config: Config): Bitmap? {
internal fun getBitmapByProperties(width: Int, height: Int, config: Config?): Bitmap? {
val key = bitmapPoolHelper.generateKey(width, height, config)
return get(key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ internal class BitmapPoolHelper(
internal fun generateKey(bitmap: Bitmap) =
generateKey(bitmap.width, bitmap.height, bitmap.config)

internal fun generateKey(width: Int, height: Int, config: Bitmap.Config) =
internal fun generateKey(width: Int, height: Int, config: Bitmap.Config?) =
"$width-$height-$config"

internal fun<R> safeCall(call: () -> R): R? =
internal fun <R> safeCall(call: () -> R): R? =
invocationUtils.safeCallWithErrorLogging(
call = { call() },
failureMessage = BITMAP_OPERATION_FAILED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import androidx.collection.LruCache
internal class CacheUtils<K : Any, V : Any>(
private val invocationUtils: InvocationUtils = InvocationUtils()
) {

// some of this memory level are not being triggered after API 34. We still need to keep them for now
// for lower versions
@Suppress("DEPRECATION")
Copy link
Member

Choose a reason for hiding this comment

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

what is the replacement then? should we use it for newer APIs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can leave it like it is and prepare a task to remove those later. The only think that will happen for newer APIs is that those level will never be triggered. I don't see any harm now, maybe to create a task to clean these levels ?

Copy link
Member

Choose a reason for hiding this comment

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

yes, no harm. My point is just that if something is deprecated, then probably there is a replacement for the newer APIs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. no replacement suggested in their docs, I think they simply don't support these levels anymore and only kept few important ones. I think they did not need this granularity anymore.

internal fun handleTrimMemory(level: Int, cache: LruCache<K, V>) {
@Suppress("MagicNumber")
val onLowMemorySizeBytes = cache.maxSize() / 2 // 50%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal class NodeFlattenerTest {

private fun generateTreeFromList(list: List<MobileSegment.Wireframe>): Node {
val mutableList = list.toMutableList()
val root = mutableList.removeFirst().toNode()
val root = mutableList.removeAt(0).toNode()
val middle = mutableList.size / 2
// add left
// we need to create a new list as Kotlin .subList re - uses the old list
Expand All @@ -155,7 +155,7 @@ internal class NodeFlattenerTest {
if (leafs.isEmpty()) {
return
}
val leafToAdd = leafs.removeFirst().toNode()
val leafToAdd = leafs.removeAt(0).toNode()
parent.addChild(leafToAdd)
val middle = leafs.size / 2
// add left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ internal class BitmapPoolTest {
testedCache.put(mockBitmap)

// Then
val actualBitmap = testedCache.getBitmapByProperties(mockBitmap.width, mockBitmap.height, mockBitmap.config)
val actualBitmap =
testedCache.getBitmapByProperties(mockBitmap.width, mockBitmap.height, mockBitmap.config)
assertThat(actualBitmap).isEqualTo(mockBitmap)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.sessionreplay.internal.utils

import android.graphics.Bitmap
import com.datadog.android.sessionreplay.forge.ForgeConfigurator
import com.datadog.android.sessionreplay.internal.recorder.resources.BitmapPoolHelper
import fr.xgouchet.elmyr.Forge
import fr.xgouchet.elmyr.annotation.IntForgery
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
import fr.xgouchet.elmyr.junit5.ForgeExtension
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.Extensions
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.kotlin.whenever
import org.mockito.quality.Strictness

@Extensions(
ExtendWith(MockitoExtension::class),
ExtendWith(ForgeExtension::class)
)
@MockitoSettings(strictness = Strictness.LENIENT)
@ForgeConfiguration(ForgeConfigurator::class)
internal class BitmapPoolHelperTest {

lateinit var testedHelper: BitmapPoolHelper

@Mock
lateinit var mockBitmap: Bitmap

@IntForgery
var fakeWidth: Int = 0

@IntForgery
var fakeHeight: Int = 0
private lateinit var fakeConfig: Bitmap.Config

@BeforeEach
fun `set up`(forge: Forge) {
fakeConfig = forge.aValueFrom(Bitmap.Config::class.java)
testedHelper = BitmapPoolHelper()
whenever(mockBitmap.width).thenReturn(fakeWidth)
whenever(mockBitmap.height).thenReturn(fakeHeight)
whenever(mockBitmap.config).thenReturn(fakeConfig)
}

@Test
fun `M generate bitmap key W generateKey`() {
// When
val key = testedHelper.generateKey(mockBitmap)

// Then
assertThat(key).isEqualTo("$fakeWidth-$fakeHeight-$fakeConfig")
}

@Test
fun `M generate bitmap key W generateKey { config is null }`() {
// Given
whenever(mockBitmap.config).thenReturn(null)

// When
val key = testedHelper.generateKey(mockBitmap)

// Then
assertThat(key).isEqualTo("$fakeWidth-$fakeHeight-null")
}
}