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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ dependencies {

testImplementation 'org.testng:testng:7.11.0' // use for reactive streams test inheritance
testImplementation "com.tngtech.archunit:archunit-junit5:1.4.1"
testImplementation 'org.openjdk.jmh:jmh-core:1.37' // required for ArchUnit to check JMH tests

antlr 'org.antlr:antlr4:' + antlrVersion

Expand Down Expand Up @@ -309,13 +310,17 @@ artifacts {

List<TestDescriptor> failedTests = []

test {
tasks.withType(Test) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reorganising tests: let's have a common set of config across all Test tasks

useJUnitPlatform()
testLogging {
events "FAILED", "SKIPPED"
exceptionFormat = "FULL"
}

// Required for JMH ArchUnit tests
classpath += sourceSets.jmh.output
dependsOn "jmhClasses"

afterTest { TestDescriptor descriptor, TestResult result ->
if (result.getFailedTestCount() > 0) {
failedTests.add(descriptor)
Expand All @@ -327,34 +332,11 @@ tasks.register('testWithJava17', Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
useJUnitPlatform()
testLogging {
events "FAILED", "SKIPPED"
exceptionFormat = "FULL"
}

afterTest { TestDescriptor descriptor, TestResult result ->
if (result.getFailedTestCount() > 0) {
failedTests.add(descriptor)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to common config

}
tasks.register('testWithJava11', Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
useJUnitPlatform()
testLogging {
events "FAILED", "SKIPPED"
exceptionFormat = "FULL"
}

afterTest { TestDescriptor descriptor, TestResult result ->
if (result.getFailedTestCount() > 0) {
failedTests.add(descriptor)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to common config

}
test.dependsOn testWithJava17
test.dependsOn testWithJava11
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/AssertBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Warmup(iterations = 2, time = 5, batchSize = 50)
@Measurement(iterations = 3, batchSize = 50)
@Fork(3)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix offending tests, even though these are in the benchmark package, and not performance (used by the automated pipeline)

@Fork(2)
public class AssertBenchmark {

private static final int LOOPS = 100;
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/AstPrinterBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3, time = 10)
@Fork(3)
@Fork(2)
public class AstPrinterBenchmark {
/**
* Note: this query is a redacted version of a real query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class ChainedInstrumentationBenchmark {

@Param({"0", "1", "10"})
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/CompletableFuturesBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 1)
@Measurement(iterations = 3, time = 10, batchSize = 10)
@Fork(3)
@Fork(2)
public class CompletableFuturesBenchmark {


Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/CreateExtendedSchemaBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class CreateExtendedSchemaBenchmark {

private static final String SDL = mkSDL();
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/CreateSchemaBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class CreateSchemaBenchmark {

static String largeSDL = BenchmarkUtils.loadResource("large-schema-3.graphqls");
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/GetterAccessBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Warmup(iterations = 2, time = 5, batchSize = 500)
@Measurement(iterations = 3, batchSize = 500)
@Fork(3)
@Fork(2)
public class GetterAccessBenchmark {

public static class Pojo {
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/IntMapBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class IntMapBenchmark {

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/IntrospectionBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class IntrospectionBenchmark {

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/MapBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 1)
@Measurement(iterations = 3, time = 1, batchSize = 1000)
@Fork(3)
@Fork(2)
public class MapBenchmark {

@Param({"10", "50", "300"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@State(Scope.Benchmark)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class OverlappingFieldValidationBenchmark {

@State(Scope.Benchmark)
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/PropertyFetcherBenchMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@Warmup(iterations = 2, time = 5, batchSize = 50)
@Measurement(iterations = 3, batchSize = 50)
@Fork(3)
@Fork(2)
public class PropertyFetcherBenchMark {

@Benchmark
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/SchemaTransformerBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3, time = 10)
@Fork(3)
@Fork(2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class SchemaTransformerBenchmark {

Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/SimpleQueryBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class SimpleQueryBenchmark {

private static final int NUMBER_OF_FRIENDS = 10 * 100;
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/TwitterBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class TwitterBenchmark {
private static final int BREADTH = 150;
private static final int DEPTH = 150;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
public class TypeDefinitionParserVersusSerializeBenchmark {

static SchemaParser schemaParser = new SchemaParser();
Expand Down
2 changes: 1 addition & 1 deletion src/jmh/java/benchmark/ValidatorBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 2, time = 5)
@Measurement(iterations = 3)
@Fork(3)
@Fork(2)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class ValidatorBenchmark {

Expand Down
50 changes: 50 additions & 0 deletions src/test/groovy/graphql/archunit/JMHForkArchRuleTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package graphql.archunit

import com.tngtech.archunit.core.domain.JavaClass
import com.tngtech.archunit.core.importer.ClassFileImporter
import com.tngtech.archunit.lang.ArchCondition
import com.tngtech.archunit.lang.ConditionEvents
import com.tngtech.archunit.lang.EvaluationResult
import com.tngtech.archunit.lang.SimpleConditionEvent
import org.openjdk.jmh.annotations.Fork
import spock.lang.Specification

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes

class JMHForkArchRuleTest extends Specification {

def "JMH benchmarks on classes should not have a fork value greater than 2"() {
given:
def importedClasses = new ClassFileImporter()
.importPackages("benchmark", "performance", "graphql.execution")

def rule = classes()
.that().areAnnotatedWith(Fork.class)
.and().areTopLevelClasses()
.should(haveForkValueNotGreaterThan(2))

when:
EvaluationResult result = rule.evaluate(importedClasses)

then:
!result.hasViolation()

cleanup:
if (result.hasViolation()) {
println result.getFailureReport().toString()
}
}

private static ArchCondition<JavaClass> haveForkValueNotGreaterThan(int maxFork) {
return new ArchCondition<JavaClass>("have a @Fork value of at most $maxFork") {
@Override
void check(JavaClass javaClass, ConditionEvents events) {
def forkAnnotation = javaClass.getAnnotationOfType(Fork.class)
if (forkAnnotation.value() > maxFork) {
def message = "Class ${javaClass.name} has a @Fork value of ${forkAnnotation.value()} which is > $maxFork"
events.add(SimpleConditionEvent.violated(javaClass, message))
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graphql
package graphql.archunit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to write a few more ArchUnit tests, let's start organising them in 1 place

import com.tngtech.archunit.core.domain.JavaClasses
import com.tngtech.archunit.core.importer.ClassFileImporter
Expand Down