コード例 #1
0
  @Test
  public void testCacheIsUsed() throws IOException, InvalidRangeException {
    String filename = "file:TestAggExistingCache.xml";
    System.out.printf("%s%n", filename);

    String cacheDirName = TestDir.temporaryLocalDataDir + "testAggExistingCache/";
    System.out.printf("cacheDir=%s%n", cacheDirName);
    File cacheDir = new File(cacheDirName);
    FileUtils.deleteDirectory(cacheDir); // from commons-io
    assert !cacheDir.exists();

    DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0);
    cache.setAlwaysUseCache(true);
    Assert.assertEquals(cache.getRootDirectory(), cacheDirName);
    assert new File(cache.getRootDirectory()).exists();

    Aggregation.setPersistenceCache(cache);
    AggregationExisting.countCacheUse = 0;

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) {
      System.out.println(" TestNcmlAggExisting.open " + filename);
      Array ATssta = ncfile.readSection("ATssta(:,0,0,0)");
      Assert.assertEquals(4, ATssta.getSize());
    }
    Assert.assertEquals(0, AggregationExisting.countCacheUse);
    AggregationExisting.countCacheUse = 0;

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) {
      System.out.println(" TestNcmlAggExisting.open " + filename);
      Array ATssta = ncfile.readSection("ATssta(:,0,0,0)");
      Assert.assertEquals(4, ATssta.getSize());
    }
    Assert.assertEquals(8, AggregationExisting.countCacheUse);
  }
コード例 #2
0
  @Ignore("files not available")
  @Test
  public void testCacheTiming() throws IOException, InvalidRangeException {
    String filename = "file:testCacheTiming.xml";
    System.out.printf("%s%n", filename);

    String cacheDirName = TestDir.temporaryLocalDataDir + "testAggExistingCache/";
    System.out.printf("cacheDir=%s%n", cacheDirName);
    File cacheDir = new File(cacheDirName);
    FileUtils.deleteDirectory(cacheDir); // from commons-io
    assert !cacheDir.exists();

    DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0);
    cache.setAlwaysUseCache(true);
    Assert.assertEquals(cache.getRootDirectory(), cacheDirName);
    assert new File(cache.getRootDirectory()).exists();

    Aggregation.setPersistenceCache(cache);
    AggregationExisting.countCacheUse = 0;

    long start = System.currentTimeMillis();

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml2), filename, null)) {
      System.out.printf("%nTestNcmlAggExisting.open %s%n", filename);
      Variable time = ncfile.findVariable("time");
      System.out.printf(" Variable %s%n", time.getNameAndDimensions());
      time.read();
    }
    System.out.printf(" countCacheUse = %d%n", AggregationExisting.countCacheUse);

    long took = System.currentTimeMillis() - start;
    System.out.printf(" first took %d msecs%n", took);

    AggregationExisting.countCacheUse = 0;
    start = System.currentTimeMillis();

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml2), filename, null)) {
      System.out.printf("%nTestNcmlAggExisting.open %s%n", filename);
      Variable time = ncfile.findVariable("time");
      System.out.printf(" Variable %s%n", time.getNameAndDimensions());
      time.read();
    }
    System.out.printf(" countCacheUse = %d%n", AggregationExisting.countCacheUse);
    took = System.currentTimeMillis() - start;
    System.out.printf(" second took %d msecs%n", took);
  }