Skip to content

Commit 5c0c68b

Browse files
authored
Fixes in TwitterBenchmark (graphql-java#3006)
* Remove unused imports and warnings from TwitterBenchmark * Configure ParserOptions for TwitterBenchmark * Fix javadoc of PersistedQueryCache
1 parent 13ab000 commit 5c0c68b

2 files changed

Lines changed: 27 additions & 51 deletions

File tree

src/main/java/graphql/execution/preparsed/persisted/PersistedQueryCache.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public interface PersistedQueryCache {
1919
* If its present in cache then it must return a PreparsedDocumentEntry where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()}
2020
* is already parsed and validated. This will be passed onto the graphql engine as is.
2121
* <p>
22-
* If its a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
23-
* This will be compiled and validated by the graphql engine and the a PreparsedDocumentEntry will be passed back ready for you to cache it.
22+
* If it's a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
23+
* This will be compiled and validated by the graphql engine and the PreparsedDocumentEntry will be passed back ready for you to cache it.
2424
* <p>
25-
* If its not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
25+
* If it's not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
2626
*
2727
* @param persistedQueryId the persisted query id
2828
* @param executionInput the original execution input
29-
* @param onCacheMiss the call back should it be a valid query id but its not currently not in the cache
29+
* @param onCacheMiss the call back should it be a valid query id but it's not currently in the cache
3030
* @return a parsed and validated PreparsedDocumentEntry where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()} is set
3131
* @throws graphql.execution.preparsed.persisted.PersistedQueryNotFound if the query id is not know at all and you have no query text
3232
*
@@ -42,14 +42,14 @@ public interface PersistedQueryCache {
4242
* If its present in cache then it must return a PreparsedDocumentEntry where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()}
4343
* is already parsed and validated. This will be passed onto the graphql engine as is.
4444
* <p>
45-
* If its a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
46-
* This will be compiled and validated by the graphql engine and the a PreparsedDocumentEntry will be passed back ready for you to cache it.
45+
* If it's a valid query id but its no present in cache, (cache miss) then you need to call back the "onCacheMiss" function with associated query text.
46+
* This will be compiled and validated by the graphql engine and the PreparsedDocumentEntry will be passed back ready for you to cache it.
4747
* <p>
48-
* If its not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
48+
* If it's not a valid query id then throw a {@link graphql.execution.preparsed.persisted.PersistedQueryNotFound} to indicate this.
4949
*
5050
* @param persistedQueryId the persisted query id
5151
* @param executionInput the original execution input
52-
* @param onCacheMiss the call back should it be a valid query id but its not currently not in the cache
52+
* @param onCacheMiss the call back should it be a valid query id but it's not currently in the cache
5353
* @return a promise to parsed and validated {@link PreparsedDocumentEntry} where {@link graphql.execution.preparsed.PreparsedDocumentEntry#getDocument()} is set
5454
* @throws graphql.execution.preparsed.persisted.PersistedQueryNotFound if the query id is not know at all and you have no query text
5555
*/

src/test/java/benchmark/TwitterBenchmark.java

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,34 @@
11
package benchmark;
22

3-
import java.io.InputStream;
4-
import java.io.InputStreamReader;
5-
import java.util.ArrayList;
6-
import java.util.HashMap;
7-
import java.util.List;
8-
import java.util.Map;
9-
import java.util.Optional;
10-
import java.util.concurrent.TimeUnit;
11-
import java.util.function.Function;
12-
13-
import com.github.javafaker.Code;
14-
15-
import org.openjdk.jmh.annotations.Benchmark;
16-
import org.openjdk.jmh.annotations.BenchmarkMode;
17-
import org.openjdk.jmh.annotations.Fork;
18-
import org.openjdk.jmh.annotations.Measurement;
19-
import org.openjdk.jmh.annotations.Mode;
20-
import org.openjdk.jmh.annotations.OutputTimeUnit;
21-
import org.openjdk.jmh.annotations.Threads;
22-
import org.openjdk.jmh.annotations.Warmup;
23-
import org.openjdk.jmh.infra.Blackhole;
24-
253
import graphql.ExecutionInput;
264
import graphql.ExecutionResult;
275
import graphql.GraphQL;
28-
import graphql.execution.ExecutionStepInfo;
29-
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
30-
import graphql.execution.preparsed.PreparsedDocumentEntry;
31-
import graphql.execution.preparsed.PreparsedDocumentProvider;
326
import graphql.execution.preparsed.persisted.InMemoryPersistedQueryCache;
337
import graphql.execution.preparsed.persisted.PersistedQueryCache;
348
import graphql.execution.preparsed.persisted.PersistedQuerySupport;
9+
import graphql.parser.ParserOptions;
3510
import graphql.schema.DataFetcher;
36-
import graphql.schema.DataFetcherFactory;
37-
import graphql.schema.DataFetcherFactoryEnvironment;
38-
import graphql.schema.DataFetchingEnvironment;
39-
import graphql.schema.FieldCoordinates;
4011
import graphql.schema.GraphQLCodeRegistry;
4112
import graphql.schema.GraphQLFieldDefinition;
4213
import graphql.schema.GraphQLObjectType;
4314
import graphql.schema.GraphQLSchema;
4415
import graphql.schema.GraphQLTypeReference;
45-
import graphql.schema.idl.RuntimeWiring;
46-
import graphql.schema.idl.SchemaGenerator;
47-
import graphql.schema.idl.SchemaGeneratorHelper;
48-
import graphql.schema.idl.SchemaParser;
49-
import graphql.schema.idl.TypeDefinitionRegistry;
16+
import org.openjdk.jmh.annotations.Benchmark;
17+
import org.openjdk.jmh.annotations.BenchmarkMode;
18+
import org.openjdk.jmh.annotations.Fork;
19+
import org.openjdk.jmh.annotations.Measurement;
20+
import org.openjdk.jmh.annotations.Mode;
21+
import org.openjdk.jmh.annotations.OutputTimeUnit;
22+
import org.openjdk.jmh.annotations.Threads;
23+
import org.openjdk.jmh.annotations.Warmup;
24+
import org.openjdk.jmh.infra.Blackhole;
25+
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
import java.util.Optional;
29+
import java.util.concurrent.TimeUnit;
5030

5131
import static graphql.Scalars.GraphQLString;
52-
import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring;
5332

5433
@Warmup(iterations = 8, time = 10)
5534
@Measurement(iterations = 25, time = 10)
@@ -94,6 +73,8 @@ public static String mkQuery() {
9473
}
9574

9675
private static GraphQL buildGraphQL() {
76+
ParserOptions.setDefaultOperationParserOptions(ParserOptions.newParserOptions().maxTokens(100_000).build());
77+
9778
List<GraphQLFieldDefinition> leafFields = new ArrayList<>(BREADTH);
9879
for (int i = 1; i <= BREADTH; i++) {
9980
leafFields.add(
@@ -116,12 +97,7 @@ private static GraphQL buildGraphQL() {
11697
DataFetcher<Object> simpleFetcher = env -> env.getField().getName();
11798
GraphQLCodeRegistry codeReg = GraphQLCodeRegistry.newCodeRegistry()
11899
.defaultDataFetcher(
119-
new DataFetcherFactory<Object>() {
120-
@Override
121-
public DataFetcher<Object> get(DataFetcherFactoryEnvironment environment) {
122-
return simpleFetcher;
123-
}
124-
}
100+
environment -> simpleFetcher
125101
)
126102
.build();
127103

@@ -156,6 +132,6 @@ protected Optional<Object> getPersistedQueryId(ExecutionInput executionInput) {
156132

157133
public static void main(String[] args) {
158134
ExecutionResult result = execute();
159-
int i = 0;
135+
System.out.println(result);
160136
}
161137
}

0 commit comments

Comments
 (0)