Skip to content

Commit cb861a6

Browse files
committed
introduce Parameterized W tests
1 parent 60ae2b7 commit cb861a6

File tree

4 files changed

+454
-0
lines changed

4 files changed

+454
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.sap.hadoop.windowing.runtime2;
2+
3+
import java.util.Arrays;
4+
import java.util.Collection;
5+
6+
import junit.framework.Assert;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.Parameterized.Parameters;
11+
12+
import com.sap.hadoop.windowing.WindowingException;
13+
import com.sap.hadoop.windowing.testutils.MRBaseTest;
14+
import com.sap.hadoop.windowing.testutils.WParameterized;
15+
import com.sap.hadoop.windowing.testutils.WindowingTest;
16+
17+
@RunWith(WParameterized.class)
18+
public class WindowingTests extends MRBaseTest
19+
{
20+
public WindowingTest wTest;
21+
22+
public WindowingTests(WindowingTest wTest)
23+
{
24+
this.wTest = wTest;
25+
}
26+
27+
@Parameters
28+
public static Collection<Object[]> propertyNames()
29+
{
30+
return Arrays.asList(WindowingTestsFactory.TESTS);
31+
}
32+
33+
@Test
34+
public void testWQuery() throws WindowingException
35+
{
36+
System.out.println("Running test: " + wTest.getName());
37+
wshell.execute(wTest.getQuery(), outPrinter);
38+
String r = outStream.toString();
39+
r = r.replace("\r\n", "\n");
40+
Assert.assertEquals(r, wTest.getResult());
41+
}
42+
}
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
package com.sap.hadoop.windowing.runtime2;
2+
3+
import com.sap.hadoop.windowing.testutils.WindowingTest;
4+
5+
public class WindowingTestsFactory
6+
{
7+
public static WindowingTest BASIC = new WindowingTest(
8+
"basicTest",
9+
"Basic Test",
10+
"select p_mfgr,p_name, p_size,\n"
11+
+ "rank() as r,\n"
12+
+ "denserank() as dr\n"
13+
+ "from part_tiny\n"
14+
+ "partition by p_mfgr\n"
15+
+ "order by p_name\n"
16+
+ "window w1 as rows between 2 preceding and 2 following\n"
17+
+ "into path='/tmp/wout2'\n"
18+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'\n"
19+
+ "with serdeproperties('field.delim'=',')\n"
20+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
21+
"Manufacturer#1 almond antique burnished rose metallic 2 1 1\n"
22+
+ "Manufacturer#1 almond antique burnished rose metallic 2 1 1\n"
23+
+ "Manufacturer#1 almond antique chartreuse lavender yellow 34 3 2\n"
24+
+ "Manufacturer#1 almond antique salmon chartreuse burlywood 6 4 3\n"
25+
+ "Manufacturer#1 almond aquamarine burnished black steel 28 5 4\n"
26+
+ "Manufacturer#1 almond aquamarine pink moccasin thistle 42 6 5\n"
27+
+ "Manufacturer#2 almond antique violet chocolate turquoise 14 1 1\n"
28+
+ "Manufacturer#2 almond antique violet turquoise frosted 40 2 2\n"
29+
+ "Manufacturer#2 almond aquamarine midnight light salmon 2 3 3\n"
30+
+ "Manufacturer#2 almond aquamarine rose maroon antique 25 4 4\n"
31+
+ "Manufacturer#2 almond aquamarine sandy cyan gainsboro 18 5 5\n"
32+
+ "Manufacturer#3 almond antique chartreuse khaki white 17 1 1\n"
33+
+ "Manufacturer#3 almond antique forest lavender goldenrod 14 2 2\n"
34+
+ "Manufacturer#3 almond antique metallic orange dim 19 3 3\n"
35+
+ "Manufacturer#3 almond antique misty red olive 1 4 4\n"
36+
+ "Manufacturer#3 almond antique olive coral navajo 45 5 5\n"
37+
+ "Manufacturer#4 almond antique gainsboro frosted violet 10 1 1\n"
38+
+ "Manufacturer#4 almond antique violet mint lemon 39 2 2\n"
39+
+ "Manufacturer#4 almond aquamarine floral ivory bisque 27 3 3\n"
40+
+ "Manufacturer#4 almond aquamarine yellow dodger mint 7 4 4\n"
41+
+ "Manufacturer#4 almond azure aquamarine papaya violet 12 5 5\n"
42+
+ "Manufacturer#5 almond antique blue firebrick mint 31 1 1\n"
43+
+ "Manufacturer#5 almond antique medium spring khaki 6 2 2\n"
44+
+ "Manufacturer#5 almond antique sky peru orange 2 3 3\n"
45+
+ "Manufacturer#5 almond aquamarine dodger light gainsboro 46 4 4\n"
46+
+ "Manufacturer#5 almond azure blanched chiffon midnight 23 5 5\n");
47+
48+
public static WindowingTest RC = new WindowingTest(
49+
"testRC",
50+
"Basic Test on RC File",
51+
"select p_mfgr,p_name, p_size,\n"
52+
+ "rank() as r,\n"
53+
+ "denserank() as dr\n"
54+
+ "from partrc_tiny\n"
55+
+ "partition by p_mfgr\n"
56+
+ "order by p_name\n"
57+
+ "window w1 as rows between 2 preceding and 2 following\n"
58+
+ "into path='/tmp/wout2'\n"
59+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'\n"
60+
+ "with serdeproperties('field.delim'=',')\n"
61+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
62+
"Manufacturer#1 almond antique burnished rose metallic 2 1 1\n"
63+
+ "Manufacturer#1 almond antique burnished rose metallic 2 1 1\n"
64+
+ "Manufacturer#1 almond antique chartreuse lavender yellow 34 3 2\n"
65+
+ "Manufacturer#1 almond antique salmon chartreuse burlywood 6 4 3\n"
66+
+ "Manufacturer#1 almond aquamarine burnished black steel 28 5 4\n"
67+
+ "Manufacturer#1 almond aquamarine pink moccasin thistle 42 6 5\n"
68+
+ "Manufacturer#2 almond antique violet chocolate turquoise 14 1 1\n"
69+
+ "Manufacturer#2 almond antique violet turquoise frosted 40 2 2\n"
70+
+ "Manufacturer#2 almond aquamarine midnight light salmon 2 3 3\n"
71+
+ "Manufacturer#2 almond aquamarine rose maroon antique 25 4 4\n"
72+
+ "Manufacturer#2 almond aquamarine sandy cyan gainsboro 18 5 5\n"
73+
+ "Manufacturer#3 almond antique chartreuse khaki white 17 1 1\n"
74+
+ "Manufacturer#3 almond antique forest lavender goldenrod 14 2 2\n"
75+
+ "Manufacturer#3 almond antique metallic orange dim 19 3 3\n"
76+
+ "Manufacturer#3 almond antique misty red olive 1 4 4\n"
77+
+ "Manufacturer#3 almond antique olive coral navajo 45 5 5\n"
78+
+ "Manufacturer#4 almond antique gainsboro frosted violet 10 1 1\n"
79+
+ "Manufacturer#4 almond antique violet mint lemon 39 2 2\n"
80+
+ "Manufacturer#4 almond aquamarine floral ivory bisque 27 3 3\n"
81+
+ "Manufacturer#4 almond aquamarine yellow dodger mint 7 4 4\n"
82+
+ "Manufacturer#4 almond azure aquamarine papaya violet 12 5 5\n"
83+
+ "Manufacturer#5 almond antique blue firebrick mint 31 1 1\n"
84+
+ "Manufacturer#5 almond antique medium spring khaki 6 2 2\n"
85+
+ "Manufacturer#5 almond antique sky peru orange 2 3 3\n"
86+
+ "Manufacturer#5 almond aquamarine dodger light gainsboro 46 4 4\n"
87+
+ "Manufacturer#5 almond azure blanched chiffon midnight 23 5 5\n");
88+
89+
public static WindowingTest NOFUNCS = new WindowingTest(
90+
"selectOnly",
91+
"Test with no Window or PTF clauses",
92+
"select p_mfgr,p_name,p_size "
93+
+ "from part_tiny "
94+
+ "partition by p_mfgr "
95+
+ "order by p_size "
96+
+ "into path='/tmp/test2' "
97+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' "
98+
+ "with serdeproperties('field.delim'=',') "
99+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
100+
"Manufacturer#1 almond antique burnished rose metallic 2\n"
101+
+ "Manufacturer#1 almond antique burnished rose metallic 2\n"
102+
+ "Manufacturer#1 almond antique salmon chartreuse burlywood 6\n"
103+
+ "Manufacturer#1 almond aquamarine burnished black steel 28\n"
104+
+ "Manufacturer#1 almond antique chartreuse lavender yellow 34\n"
105+
+ "Manufacturer#1 almond aquamarine pink moccasin thistle 42\n"
106+
+ "Manufacturer#2 almond aquamarine midnight light salmon 2\n"
107+
+ "Manufacturer#2 almond antique violet chocolate turquoise 14\n"
108+
+ "Manufacturer#2 almond aquamarine sandy cyan gainsboro 18\n"
109+
+ "Manufacturer#2 almond aquamarine rose maroon antique 25\n"
110+
+ "Manufacturer#2 almond antique violet turquoise frosted 40\n"
111+
+ "Manufacturer#3 almond antique misty red olive 1\n"
112+
+ "Manufacturer#3 almond antique forest lavender goldenrod 14\n"
113+
+ "Manufacturer#3 almond antique chartreuse khaki white 17\n"
114+
+ "Manufacturer#3 almond antique metallic orange dim 19\n"
115+
+ "Manufacturer#3 almond antique olive coral navajo 45\n"
116+
+ "Manufacturer#4 almond aquamarine yellow dodger mint 7\n"
117+
+ "Manufacturer#4 almond antique gainsboro frosted violet 10\n"
118+
+ "Manufacturer#4 almond azure aquamarine papaya violet 12\n"
119+
+ "Manufacturer#4 almond aquamarine floral ivory bisque 27\n"
120+
+ "Manufacturer#4 almond antique violet mint lemon 39\n"
121+
+ "Manufacturer#5 almond antique sky peru orange 2\n"
122+
+ "Manufacturer#5 almond antique medium spring khaki 6\n"
123+
+ "Manufacturer#5 almond azure blanched chiffon midnight 23\n"
124+
+ "Manufacturer#5 almond antique blue firebrick mint 31\n"
125+
+ "Manufacturer#5 almond aquamarine dodger light gainsboro 46\n");
126+
public static WindowingTest WHERELEAD = new WindowingTest(
127+
"testWhereLead",
128+
"Test with Lead in Where clause",
129+
" select p_mfgr,p_name, p_size \n"
130+
+ "from part_tiny \n"
131+
+ "partition by p_mfgr \n"
132+
+ "order by p_name \n"
133+
+ "where lead(p_size, 1) <= p_size \n"
134+
+ "into path='/tmp/testWhereLead' \n"
135+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' \n"
136+
+ "with serdeproperties('field.delim'=',') \n"
137+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
138+
"Manufacturer#1 almond antique burnished rose metallic 2\n"
139+
+ "Manufacturer#1 almond antique chartreuse lavender yellow 34\n"
140+
+ "Manufacturer#1 almond aquamarine pink moccasin thistle 42\n"
141+
+ "Manufacturer#2 almond antique violet turquoise frosted 40\n"
142+
+ "Manufacturer#2 almond aquamarine rose maroon antique 25\n"
143+
+ "Manufacturer#2 almond aquamarine sandy cyan gainsboro 18\n"
144+
+ "Manufacturer#3 almond antique chartreuse khaki white 17\n"
145+
+ "Manufacturer#3 almond antique metallic orange dim 19\n"
146+
+ "Manufacturer#3 almond antique olive coral navajo 45\n"
147+
+ "Manufacturer#4 almond antique violet mint lemon 39\n"
148+
+ "Manufacturer#4 almond aquamarine floral ivory bisque 27\n"
149+
+ "Manufacturer#4 almond azure aquamarine papaya violet 12\n"
150+
+ "Manufacturer#5 almond antique blue firebrick mint 31\n"
151+
+ "Manufacturer#5 almond antique medium spring khaki 6\n"
152+
+ "Manufacturer#5 almond aquamarine dodger light gainsboro 46\n"
153+
+ "Manufacturer#5 almond azure blanched chiffon midnight 23\n");
154+
public static WindowingTest CENSUSTOP4 = new WindowingTest(
155+
"testCensusTop4",
156+
"List Top 4 tracts by land area for each county",
157+
"select county, tract, arealand, rank() as r "
158+
+ "from census_tiny "
159+
+ "partition by county "
160+
+ "order by county, arealand desc "
161+
+ "where r < 5 "
162+
+ "into path='/tmp/wout' "
163+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' "
164+
+ "with serdeproperties('field.delim'=',') "
165+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
166+
"001 451101 5.52877327E8 1\n" + "001 450701 2.66251308E8 2\n"
167+
+ "001 441503 7.7476439E7 3\n"
168+
+ "001 430102 7.6698501E7 4\n"
169+
+ "003 010000 1.912271907E9 1\n"
170+
+ "005 000102 4.5622349E8 1\n"
171+
+ "005 000200 3.23078053E8 2\n"
172+
+ "005 000301 1.95628423E8 3\n"
173+
+ "005 000304 1.41639221E8 4\n"
174+
+ "007 002400 1.106587526E9 1\n"
175+
+ "007 001600 5.58529159E8 2\n"
176+
+ "007 001500 3.50730015E8 3\n"
177+
+ "007 003600 3.30874034E8 4\n");
178+
public static WindowingTest NOOPWITHWINDOWING = new WindowingTest(
179+
"testNoopWithWindowing",
180+
"List Noop PTF",
181+
"select county, tract, arealand, rank() as r "
182+
+ "from noop(census_tiny "
183+
+ " partition by county "
184+
+ " order by county, arealand desc) "
185+
+ "where r < 5 "
186+
+ "into path='/tmp/NoopWithWindowing' "
187+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' "
188+
+ "with serdeproperties('field.delim'=',') "
189+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
190+
"001 451101 5.52877327E8 1\n" + "001 450701 2.66251308E8 2\n"
191+
+ "001 441503 7.7476439E7 3\n"
192+
+ "001 430102 7.6698501E7 4\n"
193+
+ "003 010000 1.912271907E9 1\n"
194+
+ "005 000102 4.5622349E8 1\n"
195+
+ "005 000200 3.23078053E8 2\n"
196+
+ "005 000301 1.95628423E8 3\n"
197+
+ "005 000304 1.41639221E8 4\n"
198+
+ "007 002400 1.106587526E9 1\n"
199+
+ "007 001600 5.58529159E8 2\n"
200+
+ "007 001500 3.50730015E8 3\n"
201+
+ "007 003600 3.30874034E8 4\n");
202+
public static WindowingTest NOOPWITHMAPWINDOWING = new WindowingTest(
203+
"testNoopWithWindowing",
204+
"List NoopWithMap PTF",
205+
"select county, tract, arealand, rank() as r "
206+
+ "from noopwithmap(census_tiny "
207+
+ " partition by county "
208+
+ " order by county, arealand desc) "
209+
+ "where r < 5 "
210+
+ "into path='/tmp/NoopWithWindowing' "
211+
+ "serde 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' "
212+
+ "with serdeproperties('field.delim'=',') "
213+
+ "format 'org.apache.hadoop.mapred.TextOutputFormat'",
214+
"001 451101 5.52877327E8 1\n" + "001 450701 2.66251308E8 2\n"
215+
+ "001 441503 7.7476439E7 3\n"
216+
+ "001 430102 7.6698501E7 4\n"
217+
+ "003 010000 1.912271907E9 1\n"
218+
+ "005 000102 4.5622349E8 1\n"
219+
+ "005 000200 3.23078053E8 2\n"
220+
+ "005 000301 1.95628423E8 3\n"
221+
+ "005 000304 1.41639221E8 4\n"
222+
+ "007 002400 1.106587526E9 1\n"
223+
+ "007 001600 5.58529159E8 2\n"
224+
+ "007 001500 3.50730015E8 3\n"
225+
+ "007 003600 3.30874034E8 4\n");
226+
227+
public static Object[][] TESTS = new Object[][]
228+
{ new Object[]
229+
{ BASIC }, new Object[]
230+
{ RC }, new Object[]
231+
{ NOFUNCS }, new Object[]
232+
{ WHERELEAD }, new Object[]
233+
{ CENSUSTOP4 }, new Object[]
234+
{ NOOPWITHWINDOWING }, new Object[]
235+
{ NOOPWITHMAPWINDOWING } };
236+
237+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.sap.hadoop.windowing.testutils;
2+
3+
import java.lang.reflect.Modifier;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.List;
7+
8+
import org.junit.runner.Runner;
9+
import org.junit.runner.notification.RunNotifier;
10+
import org.junit.runners.BlockJUnit4ClassRunner;
11+
import org.junit.runners.Suite;
12+
import org.junit.runners.Parameterized.Parameters;
13+
import org.junit.runners.model.FrameworkMethod;
14+
import org.junit.runners.model.InitializationError;
15+
import org.junit.runners.model.Statement;
16+
import org.junit.runners.model.TestClass;
17+
18+
/*
19+
* Copy from junit Parameterized to add behavior that testName comes from WindowingTest datastruct.
20+
*/
21+
public class WParameterized extends Suite {
22+
23+
private class TestClassRunnerForParameters extends
24+
BlockJUnit4ClassRunner {
25+
private final int fParameterSetNumber;
26+
27+
private final List<Object[]> fParameterList;
28+
29+
TestClassRunnerForParameters(Class<?> type,
30+
List<Object[]> parameterList, int i) throws InitializationError {
31+
super(type);
32+
fParameterList= parameterList;
33+
fParameterSetNumber= i;
34+
}
35+
36+
@Override
37+
public Object createTest() throws Exception {
38+
return getTestClass().getOnlyConstructor().newInstance(
39+
computeParams());
40+
}
41+
42+
private Object[] computeParams() throws Exception {
43+
try {
44+
return fParameterList.get(fParameterSetNumber);
45+
} catch (ClassCastException e) {
46+
throw new Exception(String.format(
47+
"%s.%s() must return a Collection of arrays.",
48+
getTestClass().getName(), getParametersMethod(
49+
getTestClass()).getName()));
50+
}
51+
}
52+
53+
@Override
54+
protected String getName() {
55+
return String.format("[%s]", fParameterSetNumber);
56+
}
57+
58+
@Override
59+
protected String testName(final FrameworkMethod method) {
60+
Object[] params = fParameterList.get(fParameterSetNumber);
61+
WindowingTest wTest = (WindowingTest) params[0];
62+
return String.format("%s", wTest.getName());
63+
}
64+
65+
@Override
66+
protected void validateConstructor(List<Throwable> errors) {
67+
validateOnlyOneConstructor(errors);
68+
}
69+
70+
@Override
71+
protected Statement classBlock(RunNotifier notifier) {
72+
return childrenInvoker(notifier);
73+
}
74+
}
75+
76+
private final ArrayList<Runner> runners= new ArrayList<Runner>();
77+
78+
/**
79+
* Only called reflectively. Do not use programmatically.
80+
*/
81+
public WParameterized(Class<?> klass) throws Throwable {
82+
super(klass, Collections.<Runner>emptyList());
83+
List<Object[]> parametersList= getParametersList(getTestClass());
84+
for (int i= 0; i < parametersList.size(); i++)
85+
runners.add(new TestClassRunnerForParameters(getTestClass().getJavaClass(),
86+
parametersList, i));
87+
}
88+
89+
@Override
90+
protected List<Runner> getChildren() {
91+
return runners;
92+
}
93+
94+
@SuppressWarnings("unchecked")
95+
private List<Object[]> getParametersList(TestClass klass)
96+
throws Throwable {
97+
return (List<Object[]>) getParametersMethod(klass).invokeExplosively(
98+
null);
99+
}
100+
101+
private FrameworkMethod getParametersMethod(TestClass testClass)
102+
throws Exception {
103+
List<FrameworkMethod> methods= testClass
104+
.getAnnotatedMethods(Parameters.class);
105+
for (FrameworkMethod each : methods) {
106+
int modifiers= each.getMethod().getModifiers();
107+
if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers))
108+
return each;
109+
}
110+
111+
throw new Exception("No public static parameters method on class "
112+
+ testClass.getName());
113+
}
114+
115+
}

0 commit comments

Comments
 (0)