Package edu.berkeley.xtrace

Examples of edu.berkeley.xtrace.TaskID


    if (!canTest) return;
   
    long startTime = System.currentTimeMillis();
   
    /* Insert a single report into the file store */
    XTraceMetadata md = new XTraceMetadata(new TaskID(8), 0);
    Report report = randomReport(md);
    fs.receiveReport(report.toString());
   
    /* Sync() the report */
    fs.sync();
 
View Full Code Here


   
    /* Create a set of tasks */
    TaskID[] taskIds = new TaskID[NUM_STOCHASTIC_TASKS];
    String[] taskStrs = new String[NUM_STOCHASTIC_TASKS];
    for (int i = 0 ; i < taskIds.length; i++) {
      taskIds[i] = new TaskID(8);
      taskStrs[i] = taskIds[i].toString();
    }
   
    /* Create a set of reports */
    XTraceMetadata[] mds = new XTraceMetadata[TOTAL_REPORTS];
View Full Code Here

   
    /* Create a set of reports */
    Report[] reports = new Report[TOTAL_REPORTS];
    TaskID[] tasks = new TaskID[NUM_STOCHASTIC_TASKS];
    for (int i = 0; i < NUM_STOCHASTIC_TASKS; i++) {
      tasks[i] = new TaskID(8);
      for (int j = 0; j < NUM_STOCHASTIC_REPORTS_PER_TASK; j++) {
        int idx = i*NUM_STOCHASTIC_REPORTS_PER_TASK +j;
        reports[idx] = randomReport(new XTraceMetadata(tasks[i], r.nextInt()));
        if (i < NUM_STOCHASTIC_TASKS / 2) {
          reports[idx].put("Tag", "small");
View Full Code Here

  public void TODOtestDuplicateTags() throws XTraceException {
    if (!canTest) return;
   
    /* Insert a single report into the file store */
    TaskID taskId = new TaskID(8);
    Report report = randomReport(new XTraceMetadata(taskId, 0));
    report.put("Tag", "tag1");
    report.put("Tag", "tag1");
    fs.receiveReport(report.toString());
    fs.sync();
View Full Code Here

 
  public void TODOtestTitleOperations() throws XTraceException {
    if (!canTest) return;
   
    /* Insert a single report into the file store */
    TaskID taskId = new TaskID(8);
    Report report = randomReport(new XTraceMetadata(taskId, 0));
    fs.receiveReport(report.toString());
    fs.sync();
   
    /* Test that the title is the taskID (since no title field was given) */
    assertEquals(taskId.toString(), fs.getLatestTasks(0, 1).get(0).getTitle());
    assertEquals(1, fs.getTasksByTitle(taskId.toString(), 0, Integer.MAX_VALUE).size());
   
    /* Insert another report in the same task, with no title */
    report = randomReport(new XTraceMetadata(taskId, 1));
    fs.receiveReport(report.toString());
    fs.sync();
   
    /* Test that the title is the taskID (since no title field was given) */
    assertEquals(taskId.toString(), fs.getLatestTasks(0, 1).get(0).getTitle());
    assertEquals(1, fs.getTasksByTitle(taskId.toString(), 0, Integer.MAX_VALUE).size());
   
    /* Insert another report in the same task, with a title */
    report = randomReport(new XTraceMetadata(taskId, 2));
    report.put("Title", "title1");
    fs.receiveReport(report.toString());
    fs.sync();
   
    /* Test that the title is title1 */
    assertEquals("title1", fs.getLatestTasks(0, 1).get(0).getTitle());
    assertEquals(0, fs.getTasksByTitle(taskId.toString(), 0, Integer.MAX_VALUE).size());
    assertEquals(1, fs.getTasksByTitle("title1", 0, Integer.MAX_VALUE).size());
   
    /* Insert another report in the same task, with another title */
    report = randomReport(new XTraceMetadata(taskId, 3));
    report.put("Title", "title2");
    fs.receiveReport(report.toString());
    fs.sync();
   
    /* Test that the title is title1 */
    assertEquals("title2", fs.getLatestTasks(0, 1).get(0).getTitle());
    assertEquals(0, fs.getTasksByTitle(taskId.toString(), 0, Integer.MAX_VALUE).size());
    assertEquals(0, fs.getTasksByTitle("title1", 0, Integer.MAX_VALUE).size());
    assertEquals(1, fs.getTasksByTitle("title2", 0, Integer.MAX_VALUE).size());
    assertEquals(1, fs.getTasksByTitleSubstring("title2", 0, Integer.MAX_VALUE).size());
    assertEquals(1, fs.getTasksByTitleSubstring("itle", 0, Integer.MAX_VALUE).size());
    assertEquals(1, fs.getTasksByTitleSubstring("t", 0, Integer.MAX_VALUE).size());
View Full Code Here

    assertEquals(0L, fs.lastUpdatedByTaskId(TaskID.createFromString("00000000")));
   
    /* Test if an insertion updates the time */
    long startTime = System.currentTimeMillis();
   
    XTraceMetadata md = new XTraceMetadata(new TaskID(8), 0);
    Report report = randomReport(md);
    fs.receiveReport(report.toString());
   
    /* Sync() the report */
    fs.sync();
   
    long afterFirstInsertion = fs.lastUpdatedByTaskId(md.getTaskId());
    assertTrue(afterFirstInsertion > startTime);
   
    md = new XTraceMetadata(new TaskID(8), 0);
    report = randomReport(md);
    fs.receiveReport(report.toString());
   
    /* Sync() the report */
    fs.sync();
 
View Full Code Here

    if (!canTest) return;
   
    /* Create a set of reports */
    Report[] reports = new Report[10];
    for (int i = 0; i < reports.length; i++) {
      reports[i] = randomReport(new XTraceMetadata(new TaskID(8), r.nextInt()));
      fs.receiveReport(reports[i].toString());
      try {
        Thread.sleep(25);
      } catch (InterruptedException e) { }
    }
View Full Code Here

    if (!canTest) return;
   
    /* Create a set of reports */
    Report[] reports = new Report[10];
    for (int i = 0; i < reports.length; i++) {
      reports[i] = randomReport(new XTraceMetadata(new TaskID(8), r.nextInt()));
    }
    reports[2].put("Tag", "tag1");
    reports[4].put("Tag", "tag2");
    reports[5].put("Tag", "tag2");
    reports[6].put("Tag", "tag3");
    reports[6].put("Tag", "tag4");
   
    /* Send them to the report store */
    for (int i = 0; i < reports.length; i++) {
      fs.receiveReport(reports[i].toString());
    }
    fs.sync();
   
    /* Test null case */
    List<TaskRecord> nulllst = fs.getTasksByTag("foobar", 0, Integer.MAX_VALUE);
    assertNotNull(nulllst);
    assertEquals(0, nulllst.size());
   
    /* tag in exactly 1 report */
    List<TaskRecord> lst = fs.getTasksByTag("tag1", 0, Integer.MAX_VALUE);
    assertNotNull(lst);
    assertEquals(1, lst.size());
    assertEquals(reports[2].getMetadata().getTaskId(), lst.get(0).getTaskId());
   
    /* tag in two different reports */
    TaskID report4 = reports[4].getMetadata().getTaskId();
    TaskID report5 = reports[5].getMetadata().getTaskId();
    lst = fs.getTasksByTag("tag2", 0, Integer.MAX_VALUE);
    assertNotNull(lst);
    assertEquals(2, lst.size());
    assertTrue(  (report4.equals(lst.get(0).getTaskId())
                    && report5.equals(lst.get(1).getTaskId()))  ||
                 (report5.equals(lst.get(0).getTaskId())
                    && report4.equals(lst.get(1).getTaskId()))   );
   
    /* two tags in the same report */
    TaskID report6 = reports[6].getMetadata().getTaskId();
    lst = fs.getTasksByTag("tag3", 0, Integer.MAX_VALUE);
    assertNotNull(lst);
    assertEquals(1, lst.size());
    assertEquals(report6, lst.get(0).getTaskId());
    lst = fs.getTasksByTag("tag4", 0, Integer.MAX_VALUE);
View Full Code Here

    ctx.close();
  }
 
  private static void reportRandom() {
    Reporter ctx = Reporter.getReporter();
    Report rpt = randomReport(new TaskID(8));
    rpt.put("Agent", "RandomReport");
    rpt.put("Label", "report");
    rpt.put("Tag", "rnd");
    rpt.put("Tag", "rpt");
    rpt.put("Title", "RandomReport");
View Full Code Here

      Report r = Report.createFromString(msg);
      String xtraceLine = matcher.group(1);
      XTraceMetadata meta = XTraceMetadata.createFromString(xtraceLine);

      if (meta.getTaskId() != null) {
        TaskID task = meta.getTaskId();
        String taskId = task.toString().toUpperCase();
        BufferedWriter fout = fileCache.getHandle(task);
        if (fout == null) {
          LOG
              .warn("Discarding a report due to internal fileCache error: "
                  + msg);
          return;
        }
        try {
          fout.write(msg);
          fout.newLine();
          fout.newLine();
          LOG.debug("Wrote " + msg.length() + " bytes to the stream");
        } catch (IOException e) {
          LOG.warn("I/O error while writing the report", e);
        }

        // Update index
        try {
          // Extract title
          String title = null;
          List<String> titleVals = r.get("Title");
          if (titleVals != null && titleVals.size() > 0) {
            // There should be only one title field, but if there
            // are more, just
            // arbitrarily take the first one.
            title = titleVals.get(0);
          }

          // Extract tags
          TreeSet<String> newTags = null;
          List<String> list = r.get("Tag");
          if (list != null) {
            newTags = new TreeSet<String>(list);
          }

          // Find out whether to do an insert or an update
          countTasks.setString(1, taskId);
          ResultSet rs = countTasks.executeQuery();
          rs.next();
          if (rs.getInt("rowcount") == 0) {
            if (title == null) {
              title = taskId;
            }
            insert.setString(1, taskId);
            insert.setString(2, joinWithCommas(newTags));
            insert.setString(3, title);
            insert.executeUpdate();
          } else {
            // Update title if necessary
            if (title != null) {
              updateTitle.setString(1, title);
              updateTitle.setString(2, taskId);
              updateTitle.executeUpdate();
            }
            // Update tags if necessary
            if (newTags != null) {
              getTags.setString(1, taskId);
              ResultSet tagsRs = getTags.executeQuery();
              tagsRs.next();
              String oldTags = tagsRs.getString("tags");
              tagsRs.close();
              newTags.addAll(Arrays.asList(oldTags.split(",")));
              updateTags.setString(1, joinWithCommas(newTags));
              updateTags.setString(2, taskId);
              updateTags.executeUpdate();
            }
            // Update report count and last-updated date
            update.setString(1, taskId);
            update.executeUpdate();
          }
          rs.close();
          conn.commit();

        } catch (SQLException e) {
          LOG.warn("Unable to update metadata about task "
              + task.toString(), e);
        }
      } else {
        LOG
            .debug("Ignoring a report without an X-Trace taskID: "
                + msg);
View Full Code Here

TOP

Related Classes of edu.berkeley.xtrace.TaskID

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.