Equivalent of xUnit for testing Pig.
Call {@link PigTest#getCluster()} then construct a test and call an assert method.Have a look to the test of this class for more example.
269270271272273274275276277278279
"n=3", "reducers=1", "input=top_queries_input_data.txt", "output=top_3_queries", }; test = new PigTest(PIG_SCRIPT, args); // By default PigUnit removes all the STORE and DUMP test.unoverride("STORE"); test.runScript();
292293294295296297298299300
}; PigServer mockServer = null; Cluster mockCluster = null; test = new PigTest(PIG_SCRIPT, args, mockServer, mockCluster); test.assertOutput(new File("data/top_queries_expected_top_3.txt")); }
303132333435363738394041424344
@Test public void shouldAssertWithMessageOnZero() throws Exception { try { PigTest test = createPigTest("datafu/util/assertWithMessageTest.pig"); this.writeLinesToFile("input", "0"); test.runScript(); this.getLinesForAlias(test, "data2"); fail("test should have failed, but it didn't"); }
48495051525354555657585960
} @Test public void shouldNotAssertWithMessageOnOne() throws Exception { PigTest test = createPigTest("datafu/util/assertWithMessageTest.pig"); this.writeLinesToFile("input", "1"); test.runScript(); this.getLinesForAlias(test, "data2"); }
626364656667686970717273747576
@Test public void shouldAssertWithoutMessageOnZero() throws Exception { try { PigTest test = createPigTest("datafu/util/assertWithoutMessageTest.pig"); this.writeLinesToFile("input", "0"); test.runScript(); this.getLinesForAlias(test, "data2"); fail("test should have failed, but it didn't"); }
80818283848586878889909192
} @Test public void shouldNotAssertWithoutMessageOnOne() throws Exception { PigTest test = createPigTest("datafu/util/assertWithoutMessageTest.pig"); this.writeLinesToFile("input", "1"); test.runScript(); this.getLinesForAlias(test, "data2"); }
262728293031323334353637383940414243444546
public class IntBoolConversionPigTests extends PigTests { @Test public void intToBoolTest() throws Exception { PigTest test = createPigTest("datafu/util/intToBoolTest.pig"); String[] input = { "", // null "0", "1" }; String[] output = { "(false)", "(false)", "(true)" }; test.assertOutput("data",input,"data2",output); }
46474849505152535455565758596061626364656667686970717273747576
} @Test public void intToBoolToIntTest() throws Exception { PigTest test = createPigTest("datafu/util/intToBoolToIntTest.pig"); String[] input = { "", // null "0", "1", "2", "-1", "-2", "0", "" }; String[] output = { "(0)", "(0)", "(1)", "(1)", "(1)", "(1)", "(0)", "(0)" }; test.assertOutput("data",input,"data3",output); }
3334353637383940414243444546474849505152535455
public class WilsonBinConfTests extends PigTests { @Test public void wilsonTest() throws Exception { PigTest test = createPigTest("datafu/stats/wilsonBinConfTests.pig", "alpha=0.05"); // alpha is 0.05 for 95% confidence writeLinesToFile("input", "1\t1", "1\t2", "50\t100", "500\t1000", "999\t1000", "1000\t1000", "998\t1000"); test.runScript(); /* Add expected values, computed using R: * * e.g. *
78798081828384
lines[i] = lines[i].replaceAll(Pattern.quote("$" + parts[0]), parts[1]); } } } return new PigTest(lines); }