Skip to content

Commit

Permalink
Draft: Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kigamba authored and ekigamba committed Jul 13, 2023
1 parent 54d3e95 commit cfaf286
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 1 deletion.
1 change: 1 addition & 0 deletions android/engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ dependencies {
androidTestImplementation(libs.runner)
androidTestImplementation(libs.ui.test.junit4)
androidTestImplementation(libs.hilt.android.testing)
androidTestImplementation("androidx.benchmark:benchmark-junit4:1.1.1")

ktlint(libs.ktlint.main) {
attributes { attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.smartregister.fhircore.engine.performance

import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import androidx.test.ext.junit.runners.AndroidJUnit4
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.data.local.register.RegisterRepository
import javax.inject.Inject


/**
* Created by Ephraim Kigamba - [email protected] on 11-07-2023.
*/
@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class DefaultRepositoryPerformanceTests {

@get:Rule
val benchmarkRule = BenchmarkRule()

@Inject lateinit var defaultRepository: DefaultRepository
@Inject lateinit var registerRepository: RegisterRepository


@get:Rule val hiltRule = HiltAndroidRule(this)

@Test
fun benchmarkSomeWork() {
benchmarkRule.measureRepeated {
registerRepository.retrieveRegisterConfiguration("householdRegister", hashMapOf())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ constructor(
.runCatching {
withContext(dispatcherProvider.io()) { fhirEngine.search<Resource>(search) }
}
.onFailure { Timber.e(it, "Error retrieving resources. Empty list returned by default") }
.onFailure {
Timber.e(it, "Error retrieving resources. Empty list returned by default")
System.out.println("Error occurred")
it.printStackTrace()
}
.getOrDefault(emptyList())

return baseFhirResources.map { baseFhirResource ->
Expand Down
3 changes: 3 additions & 0 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ android {
buildConfigField("String", "SENTRY_DSN", """"${project.extra["SENTRY_DSN"]}"""")

testInstrumentationRunner = "org.smartregister.fhircore.quest.QuestTestRunner"
testInstrumentationRunnerArguments["additionalTestOutputDir"] = "/sdcard/Download"
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "ACTIVITY-MISSING,CODE-COVERAGE,DEBUGGABLE,UNLOCKED,EMULATOR"
}

signingConfigs {
Expand Down Expand Up @@ -361,6 +363,7 @@ dependencies {
androidTestImplementation(libs.ui.test.junit4)
androidTestImplementation(libs.hilt.android.testing)
androidTestImplementation(libs.mockk.android)
androidTestImplementation("androidx.benchmark:benchmark-junit4:1.1.1")
ktlint(libs.ktlint.main) {
attributes { attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL)) }
}
Expand Down
26 changes: 26 additions & 0 deletions android/quest/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2019 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- [START benchmark_manifest] -->

<!-- Requesting legacy storage is needed to be able to write to additionalTestOutputDir on API 29 -->
<application android:requestLegacyExternalStorage="true">

<profileable android:shell="true" />

</application>
<!-- [END benchmark_manifest] -->
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021-2023 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.quest.di.config

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.quest.QuestConfigService

@InstallIn(SingletonComponent::class)
@Module
abstract class ConfigServiceModule {
@Binds abstract fun provideConfigService(questConfigService: QuestConfigService): ConfigService
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.smartregister.fhircore.quest.performance

import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.smartregister.fhircore.engine.R
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.data.local.register.RegisterRepository
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.extension.getActivity
import org.smartregister.fhircore.engine.util.extension.launchActivityWithNoBackStackHistory
import org.smartregister.fhircore.quest.QuestTestRunner
import org.smartregister.fhircore.quest.ui.login.LoginActivity
import timber.log.Timber
import javax.inject.Inject


/**
* Created by Ephraim Kigamba - [email protected] on 11-07-2023.
*/
//@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class DefaultRepositoryPerformanceTests {

@get:Rule
val benchmarkRule = BenchmarkRule()

@Inject lateinit var defaultRepository: DefaultRepository
@Inject lateinit var registerRepository: RegisterRepository


@get:Rule val hiltRule = HiltAndroidRule(this)

@Before
fun setUp() {
hiltRule.inject()

if (InstrumentationRegistry.getInstrumentation().context.externalCacheDir == null ) {
Timber.e("Instrumentation registry is null")
} else {
Timber.e("Instrumentation registry is NOT NULL")
}

runBlocking {
defaultRepository.configurationRegistry.loadConfigurations("app/debug", InstrumentationRegistry.getInstrumentation().targetContext) { loadConfigSuccessful ->

/*if (loadConfigSuccessful) {
sharedPreferencesHelper.write(SharedPreferenceKey.APP_ID.name, thisAppId)
context.getActivity()?.launchActivityWithNoBackStackHistory<LoginActivity>()
} else {
_error.postValue(context.getString(R.string.application_not_supported, appId.value))
}*/
}
}

// Plant Timber tree to print in the console

Timber.plant(Timber.DebugTree())
}

@Test
fun benchmarkSomeWork() {
benchmarkRule.measureRepeated {
//registerRepository.retrieveRegisterConfiguration("householdRegister", hashMapOf())

runBlocking {
val repoData = registerRepository.loadRegisterData(0, "householdRegister")
System.out.println("Records fetched ${repoData.size}")
}
}
}
}
6 changes: 6 additions & 0 deletions android/quest/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.smartregister.fhircore.quest">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>

<application
android:name=".QuestApplication"
android:hardwareAccelerated="true"
Expand Down

0 comments on commit cfaf286

Please sign in to comment.