예제 #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);
 }
 @Override
 protected StatisticsItem createStatisticsItem(@NotNull Type key) {
   // if don't gather statistics just return the new item and don't register it as periodic task in
   // SharedTimer
   if (!store.getConfig().getGatherStatistics()) {
     return new StatisticsItem(this);
   }
   return super.createStatisticsItem(key);
 }
 @NotNull
 @Override
 public StatisticsItem getStatisticsItem(@NotNull final String statisticsName) {
   // if don't gather statistics just return the new item and don't register it as periodic task in
   // SharedTimer
   if (!store.getConfig().getGatherStatistics()) {
     return new StatisticsItem(this);
   }
   return super.getStatisticsItem(statisticsName);
 }
예제 #4
0
 public void testNewVaultFilesLocality() {
   final PersistentEntityStoreImpl store = getEntityStore();
   final PersistentStoreTransaction txn = getStoreTransaction();
   store.getConfig().setMaxInPlaceBlobSize(0); // no in-lace blobs
   for (int i = 0; i < 256; ++i) {
     txn.newEntity("E").setBlob("b", new ByteArrayInputStream("content".getBytes()));
   }
   Assert.assertTrue(txn.flush());
   final FileSystemBlobVaultOld blobVault = (FileSystemBlobVaultOld) store.getBlobVault();
   final File vaultLocation = blobVault.getVaultLocation();
   Assert.assertEquals(257, vaultLocation.listFiles().length); // + "version" file
   Assert.assertEquals(
       256,
       vaultLocation.listFiles(
               new FilenameFilter() {
                 @Override
                 public boolean accept(File dir, String name) {
                   return name.endsWith(PersistentEntityStoreImpl.BLOBS_EXTENSION);
                 }
               })
           .length);
   for (int i = 0; i < 256; ++i) {
     txn.newEntity("E").setBlob("b", new ByteArrayInputStream("content".getBytes()));
   }
   Assert.assertTrue(txn.flush());
   Assert.assertEquals(258, vaultLocation.listFiles().length);
   Assert.assertEquals(
       256,
       vaultLocation.listFiles(
               new FilenameFilter() {
                 @Override
                 public boolean accept(File dir, String name) {
                   return name.endsWith(PersistentEntityStoreImpl.BLOBS_EXTENSION);
                 }
               })
           .length);
 }