List of usage examples for junit.framework Assert fail
static public void fail(String message)
From source file:com.pivotal.hawq.mapreduce.TPCHClusterTester.java
@Override protected void testTPCHTable(HAWQTPCHSpec tpchSpec, String tableName) throws Exception { String caseName = tpchSpec.toString(); System.out.println("Executing test case: " + caseName); final File caseFolder = new File(FT_TEST_FOLDER, caseName); final File answerFile = new File(caseFolder, tableName + ".ans"); final File outputFile = new File(caseFolder, tableName + ".out"); if (caseFolder.exists()) { FileUtils.deleteDirectory(caseFolder); }//w w w .j a v a2 s . c o m caseFolder.mkdir(); Connection conn = null; List<String> answers; try { conn = MRFormatTestUtils.getTestDBConnection(); // 1. load TPCH data Map<String, String> rs = HAWQJdbcUtils.executeSafeQueryForSingleRow(conn, "SHOW default_segment_num;"); int segnum = Integer.parseInt(rs.get("default_segment_num")); MRFormatTestUtils.runShellCommand(tpchSpec.getLoadCmd(segnum)); // 2. generate answer answers = MRFormatTestUtils.dumpTable(conn, tableName); Collections.sort(answers); Files.write(Joiner.on('\n').join(answers).getBytes(), answerFile); } finally { HAWQJdbcUtils.closeConnection(conn); } // 3. run input format driver final Path hdfsOutput = new Path("/temp/hawqinputformat/part-r-00000"); int exitCode = MRFormatTestUtils.runMapReduceOnCluster(tableName, hdfsOutput.getParent(), null); Assert.assertEquals(0, exitCode); // 4. copy hdfs output to local MRFormatTestUtils.runShellCommand( String.format("hadoop fs -copyToLocal %s %s", hdfsOutput.toString(), outputFile.getPath())); // 5. compare result List<String> outputs = Files.readLines(outputFile, Charsets.UTF_8); if (!answers.equals(outputs)) Assert.fail(String.format("HAWQInputFormat output for table %s differs with DB output:\n%s\n%s", tableName, answerFile, outputFile)); System.out.println("Successfully finish test case: " + caseName); }
From source file:de.hybris.vjdbc.VirtualDriverTest.java
@Test public void testConnectWithAcceptedSQLUrl() throws Exception { final Properties props = new Properties(); Mockito.when(commandSinkProvider.create(Mockito.eq("//baz"), Mockito.eq(OF_EMPTY_MAP))) .thenThrow(new ExpectedException()); try {/* w ww . j av a 2 s . c o m*/ driver.connect("jdbc:hybris:sql://baz", props); Assert.fail("should have failed"); } catch (SQLException e) { assertFirstLineOfSQLException("de.hybris.vjdbc.VirtualDriverTest$ExpectedException", e); } //Mockito.verify(commandSinkProvider).get(Mockito.eq("//baz"), Mockito.eq(ImmutableMap.<String, String>of())); Mockito.verify(virtualConnectionBuilder).setProperties(props); Mockito.verify(virtualConnectionBuilder, Mockito.times(0)).setUrl(""); Mockito.verify(virtualConnectionBuilder) .setDataSourceString(Mockito.eq(VjdbcConnectionStringParser.VJDBC_DEFAULT_DATASOURCE)); }
From source file:BQJDBC.QueryResultTest.QueryResultTest.java
/** * Makes a new Bigquery Connection to Hardcoded URL and gives back the * Connection to static con member.//from w w w . j a v a2 s. c o m */ @Before public void NewConnection() { try { if (QueryResultTest.con == null || !QueryResultTest.con.isValid(0)) { this.logger.info("Testing the JDBC driver"); try { Class.forName("net.starschema.clouddb.jdbc.BQDriver"); QueryResultTest.con = DriverManager.getConnection( BQSupportFuncts.constructUrlFromPropertiesFile( BQSupportFuncts.readFromPropFile("serviceaccount.properties")), BQSupportFuncts.readFromPropFile("serviceaccount.properties")); } catch (Exception e) { this.logger.error("Error in connection" + e.toString()); Assert.fail("General Exception:" + e.toString()); } this.logger.info(((BQConnection) QueryResultTest.con).getURLPART()); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:eu.stratosphere.pact.runtime.task.CombineTaskTest.java
@Test public void testCombineTask() { int keyCnt = 100; int valCnt = 20; super.initEnvironment(3 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt, valCnt, false), 1); super.addOutput(this.outList); CombineTask<PactRecord> testTask = new CombineTask<PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.COMBININGSORT); super.getTaskConfig().setMemorySize(3 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(2); final int[] keyPos = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos, keyClasses); super.registerTask(testTask, MockCombiningReduceStub.class); try {//from w w w . ja va 2 s .c om testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expSum = 0; for (int i = 1; i < valCnt; i++) { expSum += i; } Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + keyCnt, this.outList.size() == keyCnt); for (PactRecord record : this.outList) { Assert.assertTrue("Incorrect result", record.getField(1, PactInteger.class).getValue() == expSum); } this.outList.clear(); }
From source file:com.github.magicsky.sya.checkers.TestSourceReader.java
/** * Returns an array of StringBuilder objects for each comment section found preceding the named * test in the source code.//w w w .j a va2 s . c o m * * @param srcRoot the directory inside the bundle containing the packages * @param clazz the name of the class containing the test * @param testName the name of the test * @param numSections the number of comment sections preceding the named test to return. * Pass zero to get all available sections. * @return an array of StringBuilder objects for each comment section found preceding the named * test in the source code. * @throws IOException */ public static StringBuilder[] getContentsForTest(String srcRoot, Class clazz, final String testName, int numSections) throws IOException { // Walk up the class inheritance chain until we find the test method. try { while (clazz.getMethod(testName).getDeclaringClass() != clazz) { clazz = clazz.getSuperclass(); } } catch (SecurityException e) { Assert.fail(e.getMessage()); } catch (NoSuchMethodException e) { Assert.fail(e.getMessage()); } while (true) { // Find and open the .java file for the class clazz. String fqn = clazz.getName().replace('.', '/'); fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$")); String classFile = fqn + ".java"; InputStream in; Class superclass = clazz.getSuperclass(); try { in = FileUtils.openInputStream(new File(srcRoot + '/' + classFile)); } catch (IOException e) { if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { throw e; } clazz = superclass; continue; } BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { // Read the java file collecting comments until we encounter the test method. List<StringBuilder> contents = new ArrayList<StringBuilder>(); StringBuilder content = new StringBuilder(); for (String line = br.readLine(); line != null; line = br.readLine()) { line = line.replaceFirst("^\\s*", ""); // Replace leading whitespace, preserve trailing if (line.startsWith("//")) { content.append(line.substring(2) + "\n"); } else { if (!line.startsWith("@") && content.length() > 0) { contents.add(content); if (numSections > 0 && contents.size() == numSections + 1) contents.remove(0); content = new StringBuilder(); } if (line.length() > 0 && !contents.isEmpty()) { int idx = line.indexOf(testName); if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) { return contents.toArray(new StringBuilder[contents.size()]); } if (!line.startsWith("@")) { contents.clear(); } } } } } finally { br.close(); } if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) { throw new IOException("Test data not found for " + clazz.getName() + "." + testName); } clazz = superclass; } }
From source file:org.apache.synapse.transport.passthru.TargetResponseTest.java
/** * Testing the starting of target response when response body is not expected * * @throws Exception//w ww . java 2 s .c o m */ @Test public void testFalse() throws Exception { ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration()); WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id"); PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme"); TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null); HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS); NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS); TargetConnections connections = PowerMockito.mock(TargetConnections.class); targetConfiguration.setConnections(connections); PowerMockito.mockStatic(TargetContext.class); TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, false, false); try { targetResponse.start(conn); } catch (Exception e) { logger.error(e); Assert.fail("Unable to start the target response!"); } }
From source file:eagle.dataproc.util.TestConfigOptionParser.java
@Test public void testInvalidCommandArgument2() { String[] arguments = new String[] { "-D", "=value" }; try {//from w ww . j a v a 2 s . c o m new ConfigOptionParser().parseConfig(arguments); Assert.fail("Should throw ParseException"); } catch (ParseException e) { LOG.info("Expected exception: " + e.getMessage()); } }
From source file:com.facebook.TestUtils.java
public static void assertEqualContents(final Bundle a, final Bundle b) { for (String key : a.keySet()) { if (!b.containsKey(key)) { Assert.fail("bundle does not include key " + key); }//w ww . j av a 2 s.c o m Assert.assertEquals(a.get(key), b.get(key)); } for (String key : b.keySet()) { if (!a.containsKey(key)) { Assert.fail("bundle does not include key " + key); } } }
From source file:eu.stratosphere.pact.runtime.task.DataSinkTaskTest.java
@Test public void testDataSinkTask() { int keyCnt = 100; int valCnt = 20; super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE); super.addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0); DataSinkTask<Record> testTask = new DataSinkTask<Record>(); super.registerFileOutputTask(testTask, MockOutputFormat.class, new File(tempTestPath).toURI().toString()); try {/*w w w. j a v a 2 s. co m*/ testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } File tempTestFile = new File(this.tempTestPath); Assert.assertTrue("Temp output file does not exist", tempTestFile.exists()); FileReader fr = null; BufferedReader br = null; try { fr = new FileReader(tempTestFile); br = new BufferedReader(fr); HashMap<Integer, HashSet<Integer>> keyValueCountMap = new HashMap<Integer, HashSet<Integer>>(keyCnt); while (br.ready()) { String line = br.readLine(); Integer key = Integer.parseInt(line.substring(0, line.indexOf("_"))); Integer val = Integer.parseInt(line.substring(line.indexOf("_") + 1, line.length())); if (!keyValueCountMap.containsKey(key)) { keyValueCountMap.put(key, new HashSet<Integer>()); } keyValueCountMap.get(key).add(val); } Assert.assertTrue("Invalid key count in out file. Expected: " + keyCnt + " Actual: " + keyValueCountMap.keySet().size(), keyValueCountMap.keySet().size() == keyCnt); for (Integer key : keyValueCountMap.keySet()) { Assert.assertTrue("Invalid value count for key: " + key + ". Expected: " + valCnt + " Actual: " + keyValueCountMap.get(key).size(), keyValueCountMap.get(key).size() == valCnt); } } catch (FileNotFoundException e) { Assert.fail("Out file got lost..."); } catch (IOException ioe) { Assert.fail("Caught IOE while reading out file"); } finally { if (br != null) { try { br.close(); } catch (Throwable t) { } } if (fr != null) { try { fr.close(); } catch (Throwable t) { } } } }
From source file:eu.stratosphere.pact.runtime.task.CoGroupTaskExternalITCase.java
@Test public void testExternalSortCoGroupTask() { int keyCnt1 = 16384; int valCnt1 = 4 * 2; int keyCnt2 = 65536 * 2; int valCnt2 = 1; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false), 1); super.addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false), 2); super.addOutput(this.outList); CoGroupTask<PactRecord, PactRecord, PactRecord> testTask = new CoGroupTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockCoGroupStub.class); try {/*from w w w . j a v a 2 s. c o m*/ testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2) + Math.max(keyCnt1, keyCnt2) - Math.min(keyCnt1, keyCnt2); Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + expCnt, this.outList.size() == expCnt); this.outList.clear(); }