Repository: vxquery Updated Branches: refs/heads/master 015c5f6ca -> 7de1fbaa3
http://git-wip-us.apache.org/repos/asf/vxquery/blob/7de1fbaa/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/LineFileReporterImpl.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/LineFileReporterImpl.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/LineFileReporterImpl.java index dce59b0..12a69c3 100644 --- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/LineFileReporterImpl.java +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/LineFileReporterImpl.java @@ -17,13 +17,16 @@ package org.apache.vxquery.xtest; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; public class LineFileReporterImpl implements ResultReporter { private PrintWriter out; + private File file; public LineFileReporterImpl(File file) throws IOException { + this.file = file; out = new PrintWriter(file); } @@ -36,6 +39,14 @@ public class LineFileReporterImpl implements ResultReporter { @Override public void close() { + //Perform the sorting process. out.close(); + try { + ResultFileSorter sorter = new ResultFileSorter(file.getPath()); + sorter.sortFile(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } } } + http://git-wip-us.apache.org/repos/asf/vxquery/blob/7de1fbaa/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/ResultFileSorter.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/ResultFileSorter.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/ResultFileSorter.java new file mode 100644 index 0000000..c048138 --- /dev/null +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/ResultFileSorter.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.vxquery.xtest; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Class to sort the final test results. + */ + +//TODO : Optimize for large files. +public class ResultFileSorter { + + private final String path; + private static final Logger LOGGER = Logger.getLogger(ResultFileSorter.class.getName()); + + public ResultFileSorter(String path) throws FileNotFoundException { + this.path = path; + } + + /** + * The method to sort the test case results. + */ + public void sortFile() { + File resultFile = new File(path); + try { + FileReader fileReader = new FileReader(resultFile); + BufferedReader reader = new BufferedReader(fileReader); + String line; + ArrayList<String> fullText = new ArrayList<>(); + while ((line = reader.readLine()) != null) { + fullText.add(line); + } + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.log(Level.INFO, "Sorting....."); + } + Collections.sort(fullText, String.CASE_INSENSITIVE_ORDER); + String[] sortedText = fullText.toArray(new String[fullText.size()]); + this.eraseFile(resultFile); + this.writeToFile(sortedText); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Method to delete existing the file. + * + * @throws FileNotFoundException + */ + private boolean eraseFile(File file) throws FileNotFoundException { + return file.delete(); + } + + /** + * Method to write the sorted content to the new file. + * + * @param text + * : The sorted array of test case results. + * @throws FileNotFoundException + */ + private void writeToFile(String[] text) throws FileNotFoundException { + File newFile = new File(path); + PrintWriter writer = new PrintWriter(newFile); + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.log(Level.INFO, "Writing to file started."); + } + + for (String s : text) { + writer.write(s + "\n"); + } + writer.close(); + if (LOGGER.isLoggable(Level.INFO)) { + LOGGER.log(Level.INFO, "Writing to file finished successfully."); + } + + } +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/7de1fbaa/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java ---------------------------------------------------------------------- diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java index b216240..17dea60 100644 --- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java +++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java @@ -16,6 +16,8 @@ */ package org.apache.vxquery.xtest; +import org.mortbay.jetty.Server; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -23,8 +25,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.mortbay.jetty.Server; - public class XTest { private XTestOptions opts; private Server server; @@ -36,7 +36,7 @@ public class XTest { XTest(XTestOptions opts) { this.opts = opts; - reporters = new ArrayList<ResultReporter>(); + reporters = new ArrayList<>(); } void init() throws Exception { @@ -100,6 +100,7 @@ public class XTest { eSvc.awaitTermination(opts.keepalive, TimeUnit.MILLISECONDS); } finally { try { + if (server != null) { server.stop(); }
