-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add local database instrumented test
This patch adds local database instrumented test. Signed-off-by: Yelin Jeong <[email protected]>
- Loading branch information
Showing
2 changed files
with
70 additions
and
24 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
...ing/src/androidTest/java/ai/nnstreamer/ml/inference/offloading/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...ffloading/src/androidTest/java/ai/nnstreamer/ml/inference/offloading/LocalDatabaseTest.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,70 @@ | ||
package ai.nnstreamer.ml.inference.offloading | ||
|
||
import ai.nnstreamer.ml.inference.offloading.data.AppDatabase | ||
import ai.nnstreamer.ml.inference.offloading.data.Model | ||
import ai.nnstreamer.ml.inference.offloading.data.ModelDao | ||
import ai.nnstreamer.ml.inference.offloading.data.OffloadingService | ||
import ai.nnstreamer.ml.inference.offloading.data.OffloadingServiceDao | ||
import android.content.Context | ||
import androidx.room.Room | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import kotlinx.coroutines.flow.take | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.After | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Before | ||
import org.nnsuite.nnstreamer.Pipeline | ||
import java.io.IOException | ||
import kotlin.jvm.Throws | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class LocalDatabaseTest { | ||
private lateinit var database: AppDatabase | ||
private lateinit var modelDao: ModelDao | ||
private lateinit var offloadingServiceDao: OffloadingServiceDao | ||
|
||
@Before | ||
fun createDb() { | ||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
database = Room.inMemoryDatabaseBuilder( | ||
context, AppDatabase::class.java | ||
).build() | ||
modelDao = database.modelDao() | ||
offloadingServiceDao = database.offloadingServiceDao() | ||
} | ||
|
||
@After | ||
@Throws(IOException::class) | ||
fun closeDb() { | ||
database.close() | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun writeOffloadingServiceAndReadInList() = runTest { | ||
val modelId = 1 | ||
val model = Model(modelId, "model_name") | ||
modelDao.insert(model) | ||
|
||
val serviceId = 1 | ||
val port = 3030 | ||
val offloadingService = OffloadingService(serviceId, modelId, port, Pipeline.State.NULL) | ||
offloadingServiceDao.insert(offloadingService) | ||
|
||
launch { | ||
val byId = offloadingServiceDao.getOffloadingService(1) | ||
byId.take(1).collect { | ||
assertEquals(serviceId, it.serviceId) | ||
assertEquals(modelId, it.modelId) | ||
assertEquals(port, it.port) | ||
assertEquals(Pipeline.State.NULL, it.state) | ||
} | ||
} | ||
} | ||
} |