forked from Unidata/netcdf-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMCollection.java
More file actions
87 lines (72 loc) · 3.14 KB
/
TestMCollection.java
File metadata and controls
87 lines (72 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 1998-2026 University Corporation for Atmospheric Research/Unidata
* See LICENSE for license information.
*/
package thredds.inventory;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import thredds.featurecollection.FeatureCollectionConfig;
import thredds.featurecollection.FeatureCollectionType;
import thredds.inventory.filter.RegExpMatch;
import thredds.inventory.partition.DirectoryCollection;
import thredds.inventory.partition.TimePartition;
import ucar.unidata.util.test.category.NeedsCdmUnitTest;
import ucar.unidata.util.test.TestDir;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Formatter;
@Category(NeedsCdmUnitTest.class)
public class TestMCollection {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Test
public void testStreamFilterInDirPartition() throws IOException {
// this dataset 0-6 hour forecasts x 124 runtimes (4x31)
// there are 2 groups, likely miscoded, the smaller group are 0 hour, duplicates, possibly miscoded
FeatureCollectionConfig config =
new FeatureCollectionConfig("cfrsAnalysis_46", "test/testCfrsAnalysisOnly", FeatureCollectionType.GRIB2,
TestDir.cdmUnitTestDir + "gribCollections/cfsr/.*grb2", null, null, null, "directory", null);
Formatter errlog = new Formatter();
CollectionSpecParser specp = new CollectionSpecParser(config.spec, errlog);
Path rootPath = Paths.get(specp.getRootDir());
try (DirectoryCollection dcm =
new DirectoryCollection(config.collectionName, rootPath.toString(), true, config.olderThan, logger)) {
dcm.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, config);
if (specp.getFilter() != null)
dcm.setStreamFilter(new RegExpMatch(specp.getFilter(), specp.getFilterOnName()));
int count = 0;
for (MFile mfile : dcm.getFilesSorted()) {
System.out.printf("%s%n", mfile);
assert mfile.getName().equals("pwat.gdas.199612.grb2");
count++;
}
assert count == 1;
}
}
@Test
public void testTimePartition() throws IOException {
FeatureCollectionConfig config = new FeatureCollectionConfig("ds627.1", "test/ds627.1", FeatureCollectionType.GRIB1,
TestDir.cdmUnitTestDir + "gribCollections/rdavm/ds627.1/.*gbx9", null,
"#ei.mdfa.fc12hr.sfc.regn128sc.#yyyyMMddhh", null, "year", null);
Formatter errlog = new Formatter();
CollectionSpecParser specp = new CollectionSpecParser(config.spec, errlog);
try (TimePartition tp = new TimePartition(config, specp, logger)) {
tp.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, config);
int countP = 0;
for (MCollection mc : tp.makePartitions(CollectionUpdateType.always)) {
System.out.printf("%s%n", mc);
countP++;
int count = 0;
for (MFile mfile : mc.getFilesSorted()) {
System.out.printf(" %s%n", mfile);
count++;
}
assert count == 12 : count;
}
assert countP == 34 : countP;
}
}
}