@BeforeClass public static void setUpClass() throws Exception { faker = new Faker(); String ip = esContainer.getContainerIpAddress(); Integer transportPort = esContainer.getMappedPort(9300); MapConfiguration memoryParams = new MapConfiguration(new HashMap<>()); memoryParams.setProperty(CONFIG_ES_CLUSTER_HOST, ip); memoryParams.setProperty(CONFIG_ES_CLUSTER_PORT, transportPort); memoryParams.setProperty(CONFIG_ES_CLUSTER_NAME, "elasticsearch"); injector = Guice.createInjector( Modules.override(new ElasticSearchModule()) .with(binder -> { binder.bind(Configuration.class).toProvider(() -> memoryParams); }) ); productDao = injector.getInstance(ProductDao.class); esClient = injector.getInstance(TransportClient.class); }
/** * Save property for standalone profile. * * @param pair the pair */ public void savePropertyForStandaloneProfile(final Pair<String, String> pair) { try { final File file = getStandaloneProfileConfigurationDirectory(); final Parameters params = new Parameters(); final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties().setFile(new File(file, getApplicationName() + ".properties"))); final Configuration config = builder.getConfiguration(); config.setProperty(pair.getKey(), pair.getValue()); builder.save(); } catch (final Exception e) { throw Throwables.propagate(e); } }
@Override protected void configure() { bind(Configuration.class).toProvider(ConfigurationProvider.class).in(Singleton.class); bind(TransportClient.class).toProvider(TransportClientProvider.class).in(Singleton.class); bind(JsonFormat.Printer.class).toInstance(JsonFormat.printer()); bind(JsonFormat.Parser.class).toInstance(JsonFormat.parser()); }
@Before public void setUp() throws Exception { String ip = esContainer.getContainerIpAddress(); Integer transportPort = esContainer.getMappedPort(9300); MapConfiguration memoryParams = new MapConfiguration(new HashMap<>()); memoryParams.setProperty(CONFIG_ES_CLUSTER_HOST, ip); memoryParams.setProperty(CONFIG_ES_CLUSTER_PORT, transportPort); memoryParams.setProperty(CONFIG_ES_CLUSTER_NAME, "elasticsearch"); Injector injector = Guice.createInjector( Modules.override(new ElasticSearchModule()).with( binder -> { binder.bind(Configuration.class).toInstance(memoryParams); } ) ); transportClientProvider = injector.getInstance(TransportClientProvider.class); }
/** * Get DebeziumSource configuration. * * @param debeziumConf An empty {@code SourceConfig} * @throws BiremeException miss some required configuration */ protected void fetchDebeziumConfig(SourceConfig debeziumConf) throws BiremeException { Configuration subConfig = new SubsetConfiguration(config, debeziumConf.name, "."); String prefix = subConfig.getString("namespace"); if (prefix == null) { String messages = "Please designate your namespace."; logger.fatal(messages); throw new BiremeException(messages); } debeziumConf.type = SourceType.DEBEZIUM; debeziumConf.server = subConfig.getString("kafka.server"); debeziumConf.topic = prefix; debeziumConf.groupID = subConfig.getString("kafka.groupid", "bireme"); if (debeziumConf.server == null) { String message = "Please designate server for " + debeziumConf.name + "."; logger.fatal(message); throw new BiremeException(message); } }
@Test public void testGet() throws Exception { String site = "bitflyer4j-site.properties"; // Classpath exists Configuration conf = ConfigurationType.get(site, null).get(); assertEquals(conf.getString(VERSION.getKey()), "test"); // Classpath does not exist. (And should not load from file path.) assertFalse(ConfigurationType.get("build.gradle", null).isPresent()); // File exists. conf = ConfigurationType.get(site, "src/test/resources").get(); assertEquals(conf.getString(VERSION.getKey()), "test"); // File does not exist. (And should not load from classpath.) assertFalse(ConfigurationType.get(site, "build").isPresent()); }
@Test public void test() throws ConfigurationException { // Null input. (= Default value.) assertEquals(VERSION.fetch(null), VERSION.getDefaultValue()); // Not found. (= Default value.) Configuration conf = new MapConfiguration(new HashMap<>()); assertEquals(VERSION.fetch(conf), VERSION.getDefaultValue()); // Retrieved from properties. (Empty) conf.setProperty(VERSION.getKey(), ""); assertNull(VERSION.fetch(conf)); // Retrieved from properties. (Configured) conf.setProperty(VERSION.getKey(), "test"); assertEquals(VERSION.fetch(conf), "test"); }
@Override protected void configure() { bind(ConfigurationProvider.class).to(ConfigurationProviderImpl.class).asEagerSingleton(); bind(Configuration.class).toProvider(ConfigurationProvider.class).asEagerSingleton(); bind(ImmutableConfiguration.class).to(Configuration.class).asEagerSingleton(); bind(PropertyController.class).to(PropertyManagerImpl.class).asEagerSingleton(); bind(PropertyManager.class).to(PropertyController.class).asEagerSingleton(); bind(ServiceFactory.class).to(ServiceFactoryImpl.class).asEagerSingleton(); bind(ExecutorFactory.class).to(ExecutorFactoryImpl.class).asEagerSingleton(); bind(Context.class).to(ContextImpl.class).asEagerSingleton(); bind(Estimator.class).to(EstimatorImpl.class).asEagerSingleton(); bind(Adviser.class).to(AdviserImpl.class).asEagerSingleton(); bind(Instructor.class).to(InstructorImpl.class).asEagerSingleton(); bind(Agent.class).to(AgentImpl.class).asEagerSingleton(); bind(Pipeline.class).to(PipelineImpl.class).asEagerSingleton(); bind(Trader.class).to(traderClass).asEagerSingleton(); bind(Cryptotrader.class).to(CryptotraderImpl.class); }
@BeforeMethod public void setUp() throws Exception { module = new TestModule(); accountService = module.getMock(AccountService.class); marketService = module.getMock(MarketService.class); orderService = module.getMock(OrderService.class); realtimeService = module.getMock(RealtimeService.class); when(module.getMock(Bitflyer4j.class).getAccountService()).thenReturn(accountService); when(module.getMock(Bitflyer4j.class).getMarketService()).thenReturn(marketService); when(module.getMock(Bitflyer4j.class).getOrderService()).thenReturn(orderService); when(module.getMock(Bitflyer4j.class).getRealtimeService()).thenReturn(realtimeService); target = new BitflyerContext(module.getMock(Bitflyer4j.class)); target.setConfiguration(module.getMock(Configuration.class)); target = spy(target); }
@Test public void testGet() throws Exception { // Proxy (Invoke to initialize delegate) Configuration c = target.get(); String version = c.getString(KEY); // Same proxy, same delegate. assertSame(target.get(), c); assertEquals(c.getString(KEY), version); // Same proxy, new delegate. target.clear(); assertSame(target.get(), c); assertEquals(c.getString(KEY), version); }
private static String getName(Configuration _config) { String result = ""; if (_config == null) return result; if (_config.getBoolean("wrapper.service", false)) result += "Service "; String name = _config.getString("wrapper.console.title"); if (name == null) name = _config.getString("wrapper.ntservice.name"); if (name == null) name = _config.getString("wrapper.image"); if (name == null) name = _config.getString("wrapper.groovy"); if (name == null) name = _config.getString("wrapper.java.app.mainclass"); if (name == null) name = _config.getString("wrapper.java.app.jar"); if (name == null) name = ""; result += name; return result; }
/** * Do reconnect. */ private static void doReconnect() { prepareProperties(); Configuration localConf = new MapConfiguration(_properties); YajswConfiguration conf = new YajswConfigurationImpl(localConf, true); WrappedProcess w = WrappedProcessFactory.createProcess(conf); System.out.println("************* RECONNECTING WRAPPER TO PID " + pid + " ***********************"); System.out.println(); if (w.reconnect(pid)) System.out.println("Connected to PID " + pid); else System.out.println("NOT connected to PID " + pid); _exitOnTerminate = false; }
public Configuration getConfiguration() { if (_config == null) { Map utils = new HashMap(); utils.put("util", new Utils(this)); try { VFSUtils.init(); } catch (FileSystemException e) { e.printStackTrace(); } _config = new YajswConfigurationImpl(_localConfiguration, _useSystemProperties, utils); } return _config; }
private YajswConfigurationInterpolator createGInterpolatornew(Configuration conf, boolean b, String[] object, Map utils) { YajswConfigurationInterpolator result = null; try { Class clazz = conf .getClass() .getClassLoader() .loadClass("org.rzo.yajsw.config.groovy.GInterpolator"); Constructor rc = clazz.getDeclaredConstructor(Configuration.class, boolean.class, String[].class, Map.class); result = (YajswConfigurationInterpolator) rc.newInstance(conf, b, object, utils); } catch (Exception e) { // e.printStackTrace(); log.warn("WARNING: could not load configuration groovy interpolator"); } return result; }
@Test public void testOverride() { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties() .setFileName("file.properties")); Configuration config = null; try { config = builder.getConfiguration(); config.setProperty("somekey", "somevalue"); builder.save(); } catch (ConfigurationException e) { e.printStackTrace(); } }
private JndiConfigurationSource(Configuration configuration, int priority) { if (configuration == null) { throw new NullPointerException("configuration: null"); } if (priority < 0) { throw new IllegalArgumentException("priority of a configuration cannot be negative"); } this.configuration = configuration; this.priority = priority; }
@Override public Configuration get() { Configurations configs = new Configurations(); try { return configs.properties(new File(getPropertyFilePath())); } catch (ConfigurationException e) { log.error(" error on build configuration", e); throw new IllegalStateException(e); } }
@Test public void testConfigure() throws Exception { Injector injector = Guice.createInjector(new ElasticSearchModule()); Configuration configuration = injector.getInstance(Configuration.class); assertThat(configuration.getString("key1")).isEqualTo("value1"); }
/** * Get the connection configuration to database. * * @param prefix "target" database * @throws BiremeException when url of database is null */ protected void connectionConfig(String prefix) throws BiremeException { Configuration subConfig = new SubsetConfiguration(config, "target", "."); targetDatabase = new ConnectionConfig(); targetDatabase.jdbcUrl = subConfig.getString("url"); targetDatabase.user = subConfig.getString("user"); targetDatabase.passwd = subConfig.getString("passwd"); if (targetDatabase.jdbcUrl == null) { String message = "Please designate url for target Database."; throw new BiremeException(message); } }
private HashMap<String, String> fetchTableMap(String dataSource) throws ConfigurationException, BiremeException { Configurations configs = new Configurations(); Configuration tableConfig = null; tableConfig = configs.properties(new File(DEFAULT_TABLEMAP_DIR + dataSource + ".properties")); String originTable, mappedTable; HashMap<String, String> localTableMap = new HashMap<String, String>(); Iterator<String> tables = tableConfig.getKeys(); while (tables.hasNext()) { originTable = tables.next(); mappedTable = tableConfig.getString(originTable); if (originTable.split("\\.").length != 2 || mappedTable.split("\\.").length != 2) { String message = "Wrong format: " + originTable + ", " + mappedTable; logger.fatal(message); throw new BiremeException(message); } localTableMap.put(dataSource + "." + originTable, mappedTable); if (!tableMap.values().contains(mappedTable)) { loadersCount++; } tableMap.put(dataSource + "." + originTable, mappedTable); } return localTableMap; }
public DatabricksClientConfiguration(Configuration configuration) { this(); if (configuration instanceof AbstractConfiguration) { AbstractConfiguration aconf = (AbstractConfiguration) configuration; } addConfiguration(configuration); }
public Configuration getClientConfiguration() { Configuration clientConfig = new CompositeConfiguration(); Iterator<String> iter = getKeys(); while (iter.hasNext()) { String key = iter.next(); if (key.startsWith(CLIENT_PREFIX)) { clientConfig.setProperty(key, getProperty(key)); } } return clientConfig; }
@Test public void testCreateConfiguration() throws Exception { Configuration conf = target.createConfiguration(); for (Object name : Collections.list(System.getProperties().propertyNames())) { // All system properties must exist. assertTrue(conf.containsKey(name.toString()), "Missing system : " + name); } Configuration v = new Configurations().properties(getResource(ConfigurationType.VERSION.getPath())); Configuration s = new Configurations().properties(getResource(ConfigurationType.SITE.getPath())); // 1st should be version. assertEquals(VERSION.fetch(conf), v.getString(VERSION.getKey())); assertNotEquals(VERSION.fetch(conf), s.getString(VERSION.getKey())); assertEquals(s.getString(VERSION.getKey()), "test"); // 2nd should be system. (Should not be overridden.) String system = "java.version"; assertEquals(conf.getString(system), System.getProperty(system)); assertNotEquals(conf.getString(system), s.getString(system)); assertEquals(s.getString(system), "test"); // 3rd should be site. assertEquals(SITE.fetch(conf), s.getString(SITE.getKey())); assertEquals(s.getString(SITE.getKey()), "test"); // Last should be default. assertEquals(HTTP_URL.fetch(conf), HTTP_URL.getDefaultValue()); }
private Config() { Configuration configuration; try { Configurations configurations = new Configurations(); configuration = configurations.properties(new File("configuration.properties")); } catch (ConfigurationException ce) { ce.printStackTrace(); configuration = null; } this.properties = configuration; this.initSuccess = configuration != null; }
public static Configuration getConfiguration(){ if (config == null) { try { ConfigurationManager.getInstance(); return config; } catch (ConfigurationException e) { return null; } } else return config; }
@GET @Path("/configuration") @Produces(MediaType.APPLICATION_JSON) public String getConfiguration() { Configuration c = configurationProvider.get(); Collection<String> keys = new TreeSet<>(); CollectionUtils.addAll(keys, c.getKeys()); StringBuilder sb = new StringBuilder(); for (String key : keys) { sb.append(key); sb.append('='); sb.append(c.getString(key)); sb.append(System.lineSeparator()); } String data = sb.toString(); Map<String, Object> map = new TreeMap<>(); map.put("data", data); map.put("size", data.length()); map.put("hash", DigestUtils.md5Hex(data)); return gson.toJson(map); }
@Test public void testCreate() throws Exception { // Plain Configuration c = target.create(VERSION, SITE, DEFAULT); assertNotNull(c.getString(KEY)); assertNotEquals(c.getString(KEY), "default"); assertNotEquals(c.getString(KEY), "test"); // Version = test c = target.create(TEST, SITE, DEFAULT); assertEquals(c.getString(KEY), "test"); // Site = test (found) c = target.create(VERSION, "src/test/resources/" + TEST, DEFAULT); assertNotNull(c.getString(KEY)); assertNotEquals(c.getString(KEY), "default"); assertNotEquals(c.getString(KEY), "test"); // Site = test (not found) c = target.create(VERSION, "/dev/null/" + TEST, DEFAULT); assertNotNull(c.getString(KEY)); assertNotEquals(c.getString(KEY), "default"); assertNotEquals(c.getString(KEY), "test"); // Default = test c = target.create(VERSION, SITE, TEST); assertNotNull(c.getString(KEY)); assertNotEquals(c.getString(KEY), "default"); assertNotEquals(c.getString(KEY), "test"); // Invalid path try { target.create("/tmp/" + TEST, SITE, DEFAULT); fail(); } catch (RuntimeException e) { // Success } }
/** * * @return */ public static StyleList getStyleForMapFromProperties() { StyleList style = null; try { final Configuration config = FILE_BASED_CONFIGURATION_BUILDER.getConfiguration(); final String styleName = config.getString(PropertyList.STYLE.toString()); style = StyleList.valueOf(styleName); } catch (ConfigurationException cex) { LOGGER.error("\n" + cex.getCause()); cex.printStackTrace(); } return style; }
public static String getVideoFolderFromProperties() { String videoFolder = null; try { final Configuration config = FILE_BASED_CONFIGURATION_BUILDER.getConfiguration(); videoFolder = config.getString(PropertyList.VIDEO_FOLDER.toString()); } catch (ConfigurationException cex) { LOGGER.error("\n" + cex.getCause()); cex.printStackTrace(); } return videoFolder; }
public static void setProperty(final PropertyList property, final String value) { try { Configuration config = FILE_BASED_CONFIGURATION_BUILDER.getConfiguration(); config.setProperty(property.toString(), value); FILE_BASED_CONFIGURATION_BUILDER.save(); } catch (ConfigurationException cex) { LOGGER.error("\n" + cex.getCause()); cex.printStackTrace(); } }
public boolean yajswInstall(String configuration) { WrappedService w = new WrappedService(); Configuration c = w.getLocalConfiguration(); c.setProperty("wrapper.config", configuration); w.init(); return w.install(); }
private static void clearKeys(Configuration conf, String key) { if (conf.containsKey(key)) conf.clearProperty(key); Iterator<String> keys = conf.getKeys(key); while (keys.hasNext()) conf.clearProperty(keys.next()); }
public PosixJavaHome(Configuration config) { if (config != null) _config = config; else _config = new BaseConfiguration(); }
public static void main(String[] args) { WrappedRuntimeProcess p = new WrappedRuntimeProcess(); Configuration c = p.getLocalConfiguration(); c.setProperty("wrapper.image", "notepad");// "test.bat");//notepad");//"c:/temp/test.bat");// c.setProperty("wrapper.working.dir", "c:/"); p.init(); p.start(); p.waitFor(10000); System.out.println("stopping"); p.stop(); System.out.println("stopped " + p.getExitCode()); }
public static WrappedProcess createProcess(Map map, boolean useSystemProperties) { Configuration localConf = new MapConfiguration(map); YajswConfiguration conf = new YajswConfigurationImpl(localConf, true); WrappedProcess process = createProcess(conf); process.setLocalConfiguration(localConf); process.setUseSystemProperties(useSystemProperties); process.init(); return process; }
public static Object createService(Map map) { Configuration localConf = new MapConfiguration(map); WrappedService service = new WrappedService(); service.setLocalConfiguration(localConf); service.init(); return service; }
public static Object createServiceList(Map map, List<String> confFiles) { Configuration localConf = new MapConfiguration(map); WrappedService service = new WrappedService(); service.setLocalConfiguration(localConf); service.setConfFilesList(confFiles); service.init(); return service; }
public static Properties asProperties(Configuration config) { Properties result = new Properties(); for (Iterator it = config.getKeys(); it.hasNext();) { String key = (String) it.next(); result.setProperty(key, config.getProperty(key).toString()); } return result; }
/** * Instantiates a new ajsw configuration impl. * * @param localConfiguration * the local configuration * @param useSystemProperties * the use system properties */ public YajswConfigurationImpl(Configuration localConfiguration, boolean useSystemProperties, Map scriptUtils) { _localConfiguration = localConfiguration; _useSystemProperties = useSystemProperties; _scriptUtils = scriptUtils; init(); }
public GInterpolator(Configuration conf, boolean cache, String[] imports, Map utils) { _conf = conf; _binding = new ConfigurationBinding(conf, utils); _shell = new GroovyShell(_binding); setCache(cache); _imports = imports; }