Search in sources :

Example 1 with JDBCConfigurationSource

use of com.netflix.config.sources.JDBCConfigurationSource in project archaius by Netflix.

the class JDBCConfigurationSourceTest method testSimpleInMemoryJDBCDynamicPropertySource.

@Test
public void testSimpleInMemoryJDBCDynamicPropertySource() throws Throwable {
    final String dbName = "MySiteConfiguration";
    DataSource ds = createDataConfigSource(dbName);
    try {
        JDBCConfigurationSource source = new JDBCConfigurationSource(ds, "select distinct property_key, property_value from MySiteProperties", "property_key", "property_value");
        FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, false);
        DynamicConfiguration configuration = new DynamicConfiguration(source, scheduler);
        DynamicPropertyFactory.initWithConfigurationSource(configuration);
        DynamicStringProperty defaultProp = DynamicPropertyFactory.getInstance().getStringProperty("this.prop.does.not.exist.use.default", "default");
        assertEquals("default", defaultProp.get());
        DynamicStringProperty prop1 = DynamicPropertyFactory.getInstance().getStringProperty("prop1", "default");
        assertEquals("value1", prop1.get());
    } finally {
        //Clean up the data files generated by the embedded DB.
        FileUtils.deleteDirectory(new File(".", dbName));
    }
}
Also used : DynamicConfiguration(com.netflix.config.DynamicConfiguration) DynamicStringProperty(com.netflix.config.DynamicStringProperty) FixedDelayPollingScheduler(com.netflix.config.FixedDelayPollingScheduler) File(java.io.File) JDBCConfigurationSource(com.netflix.config.sources.JDBCConfigurationSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

DynamicConfiguration (com.netflix.config.DynamicConfiguration)1 DynamicStringProperty (com.netflix.config.DynamicStringProperty)1 FixedDelayPollingScheduler (com.netflix.config.FixedDelayPollingScheduler)1 JDBCConfigurationSource (com.netflix.config.sources.JDBCConfigurationSource)1 File (java.io.File)1 DataSource (javax.sql.DataSource)1 Test (org.junit.Test)1