forked from Unidata/tds
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Unidata:main' into metno
- Loading branch information
Showing
36 changed files
with
512 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
tdcommon/src/test/java/thredds/server/catalog/tracker/TestDatasetTrackerChronicle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package thredds.server.catalog.tracker; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.lang.invoke.MethodHandles; | ||
import org.jdom2.Element; | ||
import org.jdom2.output.Format; | ||
import org.jdom2.output.XMLOutputter; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import thredds.client.catalog.Dataset; | ||
|
||
public class TestDatasetTrackerChronicle { | ||
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
@Rule | ||
public final TemporaryFolder tempFolder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void shouldNotTrackDatasetWithoutNcmlAndRestrictions() throws IOException { | ||
try (DatasetTrackerChronicle datasetTracker = | ||
new DatasetTrackerChronicle(tempFolder.getRoot().getAbsolutePath(), 1, 1)) { | ||
assertThat(datasetTracker.getCount()).isEqualTo(0); | ||
|
||
final Dataset dataset = Dataset.makeStandalone("path", "featureType", "dataFormat", "serviceType"); | ||
datasetTracker.trackDataset(1, dataset, null); | ||
assertThat(datasetTracker.getCount()).isEqualTo(0); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldTrackDatasetWithShortNcml() throws IOException { | ||
try (DatasetTrackerChronicle datasetTracker = | ||
new DatasetTrackerChronicle(tempFolder.getRoot().getAbsolutePath(), 1, 1)) { | ||
assertThat(datasetTracker.getCount()).isEqualTo(0); | ||
|
||
datasetTracker.trackDataset(1, mockDataset(100, "path"), null); | ||
assertThat(datasetTracker.getCount()).isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldTrackDatasetWithLongNcml() throws IOException { | ||
try (DatasetTrackerChronicle datasetTracker = | ||
new DatasetTrackerChronicle(tempFolder.getRoot().getAbsolutePath(), 1, 1, "Large")) { | ||
assertThat(datasetTracker.getCount()).isEqualTo(0); | ||
|
||
datasetTracker.trackDataset(1, mockDataset(10_000, "path"), null); | ||
assertThat(datasetTracker.getCount()).isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldTrackMultipleDatasetsWithNcml() throws IOException { | ||
try (DatasetTrackerChronicle datasetTracker = | ||
new DatasetTrackerChronicle(tempFolder.getRoot().getAbsolutePath(), 10, 1, "medium")) { | ||
assertThat(datasetTracker.getCount()).isEqualTo(0); | ||
|
||
datasetTracker.trackDataset(1, mockDataset(100, "path1"), null); | ||
datasetTracker.trackDataset(1, mockDataset(1_000, "path2"), null); | ||
datasetTracker.trackDataset(1, mockDataset(10_000, "path3"), null); | ||
assertThat(datasetTracker.getCount()).isEqualTo(3); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldReturnNcml() throws IOException { | ||
try (DatasetTrackerChronicle datasetTracker = | ||
new DatasetTrackerChronicle(tempFolder.getRoot().getAbsolutePath(), 1, 1)) { | ||
datasetTracker.trackDataset(1, mockDataset(100, "path"), null); | ||
|
||
final XMLOutputter xmlOut = new XMLOutputter(Format.getCompactFormat()); | ||
final String expectedNcml = xmlOut.outputString(createNcml(100)); | ||
final String ncml = datasetTracker.findNcml("path"); | ||
assertThat(ncml).isEqualTo(expectedNcml); | ||
assertThat(ncml.length()).isEqualTo(139); | ||
} | ||
} | ||
|
||
private static Dataset mockDataset(int ncmlLength, String path) { | ||
final Dataset dataset = mock(Dataset.class); | ||
when(dataset.getNcmlElement()).thenReturn(createNcml(ncmlLength)); | ||
when(dataset.getUrlPath()).thenReturn(path); | ||
return dataset; | ||
} | ||
|
||
private static Element createNcml(int ncmlLength) { | ||
final Element element = new Element("name", "namespace"); | ||
element.setAttribute("attribute", "a".repeat(ncmlLength)); | ||
return element; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- Encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default. --> | ||
<encoder> | ||
<!-- See https://logback.qos.ch/manual/layouts.html#ClassicPatternLayout --> | ||
<pattern>%highlight([%d{HH:mm:ss.SSS} %-5level %logger{36}]) %message%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<!-- Log all messages at level WARN or higher to STDOUT. --> | ||
<root level="WARN"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tds/src/integrationTests/java/opendap/test/TestNcmlWithOpendap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package opendap.test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static ucar.ma2.MAMath.nearlyEquals; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.text.DecimalFormat; | ||
import java.util.Arrays; | ||
import javax.servlet.http.HttpServletResponse; | ||
import org.junit.Test; | ||
import thredds.test.util.TestOnLocalServer; | ||
import ucar.ma2.Array; | ||
import ucar.nc2.NetcdfFile; | ||
import ucar.nc2.Variable; | ||
import ucar.nc2.dataset.NetcdfDatasets; | ||
import ucar.unidata.util.test.TestDir; | ||
|
||
public class TestNcmlWithOpendap { | ||
private static final double[] expectedValues = new double[] {Double.NaN, 1, 2, 3}; | ||
|
||
@Test | ||
public void shouldUseNcmlToModifyDatasetScanValues() throws IOException { | ||
final String path = "/thredds/dodsC/EnhancedDatasetScan/testgrid1.nc"; | ||
final String url = "dods://" + TestDir.remoteTestServer + path; | ||
try (NetcdfFile ncFile = NetcdfDatasets.openDataset(url)) { | ||
final Variable var = ncFile.findVariable("enhancedVar"); | ||
assertThat((Object) var).isNotNull(); | ||
final Array values = var.read(); | ||
assertThat(nearlyEquals(values, Array.makeFromJavaArray(expectedValues))).isTrue(); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldUseNcmlToModifyDatasetScanAsciiValues() { | ||
final String path = "/dodsC/EnhancedDatasetScan/testgrid1.nc.ascii?enhancedVar%5B0:1:1%5D%5B0:1:1%5D"; | ||
final String endpoint = TestOnLocalServer.withHttpPath(path); | ||
|
||
final byte[] content = TestOnLocalServer.getContent(endpoint, HttpServletResponse.SC_OK); | ||
final String stringContent = new String(content, StandardCharsets.UTF_8); | ||
final DecimalFormat df = new DecimalFormat("#.#"); | ||
Arrays.stream(expectedValues).forEach(d -> assertThat(stringContent).contains(df.format(d))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.