Java Code Examples for ucar.unidata.io.RandomAccessFile#enableDefaultGlobalFileCache()

The following examples show how to use ucar.unidata.io.RandomAccessFile#enableDefaultGlobalFileCache() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestGribIndexCreation.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@BeforeClass
static public void before() {
  GribIosp.debugIndexOnlyCount = 0;
  GribCollectionImmutable.countGC = 0;
  PartitionCollectionImmutable.countPC = 0;
  RandomAccessFile.enableDefaultGlobalFileCache();
  RandomAccessFile.setDebugLeaks(true);
  // Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly"));
  GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100));
  GribCdmIndex.gribCollectionCache.resetTracking();

  // make sure that the indexes are created with the data files
  DiskCache2 diskCache = GribIndexCache.getDiskCache2();
  diskCache.setNeverUseCache(true);
  diskCache.setAlwaysUseCache(false);
}
 
Example 2
Source File: TestGribCollectionsDense.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
static public void before() {
  GribIosp.debugIndexOnlyCount = 0;
  GribCollectionImmutable.countGC = 0;
  PartitionCollectionImmutable.countPC = 0;
  RandomAccessFile.enableDefaultGlobalFileCache();
  RandomAccessFile.setDebugLeaks(true);
  Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly"));
  GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100));
  GribCdmIndex.gribCollectionCache.resetTracking();
}
 
Example 3
Source File: TestGribIndexCreationOther.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
static public void before() {
  GribIosp.debugIndexOnlyCount = 0;
  GribCollectionImmutable.countGC = 0;
  PartitionCollectionImmutable.countPC = 0;
  RandomAccessFile.enableDefaultGlobalFileCache();
  RandomAccessFile.setDebugLeaks(true);
  // Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly"));
  GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100));
  GribCdmIndex.gribCollectionCache.resetTracking();
}
 
Example 4
Source File: TestGribCollectionMissing.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
static public void before() {
  GribIosp.debugIndexOnlyCount = 0;
  GribCollectionImmutable.countGC = 0;
  PartitionCollectionImmutable.countPC = 0;
  RandomAccessFile.enableDefaultGlobalFileCache();
  RandomAccessFile.setDebugLeaks(true);
  Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly"));
  GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100));
  GribCdmIndex.gribCollectionCache.resetTracking();
}
 
Example 5
Source File: TestGribCollectionCoordinates.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
static public void before() throws IOException {
  GribIosp.debugIndexOnlyCount = 0;
  GribCollectionImmutable.countGC = 0;
  PartitionCollectionImmutable.countPC = 0;
  RandomAccessFile.enableDefaultGlobalFileCache();
  RandomAccessFile.setDebugLeaks(true);
  Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly"));
  GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100));
  GribCdmIndex.gribCollectionCache.resetTracking();
}
 
Example 6
Source File: TestGribCollectionsBig.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@BeforeClass
static public void before() {
  GribIosp.debugIndexOnlyCount = 0;
  GribCollectionImmutable.countGC = 0;
  PartitionCollectionImmutable.countPC = 0;
  RandomAccessFile.enableDefaultGlobalFileCache();
  RandomAccessFile.setDebugLeaks(true);
  Grib.setDebugFlags(new DebugFlagsImpl("Grib/indexOnly"));
  GribCdmIndex.setGribCollectionCache(new ucar.nc2.util.cache.FileCacheGuava("GribCollectionCacheGuava", 100));
  GribCdmIndex.gribCollectionCache.resetTracking();
}
 
Example 7
Source File: TestCompositeStationCollectionsWithCaches.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@BeforeClass
public static void setupCaches() {
  RandomAccessFile.enableDefaultGlobalFileCache();
  NetcdfDataset.initNetcdfFileCache(1, 10, 15, 200);
}
 
Example 8
Source File: TestCompositeStationCollectionsWithCaches.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void testOpenFileHandles() throws IOException {

    if (checkRafCache) {
      if (RandomAccessFile.getGlobalFileCache() != null) {
        RandomAccessFile.getGlobalFileCache().enable();
      } else {
        RandomAccessFile.enableDefaultGlobalFileCache();
      }
    } else {
      RandomAccessFile.getGlobalFileCache().clearCache(true);
      RandomAccessFile.shutdown();
      // RandomAccessFile.getGlobalFileCache().disable();
    }


    if (checkNetcdfFileCache) {
      // FeatureCollections still use NetcdfDataset, so work with that cache.
      NetcdfDataset.getNetcdfFileCache().enable();
    } else {
      NetcdfDataset.getNetcdfFileCache().clearCache(true);
      NetcdfDataset.getNetcdfFileCache().disable();
    }

    // open the collection
    String collection = ucar.nc2.ft.point.collection.CompositeDatasetFactory.SCHEME + TestDir.cdmUnitTestDir
        + "/ft/station/gempak/collection_with_missing_station_features/#yyMMdd#.sf$";
    FeatureDataset fds = FeatureDatasetFactoryManager.open(FeatureType.STATION, collection, null, null);
    assertThat(fds instanceof FeatureDatasetPoint);
    FeatureDatasetPoint fdp = (FeatureDatasetPoint) fds;

    // the collection dataset should have one feature collection, and it should
    // be a CompositeStationCollection
    assertThat(fdp.getPointFeatureCollectionList()).hasSize(1);
    DsgFeatureCollection dfc = fdp.getPointFeatureCollectionList().get(0);
    assertThat(dfc instanceof CompositeStationCollection);
    CompositeStationCollection csc = (CompositeStationCollection) dfc;

    // now it gets tricky. We have to tickle the PointFeatureIterator for each station trigger
    // the bug, but the iterator is hidden within the station collection because the collection
    // is made up of multiple files. Here, we use the StationHelper to get at the PointFeatureIterator
    // at the individual file level of the collection.
    StationHelper helper = csc.createStationHelper();
    List<Station> stations = helper.getStations();

    // Ensure the RandomAccessFile cache does not contain any locked files
    if (checkRafCache) {
      testRafCache();
    }

    if (checkNetcdfFileCache) {
      testNetcdfFileCache();
    }

    // Now, iterate over the stations. Each station cycles through one or more files of the collection,
    // and the bug is that the file isn't closed or released if it does not contain the given station.
    for (int station = 0; station < 2; station++) {
      // Get the PointFeatureIterator for the given station
      PointFeatureIterator pointFeatureIterator =
          ((StationTimeSeriesFeature) stations.get(station)).getPointFeatureIterator();
      // all we have to do is call .hasNext(), and if not, the underlying code will cycle through the
      // datasets of the collection but not close them
      pointFeatureIterator.hasNext();
      pointFeatureIterator.close();
    }

    if (checkRafCache) {
      testRafCache();
    }

    if (checkNetcdfFileCache) {
      testNetcdfFileCache();
    }
  }
 
Example 9
Source File: TestMiscIosp.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@BeforeClass
static public void startup() {
  RandomAccessFile.setDebugLeaks(true);
  RandomAccessFile.enableDefaultGlobalFileCache();
  leaks = RandomAccessFile.getOpenFiles().size();
}