@Test
public void HttpGetTest() {

    SqlParser parser = new SqlParser();
    Query q = null;
    Object o = new Object();
    JSONArray jsonArray = null;
    int num = 0, cou = 0;
    while (true) {
        try {
            o = HttpUtil.HttpGet(Settings.PRESTO_QUERY);
        } catch (Exception e) {
            ExceptionHandler.Instance().log(ExceptionType.ERROR, "http get error", e);
        }
        jsonArray = JSON.parseArray(o.toString());
        String queryId = null;
        String query = null;
        for (int i = count; i < jsonArray.size(); i++) {
            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            if (jsonObject.size() == 8) {
                queryId = jsonObject.get("queryId").toString();
                query = jsonObject.get("query").toString();
                  System.out.println(queryId + "\t" + i + "\t" + query);
                // Parser
                try {
                    q = (Query) parser.createStatement(query);
                } catch (Exception e) {
                    ExceptionHandler.Instance().log(ExceptionType.ERROR, "query error", e);
                }
              System.out.println(q.toString());
                QuerySpecification queryBody = (QuerySpecification) q.getQueryBody();
                // get columns
                List<SelectItem> selectItemList = queryBody.getSelect().getSelectItems();
                // tableName
                Table t = (Table) queryBody.getFrom().get();
                  System.out.println(t.getName());
                if (t.getName().toString().equals("text")) {
                    System.out.println("Text visit: " + cou++);
                    int j = 0;
                    Random random = new Random(System.currentTimeMillis());
                    AccessPatternCache APC = new AccessPatternCache(100000, 0.1);
                    String time = DateUtil.formatTime(new Date());
                    System.out.println(time);
                    try {
                        if (!flag) {
                            flag = true;
                            FileUtil.writeFile(time + "\tBegin\t" + i + "\r\n", Settings.APC_PATH, true);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    double weight = Double.parseDouble("1");
                    AccessPattern pattern = new AccessPattern(queryId, weight);
                    for (SelectItem column : selectItemList) {
                      System.out.println(scolumn.toString());
                        pattern.addColumn(column.toString());
                    }
                    if (APC.cache(pattern)) {
                        System.out.println(i + ", trigger layout optimization.");
                        j++;
                        APC.saveAsWorkloadFile("/home/tao/software/station/Workplace/workload_" + j + ".txt");
                        try {
                            flag = false;
                            System.out.println(time);
                            FileUtil.writeFile(time + "\tEnd\t" + i + "\r\n", Settings.APC_PATH, true);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    try {
                        Thread.sleep(random.nextInt(500));
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        // update count
        count = jsonArray.size();
        num++;
        o = new Object();
    }
}