Skip to content

Commit

Permalink
make ordinal configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rikcarve committed Dec 18, 2019
1 parent b9b8d0f commit 8edc68c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The eclipse microprofile config framework is a simple yet powerful configuration
<dependency>
<groupId>ch.carve</groupId>
<artifactId>mp-config-db</artifactId>
<version>0.5</version>
<version>0.6</version>
</dependency>
```

Expand All @@ -25,6 +25,9 @@ Currently there are 5 values you can configure, either through Java system prope
* **configsource.db.value-column** name of the column containing the value, default value is "value"
* **configsource.db.validity** how long to cache values (in seconds), default is 30s

## Ordinal
Config sources have priorities called ordinal. This config source has ordinal 450, but can be overriden with setting 'configsource.db.ordinal' in one of the default config sources (NOT in this source like specified in the spec, as the datasource is not yet ready when getOrdinal() is called).

## Hint
Use memory config source from [microprofile-extensions](https://github.com/microprofile-extensions/config-ext/tree/master/configsource-memory) to get a REST interface and the possibility to change values on the fly (in-memory)

Expand Down
13 changes: 3 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ch.carve</groupId>
<artifactId>mp-config-db</artifactId>
<version>0.5</version>
<version>0.6</version>
<packaging>jar</packaging>
<name>mp-config-db</name>
<description>ConfigurationSource for eclipse microprofile config based on a database</description>
Expand All @@ -31,8 +31,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
<junit.platform.version>1.4.2</junit.platform.version>
<junit.jupiter.version>5.5.2</junit.jupiter.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -65,15 +64,9 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class DatasourceConfigSource implements ConfigSource {

private static final String VALIDITY_KEY = "configsource.db.validity";
private static final String CONFIGSOURCE_ORDINAL_KEY = "configsource.db.ordinal";

private Config config;
Repository repository = null;
Expand Down Expand Up @@ -50,7 +51,7 @@ public String getName() {

@Override
public int getOrdinal() {
return 450;
return config.getOptionalValue(CONFIGSOURCE_ORDINAL_KEY, Integer.class).orElse(450);
}

private void initRepository() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/carve/microprofile/config/db/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public synchronized String getConfigValue(String key) throws SQLException {
if (rs.next()) {
return rs.getString(1);
}
} else {
throw new SQLException("datasource not initialized");
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ch.carve.microprofile.config.db;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -42,7 +45,7 @@ void testGetConfigValue_none() throws SQLException {

@Test
void testGetConfigValue_no_stmt() throws SQLException {
assertNull(repository.getConfigValue("test"));
assertThrows(SQLException.class, () -> repository.getConfigValue("test"));
}

@Test
Expand Down

0 comments on commit 8edc68c

Please sign in to comment.