public void testBackwardIteration() throws IOException {
    final int records = 10000;

    long seed = System.currentTimeMillis();
    MersenneTwisterFast mersenneTwisterFast = new MersenneTwisterFast(1381162033616L);
    System.out.println("testBackwardIteration seed : " + seed);

    NavigableMap<OClusterPosition, byte[]> positionRecordMap = new TreeMap<OClusterPosition, byte[]>();

    ORecordVersion recordVersion = OVersionFactory.instance().createVersion();
    recordVersion.increment();
    recordVersion.increment();

    for (int i = 0; i < records; i++) {
      int recordSize = mersenneTwisterFast.nextInt(2 * OClusterPage.MAX_RECORD_SIZE) + 1;
      byte[] record = new byte[recordSize];
      mersenneTwisterFast.nextBytes(record);

      final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, recordVersion, (byte) 2);
      positionRecordMap.put(physicalPosition.clusterPosition, record);
    }

    Iterator<OClusterPosition> positionIterator = positionRecordMap.keySet().iterator();
    while (positionIterator.hasNext()) {
      OClusterPosition clusterPosition = positionIterator.next();
      if (mersenneTwisterFast.nextBoolean()) {
        Assert.assertTrue(paginatedCluster.deleteRecord(clusterPosition));
        positionIterator.remove();
      }
    }

    OPhysicalPosition physicalPosition = new OPhysicalPosition();
    physicalPosition.clusterPosition = OClusterPositionFactory.INSTANCE.valueOf(Long.MAX_VALUE);

    OPhysicalPosition[] positions = paginatedCluster.floorPositions(physicalPosition);
    Assert.assertTrue(positions.length > 0);

    positionIterator = positionRecordMap.descendingKeySet().iterator();
    int counter = 0;
    while (positionIterator.hasNext()) {
      Assert.assertTrue(positions.length > 0);

      OClusterPosition testedPosition = positionIterator.next();
      Assert.assertEquals(positions[positions.length - 1].clusterPosition, testedPosition);

      OPhysicalPosition positionToFind = positions[positions.length - 1];
      positions = paginatedCluster.lowerPositions(positionToFind);

      counter++;
    }

    Assert.assertEquals(paginatedCluster.getEntries(), counter);

    Assert.assertEquals(paginatedCluster.getFirstPosition(), positionRecordMap.firstKey());
    Assert.assertEquals(paginatedCluster.getLastPosition(), positionRecordMap.lastKey());
  }
예제 #2
0
  @Test
  public void NoSuchElem_After_Clear() {
    //      bug reported by :	Lazaros Tsochatzidis
    //        But after clearing the tree using:
    //
    //        public void Delete() {
    //            db.getTreeMap("Names").clear();
    //            db.compact();
    //        }
    //
    //        every next call of getLastKey() leads to the exception "NoSuchElement". Not
    //        only the first one...

    DB db = DBMaker.memoryDB().transactionDisable().make();
    NavigableMap m = db.treeMap("name");
    try {
      m.lastKey();
      fail();
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
    db.treeMap("name").clear();
    db.compact();
    try {
      Object key = m.lastKey();
      fail(key.toString());
    } catch (NoSuchElementException e) {
    }
    m.put("aa", "aa");
    assertEquals("aa", m.lastKey());
    m.put("bb", "bb");
    assertEquals("bb", m.lastKey());
  }
예제 #3
0
 /**
  * Answers the last element in this TreeSet.
  *
  * @return the last element
  * @exception NoSuchElementException when this TreeSet is empty
  */
 public E last() {
   return backingMap.lastKey();
 }
예제 #4
0
 /** @throws NoSuchElementException {@inheritDoc} */
 public E last() {
   return m.lastKey();
 }