Пример #1
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);
    }
  }
Пример #2
0
  public void testWriteRecords() {
    HistoryWriter writer = this.history.getWriter();

    try {
      for (int i = 0; i < 202; i++) {
        writer.addRecord(new String[] {"" + random.nextInt(), "name" + i, i % 2 == 0 ? "m" : "f"});
      }
    } catch (Exception e) {
      fail("Could not write records. Reason: " + e);
    }
  }
Пример #3
0
  /** Adds recent message in history. */
  private void saveRecentMessageToHistory(ComparableEvtObj msc) {
    synchronized (historyID) {
      // and create it
      try {
        History history = getHistory();
        HistoryWriter writer = history.getWriter();

        SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT);

        writer.addRecord(
            new String[] {
              msc.getProtocolProviderService().getAccountID().getAccountUniqueID(),
              msc.getContactAddress(),
              sdf.format(msc.getTimestamp()),
              RECENT_MSGS_VER
            },
            NUMBER_OF_MSGS_IN_HISTORY);
      } catch (IOException ex) {
        logger.error("cannot create recent_messages history", ex);
        return;
      }
    }
  }