@Override
 public void doSetup(final ManagementClient managementClient) throws Exception {
   try {
     dsAddress = createDataSource(false, jndiDs);
     dsXaAddress = createDataSource(true, jndiXaDs);
     StringBuffer sb = cleanStats(dsAddress).append(cleanStats(dsXaAddress));
     if (sb.length() > 0) fail(sb.toString());
   } catch (Throwable e) {
     removeDss();
     throw new Exception(e);
   }
 }
    @Override
    public void tearDown(final ManagementClient managementClient, final String containerId)
        throws Exception {
      try {
        StringBuffer sb =
            assertStatisticsSet(true, getStatAddr(dsAddress))
                .append(assertStatisticsSet(true, getStatAddr(dsXaAddress)));
        if (sb.length() > 0) fail(sb.toString());

      } catch (Throwable e) {
        throw new Exception(e);
      } finally {
        removeDss();
      }
    }
    /**
     * Checks, if some parameters are set on data source statistics node
     *
     * @param yes - should be parameters set?
     * @param statisticNode - address, where to check
     * @return StringBuffer, contains error message, if operation fails
     * @throws Exception
     */
    public StringBuffer assertStatisticsSet(boolean yes, ModelNode statisticNode) throws Exception {
      StringBuffer sb = new StringBuffer();
      String[] params = {
        "PreparedStatementCacheAccessCount", // The number of times that the statement cache was
        // accessed
        "PreparedStatementCacheAddCount", // The number of statements added to the statement cache
        "PreparedStatementCacheCurrentSize", // The number of prepared and callable statements
                                             // currently cached in
        // the statement cache
        "PreparedStatementCacheDeleteCount", // The number of statements discarded from the cache
        "PreparedStatementCacheHitCount" // The number of times that statements from the cache were
                                         // used
      };
      for (String param : params)
        if ((getStatisticsAttribute(param, statisticNode) == 0) == yes)
          sb.append("\nAttribute " + param + " is " + (yes ? "not " : "") + "set");

      if (sb.length() > 0) sb.insert(1, "Address:" + statisticNode.toString());
      return sb;
    }
예제 #4
0
  public void loadScript(String name) throws IOException {
    BufferedReader reader = null;
    StringBuffer contents = new StringBuffer();

    try {
      InputStream in = new FileInputStream(new File(name));
      reader = new BufferedReader(new InputStreamReader(in));
      String text = null;

      // repeat until all lines is read
      while ((text = reader.readLine()) != null) {
        contents.append(text).append(EOL);
      }
    } finally {
      if (reader != null) {
        reader.close();
      }
    }
    assertTrue(contents.length() > 0);
    eval(contents.toString());
  }
예제 #5
0
 private boolean appendToList(List<JSONObject> tx, StringBuffer buffer) {
   if (buffer.length() == 0) return true;
   switch (buffer.charAt(0)) {
     case '[':
       int closePos = 0;
       boolean inString = false;
       int inArray = 0;
       for (int i = 1; i < buffer.length() && closePos == 0; i++) {
         switch (buffer.charAt(i)) {
           case '"':
             if (buffer.charAt(i - 1) != '\\') inString = !inString;
             break;
           case ']':
             if (!inString) {
               if (inArray == 0) closePos = i;
               else inArray--;
             }
             break;
           case '[':
             if (!inString) inArray++;
             break;
           default:
             break;
         }
       }
       if (inArray != 0 || closePos == 0) return false;
       List<JSONObject> subList = new ArrayList<JSONObject>(5);
       StringBuffer subBuff = new StringBuffer(buffer.substring(1, closePos));
       boolean finished = appendToList(subList, subBuff);
       if (finished) {
         buffer.delete(0, closePos + 1);
         tx.add(new JSONObject(subList));
         return appendToList(tx, buffer);
       } else return false;
     case '"':
       int finishPos = 0;
       do {
         finishPos = buffer.indexOf("\"", finishPos + 1);
       } while (finishPos == -1 || buffer.charAt(finishPos - 1) == '\\');
       if (finishPos == -1) return false;
       tx.add(new JSONObject(buffer.substring(1, finishPos)));
       buffer.delete(0, finishPos + 1);
       return appendToList(tx, buffer);
     case ',':
     case ' ':
       buffer.delete(0, 1);
       return appendToList(tx, buffer);
     default:
       String first = buffer.toString().split(",")[0].trim();
       if (first.equals("true")) {
         tx.add(new JSONObject(true));
         buffer.delete(0, 4);
         return appendToList(tx, buffer);
       } else if (first.equals("false")) {
         tx.add(new JSONObject(false));
         buffer.delete(0, 5);
         return appendToList(tx, buffer);
       } else if (first.matches("^-?[0-9]*$")) {
         tx.add(new JSONObject(Integer.parseInt(first)));
         buffer.delete(0, first.length());
         return appendToList(tx, buffer);
       } else fail();
   }
   return false;
 }