Heroku本地应用程序测试在控制台

时间:2015-11-06 08:06:43

标签: java maven heroku

我曾尝试在很多地方寻找可能发生这种情况的原因,但我不能为我的生活弄清楚。有调用System.out.printf(...);当main执行时,终端只是丢失了。另一个奇怪的是每次都不一样。我可以连续两次运行应用程序,无需更改代码或重新构建,输出缺少不同的System.out调用。

这是一个Maven Build。我有三个对象。包含main,User对象和DB访问对象的类。

主要对象是使用连接来构建和发送电子邮件。 Db对象使用连接来访问psql本地数据库。

以下是一些显示问题的代码片段。

public static List<User_Search_Profile> getAllTable(String tableName, PrintStream out){
    List<User_Search_Profile> users = new ArrayList<User_Search_Profile>();
    Connection connection = Database_Access.establishConnection();
    try{                        
        ResultSet resultTable = Database_Access.generateResultSet("SELECT * FROM " + tableName, connection);
        ResultSetMetaData resultTableMetaData = resultTable.getMetaData();
        ResultSet abvTable = Database_Access.generateResultSet("SELECT * FROM CLSEARCHTABLE", connection);
        connection.close();

        int columns = resultTableMetaData.getColumnCount();
        out.printf("Columns: " + columns + "%n");

        String [] labels = new String[columns];                     
        for(int i = 1; i <= columns; i++){
            labels[i-1] = resultTableMetaData.getColumnLabel(i).toString();
            out.printf("Label: " + labels[i-1] + "%n");

        }

        Map<String, String> dbVals = new HashMap<String, String>();

        resultTable.first();                
        while(!resultTable.isAfterLast()){

            for(String s: labels){
                dbVals.put(s, resultTable.getString(s));
            }               
            User_Search_Profile user = new User_Search_Profile(dbVals.get("region"), dbVals.get("category"),
                    dbVals.get("name"), dbVals.get("email"), dbVals.get("search"), dbVals.get("lasthash"));                 
            users.add(user);                    
            resultTable.next();


        }           
        resultTable.close();  


        abvTable.first();
        for(User_Search_Profile user: users){                   

            while(!abvTable.isAfterLast()){
                if(abvTable.getString(1) == user.getCategory()){
                    user.setCategoryAbv(abvTable.getString(2));
                }
                if(abvTable.getString(1) == user.getRegion()){
                    user.setRegionAbv(abvTable.getString(2));
                }
                abvTable.next();

            }   
            user.printUser(out); //Calls the user object print
        }

    }

用户对象部分:

    public void printUser(PrintStream out){
    out.printf("--User--%n%n");
    out.printf("Name: " + name + "%n");
    out.printf("Email: " + email + "%n");
    out.printf("Reg: " + region + "%n");
    out.printf("Abv: " + regionAbv + "%n");
    out.printf("Cat: " + category + "%n");
    out.printf("Abv: " + categoryAbv + "%n");
    out.printf("Search: " + searchString + "%n");
    out.printf("Hash: " + lastHash + "%n");
    //out.flush();

}

这是连续运行的输出:

james ~/heroku/java-getting-started $ heroku local worker
forego  | starting worker.1 on port 5100
worker.1 | Columns: 6
worker.1 | Label: region
worker.1 | Label: category
worker.1 | Label: name
worker.1 | Label: email
worker.1 | Label: search
worker.1 | Label: lasthash
worker.1 | --User--
worker.1 | 
worker.1 | Name: James
worker.1 | Email: ************
worker.1 | Reg: Clackamas County
worker.1 | Abv: null
worker.1 | Cat: Jobs
worker.1 | Abv: null
worker.1 | Search: Web Developer
worker.1 | Hash: ccdd352048003f7feae23004c5df2caa
james ~/heroku/java-getting-started $ heroku local worker
forego  | starting worker.1 on port 5100
worker.1 | Columns: 6
worker.1 | Label: region
worker.1 | Label: category
worker.1 | Label: name
worker.1 | Label: email
worker.1 | Label: search
worker.1 | Label: lasthash
worker.1 | --User--
worker.1 | 
worker.1 | Name: James
worker.1 | Email: **********
james ~/heroku/java-getting-started $ heroku local worker
forego  | starting worker.1 on port 5100
worker.1 | Columns: 6
worker.1 | Label: region
worker.1 | Label: category
worker.1 | Label: name
worker.1 | Label: search
worker.1 | Label: lasthash
worker.1 | --User--
worker.1 | 
worker.1 | Name: James
worker.1 | Email: ***********   // not encrypted just personal
worker.1 | 
worker.1 | Abv: null
worker.1 | Cat: Jobs
james ~/heroku/java-getting-started $ 

我非常困惑。似乎存在缓冲问题,或输出正在其他地方,但如果我知道在哪里该死的。任何帮助将不胜感激,因为我无法在无法验证输出的情况下进行调试。

1 个答案:

答案 0 :(得分:1)

问题是基础forego工具,heroku local用来运行您的流程。

我认为工具带仍会安装foreman,因此您可以尝试运行foreman start worker

最后,您可以随时手动运行Procfile命令,但您也需要手动设置env vars。