public static void compareResultsByLinesInMemory( String expectedResultStr, String resultPath, String[] excludePrefixes) throws Exception { ArrayList<String> list = new ArrayList<>(); readAllResultLines(list, resultPath, excludePrefixes, false); String[] result = list.toArray(new String[list.size()]); Arrays.sort(result); String[] expected = expectedResultStr.isEmpty() ? new String[0] : expectedResultStr.split("\n"); Arrays.sort(expected); if (expected.length != result.length || !Arrays.deepEquals(expected, result)) { String msg = String.format( "Different elements in arrays: expected %d elements and received %d\n" + "files: %s\n expected: %s\n received: %s", expected.length, result.length, Arrays.toString(getAllInvolvedFiles(resultPath, excludePrefixes)), Arrays.toString(expected), Arrays.toString(result)); fail(msg); } }
private static File[] getAllInvolvedFiles(String resultPath, final String[] excludePrefixes) { final File result = asFile(resultPath); assertTrue("Result file was not written", result.exists()); if (result.isDirectory()) { return result.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { for (String p: excludePrefixes) { if (name.startsWith(p)) { return false; } } return true; } }); } else { return new File[] { result }; } }
public static void compareKeyValuePairsWithDelta(String expectedLines, String resultPath, String delimiter, double maxDelta) throws Exception { compareKeyValuePairsWithDelta(expectedLines, resultPath, new String[]{}, delimiter, maxDelta); }
public static BufferedReader[] getResultReader( String resultPath, String[] excludePrefixes, boolean inOrderOfFiles) throws IOException { File[] files = getAllInvolvedFiles(resultPath, excludePrefixes); if (inOrderOfFiles) { // sort the files after their name (1, 2, 3, 4)... // we cannot sort by path, because strings sort by prefix Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { try { int f1 = Integer.parseInt(o1.getName()); int f2 = Integer.parseInt(o2.getName()); return f1 < f2 ? -1 : (f1 > f2 ? 1 : 0); } catch (NumberFormatException e) { throw new RuntimeException("The file names are no numbers and cannot be ordered: " + o1.getName() + "/" + o2.getName()); } } }); } BufferedReader[] readers = new BufferedReader[files.length]; for (int i = 0; i < files.length; i++) { readers[i] = new BufferedReader(new FileReader(files[i])); } return readers; }
public static void readAllResultLines( List<String> target, String resultPath, String[] excludePrefixes, boolean inOrderOfFiles) throws IOException { checkArgument(resultPath != null, "resultPath cannot be be null"); final BufferedReader[] readers = getResultReader(resultPath, excludePrefixes, inOrderOfFiles); try { for (BufferedReader reader : readers) { String s; while ((s = reader.readLine()) != null) { target.add(s); } } } finally { for (BufferedReader reader : readers) { org.apache.flink.util.IOUtils.closeQuietly(reader); } } }
public static <T> void compareResultAsText(List<T> result, String expected) { compareResult(result, expected, false, true); }
public static String getFromHTTP(String url) throws Exception { return getFromHTTP(url, DEFAULT_HTTP_TIMEOUT); }
public static BufferedInputStream[] getResultInputStream(String resultPath, String[] excludePrefixes) throws IOException { File[] files = getAllInvolvedFiles(resultPath, excludePrefixes); BufferedInputStream[] inStreams = new BufferedInputStream[files.length]; for (int i = 0; i < files.length; i++) { inStreams[i] = new BufferedInputStream(new FileInputStream(files[i])); } return inStreams; }
public static void compareResultsByLinesInMemoryWithStrictOrder(String expectedResultStr, String resultPath) throws Exception { compareResultsByLinesInMemoryWithStrictOrder(expectedResultStr, resultPath, new String[]{}); }
public static String constructTestURI(Class<?> forClass, String folder) { return new File(constructTestPath(forClass, folder)).toURI().toString(); }
public static BufferedInputStream[] getResultInputStream(String resultPath) throws IOException { return getResultInputStream(resultPath, new String[]{}); }
@Test public void testTopSpeedWindowingExampleITCase() throws Exception { File inputFile = temporaryFolder.newFile(); FileUtils.writeFileUtf8(inputFile, TopSpeedWindowingExampleData.CAR_DATA); final String resultPath = temporaryFolder.newFolder().toURI().toString(); TopSpeedWindowing.main(new String[] { "--input", inputFile.getAbsolutePath(), "--output", resultPath}); compareResultsByLinesInMemory(TopSpeedWindowingExampleData.TOP_SPEEDS, resultPath); } }
public static <T> void compareOrderedResultAsText(List<T> result, String expected) { compareResult(result, expected, false, false); }
public static void readAllResultLines( List<String> target, String resultPath, String[] excludePrefixes, boolean inOrderOfFiles) throws IOException { checkArgument(resultPath != null, "resultPath cannot be be null"); final BufferedReader[] readers = getResultReader(resultPath, excludePrefixes, inOrderOfFiles); try { for (BufferedReader reader : readers) { String s; while ((s = reader.readLine()) != null) { target.add(s); } } } finally { for (BufferedReader reader : readers) { org.apache.flink.util.IOUtils.closeQuietly(reader); } } }
public static BufferedReader[] getResultReader( String resultPath, String[] excludePrefixes, boolean inOrderOfFiles) throws IOException { File[] files = getAllInvolvedFiles(resultPath, excludePrefixes); if (inOrderOfFiles) { // sort the files after their name (1, 2, 3, 4)... // we cannot sort by path, because strings sort by prefix Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { try { int f1 = Integer.parseInt(o1.getName()); int f2 = Integer.parseInt(o2.getName()); return f1 < f2 ? -1 : (f1 > f2 ? 1 : 0); } catch (NumberFormatException e) { throw new RuntimeException("The file names are no numbers and cannot be ordered: " + o1.getName() + "/" + o2.getName()); } } }); } BufferedReader[] readers = new BufferedReader[files.length]; for (int i = 0; i < files.length; i++) { readers[i] = new BufferedReader(new FileReader(files[i])); } return readers; }
@Test public void getLogAndStdoutFiles() throws Exception { WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation.find(CLUSTER_CONFIGURATION); FileUtils.writeStringToFile(logFiles.logFile, "job manager log"); String logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/log"); assertTrue(logs.contains("job manager log")); FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out"); logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/stdout"); assertTrue(logs.contains("job manager out")); }
public static BufferedInputStream[] getResultInputStream(String resultPath, String[] excludePrefixes) throws IOException { File[] files = getAllInvolvedFiles(resultPath, excludePrefixes); BufferedInputStream[] inStreams = new BufferedInputStream[files.length]; for (int i = 0; i < files.length; i++) { inStreams[i] = new BufferedInputStream(new FileInputStream(files[i])); } return inStreams; }
public static void compareResultsByLinesInMemoryWithStrictOrder(String expectedResultStr, String resultPath) throws Exception { compareResultsByLinesInMemoryWithStrictOrder(expectedResultStr, resultPath, new String[]{}); }
public static String constructTestURI(Class<?> forClass, String folder) { return new File(constructTestPath(forClass, folder)).toURI().toString(); }
public static BufferedInputStream[] getResultInputStream(String resultPath) throws IOException { return getResultInputStream(resultPath, new String[]{}); }