-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integration Junit for OSS #778
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b6d42be
1st cut integration tests for OSS
vikasgupta78 91c762e
TestSparkExecutors integrated
vikasgupta78 44e1b1a
refactor integrations tests for reuse
vikasgupta78 8a48c06
test modules in build xml
vikasgupta78 b33ad63
junit dependency
vikasgupta78 b2bd765
merge enterprise branch
vikasgupta78 f0dbcf3
moved to test folder
vikasgupta78 7837c3c
move to test and generate test jars
vikasgupta78 56c47e6
reduce scope of test jar production
vikasgupta78 e0b9453
generate test jar for spark test
vikasgupta78 2c7f744
move intersect, substr and gt to ZFrame
vikasgupta78 e18399e
refactor testExecutors to base class
vikasgupta78 6423793
refactor init to base class
vikasgupta78 227764f
round not needed
vikasgupta78 3a79946
moved to common test
vikasgupta78 2184a84
move tests to common tests
vikasgupta78 6b97885
removed module common-test
vikasgupta78 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
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
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,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>zingg</groupId> | ||
<artifactId>zingg-common</artifactId> | ||
<version>${zingg.version}</version> | ||
</parent> | ||
<artifactId>zingg-common-test</artifactId> | ||
<packaging>jar</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>zingg</groupId> | ||
<artifactId>zingg-common-core</artifactId> | ||
<version>${zingg.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>zingg</groupId> | ||
<artifactId>zingg-common-client</artifactId> | ||
<version>${zingg.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<version>5.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
common/common-test/src/test/java/zingg/common/core/executor/ExecutorTester.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,24 @@ | ||
package zingg.common.core.executor; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import zingg.common.client.ZinggClientException; | ||
|
||
public abstract class ExecutorTester<S, D, R, C, T> { | ||
|
||
public static final Log LOG = LogFactory.getLog(ExecutorTester.class); | ||
|
||
public ZinggBase<S,D, R, C, T> executor; | ||
|
||
public ExecutorTester(ZinggBase<S, D, R, C, T> executor) { | ||
this.executor = executor; | ||
} | ||
|
||
public void execute() throws ZinggClientException { | ||
executor.execute(); | ||
} | ||
|
||
public abstract void validateResults() throws ZinggClientException; | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
common/common-test/src/test/java/zingg/common/core/executor/JunitLabeller.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,60 @@ | ||
package zingg.common.core.executor; | ||
|
||
import zingg.common.client.ZFrame; | ||
import zingg.common.client.ZinggClientException; | ||
import zingg.common.client.options.ZinggOptions; | ||
import zingg.common.client.util.ColName; | ||
import zingg.common.client.util.ColValues; | ||
import zingg.common.core.context.Context; | ||
|
||
public class JunitLabeller<S,D,R,C,T> extends Labeller<S,D,R,C,T> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public JunitLabeller(Context<S,D,R,C,T> context) { | ||
setZinggOption(ZinggOptions.LABEL); | ||
setContext(context); | ||
} | ||
|
||
@Override | ||
public ZFrame<D, R, C> processRecordsCli(ZFrame<D, R, C> lines) | ||
throws ZinggClientException { | ||
|
||
// now get a list of all those rows which have same cluster and match due to fname => mark match | ||
ZFrame<D, R, C> lines2 = getDSUtil().getPrefixedColumnsDS(lines); | ||
|
||
// construct AND condition | ||
C clusterCond = getJoinCondForCol(lines, lines2, ColName.CLUSTER_COLUMN,true); | ||
C fnameCond = getJoinCondForCol(lines, lines2, "FNAME",true); | ||
C idCond = getJoinCondForCol(lines, lines2, "ID",false); | ||
C filterCond = lines2.and(lines2.and(clusterCond,idCond),fnameCond); | ||
|
||
ZFrame<D, R, C> filtered = lines.joinOnCol(lines2, filterCond).cache(); | ||
|
||
ZFrame<D, R, C> matches = filtered.select(ColName.CLUSTER_COLUMN).distinct().withColumn(ColName.MATCH_FLAG_COL, ColValues.IS_MATCH_PREDICTION).cache(); | ||
|
||
ZFrame<D, R, C> nonMatches = lines.select(ColName.CLUSTER_COLUMN).except(matches.select(ColName.CLUSTER_COLUMN)).distinct().withColumn(ColName.MATCH_FLAG_COL, ColValues.IS_NOT_A_MATCH_PREDICTION).cache(); | ||
|
||
ZFrame<D, R, C> all = matches.unionAll(nonMatches); | ||
|
||
ZFrame<D, R, C> linesMatched = lines; | ||
linesMatched = linesMatched.drop(ColName.MATCH_FLAG_COL); | ||
linesMatched = linesMatched.joinOnCol(all, ColName.CLUSTER_COLUMN); | ||
linesMatched = linesMatched.select(lines.columns()); // make same order | ||
|
||
return linesMatched; | ||
} | ||
|
||
private C getJoinCondForCol(ZFrame<D, R, C> df1, ZFrame<D, R, C> dfToJoin,String colName, boolean equal) { | ||
C column = df1.col(colName); | ||
C columnWithPrefix = dfToJoin.col(ColName.COL_PREFIX + colName); | ||
C equalTo = df1.equalTo(column,columnWithPrefix); | ||
if (equal) { | ||
return equalTo; | ||
} else { | ||
return df1.not(equalTo); | ||
} | ||
} | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
common/common-test/src/test/java/zingg/common/core/executor/LabellerTester.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,36 @@ | ||
package zingg.common.core.executor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import zingg.common.client.ZFrame; | ||
import zingg.common.client.ZinggClientException; | ||
import zingg.common.client.util.ColName; | ||
|
||
public class LabellerTester<S, D, R, C, T> extends ExecutorTester<S, D, R, C, T> { | ||
|
||
public static final Log LOG = LogFactory.getLog(LabellerTester.class); | ||
|
||
public LabellerTester(Labeller<S, D, R, C, T> executor) { | ||
super(executor); | ||
} | ||
|
||
@Override | ||
public void validateResults() throws ZinggClientException { | ||
// check that marked data has at least 1 match row and 1 unmatch row | ||
ZFrame<D, R, C> dfMarked = executor.getContext().getPipeUtil(). | ||
read(false, false, executor.getContext().getPipeUtil().getTrainingDataMarkedPipe(executor.getArgs())); | ||
|
||
C matchCond = dfMarked.equalTo(ColName.MATCH_FLAG_COL, 1); | ||
C notMatchCond = dfMarked.equalTo(ColName.MATCH_FLAG_COL, 0); | ||
|
||
long matchCount = dfMarked.filter(matchCond).count(); | ||
assertTrue(matchCount > 1); | ||
long unmatchCount = dfMarked.filter(notMatchCond).count(); | ||
assertTrue(unmatchCount > 1); | ||
LOG.info("matchCount : "+ matchCount + ", unmatchCount : " + unmatchCount); | ||
|
||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
common/common-test/src/test/java/zingg/common/core/executor/MatcherTester.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,78 @@ | ||
package zingg.common.core.executor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import zingg.common.client.ZFrame; | ||
import zingg.common.client.ZinggClientException; | ||
import zingg.common.client.util.ColName; | ||
|
||
public class MatcherTester<S, D, R, C, T> extends ExecutorTester<S, D, R, C, T> { | ||
|
||
public static final Log LOG = LogFactory.getLog(MatcherTester.class); | ||
|
||
public MatcherTester(Matcher<S, D, R, C, T> executor) { | ||
super(executor); | ||
} | ||
|
||
@Override | ||
public void validateResults() throws ZinggClientException { | ||
assessAccuracy(); | ||
} | ||
|
||
public String getClusterColName() { | ||
return ColName.CLUSTER_COLUMN; | ||
} | ||
|
||
protected void assessAccuracy() throws ZinggClientException { | ||
ZFrame<D, R, C> df = getOutputData(); | ||
|
||
df = df.withColumn("fnameId",df.concat(df.col("fname"), df.col("id"))); | ||
df = df.select("fnameId", getClusterColName()); | ||
df = df.withColumn("dupeFnameId",df.substr(df.col("fnameId"),0,8)).cache(); | ||
ZFrame<D, R, C> df1 = df.withColumnRenamed("fnameId", "fnameId1").withColumnRenamed("dupeFnameId", "dupeFnameId1") | ||
.withColumnRenamed(getClusterColName(), getClusterColName() + "1").cache(); | ||
|
||
|
||
ZFrame<D, R, C> gold = joinAndFilter("dupeFnameId", df, df1).cache(); | ||
ZFrame<D, R, C> result = joinAndFilter(getClusterColName(), df, df1).cache(); | ||
|
||
ZFrame<D, R, C> fn = gold.except(result); | ||
ZFrame<D, R, C> tp = gold.intersect(result); | ||
ZFrame<D, R, C> fp = result.except(gold); | ||
|
||
long fnCount = fn.count(); | ||
long tpCount = tp.count(); | ||
long fpCount = fp.count(); | ||
double score1 = tpCount*1.0d/(tpCount+fpCount); | ||
double score2 = tpCount*1.0d/(tpCount+fnCount); | ||
|
||
LOG.info("False negative " + fnCount); | ||
|
||
LOG.info("True positive " + tpCount); | ||
|
||
LOG.info("False positive " + fpCount); | ||
|
||
LOG.info("precision " + score1); | ||
|
||
LOG.info("recall " + tpCount + " denom " + (tpCount+fnCount) + " overall " + score2); | ||
|
||
|
||
System.out.println("precision score1 " + score1); | ||
|
||
System.out.println("recall score2 " + score2); | ||
|
||
assertTrue(0.8 <= score1); | ||
assertTrue(0.8 <= score2); | ||
} | ||
|
||
public ZFrame<D, R, C> getOutputData() throws ZinggClientException { | ||
ZFrame<D, R, C> output = executor.getContext().getPipeUtil().read(false, false, executor.getArgs().getOutput()[0]); | ||
return output; | ||
} | ||
|
||
protected ZFrame<D, R, C> joinAndFilter(String colName, ZFrame<D, R, C> df, ZFrame<D, R, C> df1){ | ||
C col1 = df.col(colName); | ||
C col2 = df1.col(colName+"1"); | ||
ZFrame<D, R, C> joined = df.joinOnCol(df1, df.equalTo(col1, col2)); | ||
return joined.filter(joined.gt(joined.col("fnameId"), joined.col("fnameId1"))); | ||
} | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
common/common-test/src/test/java/zingg/common/core/executor/TestExecutorsGeneric.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,104 @@ | ||
package zingg.common.core.executor; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import zingg.common.client.ArgumentsUtil; | ||
import zingg.common.client.IArguments; | ||
import zingg.common.client.ZinggClientException; | ||
|
||
public abstract class TestExecutorsGeneric<S, D, R, C, T> { | ||
|
||
public static final Log LOG = LogFactory.getLog(TestExecutorsGeneric.class); | ||
|
||
protected IArguments args; | ||
|
||
|
||
protected S session; | ||
|
||
public TestExecutorsGeneric() { | ||
|
||
} | ||
|
||
public TestExecutorsGeneric(S s) throws ZinggClientException, IOException { | ||
init(s); | ||
} | ||
|
||
public void init(S s) throws ZinggClientException, IOException { | ||
this.session = s; | ||
// set up args | ||
setupArgs(); | ||
} | ||
|
||
public String setupArgs() throws ZinggClientException, IOException { | ||
String configFile = getClass().getClassLoader().getResource(getConfigFile()).getFile(); | ||
args = new ArgumentsUtil().createArgumentsFromJSON( | ||
configFile, | ||
"findTrainingData"); | ||
return configFile; | ||
} | ||
|
||
public abstract String getConfigFile(); | ||
|
||
|
||
@Test | ||
public void testExecutors() throws ZinggClientException { | ||
List<ExecutorTester<S, D, R, C, T>> executorTesterList = new ArrayList<ExecutorTester<S, D, R, C, T>>(); | ||
|
||
TrainingDataFinder<S, D, R, C, T> trainingDataFinder = getTrainingDataFinder(); | ||
trainingDataFinder.init(args); | ||
TrainingDataFinderTester<S, D, R, C, T> tdft = new TrainingDataFinderTester<S, D, R, C, T>(trainingDataFinder); | ||
executorTesterList.add(tdft); | ||
|
||
Labeller<S, D, R, C, T> labeller = getLabeller(); | ||
labeller.init(args); | ||
LabellerTester<S, D, R, C, T> lt = new LabellerTester<S, D, R, C, T>(labeller); | ||
executorTesterList.add(lt); | ||
|
||
// training and labelling needed twice to get sufficient data | ||
TrainingDataFinder<S, D, R, C, T> trainingDataFinder2 = getTrainingDataFinder(); | ||
trainingDataFinder2.init(args); | ||
TrainingDataFinderTester<S, D, R, C, T> tdft2 = new TrainingDataFinderTester<S, D, R, C, T>(trainingDataFinder2); | ||
executorTesterList.add(tdft2); | ||
|
||
Labeller<S, D, R, C, T> labeller2 = getLabeller(); | ||
labeller2.init(args); | ||
LabellerTester<S, D, R, C, T> lt2 = new LabellerTester<S, D, R, C, T>(labeller2); | ||
executorTesterList.add(lt2); | ||
|
||
Trainer<S, D, R, C, T> trainer = getTrainer(); | ||
trainer.init(args); | ||
TrainerTester<S, D, R, C, T> tt = new TrainerTester<S, D, R, C, T>(trainer); | ||
executorTesterList.add(tt); | ||
|
||
Matcher<S, D, R, C, T> matcher = getMatcher(); | ||
matcher.init(args); | ||
MatcherTester<S, D, R, C, T> mt = new MatcherTester(matcher); | ||
executorTesterList.add(mt); | ||
|
||
testExecutors(executorTesterList); | ||
} | ||
|
||
|
||
public void testExecutors(List<ExecutorTester<S, D, R, C, T>> executorTesterList) throws ZinggClientException { | ||
for (ExecutorTester<S, D, R, C, T> executorTester : executorTesterList) { | ||
executorTester.execute(); | ||
executorTester.validateResults(); | ||
} | ||
} | ||
|
||
public abstract void tearDown(); | ||
|
||
protected abstract TrainingDataFinder<S, D, R, C, T> getTrainingDataFinder() throws ZinggClientException; | ||
|
||
protected abstract Labeller<S, D, R, C, T> getLabeller() throws ZinggClientException; | ||
|
||
protected abstract Trainer<S, D, R, C, T> getTrainer() throws ZinggClientException; | ||
|
||
protected abstract Matcher<S, D, R, C, T> getMatcher() throws ZinggClientException; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
common/common-test/src/test/java/zingg/common/core/executor/TrainerTester.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,19 @@ | ||
package zingg.common.core.executor; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class TrainerTester<S, D, R, C, T> extends ExecutorTester<S, D, R, C, T> { | ||
|
||
public static final Log LOG = LogFactory.getLog(TrainerTester.class); | ||
|
||
public TrainerTester(Trainer<S, D, R, C, T> executor) { | ||
super(executor); | ||
} | ||
|
||
@Override | ||
public void validateResults() { | ||
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. we should validate that a model has been created - you can add a separate issue for that and we can take it up later 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. #783 created |
||
LOG.info("train successful"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
move tests to common test as discussed
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.
done as part of commits 3a79946 , 2184a84 and 6b97885
Please let me know if spark-test module also needs to be removed and tests moved to spark-core