예제 #1
0
 public void testPurgeLocallyStoredHistory() {
   try {
     this.historyService.purgeLocallyStoredHistory(this.history.getID());
   } catch (Exception ex) {
     fail("Cannot delete local history with id " + this.history.getID() + " : " + ex.getMessage());
   }
 }
예제 #2
0
  public void testWriteRecordsWithMaxNumber() {
    HistoryWriter writer = this.history.getWriter();
    HistoryReader reader = this.history.getReader();

    try {

      for (int i = 0; i < 20; i++) {
        writer.addRecord(new String[] {"" + i, "name" + i, i % 2 == 0 ? "m" : "f"}, 20);
        synchronized (this) {
          try {
            wait(100);
          } catch (Throwable t) {
          }
        }
      }

      QueryResultSet<HistoryRecord> recs = reader.findLast(20);
      int count = 0;
      while (recs.hasNext()) {
        count++;
        recs.next();
      }

      assertEquals("Wrong count of messages", 20, count);

      writer.addRecord(new String[] {"" + 21, "name" + 21, "f"}, 20);

      recs = reader.findLast(20);
      count = 0;
      boolean foundFirstMessage = false;
      while (recs.hasNext()) {
        count++;
        HistoryRecord hr = recs.next();

        if (hr.getPropertyValues()[0].equals("0")) foundFirstMessage = true;
      }

      assertEquals("Wrong count of messages", 20, count);

      assertFalse("Wrong message removed, must be the first one", foundFirstMessage);

    } catch (Exception e) {
      e.printStackTrace();
      fail("Could not write records. Reason: " + e);
    }
  }
예제 #3
0
  public void testCreateDB() {
    ArrayList<String> al = new ArrayList<String>();

    Iterator<HistoryID> i = this.historyService.getExistingIDs();
    while (i.hasNext()) {
      HistoryID id = i.next();
      String[] components = id.getID();

      if (components.length == 2 && "test".equals(components[0])) {
        al.add(components[1]);
      }
    }

    int count = al.size();
    boolean unique = false;
    String lastComp = null;
    while (!unique) {
      lastComp = Integer.toHexString(random.nextInt());
      for (int j = 0; j < count; j++) {
        if (lastComp.equals(al.get(j))) {
          continue;
        }
      }
      unique = true;
    }

    HistoryID id = HistoryID.createFromRawID(new String[] {"test", lastComp});

    try {
      this.historyService.createHistory(id, recordStructure);
    } catch (Exception e) {
      fail("Could not create database with id " + id + " with error " + e);
    }

    try {
      // after creating, remove it - do not leave content
      this.historyService.purgeLocallyStoredHistory(id);
    } catch (Exception ex) {
      fail("Cannot delete local history with id " + this.history.getID() + " : " + ex.getMessage());
    }
  }