-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental wasm-open-helper library (draft) (#276)
* Add experimental wasm-open-helper library (draft)
- Loading branch information
1 parent
a78dc8e
commit af0d712
Showing
20 changed files
with
545 additions
and
21 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-sdk | ||
android:minSdkVersion="26" | ||
tools:overrideLibrary="ru.pixnews.wasm.sqlite.open.helper" /> | ||
</manifest> |
83 changes: 83 additions & 0 deletions
83
...data/src/test/kotlin/ru/pixnews/feature/calendar/data/sync/IgdbGameModeSyncServiceTest.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,83 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.sync | ||
|
||
import android.content.ContextWrapper | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase.JournalMode.WRITE_AHEAD_LOGGING | ||
import co.touchlab.kermit.LoggerConfig | ||
import co.touchlab.kermit.Severity | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import ru.pixnews.foundation.database.PixnewsDatabase | ||
import ru.pixnews.foundation.database.util.QueryLogger | ||
import ru.pixnews.library.test.TestingLoggers | ||
import ru.pixnews.wasm.sqlite.open.helper.SQLiteDatabaseJournalMode.PERSIST | ||
import ru.pixnews.wasm.sqlite.open.helper.SQLiteDatabaseSyncMode | ||
import ru.pixnews.wasm.sqlite.open.helper.WasmSqliteOpenHelperFactory | ||
import ru.pixnews.wasm.sqlite.open.helper.graalvm.GraalvmSqliteEmbedder | ||
import ru.pixnews.wasm.sqlite.open.helper.path.JvmDatabasePathResolver | ||
import java.io.File | ||
import co.touchlab.kermit.Logger as KermitLogger | ||
|
||
class IgdbGameModeSyncServiceTest { | ||
val logger = TestingLoggers.consoleLogger | ||
val mockContext = ContextWrapper(null) | ||
|
||
@TempDir | ||
lateinit var tempDir: File | ||
lateinit var db: PixnewsDatabase | ||
|
||
@BeforeEach | ||
fun createDb() { | ||
val dbLogger = KermitLogger( | ||
config = object : LoggerConfig by logger.config { | ||
override val minSeverity: Severity = Severity.Info | ||
}, | ||
"Sqlite", | ||
) | ||
|
||
val helperFactory = WasmSqliteOpenHelperFactory(GraalvmSqliteEmbedder) { | ||
logger = SqliteLogger(dbLogger) | ||
pathResolver = JvmDatabasePathResolver(tempDir) | ||
openParams { | ||
journalMode = PERSIST | ||
syncMode = SQLiteDatabaseSyncMode.OFF | ||
} | ||
debug { | ||
sqlLog = false | ||
sqlStatements = false | ||
sqlTime = false | ||
logSlowQueries = false | ||
} | ||
} | ||
|
||
db = Room.databaseBuilder( | ||
mockContext, | ||
PixnewsDatabase::class.java, | ||
"pixnews", | ||
) | ||
.setJournalMode(WRITE_AHEAD_LOGGING) | ||
// .createFromAsset("pixnews.db") | ||
.setQueryCallback(QueryLogger(logger), QueryLogger.createLoggerExecutor()) | ||
.openHelperFactory(helperFactory) | ||
.allowMainThreadQueries() | ||
.build() | ||
} | ||
|
||
@AfterEach | ||
fun closeDb() { | ||
db.close() | ||
} | ||
|
||
@Test | ||
fun dbTest() { | ||
val gameMode = db.gameModeNameDao().getByIdTestBlocking(1) | ||
logger.i { "gem mode: $gameMode" } | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
feature/calendar/data/src/test/kotlin/ru/pixnews/feature/calendar/data/sync/SqliteLogger.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,66 @@ | ||
/* | ||
* Copyright (c) 2024, the Pixnews project authors and contributors. Please see the AUTHORS file for details. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
*/ | ||
|
||
package ru.pixnews.feature.calendar.data.sync | ||
|
||
import co.touchlab.kermit.Logger | ||
import ru.pixnews.wasm.sqlite.open.helper.common.api.Logger as WasmHelperLogger | ||
|
||
@Suppress("IDENTIFIER_LENGTH") | ||
internal class SqliteLogger( | ||
private val kermitLogger: Logger, | ||
) : WasmHelperLogger { | ||
override fun a(throwable: Throwable?, message: () -> String) { | ||
if (throwable != null) { | ||
kermitLogger.a(throwable, message) | ||
} else { | ||
kermitLogger.a(message) | ||
} | ||
} | ||
|
||
override fun d(throwable: Throwable?, message: () -> String) { | ||
if (throwable != null) { | ||
kermitLogger.d(throwable, message) | ||
} else { | ||
kermitLogger.d(message) | ||
} | ||
} | ||
|
||
override fun e(throwable: Throwable?, message: () -> String) { | ||
if (throwable != null) { | ||
kermitLogger.e(throwable, message) | ||
} else { | ||
kermitLogger.e(message) | ||
} | ||
} | ||
|
||
override fun i(throwable: Throwable?, message: () -> String) { | ||
if (throwable != null) { | ||
kermitLogger.i(throwable, message) | ||
} else { | ||
kermitLogger.i(message) | ||
} | ||
} | ||
|
||
override fun v(throwable: Throwable?, message: () -> String) { | ||
if (throwable != null) { | ||
kermitLogger.v(throwable, message) | ||
} else { | ||
kermitLogger.v(message) | ||
} | ||
} | ||
|
||
override fun w(throwable: Throwable?, message: () -> String) { | ||
if (throwable != null) { | ||
kermitLogger.w(throwable, message) | ||
} else { | ||
kermitLogger.w(message) | ||
} | ||
} | ||
|
||
override fun withTag(tag: String): WasmHelperLogger { | ||
return SqliteLogger(kermitLogger.withTag(tag)) | ||
} | ||
} |
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
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
Oops, something went wrong.