Search in sources :

Example 1 with Config

use of com.qlangtech.tis.manage.common.Config in project tis by qlangtech.

the class TestSysInitializeAction method testSystemDBInitializWithDerby.

// public void testInitializeAppAndSchema() throws Exception {
// request.setParameter("emethod", "init");
// request.setParameter("action", "sys_initialize_action");
// 
// ActionProxy proxy = getActionProxy("/runtime/index_query.ajax");
// assertNotNull(proxy);
// SysInitializeAction initAction = (SysInitializeAction) proxy.getAction();
// assertNotNull(initAction);
// initAction.initializeAppAndSchema();
// 
// }
/**
 * 测试系统数据库初始化
 */
public void testSystemDBInitializWithDerby() throws Exception {
    File initialSuccessToken = SysInitializeAction.getSysInitializedTokenFile();
    FileUtils.deleteQuietly(initialSuccessToken);
    final String tis_ansible_home = StringUtils.defaultIfEmpty(System.getenv("tis_ansible_home"), "/opt/misc/tis-ansible");
    String[] args = new String[] { tis_ansible_home + "/tis_console_derby.sql", Config.DB_TYPE_DERBY };
    Config config = this.mock("config", Config.class);
    EasyMock.expect(config.getZkHost()).andReturn("192.168.28.200:2181/tis/cloud");
    EasyMock.expect(config.getRuntime()).andReturn(RunEnvironment.DAILY.getKeyName()).anyTimes();
    Config.TisDbConfig mockDBType = new Config.TisDbConfig();
    mockDBType.dbtype = Config.DB_TYPE_DERBY;
    mockDBType.dbname = "tis_console_db";
    File dbDir = new File(Config.getDataDir(), mockDBType.dbname);
    FileUtils.deleteQuietly(dbDir);
    EasyMock.expect(config.getDbConfig()).andReturn(mockDBType).anyTimes();
    Config.setConfig(config);
    replay();
    int[] tryIndex = new int[1];
    AtomicBoolean hasExecDSCreateInspector = new AtomicBoolean();
    TISDataSourceFactory.dsCreateInspector = new TISDataSourceFactory.IDSCreatorInspect() {

        @Override
        public void checkDataSource(boolean getDSFromJNDI, BasicDataSource dataSource) {
            assertFalse(getDSFromJNDI);
            if (tryIndex[0]++ == 0) {
                assertEquals("jdbc:derby:" + mockDBType.dbname + ";create=true", dataSource.getUrl());
            } else {
                assertEquals("jdbc:derby:" + mockDBType.dbname + ";create=false", dataSource.getUrl());
            }
            hasExecDSCreateInspector.set(true);
        }
    };
    SysInitializeAction.main(args);
    assertTrue("hasExecDSCreateInspector must be true", hasExecDSCreateInspector.get());
    // File initialSuccessToken = SysInitializeAction.getSysInitializedTokenFile();
    assertTrue("initialSuccessToken fiel:" + initialSuccessToken.getAbsolutePath(), initialSuccessToken.exists());
    assertEquals("create db 2 times", tryIndex[0], 2);
    assertTrue("dbDir must exist:" + dbDir.getAbsolutePath(), dbDir.exists());
    verifyAll();
}
Also used : TISDataSourceFactory(com.qlangtech.tis.manage.spring.TISDataSourceFactory) Config(com.qlangtech.tis.manage.common.Config) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) File(java.io.File) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 2 with Config

use of com.qlangtech.tis.manage.common.Config in project tis by qlangtech.

the class TisPropertiesFileConfigurationProvider method toMap.

@Override
protected Map<String, String> toMap(Properties properties) {
    PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
    Config config = Config.getInstance();
    PropertyPlaceholderHelper.PlaceholderResolver resolver = new PropertyPlaceholderHelper.PlaceholderResolver() {

        @Override
        public String resolvePlaceholder(String placeholderName) {
            return config.getAllKV().get(placeholderName);
        }
    };
    Map<String, String> result = super.toMap(properties);
    return result.entrySet().stream().collect(Collectors.toMap((e) -> e.getKey(), (e) -> helper.replacePlaceholders(e.getValue(), resolver)));
}
Also used : PropertyPlaceholderHelper(com.qlangtech.tis.manage.common.PropertyPlaceholderHelper) Config(com.qlangtech.tis.manage.common.Config) AbstractConfigurationProvider(org.apache.flume.node.AbstractConfigurationProvider) Properties(java.util.Properties) FlumeConfiguration(org.apache.flume.conf.FlumeConfiguration) Map(java.util.Map) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) InputStream(java.io.InputStream) PropertyPlaceholderHelper(com.qlangtech.tis.manage.common.PropertyPlaceholderHelper) Config(com.qlangtech.tis.manage.common.Config)

Aggregations

Config (com.qlangtech.tis.manage.common.Config)2 PropertyPlaceholderHelper (com.qlangtech.tis.manage.common.PropertyPlaceholderHelper)1 TISDataSourceFactory (com.qlangtech.tis.manage.spring.TISDataSourceFactory)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Properties (java.util.Properties)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 FlumeConfiguration (org.apache.flume.conf.FlumeConfiguration)1 AbstractConfigurationProvider (org.apache.flume.node.AbstractConfigurationProvider)1