use of org.geotoolkit.processing.ProcessListenerAdapter in project geotoolkit by Geomatys.
the class PredictorTest method sampleDrift.
@Test
public void sampleDrift() throws Exception {
final Parameters input = Parameters.castOrWrap(DESCRIPTOR.getInputDescriptor().createValue());
input.getOrCreate(PredictorDescriptor.MAX_POINTS).setValue(200);
addWeight(input, 0.5f, 0.5f, 0.5f);
addWeight(input, 0.2f, 0.8f, 0.8f);
input.getOrCreate(PredictorDescriptor.TARGET_RESOLUTION).setValue(1);
input.getOrCreate(PredictorDescriptor.TARGET_WIDTH).setValue(256);
input.getOrCreate(PredictorDescriptor.TARGET_HEIGHT).setValue(256);
input.getOrCreate(PredictorDescriptor.TIMESTEP).setValue(1);
input.getOrCreate(PredictorDescriptor.START_TIMESTAMP).setValue(0);
final long expectedEndTime = 7000;
input.getOrCreate(PredictorDescriptor.END_TIMESTAMP).setValue(expectedEndTime);
input.getOrCreate(PredictorDescriptor.START_POINT).setValue(new DirectPosition2D(CommonCRS.defaultGeographic(), 0.1, 0.2));
input.getOrCreate(PredictorDescriptor.WIND_RESOURCE).setValue(new MemoryGridResource(null, MOCK_UV_DATA));
input.getOrCreate(PredictorDescriptor.CURRENT_RESOURCE).setValue(new MemoryGridResource(null, MOCK_UV_DATA));
final Predictor predictor = new Predictor(DESCRIPTOR, input);
predictor.addListener(new ProcessListenerAdapter() {
@Override
public void progressing(ProcessEvent event) {
final Exception error = event.getException();
if (error != null) {
Utilities.LOGGER.log(Level.WARNING, event.getTask().toString(), error);
} else {
Utilities.LOGGER.log(Level.INFO, event.getTask().toString());
}
}
});
Utilities.LOGGER.info("Starting drift processing");
final Parameters output = CompletableFuture.supplyAsync(() -> {
try {
return predictor.call();
} catch (ProcessException ex) {
throw new RuntimeException(ex);
}
}).thenApply(Parameters::castOrWrap).get(30, TimeUnit.SECONDS);
final long outTime = output.getMandatoryValue(PredictorDescriptor.ACTUAL_END_TIMESTAMP);
final Path netcdf = output.getMandatoryValue(PredictorDescriptor.OUTPUT_DATA);
try {
assertEquals("Expected time of ending", expectedEndTime, outTime);
assertNotNull("Output file path", netcdf);
assertTrue("Output file is not readable", Files.isRegularFile(netcdf));
checkContent(netcdf);
} finally {
Files.delete(netcdf);
}
}
Aggregations