This repository was archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Initial design for Build A/B testing epic story #114
Open
mockitoguy
wants to merge
17
commits into
master
Choose a base branch
from
abTesting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fd6a48d
Initial design for Build A/B testing epic story
mockitoguy e49aac1
Added documentation!
mockitoguy abded4f
step 1: git clone
epeee 2899e46
step 2. Run A test
epeee c764a13
Merge remote-tracking branch 'remotes/origin/master' into abTesting
epeee 4919fee
make use of clonegitrepositorytask
epeee 376226c
clean targetDir if it already exists
epeee 9a56344
configure CloneGitRepositoryTask (repository)
epeee 059429f
step 3: compare directories and serialize result to json file
epeee 175a1c0
extract filedifferenceprovider
epeee a6fa4e9
some more tests
epeee aab5264
even more tests
epeee 7ae953b
move CompareResult and CompareResultSerializer
epeee 14a85b0
extract CompareDirectoriesTask from BuildABTestingPlugin
epeee 64a59b9
javadoc
epeee 616ae01
FileDifferenceProvider: calculate md5 + enable test case which was fa…
epeee 04154f6
remove outdated todo
epeee 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
There are no files selected for viewing
190 changes: 190 additions & 0 deletions
190
src/main/groovy/org/mockito/release/internal/gradle/BuildABTestingPlugin.java
This file contains hidden or 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,190 @@ | ||
package org.mockito.release.internal.gradle; | ||
|
||
import org.gradle.api.Action; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.file.CopySpec; | ||
import org.gradle.api.tasks.*; | ||
import org.mockito.release.exec.DefaultProcessRunner; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* See rationale and design at: https://github.com/mockito/mockito-release-tools/issues/113 | ||
*/ | ||
public class BuildABTestingPlugin implements Plugin<Project> { | ||
|
||
public void apply(final Project project) { | ||
//Step 1. Clone the repo for A/B testing | ||
CloneGitHubRepositoryTask clone = project.getTasks().create("cloneGitHubRepository", CloneGitHubRepositoryTask.class); | ||
clone.setRepository("mockito/mockito"); | ||
clone.setTargetDir(new File(project.getBuildDir(), "abTesting/mockito/pristine")); | ||
|
||
//Step 2. Run A test | ||
RunTestTask runA = project.getTasks().create("runA", RunTestTask.class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can reuse |
||
runA.dependsOn(clone); | ||
runA.setSourceDir(new File(clone.getTargetDir(), "mockito")); | ||
runA.setWorkDir(new File(project.getBuildDir(), "abTesting/mockito/testA-" + System.currentTimeMillis())); | ||
runA.commandLine("./gradlew", "build"); | ||
runA.setOutputDir(new File(runA.getWorkDir(), "build")); | ||
|
||
//Step 3. Run B test | ||
RunTestTask runB = project.getTasks().create("runB", RunTestTask.class); | ||
runB.dependsOn(clone); | ||
runB.setSourceDir(new File(clone.getTargetDir(), "mockito")); | ||
runB.setWorkDir(new File(project.getBuildDir(), "abTesting/mockito/testB-" + System.currentTimeMillis())); | ||
runB.commandLine("./gradlew", "build"); | ||
runB.setOutputDir(new File(runB.getWorkDir(), "build")); | ||
|
||
//Step 4. Compare test outcomes | ||
CompareDirectoriesTask compare = project.getTasks().create("compareAB", CompareDirectoriesTask.class); | ||
compare.dependsOn(runA, runB); | ||
compare.setDirA(runA.getOutputDir()); | ||
compare.setDirB(runB.getOutputDir()); | ||
compare.setResultsFile(new File(project.getBuildDir(), "abTesting/mockito/results.ser")); //or JSON :) | ||
|
||
//Step 5. Analyze comparison results | ||
AnalyzeComparisonResultsTask analyze = project.getTasks().create("analyzeAB", AnalyzeComparisonResultsTask.class); | ||
analyze.dependsOn(compare); | ||
analyze.setComparisonResultsFile(compare.getResultsFile()); | ||
} | ||
|
||
/** | ||
* BELOW task types are only empty shells. | ||
* They act as suggestions for workflow / API design. | ||
*/ | ||
|
||
public static class AnalyzeComparisonResultsTask extends DefaultTask { | ||
|
||
private File comparisonResultsFile; | ||
|
||
@InputFile | ||
public void setComparisonResultsFile(File comparisonResultsFile) { | ||
this.comparisonResultsFile = comparisonResultsFile; | ||
} | ||
} | ||
|
||
public static class CompareDirectoriesTask extends DefaultTask { | ||
|
||
private File dirA; | ||
private File dirB; | ||
private File resultsFile; | ||
|
||
@InputDirectory | ||
public void setDirA(File dir) { | ||
this.dirA = dir; | ||
} | ||
|
||
@InputDirectory | ||
public void setDirB(File dir) { | ||
this.dirB = dir; | ||
} | ||
|
||
public void setResultsFile(File file) { | ||
this.resultsFile = file; | ||
} | ||
|
||
@OutputFile | ||
public File getResultsFile() { | ||
return resultsFile; | ||
} | ||
} | ||
|
||
public static class RunTestTask extends DefaultTask { | ||
|
||
private File sourceDir; | ||
private File workDir; | ||
private File outputDir; | ||
private String[] arg; | ||
|
||
@InputDirectory | ||
public void setSourceDir(File sourceDir) { | ||
this.sourceDir = sourceDir; | ||
} | ||
|
||
public void setWorkDir(File workDir) { | ||
this.workDir = workDir; | ||
} | ||
|
||
@Input | ||
public void commandLine(String ... arg) { | ||
this.arg = arg; | ||
} | ||
|
||
public File getWorkDir() { | ||
return workDir; | ||
} | ||
|
||
public void setOutputDir(File outputDir) { | ||
this.outputDir = outputDir; | ||
} | ||
|
||
@OutputDirectory | ||
public File getOutputDir() { | ||
return outputDir; | ||
} | ||
|
||
@TaskAction | ||
public void executeTestTask() { | ||
if (outputDir != null && !outputDir.exists()) { | ||
outputDir.mkdirs(); | ||
} | ||
getProject().copy(new Action<CopySpec>() { | ||
public void execute(CopySpec copy) { | ||
copy.from(sourceDir).into(workDir); | ||
} | ||
}); | ||
new DefaultProcessRunner(workDir).run(arg); | ||
} | ||
} | ||
|
||
public static class CompareABTask extends DefaultTask { | ||
} | ||
|
||
public static class CloneGitHubRepositoryTask extends DefaultTask { | ||
|
||
private String repository; | ||
private File targetDir; | ||
private static final String REPO_BASE_URL = "https://github.com/"; | ||
|
||
@Input | ||
public void setRepository(String repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public void setTargetDir(File targetDir) { | ||
this.targetDir = targetDir; | ||
} | ||
|
||
@OutputDirectory | ||
public File getTargetDir() { | ||
return targetDir; | ||
} | ||
|
||
@TaskAction | ||
public void cloneGit() { | ||
if(targetDir != null && !targetDir.exists()) { | ||
targetDir.mkdirs(); | ||
} | ||
|
||
if (repository == null || repository.isEmpty()) { | ||
throw new RuntimeException("Invalid repository '" + repository + "' given!"); | ||
} | ||
|
||
String url = REPO_BASE_URL + repository; | ||
|
||
new DefaultProcessRunner(targetDir).run("git", "clone", url); | ||
} | ||
} | ||
|
||
public static class PrepareABTestingTask extends DefaultTask { | ||
|
||
private File sourceDir; | ||
|
||
@InputDirectory | ||
public void setSourceDir(File sourceDir) { | ||
this.sourceDir = sourceDir; | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ces/META-INF/gradle-plugins/org.mockito.mockito-release-tools.build-ab-testing.properties
This file contains hidden or 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 @@ | ||
implementation-class=org.mockito.release.internal.gradle.BuildABTestingPlugin |
14 changes: 14 additions & 0 deletions
14
src/test/groovy/org/mockito/release/internal/gradle/BuildABTestingPluginTest.groovy
This file contains hidden or 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,14 @@ | ||
package org.mockito.release.internal.gradle | ||
|
||
import org.gradle.testfixtures.ProjectBuilder | ||
import spock.lang.Specification | ||
|
||
class BuildABTestingPluginTest extends Specification { | ||
|
||
def project = new ProjectBuilder().build() | ||
|
||
def "applies"() { | ||
expect: | ||
project.plugins.apply(BuildABTestingPlugin.class); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can reuse
CloneGitRepositoryTask
from master nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k, thx. I will make use of it.