-
Notifications
You must be signed in to change notification settings - Fork 120
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
Test refactor #864
Test refactor #864
Conversation
updated jackson version in spark-client -> 2.12.0
…Nitish into testRefactor
…zingg-Nitish into testRefactor # Conflicts: # common/client/src/main/java/zingg/common/client/util/PojoToArrayConverter.java # common/client/src/main/java/zingg/common/client/util/StructTypeFromPojoClass.java # common/client/src/main/java/zingg/common/client/util/WithSession.java # common/core/src/test/java/zingg/common/core/block/TestBlockBase.java # common/core/src/test/java/zingg/common/core/preprocess/TestStopWordsBase.java # spark/client/src/main/java/zingg/spark/client/util/SparkDFObjectUtil.java # spark/core/src/test/java/zingg/common/core/block/TestSparkBlock.java # spark/core/src/test/java/zingg/common/core/preprocess/TestSparkStopWords.java # spark/core/src/test/java/zingg/common/core/util/SparkStopWordRemoverUtility.java
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.
- Common naming for test data. We can define model package inside the package of the class we are testing. Can you come up with good naming here?
- Assertions should not be repeated. Move to common utility and use throughout.
- Other changes requested at different places
common/client/src/test/java/zingg/common/client/TestZFrameBase.java
Outdated
Show resolved
Hide resolved
common/client/src/test/java/zingg/common/client/TestZFrameBase.java
Outdated
Show resolved
Hide resolved
|
||
ZFrame<D, R, C> zFrame = dfObjectUtil.getDFFromObjectList(sampleDataSet, Person.class); | ||
|
||
List<C> columnList = (List<C>) Arrays.asList("recid", "surname", "postcode"); |
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.
wont this give List ?
common/client/src/test/java/zingg/common/client/TestZFrameBase.java
Outdated
Show resolved
Hide resolved
common/client/src/test/java/zingg/common/client/model/PairPartOne.java
Outdated
Show resolved
Hide resolved
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestData { |
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.
rename to add the test class which is using this.
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
@@ -0,0 +1,23 @@ | |||
package zingg.common.core.model; | |||
|
|||
public class EventCluster { |
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.
rename to EventPair
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.
use base class EventBase and exetnd in both Event and EventPair?
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
} | ||
public class TestSparkFrame extends TestZFrameBase<SparkSession, Dataset<Row>, Row, Column, DataType> { | ||
public static final Log LOG = LogFactory.getLog(TestSparkFrame.class); | ||
public static IArguments args; |
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.
why do oyu need args here?
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.
removed
public static final Log LOG = LogFactory.getLog(TestSparkFrame.class); | ||
public static IArguments args; | ||
public static JavaSparkContext ctx; | ||
public static SparkSession spark; |
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.
these should be part of the base class - when you add the concrete class here, they will automatically have the right strucgture.
} | ||
|
||
protected static void setUpSpark() { | ||
try { |
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.
we have a generic sparkbasetester which sets the session, we should use that
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
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.
Sorry I dont see you using the common base class which sets up Spark session. Please move it from enterprise and use it here.
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.
please check comments
stmtArgs.setFieldDefinition(fdList); | ||
sparkStopWordsRemovers.add(new SparkStopWordsRemover(context,stmtArgs)); | ||
|
||
//add second stopWordRemover |
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.
setting up the stop word removers should be in generic base class
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.
getStopWordRemovers() will provide different kind and number of stopword removers based on Spark or Snow implementation. IStopWordsRemoverutility interface only exposes getStopWordRemovers() method
spark/client/pom.xml
Outdated
@@ -8,8 +8,8 @@ | |||
<artifactId>zingg-spark-client</artifactId> | |||
<packaging>jar</packaging> | |||
<properties> | |||
<fasterxml.jackson.version>2.15.2</fasterxml.jackson.version> | |||
<fasterxml.jackson.databind.version>2.15.2</fasterxml.jackson.databind.version> | |||
<fasterxml.jackson.version>2.12.0</fasterxml.jackson.version> |
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.
why are we changing this?
//sample data classes to be used for testing | ||
public static List<Person> createEmptySampleData() { | ||
|
||
return new ArrayList<>(); |
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.
No empty diamond operators
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.
refactored
|
||
import java.util.Arrays; |
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.
please avoid changes to classes you are not touching
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.
only removed unused import
public static List<Event> createSampleEventData() { | ||
|
||
int row_id = 1; | ||
List<Event> sample = new ArrayList<>(); |
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.
please give class when you instantiate
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.
It is a class static property for test purpose, there's no reason to make it instance dependent
ZFrame<Dataset<Row>,Row,Column> sf2 = sf.withColumn(newCol, newColVal); | ||
assertTrueCheckingExceptOutput(sf2, df.withColumn(newCol, functions.lit(newColVal)), "SparkFrame.withColumn(c, double) output is not as expected"); | ||
} | ||
protected static void setUpSpark() { |
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.
we need to use the common testsparkbase or move the enterprise SparkSession weaving here which can inject the session. session for tests should not get created in multiple places
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
setUpSpark(); | ||
} | ||
|
||
StructType schemaOfSample = new StructType(new StructField[]{ |
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.
these should be coming from the base test class. Why are they here?
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.
refactored
ZFrame<Dataset<Row>, Row, Column> filteredData = clusterData.filterNotNullCond(ColName.SOURCE_COL); | ||
assertEquals(3,filteredData.count()); | ||
} | ||
protected void assertTrueCheckingExceptOutput(ZFrame<Dataset<Row>, Row, Column> sf1, ZFrame<Dataset<Row>, Row, Column> sf2, String message) { |
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.
this should be part of the base test class so it can be used in enterprise and SnowFrame directly
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.
refactored
} | ||
|
||
protected static void setUpSpark() { | ||
try { |
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.
Sorry I dont see you using the common base class which sets up Spark session. Please move it from enterprise and use it here.
fdList.add(eventFD); | ||
IArguments stmtArgs = new Arguments(); | ||
stmtArgs.setFieldDefinition(fdList); | ||
sparkStopWordsRemovers.add(new SparkStopWordsRemover(context,stmtArgs)); |
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.
only this should be done here. the rest of the code is common and should move to an abstract class impl of IStopWordRemoverUtility
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
Refactored ZFrame, Block and StopWord test classes