Skip to content

Commit

Permalink
Merge branch 'maint-5.x' into handle-zero-dimension-2
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlerman authored Jan 4, 2023
2 parents 6d44d10 + 9fb75d5 commit 4d6b715
Show file tree
Hide file tree
Showing 22 changed files with 1,169 additions and 662 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/tds-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ jobs:
sed -i 's/versions\["ncj"\] =.*$/versions["ncj"] ="'${NCJ_VERSION}'"/g' ./gradle/any/dependencies.gradle
# setup env vars for tds buildTestDSR
CONTENT_ROOT="-Dtds.content.root.path=${TDS_BUILD_DIR}/tds/src/test/content"
DOWNLOAD_DIR="-Dtds.download.dir=/tmp/download"
UPLOAD_DIR="-Dtds.upload.dir=/tmp/upload"
SYSTEM_PROPS="$CONTENT_ROOT $DOWNLOAD_DIR $UPLOAD_DIR"
SYSTEM_PROPS="$CONTENT_ROOT"
# run tds tests
echo "Run the TDS tests"
./gradlew $SYSTEM_PROPS --info --stacktrace testAll
Expand Down Expand Up @@ -96,10 +94,8 @@ jobs:
sed -i 's/versions\["ncj"\] =.*$/versions["ncj"] ="'${NCJ_VERSION}'"/g' ./gradle/any/dependencies.gradle
# setup env vars for tds buildTestDSR
CONTENT_ROOT="-Dtds.content.root.path=${TDS_BUILD_DIR}/tds/src/test/content"
DOWNLOAD_DIR="-Dtds.download.dir=/tmp/download"
UPLOAD_DIR="-Dtds.upload.dir=/tmp/upload"
BUILDERS="-Dthredds.test.experimental.useNetcdfJavaBuilders=true"
SYSTEM_PROPS="$CONTENT_ROOT $DOWNLOAD_DIR $UPLOAD_DIR $BUILDERS"
SYSTEM_PROPS="$CONTENT_ROOT $BUILDERS"
# run tds tests
echo "Run the TDS tests"
./gradlew $SYSTEM_PROPS --info --stacktrace testAll --refresh-dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ucar.nc2.ft.coverage;

import static com.google.common.truth.Truth.assertThat;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import ucar.nc2.dataset.NetcdfDatasets;
import ucar.nc2.ft2.coverage.CoverageDatasetFactory;
import ucar.nc2.ft2.coverage.FeatureDatasetCoverage;
import ucar.unidata.io.RandomAccessFile;

public class TestCoverageDatasetFactory {

@BeforeClass
public static void setupCaches() {
RandomAccessFile.enableDefaultGlobalFileCache();
NetcdfDatasets.initNetcdfFileCache(1, 10, 15, 200);
}

@AfterClass
public static void shutdownCaches() {
NetcdfDatasets.shutdown();
RandomAccessFile.setGlobalFileCache(null);
}

@After
public void cleanupAfterEach() {
NetcdfDatasets.getNetcdfFileCache().clearCache(true);
RandomAccessFile.getGlobalFileCache().clearCache(true);
}

@Test
public void shouldReleaseCacheResources() throws Exception {
final String filename = "src/test/data/ucar/nc2/ft/coverage/coverageWithLambertConformalConic_m.nc";

try (FeatureDatasetCoverage featureDatasetCoverage = CoverageDatasetFactory.open(filename)) {
assertThat(featureDatasetCoverage).isNotNull();
}
assertThatCacheFileIsNotLocked();
}

@Test
public void shouldReleaseCacheResourcesWhenGridsAreEmpty() throws Exception {
final String filename = "../cdm/core/src/test/data/pointPre1.6/pointUnlimited.nc";

try (FeatureDatasetCoverage featureDatasetCoverage = CoverageDatasetFactory.open(filename)) {
assertThat(featureDatasetCoverage).isNull();
}
assertThatCacheFileIsNotLocked();
}

private static void assertThatCacheFileIsNotLocked() {
assertThat(RandomAccessFile.getGlobalFileCache().showCache().size()).isEqualTo(1);
assertThat(RandomAccessFile.getGlobalFileCache().showCache().get(0)).startsWith("false");

assertThat(NetcdfDatasets.getNetcdfFileCache().showCache().size()).isEqualTo(1);
assertThat(NetcdfDatasets.getNetcdfFileCache().showCache().get(0)).startsWith("false");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static Optional<FeatureDatasetCoverage> openCoverageDataset(String endpoi
return Optional.empty(errlog.toString());
}

gds.close();
return Optional.empty("Could not open as a coverage dataset");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ protected void augmentGroup(Group.Builder gb, CancelTask cancelTask) throws IOEx
}

// look for time variables and check to see if they have a calendar attribute. if not, add the default
checkTimeVarForCalendar((VariableDS.Builder) vb);
if (vb instanceof VariableDS.Builder) {
checkTimeVarForCalendar((VariableDS.Builder<?>) vb);
}
}

// look for horiz transforms. only ones that are referenced by another variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public CoordSystemBuilder open(NetcdfDataset.Builder datasetBuilder) {
* time in such cases.
*/

CoardsConventions(NetcdfDataset.Builder datasetBuilder) {
CoardsConventions(NetcdfDataset.Builder<?> datasetBuilder) {
super(datasetBuilder);
this.conventionName = CONVENTION_NAME;
}

boolean checkTimeVarForCalendar(VariableDS.Builder vb) {
boolean checkTimeVarForCalendar(VariableDS.Builder<?> vb) {
boolean hasChanged = false;
String unit = vb.getUnits();
if (unit != null) {
Expand All @@ -72,9 +72,9 @@ boolean checkTimeVarForCalendar(VariableDS.Builder vb) {

@Override
protected void augmentDataset(CancelTask cancelTask) throws IOException {
for (Variable.Builder vb : rootGroup.vbuilders) {
for (Variable.Builder<?> vb : rootGroup.vbuilders) {
if (vb instanceof VariableDS.Builder) {
checkTimeVarForCalendar((VariableDS.Builder) vb);
checkTimeVarForCalendar((VariableDS.Builder<?>) vb);
}
}
}
Expand Down
Loading

0 comments on commit 4d6b715

Please sign in to comment.