forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converting Groovy to Java in the Distributed testing plugin (corda#5642)
* TM-74 Converting ParallelTestGroup * TM-74 private fields, getters, distributedTesting refactoring * TM-74 More conversions * TM-74 reinstating ListTests groovy class * TM-74 extracting enum and clas from ListTests * TM-74 switching to java ListTests * TM-74 null check * TM-74 new access modifiers * TM-74 minor changes * TM-74 scrapping the conversions of ListTests to java * TM-74 reverting build.gradle * TM-74 formatting main gradle * TM-74 removing the commented out code. It has been linked in the jira * TM-74 adding list tests back for investigation * TM-74 collecting after every operation * TM-74 collecting after every operation * TM-74 more debugging * TM-74 more debugging with lifecycle now * TM-74 debugging on the existing groovy file * TM-74 with stream output * TM-74 switching back to java * TM-74 reverting java code, fixing cast in distributed testing file? * TM-74 nailing down the line causing the problem * TM-74 casting * TM-74 changing types * TM-74 stacktrace at pod lvl * TM-74 stacktrace at pod lvl * TM-74 fix issue with immutable list * TM-74 reverting changes now that fix is in place * TM-74 switching to generic task * TM-74 turning off debugging * TM-74 allocating by method
- Loading branch information
Showing
11 changed files
with
259 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
buildSrc/src/main/groovy/net/corda/testing/DistributeTestsBy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.corda.testing; | ||
|
||
public enum DistributeTestsBy { | ||
CLASS, METHOD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
buildSrc/src/main/groovy/net/corda/testing/ListShufflerAndAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.corda.testing; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
|
||
class ListShufflerAndAllocator { | ||
|
||
private final List<String> tests; | ||
|
||
public ListShufflerAndAllocator(List<String> tests) { | ||
this.tests = new ArrayList<>(tests); | ||
} | ||
|
||
public List<String> getTestsForFork(int fork, int forks, Integer seed) { | ||
final Random shuffler = new Random(seed); | ||
final List<String> copy = new ArrayList<>(tests); | ||
while (copy.size() < forks) { | ||
//pad the list | ||
copy.add(null); | ||
} | ||
Collections.shuffle(copy, shuffler); | ||
final int numberOfTestsPerFork = Math.max((copy.size() / forks), 1); | ||
final int consumedTests = numberOfTestsPerFork * forks; | ||
final int ourStartIdx = numberOfTestsPerFork * fork; | ||
final int ourEndIdx = ourStartIdx + numberOfTestsPerFork; | ||
final int ourSupplementaryIdx = consumedTests + fork; | ||
final ArrayList<String> toReturn = new ArrayList<>(copy.subList(ourStartIdx, ourEndIdx)); | ||
if (ourSupplementaryIdx < copy.size()) { | ||
toReturn.add(copy.get(ourSupplementaryIdx)); | ||
} | ||
return toReturn.stream().filter(Objects::nonNull).collect(Collectors.toList()); | ||
} | ||
} |
110 changes: 0 additions & 110 deletions
110
buildSrc/src/main/groovy/net/corda/testing/ListTests.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package net.corda.testing; | ||
|
||
import io.github.classgraph.ClassGraph; | ||
import io.github.classgraph.ClassInfo; | ||
import io.github.classgraph.ClassInfoList; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.FileCollection; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import java.math.BigInteger; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
interface TestLister { | ||
List<String> getAllTestsDiscovered(); | ||
} | ||
|
||
public class ListTests extends DefaultTask implements TestLister { | ||
|
||
public static final String DISTRIBUTION_PROPERTY = "distributeBy"; | ||
|
||
public FileCollection scanClassPath; | ||
private List<String> allTests; | ||
private DistributeTestsBy distribution = System.getProperty(DISTRIBUTION_PROPERTY) != null && !System.getProperty(DISTRIBUTION_PROPERTY).isEmpty() ? | ||
DistributeTestsBy.valueOf(System.getProperty(DISTRIBUTION_PROPERTY)) : DistributeTestsBy.METHOD; | ||
|
||
public List<String> getTestsForFork(int fork, int forks, Integer seed) { | ||
BigInteger gitSha = new BigInteger(getProject().hasProperty("corda_revision") ? | ||
getProject().property("corda_revision").toString() : "0", 36); | ||
if (fork >= forks) { | ||
throw new IllegalArgumentException("requested shard ${fork + 1} for total shards ${forks}"); | ||
} | ||
int seedToUse = seed != null ? (seed + (this.getPath()).hashCode() + gitSha.intValue()) : 0; | ||
return new ListShufflerAndAllocator(allTests).getTestsForFork(fork, forks, seedToUse); | ||
} | ||
|
||
@Override | ||
public List<String> getAllTestsDiscovered() { | ||
return new ArrayList<>(allTests); | ||
} | ||
|
||
@TaskAction | ||
void discoverTests() { | ||
Collection<String> results; | ||
switch (distribution) { | ||
case METHOD: | ||
results = new ClassGraph() | ||
.enableClassInfo() | ||
.enableMethodInfo() | ||
.ignoreClassVisibility() | ||
.ignoreMethodVisibility() | ||
.enableAnnotationInfo() | ||
.overrideClasspath(scanClassPath) | ||
.scan() | ||
.getClassesWithMethodAnnotation("org.junit.Test") | ||
.stream() | ||
.map(classInfo -> { | ||
ClassInfoList returnList = new ClassInfoList(); | ||
returnList.add(classInfo); | ||
returnList.addAll(classInfo.getSubclasses()); | ||
return returnList; | ||
}) | ||
.flatMap(ClassInfoList::stream) | ||
.map(classInfo -> classInfo.getMethodInfo().filter(methodInfo -> methodInfo.hasAnnotation("org.junit.Test")) | ||
.stream().map(methodInfo -> classInfo.getName() + "." + methodInfo.getName())) | ||
.flatMap(Function.identity()) | ||
.collect(Collectors.toSet()); | ||
|
||
this.allTests = results.stream().sorted().collect(Collectors.toList()); | ||
break; | ||
case CLASS: | ||
results = new ClassGraph() | ||
.enableClassInfo() | ||
.enableMethodInfo() | ||
.ignoreClassVisibility() | ||
.ignoreMethodVisibility() | ||
.enableAnnotationInfo() | ||
.overrideClasspath(scanClassPath) | ||
.scan() | ||
.getClassesWithMethodAnnotation("org.junit.Test") | ||
.stream() | ||
.map(classInfo -> { | ||
ClassInfoList returnList = new ClassInfoList(); | ||
returnList.add(classInfo); | ||
returnList.addAll(classInfo.getSubclasses()); | ||
return returnList; | ||
}) | ||
.flatMap(ClassInfoList::stream) | ||
.map(ClassInfo::getName) | ||
.collect(Collectors.toSet()); | ||
this.allTests = results.stream().sorted().collect(Collectors.toList()); | ||
break; | ||
} | ||
getProject().getLogger().lifecycle("THESE ARE ALL THE TESTSSS!!!!!!!!: " + allTests.toString()); | ||
} | ||
} |
Oops, something went wrong.