Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
package com.keylesspalace.tusky
|
|
|
|
|
|
|
|
import androidx.room.testing.MigrationTestHelper
|
|
|
|
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
2019-05-01 22:10:00 +02:00
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import com.keylesspalace.tusky.db.AppDatabase
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
|
2019-03-30 15:18:16 +01:00
|
|
|
const val TEST_DB = "migration_test"
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
class MigrationsTest {
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
@Rule
|
|
|
|
var helper: MigrationTestHelper = MigrationTestHelper(
|
|
|
|
InstrumentationRegistry.getInstrumentation(),
|
|
|
|
AppDatabase::class.java.canonicalName,
|
|
|
|
FrameworkSQLiteOpenHelperFactory()
|
|
|
|
)
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun migrateTo11() {
|
|
|
|
val db = helper.createDatabase(TEST_DB, 10)
|
|
|
|
|
|
|
|
val id = 1
|
|
|
|
val domain = "domain.site"
|
|
|
|
val token = "token"
|
|
|
|
val active = true
|
|
|
|
val accountId = "accountId"
|
|
|
|
val username = "username"
|
|
|
|
val values = arrayOf(id, domain, token, active, accountId, username, "Display Name",
|
|
|
|
"https://picture.url", true, true, true, true, true, true, true,
|
|
|
|
true, "1000", "[]", "[{\"shortcode\": \"emoji\", \"url\": \"yes\"}]", 0, false,
|
|
|
|
false, true)
|
|
|
|
|
|
|
|
db.execSQL("INSERT OR REPLACE INTO `AccountEntity`(`id`,`domain`,`accessToken`,`isActive`," +
|
|
|
|
"`accountId`,`username`,`displayName`,`profilePictureUrl`,`notificationsEnabled`," +
|
|
|
|
"`notificationsMentioned`,`notificationsFollowed`,`notificationsReblogged`," +
|
|
|
|
"`notificationsFavorited`,`notificationSound`,`notificationVibration`," +
|
|
|
|
"`notificationLight`,`lastNotificationId`,`activeNotifications`,`emojis`," +
|
|
|
|
"`defaultPostPrivacy`,`defaultMediaSensitivity`,`alwaysShowSensitiveMedia`," +
|
|
|
|
"`mediaPreviewEnabled`) " +
|
|
|
|
"VALUES (nullif(?, 0),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
|
|
|
values)
|
|
|
|
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
val newDb = helper.runMigrationsAndValidate(TEST_DB, 11, true, AppDatabase.MIGRATION_10_11)
|
|
|
|
|
|
|
|
val cursor = newDb.query("SELECT * FROM AccountEntity")
|
|
|
|
cursor.moveToFirst()
|
|
|
|
assertEquals(id, cursor.getInt(0))
|
|
|
|
assertEquals(domain, cursor.getString(1))
|
|
|
|
assertEquals(token, cursor.getString(2))
|
|
|
|
assertEquals(active, cursor.getInt(3) != 0)
|
|
|
|
assertEquals(accountId, cursor.getString(4))
|
|
|
|
assertEquals(username, cursor.getString(5))
|
|
|
|
}
|
|
|
|
}
|