Skip to content

Commit

Permalink
refactor loading yaml files to new version 2.0 (no more need for glob…
Browse files Browse the repository at this point in the history
…al tags in yaml files).
  • Loading branch information
Hans-Peter Keilhofer committed Mar 7, 2023
1 parent 9b3c233 commit 4e87c17
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private JPowerMonitorConfig tryReadingFromFileSystem(String source) {

private JPowerMonitorConfig readConfigFromPath(Path path) {
try (Reader reader = Files.newBufferedReader(path, yamlFileEncoding)) {
return new Yaml().load(reader);
return new Yaml().loadAs(reader, JPowerMonitorConfig.class);
} catch (Exception e) {
System.err.println("Cannot read '" + path + "' from filesystem: " + e.getMessage());
}
Expand All @@ -123,7 +123,7 @@ private JPowerMonitorConfig tryReadingFromResources(String source) {

private JPowerMonitorConfig readConfigFromResource(String source) {
try (InputStream input = DefaultConfigProvider.class.getClassLoader().getResourceAsStream(source)) {
return new Yaml().load(input);
return new Yaml().loadAs(input, JPowerMonitorConfig.class);
} catch (Exception exc) {
System.out.println("Cannot read '" + source + "' from resources:" + exc.getMessage());
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/jpowermonitor-template.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!!group.msg.jpowermonitor.config.JPowerMonitorConfig
# Number of initial calls to open hardware monitor for measuring the power consumption in idle mode (without running any tests)
initCycles: 10
# Sampling interval in milliseconds for the initialization period. This is the interval the data source for the sensor values is questioned for new values while measuring idle energy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public JPowerMonitorConfig getCachedConfig() throws JPowerMonitorException {
public JPowerMonitorConfig readConfig(String source) throws JPowerMonitorException {
ClassLoader cl = ConfigProviderForTests.class.getClassLoader();
try (InputStream input = cl.getResourceAsStream(source)) {
return new Yaml().load(input);
return new Yaml().loadAs(input, JPowerMonitorConfig.class);
} catch (Exception exc) {
throw new JPowerMonitorException(String.format("Cannot load config for tests from '%s'", source), exc);
}
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/CommaSeparatedValuesReaderTest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!!group.msg.jpowermonitor.config.JPowerMonitorConfig
initCycles: 1
samplingIntervalForInitInMs: 1
calmDownIntervalInMs: 1
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/DefaultConfigProviderTest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!!group.msg.jpowermonitor.config.JPowerMonitorConfig
initCycles: 7
samplingIntervalForInitInMs: 8
calmDownIntervalInMs: 9
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/EndlessLoopTest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!!group.msg.jpowermonitor.config.JPowerMonitorConfig
initCycles: 0
samplingIntervalForInitInMs: 1
calmDownIntervalInMs: 1
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/JPowerMonitorConfigTest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!!group.msg.jpowermonitor.config.JPowerMonitorConfig
# Number of initial calls to open hardware monitor for measuring the power consumption in idle mode (without running any tests)
initCycles: 10
# Sampling interval in milliseconds for the initialization period. This is the interval the data source for the sensor values is questioned for new values while measuring idle energy.
Expand Down
1 change: 0 additions & 1 deletion src/test/resources/MyTest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
!!group.msg.jpowermonitor.config.JPowerMonitorConfig
initCycles: 0
samplingIntervalForInitInMs: 1
calmDownIntervalInMs: 1
Expand Down

0 comments on commit 4e87c17

Please sign in to comment.