KylinConfig extends KylinConfigBase { public static KylinConfig getInstanceFromEnv() { synchronized (KylinConfig.class) { KylinConfig config = THREAD_ENV_INSTANCE.get(); if (config != null) { return config; } if (SYS_ENV_INSTANCE == null) { try { buildDefaultOrderedProperties(); config = new KylinConfig(); config.reloadKylinConfig(buildSiteProperties()); VersionUtil.loadKylinVersion(); logger.info("Initialized a new KylinConfig from getInstanceFromEnv : " + System.identityHashCode(config)); SYS_ENV_INSTANCE = config; } catch (IllegalArgumentException e) { throw new IllegalStateException("Failed to find KylinConfig ", e); } } return SYS_ENV_INSTANCE; } } private  KylinConfig(); protected  KylinConfig(Properties props, boolean force); static File getKylinHomeAtBestEffort(); static KylinConfig getInstanceFromEnv(); static void destroyInstance(); static KylinConfig createInstanceFromUri(String uri); static Properties streamToProps(InputStream is); static void setKylinConfigInEnvIfMissing(Properties prop); static void setKylinConfigInEnvIfMissing(String propsInStr); static SetAndUnsetThreadLocalConfig setAndUnsetThreadLocalConfig(KylinConfig config); static KylinConfig createKylinConfig(String propsInStr); static KylinConfig createKylinConfig(KylinConfig another); static KylinConfig createKylinConfig(Properties prop); static File getKylinConfDir(); static void setSandboxEnvIfPossible(); T getManager(Class<T> clz); void clearManagers(); Properties exportToProperties(); String exportAllToString(); String exportToString(Collection<String> propertyKeys); void exportToFile(File file); synchronized void reloadFromSiteProperties(); KylinConfig base(); static void setKylinConfigForLocalTest(String localMetaDir); @Override int hashCode(); @Override boolean equals(Object another); static final String KYLIN_CONF_PROPERTIES_FILE; static final String KYLIN_DEFAULT_CONF_PROPERTIES_FILE; static final String KYLIN_CONF; }
@Test public void testMRConfigOverride() { KylinConfig config = KylinConfig.getInstanceFromEnv(); Map<String, String> override = config.getMRConfigOverride(); assertEquals(2, override.size()); assertEquals("test1", override.get("test1")); assertEquals("test2", override.get("test2")); }
@Test public void testBackwardCompatibility() { KylinConfig config = KylinConfig.getInstanceFromEnv(); final String oldk = "kylin.test.bcc.old.key"; final String newk = "kylin.test.bcc.new.key"; assertNull(config.getOptional(oldk)); assertNotNull(config.getOptional(newk)); Map<String, String> override = Maps.newHashMap(); override.put(oldk, "1"); KylinConfigExt ext = KylinConfigExt.createInstance(config, override); assertEquals(ext.getOptional(oldk), null); assertEquals(ext.getOptional(newk), "1"); assertNotEquals(config.getOptional(newk), "1"); config.setProperty(oldk, "2"); assertEquals(config.getOptional(newk), "2"); }
@Test public void testExtShareTheBase() { KylinConfig config = KylinConfig.getInstanceFromEnv(); Map<String, String> override = Maps.newHashMap(); KylinConfig configExt = KylinConfigExt.createInstance(config, override); assertTrue(config.properties == configExt.properties); config.setProperty("1234", "1234"); assertEquals("1234", configExt.getOptional("1234")); }
@Test public void testGetMetadataUrlPrefix() { KylinConfig config = KylinConfig.getInstanceFromEnv(); config.setMetadataUrl("testMetaPrefix@hbase"); assertEquals("testMetaPrefix", config.getMetadataUrlPrefix()); config.setMetadataUrl("testMetaPrefix@hdfs"); assertEquals("testMetaPrefix", config.getMetadataUrlPrefix()); config.setMetadataUrl("/kylin/temp"); assertEquals("/kylin/temp", config.getMetadataUrlPrefix()); }
@Test public void testHdfsWorkingDir() { KylinConfig conf = KylinConfig.getInstanceFromEnv(); String hdfsWorkingDirectory = conf.getHdfsWorkingDirectory(); assertTrue(hdfsWorkingDirectory.startsWith("file:/")); }
@Test public void testUnexpectedBlackInPro() { KylinConfig conf = KylinConfig.getInstanceFromEnv(); Map<String, String> override = conf.getPropertiesByPrefix("kylin.engine.mr.config-override."); assertEquals(2, override.size()); String s = override.get("test2"); assertEquals("test2", s); }
@Test public void testCalciteExtrasProperties() { KylinConfig conf = KylinConfig.getInstanceFromEnv(); Properties extras = conf.getCalciteExtrasProperties(); assertEquals("true", extras.getProperty("caseSensitive")); assertEquals("TO_UPPER", extras.getProperty("unquotedCasing")); assertEquals("DOUBLE_QUOTE", extras.getProperty("quoting")); assertEquals("LENIENT", extras.getProperty("conformance")); conf.setProperty("kylin.query.calcite.extras-props.caseSensitive", "false"); conf.setProperty("kylin.query.calcite.extras-props.unquotedCasing", "UNCHANGED"); conf.setProperty("kylin.query.calcite.extras-props.quoting", "BRACKET"); conf.setProperty("kylin.query.calcite.extras-props.conformance", "DEFAULT"); extras = conf.getCalciteExtrasProperties(); assertEquals("false", extras.getProperty("caseSensitive")); assertEquals("UNCHANGED", extras.getProperty("unquotedCasing")); assertEquals("BRACKET", extras.getProperty("quoting")); assertEquals("DEFAULT", extras.getProperty("conformance")); }