Skip to content

Instantly share code, notes, and snippets.

# nb -v run driver=http yaml=http-docsapi-keyvalue tags=phase:schema stargate_host=my_stargate_host auth_token=$AUTH_TOKEN
description: |
This workload emulates a key-value data model and access patterns.
This should be identical to the cql variant except for:
- Schema creation with the Docs API, we don't use cql because the Docs API is opinionated about schema.
- There is no instrumentation with the http driver.
- There is no async mode with the http driver.
Note that stargate_port should reflect the port where the Docs API is exposed (defaults to 8082).
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
buildscript {
repositories {
maven {
$ java -jar build/libs/graphql-springboot-scope-0.0.1-SNAPSHOT.jar --spring.profiles.active=global
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-30 18:09:32.476 INFO 48278 --- [ main] graphqlscope.graphql.GraphqlApplication : Starting GraphqlApplication on winter with PID 48278
2019-09-30 18:09:32.479 INFO 48278 --- [ main] graphqlscope.graphql.GraphqlApplication : The following profiles are active: global
2019-09-30 18:09:33.641 INFO 48278 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-09-30 18:09:33.684 INFO 48278 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-30 18:09:33.684 INFO 48278 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-30 18:09:33.795 INFO 48278 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
cache:
expiryInSeconds: 15
maxCacheSize: 5
@Bean
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Profile("global")
public DataLoaderRegistry globalDataLoaderRegistry(
@Value("${cache.maxCacheSize}") long maxCacheSize,
@Value("${cache.expiryInSeconds}") long expiryInSeconds
) {
DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
CacheMap customCache = new CustomGuavaBasedCache(maxCacheSize, expiryInSeconds);
public class CustomGuavaBasedCache<U, V> implements CacheMap<U, V> {
private static final Logger LOG = LoggerFactory.getLogger(CustomGuavaBasedCache.class);
private Cache<U, V> cache;
public CustomGuavaBasedCache(long maxCacheSize, long expiryInSeconds) {
this.cache = CacheBuilder
.newBuilder()
.maximumSize(maxCacheSize)
$ java -jar build/libs/graphql-springboot-scope-0.0.1-SNAPSHOT.jar --spring.profiles.active=global
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-29 20:28:00.225 INFO 38395 --- [ main] graphqlscope.graphql.GraphqlApplication : Starting GraphqlApplication on winter with PID 38395
2019-09-29 20:28:00.229 INFO 38395 --- [ main] graphqlscope.graphql.GraphqlApplication : The following profiles are active: global
2019-09-29 20:28:01.428 INFO 38395 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-09-29 20:28:01.467 INFO 38395 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-29 20:28:01.467 INFO 38395 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-29 20:28:01.565 INFO 38395 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
@Component
@Internal
@Primary
@Profile("global")
public class GlobalScopedGraphQLInvocation implements GraphQLInvocation {
private final GraphQL graphQL;
@Autowired(required = false)
DataLoaderRegistry dataLoaderRegistry;
@Bean
@Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.TARGET_CLASS)
@Profile("global")
public DataLoaderRegistry globalDataLoaderRegistry() {
DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
DataLoader<String, CountryTO> countryLoader = DataLoader.newDataLoader(graphQLDataFetchers.countryBatchLoader());
dataLoaderRegistry.register("countries", countryLoader);
return dataLoaderRegistry;
}
$ ./gradlew clean build
...
$ java -jar build/libs/graphql-springboot-scope-0.0.1-SNAPSHOT.jar --spring.profiles.active=request
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-29 20:11:24.119 INFO 38190 --- [ main] graphqlscope.graphql.GraphqlApplication : Starting GraphqlApplication on winter with PID 38190
2019-09-29 20:11:24.122 INFO 38190 --- [ main] graphqlscope.graphql.GraphqlApplication : The following profiles are active: request
2019-09-29 20:11:25.288 INFO 38190 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2019-09-29 20:11:25.331 INFO 38190 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]