Exemplo n.º 1
0
 public void testHandleToFileAndFileToHandle() {
   final PersistentEntityStoreImpl store = getEntityStore();
   final PersistentStoreTransaction txn = getStoreTransaction();
   store.getConfig().setMaxInPlaceBlobSize(0); // no in-lace blobs
   final int count = 1000;
   for (int i = 0; i < count; ++i) {
     txn.newEntity("E").setBlob("b", new ByteArrayInputStream("content".getBytes()));
   }
   Assert.assertTrue(txn.flush());
   final FileSystemBlobVault blobVault = (FileSystemBlobVault) store.getBlobVault();
   final NavigableMap<Long, File> handlesToFiles = new TreeMap<>();
   for (final BackupStrategy.FileDescriptor fd : blobVault.getBackupStrategy().listFiles()) {
     final File file = fd.getFile();
     if (file.isFile() && !file.getName().equals(FileSystemBlobVaultOld.VERSION_FILE)) {
       final long handle = blobVault.getBlobHandleByFile(file);
       Assert.assertFalse(handlesToFiles.containsKey(handle));
       handlesToFiles.put(handle, file);
       Assert.assertEquals(file, blobVault.getBlobLocation(handle));
     }
   }
   final long min = handlesToFiles.navigableKeySet().iterator().next();
   Assert.assertEquals(0L, min);
   final long max = handlesToFiles.descendingKeySet().iterator().next();
   Assert.assertEquals((long) (count - 1), max);
 }
  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());
  }
Exemplo n.º 3
0
  private static Records recordsFrom(
      final NavigableMap<Long, JournalRecord> content, boolean descending) {
    final Iterator<Long> iterator =
        descending ? content.descendingKeySet().iterator() : content.keySet().iterator();
    return new Records() {
      @Override
      public int size() {
        return content.size();
      }

      @Override
      public Iterator<JournalRecord> iterator() {
        return new Iterator<JournalRecord>() {
          @Override
          public boolean hasNext() {
            return iterator.hasNext();
          }

          @Override
          public JournalRecord next() {
            return content.get(iterator.next());
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException("This iterator is read-only");
          }
        };
      }

      @Override
      public boolean isEmpty() {
        return size() == 0;
      }
    };
  }
 public void testDescendingKeySet() {
   NavigableMap<String, Integer> map = create();
   NavigableSet<String> descendingKeySet = map.descendingKeySet();
   assertTrue(descendingKeySet instanceof SynchronizedNavigableSet);
   assertSame(mutex, ((SynchronizedNavigableSet<String>) descendingKeySet).mutex);
 }