Skip to content

Commit b4cd213

Browse files
authored
Update benchmarks to latest incubating cache version (#6566)
1 parent 5728c76 commit b4cd213

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

benchmark/microbenchmark/src/androidTest/java/com/apollographql/apollo/benchmark/ApolloStoreIncubatingTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.apollographql.apollo.benchmark.Utils.dbName
88
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
99
import com.apollographql.apollo.benchmark.Utils.resource
1010
import com.apollographql.apollo.benchmark.test.R
11-
import com.apollographql.cache.normalized.ApolloStore
11+
import com.apollographql.cache.normalized.CacheManager
1212
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
1313
import com.apollographql.cache.normalized.api.NormalizedCacheFactory
1414
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
@@ -41,7 +41,7 @@ class ApolloStoreIncubatingTests {
4141
}
4242

4343
private fun concurrentReadWrites(cacheFactory: NormalizedCacheFactory) {
44-
val apolloStore = createApolloStore(cacheFactory)
44+
val apolloStore = createCacheManager(cacheFactory)
4545
val query = operationBasedQuery
4646
val data = query.parseJsonResponse(resource(R.raw.calendar_response_simple).jsonReader()).data!!
4747
val threadPool = Executors.newFixedThreadPool(CONCURRENCY)
@@ -61,8 +61,8 @@ class ApolloStoreIncubatingTests {
6161
}
6262
}
6363

64-
private fun createApolloStore(cacheFactory: NormalizedCacheFactory): ApolloStore {
65-
return ApolloStore(cacheFactory)
64+
private fun createCacheManager(cacheFactory: NormalizedCacheFactory): CacheManager {
65+
return CacheManager(cacheFactory)
6666
}
6767

6868

benchmark/microbenchmark/src/androidTest/java/com/apollographql/apollo/benchmark/CacheIncubatingIntegrationTests.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import com.apollographql.mockserver.MockServer
1919
import com.apollographql.mockserver.MockServerHandler
2020
import com.apollographql.apollo.testing.MapTestNetworkTransport
2121
import com.apollographql.apollo.testing.registerTestResponse
22+
import com.apollographql.cache.normalized.CacheManager
2223
import com.apollographql.cache.normalized.api.NormalizedCacheFactory
24+
import com.apollographql.cache.normalized.cacheManager
2325
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
24-
import com.apollographql.cache.normalized.store
2526
import kotlinx.coroutines.joinAll
2627
import kotlinx.coroutines.launch
2728
import kotlinx.coroutines.runBlocking
@@ -76,7 +77,7 @@ class CacheIncubatingIntegrationTests {
7677
it.networkTransport(MapTestNetworkTransport())
7778
}
7879
}
79-
.store(createApolloStore(cacheFactory))
80+
.cacheManager(createCacheManager(cacheFactory))
8081
.build()
8182
if (!withMockServer) {
8283
client.registerTestResponse(operationBasedQuery, operationBasedQuery.parseJsonResponse(resource(R.raw.calendar_response_simple).jsonReader()).data!!)
@@ -99,8 +100,8 @@ class CacheIncubatingIntegrationTests {
99100
}
100101
}
101102

102-
private fun createApolloStore(cacheFactory: NormalizedCacheFactory): ApolloStore {
103-
return ApolloStore(cacheFactory)
103+
private fun createCacheManager(cacheFactory: NormalizedCacheFactory): CacheManager {
104+
return CacheManager(cacheFactory)
104105
}
105106

106107

benchmark/microbenchmark/src/androidTest/java/com/apollographql/apollo/benchmark/CacheIncubatingTests.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import com.apollographql.apollo.benchmark.Utils.registerCacheSize
1313
import com.apollographql.apollo.benchmark.Utils.resource
1414
import com.apollographql.apollo.benchmark.Utils.responseBasedQuery
1515
import com.apollographql.apollo.benchmark.test.R
16-
import com.apollographql.cache.normalized.ApolloStore
16+
import com.apollographql.cache.normalized.CacheManager
1717
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
1818
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
1919
import kotlinx.coroutines.runBlocking
@@ -55,7 +55,7 @@ class CacheIncubatingTests {
5555
}
5656

5757
private fun <D : Query.Data> readFromCache(testName: String, query: Query<D>, jsonResponseResId: Int, sql: Boolean, check: (D) -> Unit) {
58-
val store = ApolloStore(
58+
val cacheManager = CacheManager(
5959
if (sql) {
6060
dbFile.delete()
6161
SqlNormalizedCacheFactory(name = dbName)
@@ -66,14 +66,14 @@ class CacheIncubatingTests {
6666

6767
val data = query.parseJsonResponse(resource(jsonResponseResId).jsonReader()).data!!
6868
runBlocking {
69-
store.writeOperation(query, data)
69+
cacheManager.writeOperation(query, data)
7070
}
7171

7272
if (sql) {
7373
registerCacheSize("CacheIncubatingTests", testName, dbFile.length())
7474
}
7575
benchmarkRule.measureRepeated {
76-
val data2 = store.readOperation(query).data!!
76+
val data2 = cacheManager.readOperation(query).data!!
7777
check(data2)
7878
}
7979
}

benchmark/microbenchmark/src/androidTest/java/com/apollographql/apollo/benchmark/FakeData.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import com.apollographql.apollo.conferences.GetConferenceDataQuery
55
import com.apollographql.apollo.conferences.fragment.RoomDetails
66
import com.apollographql.apollo.conferences.fragment.SessionDetails
77
import com.apollographql.apollo.conferences.fragment.SpeakerDetails
8-
import com.apollographql.cache.normalized.ApolloStore
8+
import com.apollographql.cache.normalized.CacheManager
99
import com.apollographql.cache.normalized.api.ApolloCacheHeaders
1010
import com.apollographql.cache.normalized.api.CacheHeaders
1111

1212
const val SESSION_COUNT = 100
1313

14-
fun primeCache(apolloStore: ApolloStore) {
14+
fun primeCache(cacheManager: CacheManager) {
1515
val query1 = GetConferenceDataQuery(Optional.present(SESSION_COUNT))
1616
var data: GetConferenceDataQuery.Data = GetConferenceDataQuery.Data(
1717
sessions = createSessions(0),
@@ -20,7 +20,7 @@ fun primeCache(apolloStore: ApolloStore) {
2020
config = createConfig(),
2121
venues = createVenues(),
2222
)
23-
apolloStore.writeOperation(query1, data)
23+
cacheManager.writeOperation(query1, data)
2424

2525
// Sessions in the first half of the list become unreachable
2626
data = GetConferenceDataQuery.Data(
@@ -30,7 +30,7 @@ fun primeCache(apolloStore: ApolloStore) {
3030
config = createConfig(),
3131
venues = createVenues(),
3232
)
33-
apolloStore.writeOperation(query1, data)
33+
cacheManager.writeOperation(query1, data)
3434

3535
// Some stale sessions
3636
val query2 = GetConferenceDataQuery(Optional.present(SESSION_COUNT), Optional.present((SESSION_COUNT * 2).toString()))
@@ -41,7 +41,7 @@ fun primeCache(apolloStore: ApolloStore) {
4141
config = createConfig(),
4242
venues = createVenues(),
4343
)
44-
apolloStore.writeOperation(
44+
cacheManager.writeOperation(
4545
query2,
4646
data,
4747
cacheHeaders = CacheHeaders.Builder()
@@ -52,6 +52,7 @@ fun primeCache(apolloStore: ApolloStore) {
5252

5353
private fun createSessions(startingAt: Int): GetConferenceDataQuery.Sessions {
5454
return GetConferenceDataQuery.Sessions(
55+
__typename = "SessionConnection",
5556
nodes = (0 + startingAt..<SESSION_COUNT + startingAt)
5657
.map { i ->
5758
GetConferenceDataQuery.Node(
@@ -78,6 +79,7 @@ private fun createSessions(startingAt: Int): GetConferenceDataQuery.Sessions {
7879
),
7980
),
8081
room = SessionDetails.Room(
82+
__typename = "Room",
8183
name = "Room ${i % 8}",
8284
),
8385
tags = listOf("tag1", "tag2", "tag3"),
@@ -86,13 +88,15 @@ private fun createSessions(startingAt: Int): GetConferenceDataQuery.Sessions {
8688
)
8789
},
8890
pageInfo = GetConferenceDataQuery.PageInfo(
91+
__typename = "PageInfo",
8992
endCursor = "endCursor",
9093
),
9194
)
9295
}
9396

9497
private fun createSpeakers(startingAt: Int): GetConferenceDataQuery.Speakers {
9598
return GetConferenceDataQuery.Speakers(
99+
__typename = "SpeakerConnection",
96100
nodes = (0 + startingAt * 2..<(SESSION_COUNT + startingAt) * 2)
97101
.map { i ->
98102
GetConferenceDataQuery.Node1(
@@ -124,11 +128,13 @@ private fun speakerDetails(i: Int): SpeakerDetails = SpeakerDetails(
124128
),
125129
socials = listOf(
126130
SpeakerDetails.Social(
131+
__typename = "Social",
127132
name = "Twitter",
128133
url = "http://twitter.com/speaker-$i",
129134
icon = "twitter",
130135
),
131136
SpeakerDetails.Social(
137+
__typename = "Social",
132138
name = "LinkedIn",
133139
url = "http://linkedin.com/speaker-$i",
134140
icon = "linkedin",
@@ -150,6 +156,7 @@ private fun createRooms(): List<GetConferenceDataQuery.Room> {
150156
GetConferenceDataQuery.Room(
151157
__typename = "Room",
152158
roomDetails = RoomDetails(
159+
__typename = "Room",
153160
id = i.toString(),
154161
name = "Room $i",
155162
capacity = 100,
@@ -160,6 +167,7 @@ private fun createRooms(): List<GetConferenceDataQuery.Room> {
160167

161168
private fun createConfig(): GetConferenceDataQuery.Config {
162169
return GetConferenceDataQuery.Config(
170+
__typename = "Config",
163171
id = "Conference-0",
164172
name = "The Conference",
165173
timezone = "UTC",
@@ -171,6 +179,7 @@ private fun createConfig(): GetConferenceDataQuery.Config {
171179
private fun createVenues(): List<GetConferenceDataQuery.Venue> {
172180
return listOf(
173181
GetConferenceDataQuery.Venue(
182+
__typename = "Venue",
174183
id = "Venue-0",
175184
name = "The Venue",
176185
address = "123 Main St",

benchmark/microbenchmark/src/androidTest/java/com/apollographql/apollo/benchmark/GarbageCollectTests.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.apollographql.apollo.benchmark.Utils.dbFile
66
import com.apollographql.apollo.benchmark.Utils.dbName
77
import com.apollographql.apollo.conferences.cache.Cache
88
import com.apollographql.cache.normalized.ApolloStore
9+
import com.apollographql.cache.normalized.CacheManager
910
import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider
1011
import com.apollographql.cache.normalized.garbageCollect
1112
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
@@ -20,39 +21,45 @@ class GarbageCollectTests {
2021

2122
@Test
2223
fun garbageCollectMemory() {
23-
lateinit var store: ApolloStore
24+
lateinit var cacheManager: CacheManager
2425
benchmarkRule.measureRepeated {
2526
runWithTimingDisabled {
26-
store = ApolloStore(MemoryCacheFactory())
27-
primeCache(store)
27+
cacheManager = CacheManager(MemoryCacheFactory())
28+
primeCache(cacheManager)
29+
}
30+
cacheManager.accessCache {
31+
it.garbageCollect(maxAgeProvider)
2832
}
29-
store.garbageCollect(maxAgeProvider)
3033
}
3134
}
3235

3336
@Test
3437
fun garbageCollectSql() {
35-
lateinit var store: ApolloStore
38+
lateinit var cacheManager: CacheManager
3639
benchmarkRule.measureRepeated {
3740
runWithTimingDisabled {
3841
dbFile.delete()
39-
store = ApolloStore(SqlNormalizedCacheFactory(dbName))
40-
primeCache(store)
42+
cacheManager = CacheManager(SqlNormalizedCacheFactory(dbName))
43+
primeCache(cacheManager)
44+
}
45+
cacheManager.accessCache {
46+
it.garbageCollect(maxAgeProvider)
4147
}
42-
store.garbageCollect(maxAgeProvider)
4348
}
4449
}
4550

4651
@Test
4752
fun garbageCollectMemoryThenSql() {
48-
lateinit var store: ApolloStore
53+
lateinit var cacheManager: CacheManager
4954
benchmarkRule.measureRepeated {
5055
runWithTimingDisabled {
5156
dbFile.delete()
52-
store = ApolloStore(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName)))
53-
primeCache(store)
57+
cacheManager = CacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName)))
58+
primeCache(cacheManager)
59+
}
60+
cacheManager.accessCache {
61+
it.garbageCollect(maxAgeProvider)
5462
}
55-
store.garbageCollect(maxAgeProvider)
5663
}
5764
}
5865
}

gradle/libraries.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ androidx-sqlite = "2.3.1"
1717
# This is used by the gradle integration tests to get the artifacts locally
1818
apollo = "5.0.0-SNAPSHOT"
1919
apollo-execution = "0.1.0"
20-
apollo-normalizedcache-incubating = "0.0.8"
20+
apollo-normalizedcache-incubating = "1.0.0-alpha.3"
2121
# Used by the apollo-tooling project which uses a published version of Apollo
2222
apollo-published = "4.0.1"
2323
atomicfu = "0.26.0"
@@ -65,7 +65,7 @@ apollo-mockserver = { group = "com.apollographql.mockserver", name = "apollo-moc
6565
apollo-mpputils = { group = "com.apollographql.apollo", name = "apollo-mpp-utils", version.ref = "apollo" }
6666
apollo-normalizedcache = { group = "com.apollographql.apollo", name = "apollo-normalized-cache", version.ref = "apollo" }
6767
apollo-normalizedcache-sqlite = { group = "com.apollographql.apollo", name = "apollo-normalized-cache-sqlite", version.ref = "apollo" }
68-
apollo-normalizedcache-sqlite-incubating = { group = "com.apollographql.cache", name = "normalized-cache-sqlite-incubating", version.ref = "apollo-normalizedcache-incubating" }
68+
apollo-normalizedcache-sqlite-incubating = { group = "com.apollographql.cache", name = "normalized-cache-sqlite", version.ref = "apollo-normalizedcache-incubating" }
6969
apollo-normalizedcache-apollo-compiler-plugin-incubating = { group = "com.apollographql.cache", name = "normalized-cache-apollo-compiler-plugin", version.ref = "apollo-normalizedcache-incubating" }
7070
apollo-plugin = { group = "com.apollographql.apollo", name = "apollo-gradle-plugin", version.ref = "apollo" }
7171
apollo-runtime = { group = "com.apollographql.apollo", name = "apollo-runtime", version.ref = "apollo" }

0 commit comments

Comments
 (0)