Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseJsonResponse
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
import com.apollographql.apollo.benchmark.Utils.resource
import com.apollographql.apollo.benchmark.test.R
import com.apollographql.cache.normalized.CacheManager
import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator
import com.apollographql.cache.normalized.api.DefaultCacheResolver
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
import com.apollographql.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
import kotlinx.coroutines.runBlocking
import org.junit.Assert
Expand All @@ -32,14 +32,14 @@ class ApolloStoreIncubatingTests {
@Test
fun concurrentReadWritesSql() {
Utils.dbFile.delete()
val cacheFactory = SqlNormalizedCacheFactory(dbName)
val cacheFactory = SqlNormalizedCacheFactory(getDbName())
concurrentReadWrites(cacheFactory)
}

@Test
fun concurrentReadWritesMemoryThenSql() {
Utils.dbFile.delete()
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName))
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(getDbName()))
concurrentReadWrites(cacheFactory)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseJsonResponse
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
import com.apollographql.apollo.benchmark.Utils.resource
import com.apollographql.apollo.benchmark.test.R
Expand All @@ -29,14 +29,14 @@ class ApolloStoreTests {
@Test
fun concurrentReadWritesSql() {
Utils.dbFile.delete()
val cacheFactory = SqlNormalizedCacheFactory(dbName)
val cacheFactory = SqlNormalizedCacheFactory(getDbName())
concurrentReadWrites(cacheFactory)
}

@Test
fun concurrentReadWritesMemoryThenSql() {
Utils.dbFile.delete()
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName))
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(getDbName()))
concurrentReadWrites(cacheFactory)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ import androidx.benchmark.junit4.measureRepeated
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseJsonResponse
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
import com.apollographql.apollo.benchmark.Utils.resource
import com.apollographql.apollo.benchmark.test.R
import com.apollographql.cache.normalized.ApolloStore
import com.apollographql.cache.normalized.FetchPolicy
import com.apollographql.cache.normalized.fetchPolicy
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.mockserver.MockRequestBase
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.MockServerHandler
import com.apollographql.apollo.testing.MapTestNetworkTransport
import com.apollographql.apollo.testing.registerTestResponse
import com.apollographql.cache.normalized.CacheManager
import com.apollographql.cache.normalized.FetchPolicy
import com.apollographql.cache.normalized.api.DefaultCacheKeyGenerator
import com.apollographql.cache.normalized.api.DefaultCacheResolver
import com.apollographql.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.cache.normalized.cacheManager
import com.apollographql.cache.normalized.fetchPolicy
import com.apollographql.cache.normalized.memory.MemoryCacheFactory
import com.apollographql.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.mockserver.MockRequestBase
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.MockServerHandler
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand All @@ -43,14 +42,14 @@ class CacheIncubatingIntegrationTests {
@Test
fun concurrentQueriesTestNetworkTransportSql() {
Utils.dbFile.delete()
val cacheFactory = SqlNormalizedCacheFactory(dbName)
val cacheFactory = SqlNormalizedCacheFactory(getDbName())
concurrentQueries(cacheFactory, withMockServer = false)
}

@Test
fun concurrentQueriesTestNetworkTransportMemoryThenSql() {
Utils.dbFile.delete()
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName))
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(getDbName()))
concurrentQueries(cacheFactory, withMockServer = false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.apollographql.apollo.api.Query
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseJsonResponse
import com.apollographql.apollo.benchmark.Utils.dbFile
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.benchmark.Utils.largeListQuery
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
import com.apollographql.apollo.benchmark.Utils.registerCacheSize
Expand Down Expand Up @@ -60,7 +60,7 @@ class CacheIncubatingTests {
val cacheManager = CacheManager(
if (sql) {
dbFile.delete()
SqlNormalizedCacheFactory(name = dbName)
SqlNormalizedCacheFactory(name = getDbName())
} else {
MemoryCacheFactory()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.benchmark.junit4.measureRepeated
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseJsonResponse
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
import com.apollographql.apollo.benchmark.Utils.resource
import com.apollographql.apollo.benchmark.test.R
Expand All @@ -16,12 +16,12 @@ import com.apollographql.apollo.cache.normalized.api.NormalizedCacheFactory
import com.apollographql.apollo.cache.normalized.fetchPolicy
import com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory
import com.apollographql.apollo.cache.normalized.store
import com.apollographql.apollo.testing.MapTestNetworkTransport
import com.apollographql.apollo.testing.registerTestResponse
import com.apollographql.mockserver.MockRequestBase
import com.apollographql.mockserver.MockResponse
import com.apollographql.mockserver.MockServer
import com.apollographql.mockserver.MockServerHandler
import com.apollographql.apollo.testing.MapTestNetworkTransport
import com.apollographql.apollo.testing.registerTestResponse
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
Expand All @@ -40,14 +40,14 @@ class CacheIntegrationTests {
@Test
fun concurrentQueriesTestNetworkTransportSql() {
Utils.dbFile.delete()
val cacheFactory = SqlNormalizedCacheFactory(dbName)
val cacheFactory = SqlNormalizedCacheFactory(getDbName())
concurrentQueries(cacheFactory, withMockServer = false)
}

@Test
fun concurrentQueriesTestNetworkTransportMemoryThenSql() {
Utils.dbFile.delete()
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName))
val cacheFactory = MemoryCacheFactory().chain(SqlNormalizedCacheFactory(getDbName()))
concurrentQueries(cacheFactory, withMockServer = false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.apollographql.apollo.api.Query
import com.apollographql.apollo.api.json.jsonReader
import com.apollographql.apollo.api.parseJsonResponse
import com.apollographql.apollo.benchmark.Utils.dbFile
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.benchmark.Utils.largeListQuery
import com.apollographql.apollo.benchmark.Utils.operationBasedQuery
import com.apollographql.apollo.benchmark.Utils.registerCacheSize
Expand Down Expand Up @@ -58,7 +58,7 @@ class CacheTests {
val store = ApolloStore(
if (sql) {
dbFile.delete()
SqlNormalizedCacheFactory(name = dbName)
SqlNormalizedCacheFactory(name = getDbName())
} else {
MemoryCacheFactory()
}
Expand All @@ -78,4 +78,4 @@ class CacheTests {
check(data2)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.benchmark.junit4.BenchmarkRule
import androidx.benchmark.junit4.measureRepeated
import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.benchmark.Utils.dbFile
import com.apollographql.apollo.benchmark.Utils.dbName
import com.apollographql.apollo.benchmark.Utils.getDbName
import com.apollographql.apollo.conferences.cache.Cache
import com.apollographql.apollo.conferences.cache.Cache.cache
import com.apollographql.cache.normalized.CacheManager
Expand Down Expand Up @@ -45,7 +45,7 @@ class GarbageCollectTests {
benchmarkRule.measureRepeated {
runWithTimingDisabled {
dbFile.delete()
cacheManager = cacheManager(SqlNormalizedCacheFactory(dbName))
cacheManager = cacheManager(SqlNormalizedCacheFactory(getDbName()))
primeCache(cacheManager)
}
runBlocking {
Expand All @@ -62,7 +62,7 @@ class GarbageCollectTests {
benchmarkRule.measureRepeated {
runWithTimingDisabled {
dbFile.delete()
cacheManager = cacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(dbName)))
cacheManager = cacheManager(MemoryCacheFactory().chain(SqlNormalizedCacheFactory(getDbName())))
primeCache(cacheManager)
}
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import java.io.File
object Utils {
private val cache = mutableMapOf<Int, BufferedSource>()

const val dbName = "testDb"
val dbFile: File = InstrumentationRegistry.getInstrumentation().context.getDatabasePath(dbName)
fun getDbName(): String = "testDb-${System.currentTimeMillis()}"
val dbFile: File = InstrumentationRegistry.getInstrumentation().context.getDatabasePath(getDbName())
val responseBasedQuery = com.apollographql.apollo.calendar.response.ItemsQuery(endingAfter = "", startingBefore = "")
val operationBasedQuery = ItemsQuery(endingAfter = "", startingBefore = "")
val largeListQuery = PlaylistRawTracksQuery("42")
Expand Down Expand Up @@ -74,4 +74,4 @@ object Utils {
internal fun checkLargeList(data: PlaylistRawTracksQuery.Data) {
check(data.playlist!!.rawTracks.size == 10000 && data.playlist.rawTracks[9999]!!.trackId == "142429999")
}
}
}
Loading