Skip to content

Commit b9a44b7

Browse files
committed
added integration test, prevent crash when closing the reader twice
1 parent 13306c1 commit b9a44b7

File tree

4 files changed

+138
-7
lines changed

4 files changed

+138
-7
lines changed

core/src/main/java/com/bc/fiduceo/reader/slstr_subset/SlstrRegriddedSubsetReader.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ public class SlstrRegriddedSubsetReader implements Reader {
6060
private TimeLocator_MicrosSince2000 timeLocator;
6161
private long[] timeStamps2000;
6262
private TransformFactory transformFactory;
63-
private final NcCache ncCache;
63+
private NcCache ncCache;
6464
private RasterInfo rasterInfo;
6565
private Manifest manifest;
6666

6767
public SlstrRegriddedSubsetReader(ReaderContext readerContext) {
6868
this.readerContext = readerContext;
69-
ncCache = new NcCache();
7069
}
7170

7271
@Override
@@ -80,7 +79,7 @@ public void open(File file) throws IOException {
8079
}
8180
store = new FileSystemStore(file.toPath());
8281
}
83-
82+
ncCache = new NcCache();
8483

8584
try {
8685
final TreeSet<String> keyManifest = store.getKeysEndingWith("xfdumanifest.xml");
@@ -108,7 +107,10 @@ public void open(File file) throws IOException {
108107

109108
@Override
110109
public void close() throws IOException {
111-
ncCache.close();
110+
if (ncCache != null) {
111+
ncCache.close();
112+
ncCache = null;
113+
}
112114
transformFactory = null;
113115
rasterInfo = null;
114116
}

ingestion-tool/src/test/java/com/bc/fiduceo/ingest/IngestionToolIntegrationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.apache.commons.cli.PosixParser;
3838
import org.junit.After;
3939
import org.junit.Before;
40-
import org.junit.Ignore;
4140
import org.junit.Test;
4241
import org.junit.runner.RunWith;
4342

@@ -1044,9 +1043,9 @@ public void testIngest_SLSTR_SUBSET_S3A() throws SQLException, ParseException {
10441043

10451044
final Geometry geoBounds = observation.getGeoBounds();
10461045
assertEquals("POLYGON((-3.605947 -25.831709,-4.345505 -23.678649999999998,-5.052073 -21.520253000000004,-5.7285819999999985 -19.357061000000005,-6.377657 -17.189569,-6.876289 -15.461471999999999,-9.131362 -16.047251000000003,-11.394941 -16.60798799999999,-13.671509000000002 -17.155166,-15.968603 -17.663905,-18.269608000000005 -18.157285999999992,-20.575312 -18.609944000000002,-20.109500000000008 -20.816586999999995,-19.641969 -23.022255,-19.171696999999998 -25.226836000000002,-18.697578999999998 -27.430221,-18.316648999999998 -29.183193000000003,-15.807929999999999 -28.733388,-13.315321999999998 -28.24385499999999,-10.84056 -27.702752999999998,-8.400936999999999 -27.118316000000007,-5.984294 -26.500103000000006,-3.605947 -25.831709))",
1047-
geometryFactory.format(geoBounds));
1046+
geometryFactory.format(geoBounds));
10481047
assertEquals("LINESTRING(-10.851859 -27.702489000000003,-11.47645 -25.508398000000003,-12.080582999999999 -23.311636999999997,-12.666854999999996 -21.112256999999993,-13.226334000000001 -18.910415999999998,-13.671509000000002 -17.155166)",
1049-
geometryFactory.format(observation.getTimeAxes()[0].getGeometry()));
1048+
geometryFactory.format(observation.getTimeAxes()[0].getGeometry()));
10501049
} finally {
10511050
storage.clear();
10521051
storage.close();

matchup-tool/src/test/java/com/bc/fiduceo/matchup/AbstractUsecaseIntegrationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626
import com.bc.fiduceo.core.UseCaseConfig;
2727
import com.bc.fiduceo.db.Storage;
2828
import com.bc.fiduceo.geometry.GeometryFactory;
29+
import com.bc.fiduceo.geometry.GeometryUtil;
2930
import com.bc.fiduceo.matchup.writer.MmdWriterFactory;
3031
import com.bc.fiduceo.reader.AcquisitionInfo;
3132
import com.bc.fiduceo.reader.Reader;
3233
import com.bc.fiduceo.reader.ReaderFactory;
3334
import com.bc.fiduceo.util.TempFileUtils;
3435
import com.bc.fiduceo.util.TimeUtils;
36+
import com.bc.geometry.s2.S2WKTWriter;
37+
import com.vividsolutions.jts.io.WKTReader;
38+
import com.vividsolutions.jts.io.WKTWriter;
39+
import org.esa.snap.core.util.GeoUtils;
3540
import org.junit.After;
3641
import org.junit.Before;
3742

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright (C) 2016 Brockmann Consult GmbH
3+
* This code was developed for the EC project "Fidelity and Uncertainty in
4+
* Climate Data Records from Earth Observations (FIDUCEO)".
5+
* Grant Agreement: 638822
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License as published by the Free
9+
* Software Foundation; either version 3 of the License, or (at your option)
10+
* any later version.
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* more details.
15+
*
16+
* A copy of the GNU General Public License should have been supplied along
17+
* with this program; if not, see http://www.gnu.org/licenses/
18+
*
19+
*/
20+
21+
package com.bc.fiduceo.matchup;
22+
23+
import com.bc.fiduceo.FiduceoConstants;
24+
import com.bc.fiduceo.NCTestUtils;
25+
import com.bc.fiduceo.TestUtil;
26+
import com.bc.fiduceo.core.SatelliteObservation;
27+
import com.bc.fiduceo.core.Sensor;
28+
import com.bc.fiduceo.core.UseCaseConfig;
29+
import com.bc.fiduceo.db.DbAndIOTestRunner;
30+
import com.bc.fiduceo.util.NetCDFUtils;
31+
import org.apache.commons.cli.ParseException;
32+
import org.junit.Test;
33+
import org.junit.runner.RunWith;
34+
import ucar.ma2.InvalidRangeException;
35+
import ucar.nc2.NetcdfFile;
36+
37+
import java.io.File;
38+
import java.io.IOException;
39+
import java.sql.SQLException;
40+
import java.util.ArrayList;
41+
import java.util.List;
42+
43+
import static org.junit.Assert.assertEquals;
44+
import static org.junit.Assert.assertTrue;
45+
46+
@RunWith(DbAndIOTestRunner.class)
47+
public class MatchupToolIntegrationTest_AVHRR_SLSTR extends AbstractUsecaseIntegrationTest {
48+
49+
@Test
50+
public void testMatchup_AVHRR_SLSTR_UOR() throws IOException, ParseException, SQLException, InvalidRangeException {
51+
final UseCaseConfig useCaseConfig = createUseCaseConfigBuilder()
52+
.withTimeDeltaSeconds(60000, null)
53+
.withMaxPixelDistanceKm(0.1f, null)
54+
.createConfig();
55+
final File useCaseConfigFile = storeUseCaseConfig(useCaseConfig, "usecase-avhrr-slstr.xml");
56+
57+
insert_AVHRR_FRAC_MA();
58+
insert_SLSTR_UOR();
59+
60+
final String[] args = new String[]{"-c", configDir.getAbsolutePath(), "-u", useCaseConfigFile.getName(), "-start", "2020-142", "-end", "2020-143"};
61+
MatchupToolMain.main(args);
62+
63+
final File mmdFile = getMmdFilePath(useCaseConfig, "2020-142", "2020-143");
64+
assertTrue(mmdFile.isFile());
65+
66+
try (NetcdfFile mmd = NetcdfFile.open(mmdFile.getAbsolutePath())) {
67+
final int matchupCount = NetCDFUtils.getDimensionLength(FiduceoConstants.MATCHUP_COUNT, mmd);
68+
assertEquals(1380, matchupCount);
69+
70+
NCTestUtils.assert3DVariable("slstr-s3a-uor_S1_radiance_in", 0, 0, 0, -32768, mmd);
71+
NCTestUtils.assert3DVariable("slstr-s3a-uor_S7_BT_in", 1, 0, 24, 854, mmd);
72+
NCTestUtils.assert3DVariable("slstr-s3a-uor_acquisition_time", 2, 0, 25, 1590189249, mmd);
73+
NCTestUtils.assert3DVariable("slstr-s3a-uor_S8_exception_in", 0, 1, 30, 2, mmd);
74+
NCTestUtils.assert3DVariable("slstr-s3a-uor_cloud_io", 1, 1, 31, 32769, mmd);
75+
NCTestUtils.assert3DVariable("slstr-s3a-uor_detector_io", 2, 1, 32, 255, mmd);
76+
NCTestUtils.assert3DVariable("slstr-s3a-uor_latitude_in", 0, 2, 33, -19847056, mmd);
77+
NCTestUtils.assert3DVariable("slstr-s3a-uor_longitude_in", 1, 2, 34, -5812828, mmd);
78+
NCTestUtils.assert3DVariable("slstr-s3a-uor_solar_azimuth_tn", 2, 2, 35, 275.6034547080558, mmd);
79+
NCTestUtils.assert3DVariable("slstr-s3a-uor_solar_azimuth_to", 0, 0, 36, Float.NaN, mmd);
80+
81+
NCTestUtils.assert3DVariable("avhrr-frac-mc_acquisition_time", 0, 0, 1, 1590137472, mmd);
82+
NCTestUtils.assert3DVariable("avhrr-frac-mc_cloudFlag", 1, 0, 2, 0, mmd);
83+
NCTestUtils.assert3DVariable("avhrr-frac-mc_delta_azimuth", 2, 0, 3, 52.04375076293945, mmd);
84+
NCTestUtils.assert3DVariable("avhrr-frac-mc_flags", 0, 1, 4, -1, mmd);
85+
NCTestUtils.assert3DVariable("avhrr-frac-mc_latitude", 1, 1, 5, -19.104799270629883, mmd);
86+
NCTestUtils.assert3DVariable("avhrr-frac-mc_longitude", 2, 1, 6, -5.870356559753418, mmd);
87+
NCTestUtils.assert3DVariable("avhrr-frac-mc_radiance_1", 0, 2, 7, 87.23554992675781, mmd);
88+
NCTestUtils.assert3DVariable("avhrr-frac-mc_radiance_2", 1, 2, 8, 64.54716491699219, mmd);
89+
NCTestUtils.assert3DVariable("avhrr-frac-mc_radiance_3a", 2, 2, 9, 11.970253944396973, mmd);
90+
}
91+
}
92+
93+
private void insert_SLSTR_UOR() throws IOException, SQLException {
94+
final String sensorKey = "slstr-s3a-uor";
95+
final String relativeArchivePath = TestUtil.assembleFileSystemPath(new String[]{sensorKey, "1.0", "2020", "05", "22", "S3A_SL_1_RBT____20200522T231202_20200522T231502_20200524T053503_0179_058_286_5580_LN2_O_NT_004.SEN3"}, true);
96+
97+
final SatelliteObservation satelliteObservation = readSatelliteObservation(sensorKey, relativeArchivePath, "1.0");
98+
storage.insert(satelliteObservation);
99+
}
100+
101+
private void insert_AVHRR_FRAC_MA() throws IOException, SQLException {
102+
final String sensorKey = "avhrr-frac-mc";
103+
final String relativeArchivePath = TestUtil.assembleFileSystemPath(new String[]{sensorKey, "v1", "2020", "05", "22", "NSS.FRAC.M3.D20143.S0824.E1005.B0798990.SV"}, true);
104+
105+
final SatelliteObservation satelliteObservation = readSatelliteObservation(sensorKey, relativeArchivePath, "v1");
106+
storage.insert(satelliteObservation);
107+
}
108+
109+
private MatchupToolTestUseCaseConfigBuilder createUseCaseConfigBuilder() {
110+
final List<Sensor> sensorList = new ArrayList<>();
111+
final Sensor primary = new Sensor("avhrr-frac-mc");
112+
primary.setPrimary(true);
113+
sensorList.add(primary);
114+
sensorList.add(new Sensor("slstr-s3a-uor"));
115+
116+
final List<com.bc.fiduceo.core.Dimension> dimensions = new ArrayList<>();
117+
dimensions.add(new com.bc.fiduceo.core.Dimension("avhrr-frac-mc", 3, 3));
118+
dimensions.add(new com.bc.fiduceo.core.Dimension("slstr-s3a-uor", 3, 3));
119+
120+
return (MatchupToolTestUseCaseConfigBuilder) new MatchupToolTestUseCaseConfigBuilder("coo30")
121+
.withSensors(sensorList)
122+
.withOutputPath(new File(TestUtil.getTestDir().getPath(), "coo30-avhrr-slstr").getPath())
123+
.withDimensions(dimensions);
124+
}
125+
}

0 commit comments

Comments
 (0)