Fixes new generics on the benchmark classes
This commit is contained in:
+35
-21
@@ -26,12 +26,14 @@ import androidx.benchmark.junit4.BenchmarkRule
|
||||
import androidx.benchmark.junit4.measureRepeated
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.store.sqlite.EventStore
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
|
||||
import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
|
||||
import com.vitorpamplona.quartz.utils.Log
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
@@ -40,7 +42,8 @@ import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class LargeDBQueryingBenchmark : BaseLargeCacheBenchmark() {
|
||||
@get:Rule val benchmarkRule = BenchmarkRule()
|
||||
@get:Rule
|
||||
val benchmarkRule = BenchmarkRule()
|
||||
|
||||
companion object {
|
||||
val allEvents = getEventDB().distinctBy { it.id }.sortedBy { it.createdAt }
|
||||
@@ -50,16 +53,15 @@ class LargeDBQueryingBenchmark : BaseLargeCacheBenchmark() {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
println("Running Setup")
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
|
||||
context.deleteDatabase("allEvents.db")
|
||||
db = EventStore(context, "allEvents.db")
|
||||
db.store.clearDB()
|
||||
allEvents.forEach { event ->
|
||||
try {
|
||||
db.insert(event)
|
||||
} catch (e: SQLiteException) {
|
||||
Log.w("LargeDBQueryingBenchmark", "Error inserting event: ${e.message} for event: $event")
|
||||
Log.w("LargeDBQueryingBenchmark", "Error inserting event: ${e.message} for event: ${event.toJson()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,19 +69,21 @@ class LargeDBQueryingBenchmark : BaseLargeCacheBenchmark() {
|
||||
@After
|
||||
fun tearDown() {
|
||||
db.close()
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
context.deleteDatabase("allEvents.db")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun benchQuerying1000Events() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(Filter(limit = 1000))
|
||||
db.query<Event>(Filter(limit = 1000))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun benchQuerying1614GiftWrapsEvents() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(
|
||||
db.query<GiftWrapEvent>(
|
||||
Filter(
|
||||
kinds = listOf(GiftWrapEvent.KIND),
|
||||
tags = mapOf("p" to listOf("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c")),
|
||||
@@ -91,7 +95,7 @@ class LargeDBQueryingBenchmark : BaseLargeCacheBenchmark() {
|
||||
@Test
|
||||
fun benchQueryingEventsByAuthor() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(
|
||||
db.query<Event>(
|
||||
Filter(
|
||||
authors = listOf("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"),
|
||||
),
|
||||
@@ -102,38 +106,48 @@ class LargeDBQueryingBenchmark : BaseLargeCacheBenchmark() {
|
||||
@Test
|
||||
fun benchQueryingMetadataByAuthor() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(
|
||||
Filter(
|
||||
kinds = listOf(MetadataEvent.KIND),
|
||||
authors = listOf("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"),
|
||||
),
|
||||
)
|
||||
val result =
|
||||
db.query<MetadataEvent>(
|
||||
Filter(
|
||||
kinds = listOf(MetadataEvent.KIND),
|
||||
authors = listOf("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"),
|
||||
),
|
||||
)
|
||||
assertEquals(1, result.size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun benchQueryingRelayListByAuthor() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(
|
||||
Filter(
|
||||
kinds = listOf(AdvertisedRelayListEvent.KIND),
|
||||
authors = listOf("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"),
|
||||
),
|
||||
)
|
||||
val result =
|
||||
db.query<AdvertisedRelayListEvent>(
|
||||
Filter(
|
||||
kinds = listOf(AdvertisedRelayListEvent.KIND),
|
||||
authors = listOf("460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c"),
|
||||
),
|
||||
)
|
||||
assertEquals(0, result.size)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun benchQueryingEmptyReturnByTags() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(Filter(tags = mapOf("p" to listOf("176d972f60dcdc3212ed8c92ef85065c176d972f60dcdc3212ed8c92ef85065c"))))
|
||||
db.query<Event>(
|
||||
Filter(
|
||||
tags = mapOf("p" to listOf("176d972f60dcdc3212ed8c92ef85065c176d972f60dcdc3212ed8c92ef85065c")),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun benchQueryingEmptyReturnByIds() {
|
||||
benchmarkRule.measureRepeated {
|
||||
db.query(Filter(ids = listOf("176d972f60dcdc3212ed8c92ef85065c176d972f60dcdc3212ed8c92ef85065c")))
|
||||
db.query<Event>(
|
||||
Filter(ids = listOf("176d972f60dcdc3212ed8c92ef85065c176d972f60dcdc3212ed8c92ef85065c")),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user