Example #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);
    }
  }
Example #2
0
  public void testReadRecords() {
    HistoryReader reader = this.history.getReader();

    QueryResultSet<HistoryRecord> result = reader.findByKeyword("name2", "name");

    assertTrue("Nothing found", result.hasNext());

    while (result.hasNext()) {
      HistoryRecord record = result.nextRecord();

      String[] vals = record.getPropertyValues();

      try {
        int n = Integer.parseInt(vals[1].substring(4));

        assertEquals(3, vals.length);
        assertEquals(n % 2 == 0 ? "m" : "f", vals[2]);
      } catch (Exception e) {
        fail("Bad data! Expected nameXXXX, where XXXX is " + "an integer, but found: " + vals[0]);
      }
    }
  }