List of usage examples for org.apache.commons.configuration BaseConfiguration BaseConfiguration
BaseConfiguration
From source file:com.netflix.config.PollingSourceTest.java
@Test public void testIncrementalPollingSource() throws Exception { BaseConfiguration config = new BaseConfiguration(); DynamicPropertyFactory.initWithConfigurationSource(config); DynamicStringProperty prop1 = new DynamicStringProperty("prop1", null); DynamicStringProperty prop2 = new DynamicStringProperty("prop2", null); config.addProperty("prop1", "original"); DummyPollingSource source = new DummyPollingSource(true); FixedDelayPollingScheduler scheduler = new FixedDelayPollingScheduler(0, 10, true); scheduler.setIgnoreDeletesFromSource(false); // ConfigurationWithPollingSource pollingConfig = new ConfigurationWithPollingSource(config, source,scheduler); scheduler.startPolling(source, config); assertEquals("original", config.getProperty("prop1")); assertEquals("original", prop1.get()); source.setAdded("prop2=new"); Thread.sleep(200);/*from w ww .j a v a2s .c o m*/ assertEquals("original", config.getProperty("prop1")); assertEquals("new", config.getProperty("prop2")); assertEquals("new", prop2.get()); source.setDeleted("prop1=DoesNotMatter"); source.setChanged("prop2=changed"); source.setAdded(""); Thread.sleep(200); assertFalse(config.containsKey("prop1")); assertNull(prop1.get()); assertEquals("changed", config.getProperty("prop2")); assertEquals("changed", prop2.get()); }
From source file:com.evolveum.midpoint.model.common.expression.ExpressionTestUtil.java
private static Configuration createConfiguration() { BaseConfiguration config = new BaseConfiguration(); config.addProperty("foo", "foobar"); return config; }
From source file:com.comcast.viper.flume2storm.spout.FlumeSpoutConfigurationTest.java
/** * Test invalid argument for// w w w . j av a 2s .co m * {@link FlumeSpoutConfiguration#setServiceProviderSerializationClassName(String)} * * @throws F2SConfigurationException * If value is invalid */ @Test(expected = F2SConfigurationException.class) public void testServiceProviderSerializationClassName3() throws F2SConfigurationException { Configuration config = new BaseConfiguration(); config.addProperty(FlumeSpoutConfiguration.SERVICE_PROVIDER_SERIALIZATION_CLASS, "not-a-class"); FlumeSpoutConfiguration.from(config); }
From source file:co.turnus.analysis.partitioning.CommunicationCostPartitioningCli.java
private static Configuration parseCommandLine(CommandLine cmd) throws ParseException { Configuration config = new BaseConfiguration(); StringBuffer s = new StringBuffer(); config.setProperty(VERBOSE, cmd.hasOption("v")); if (!cmd.hasOption("t")) { s.append("Trace project directory not specified. "); } else {/*from ww w . jav a2 s . c o m*/ String fileName = cmd.getOptionValue("t", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Trace project does not exists. "); } else { config.setProperty(TRACE_PROJECT, fileName); } } if (!cmd.hasOption("o")) { s.append("Output directory not specified. "); } else { String fileName = cmd.getOptionValue("o", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Output directory does not exists. "); } else { config.setProperty(OUTPUT_PATH, fileName); } } if (!cmd.hasOption("p")) { s.append("The number of partitions is not specified. "); } else { String[] sp = cmd.getOptionValues("p"); if (sp.length == 1) { int value = Integer.parseInt(sp[0]); config.addProperty(PARTITION_UNITS_MIN, value); config.addProperty(PARTITION_UNITS_MAX, value); config.addProperty(PARTITION_UNITS_POINTS, 1); } else if (sp.length == 2) { int min = Integer.parseInt(sp[0]); int max = Integer.parseInt(sp[1]); config.addProperty(PARTITION_UNITS_MIN, min); config.addProperty(PARTITION_UNITS_MAX, max); config.addProperty(PARTITION_UNITS_POINTS, max - min + 1); } else { int min = Integer.parseInt(sp[0]); int max = Integer.parseInt(sp[1]); int points = Integer.parseInt(sp[2]); config.addProperty(PARTITION_UNITS_MIN, min); config.addProperty(PARTITION_UNITS_MAX, max); config.addProperty(PARTITION_UNITS_POINTS, points); } } if (cmd.hasOption("xls")) { String fileName = cmd.getOptionValue("xls", ""); if (fileName == null || fileName.isEmpty()) { s.append("XLS file name is not correct. "); } else { config.setProperty(XLS, fileName); } } if (cmd.hasOption("xcf")) { String fileName = cmd.getOptionValue("xcf", ""); if (fileName == null || fileName.isEmpty()) { s.append("XCF file name is not correct. "); } else { config.setProperty(XCF, fileName); } } String error = s.toString(); if (!error.isEmpty()) { throw new ParseException(error); } return config; }
From source file:com.feedzai.fos.impl.r.RIntegrationTest.java
@Test public void trainandAdd() throws Exception { BaseConfiguration configuration = new BaseConfiguration(); Map<String, String> properties = new HashMap<>(); List<Attribute> attributes = getAttributes(); ModelConfig modelConfig = new ModelConfig(attributes, properties); modelConfig.setProperty(RModelConfig.LIBRARIES, "e1071, foreign"); modelConfig.setProperty(RModelConfig.MODEL_SAVE_PATH, getCwd()); modelConfig.setProperty(RModelConfig.CLASS_INDEX, Integer.valueOf(attributes.size() - 1).toString()); modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION, "naiveBayes"); modelConfig.setProperty(RModelConfig.PREDICT_FUNCTION_ARGUMENTS, "type = 'raw'"); configuration.setProperty(FosConfig.FACTORY_NAME, RManagerFactory.class.getName()); FosConfig config = new FosConfig(configuration); RManagerConfig rManagerConfig = new RManagerConfig(config); RManager rManager = new RManager(rManagerConfig); UUID uuid = rManager.trainAndAdd(modelConfig, getTrainingInstances()); Scorer scorer = rManager.getScorer(); Object[] instance = { "b", 30.83, 0, "u", "g", "w", "v", 1.25, "t", "t", 1, "f", "g", 202, 0 }; List<double[]> result = scorer.score(ImmutableList.of(uuid), instance); assertEquals("Only 1 score expected", 1, result.size()); assertEquals("2 probabilities (not fraud, fraud)", 2, result.get(0).length); }
From source file:com.yahoo.omid.benchmarks.tso.TxRunner.java
public TxRunner(MetricsRegistry metrics, Config expConfig) throws IOException, InterruptedException, ExecutionException { // Tx Runner config this.outstandingTxs = new Semaphore(expConfig.maxInFlight); this.maxTxSize = expConfig.maxTxSize; this.commitDelay = expConfig.commitDelay; this.percentReads = expConfig.readproportion == -1 ? expConfig.percentReads : (expConfig.readproportion * 100); this.intGenerator = GeneratorUtils.getIntGenerator(expConfig.requestDistribution); this.randomGen = new Random(System.currentTimeMillis() * txRunnerId); // to make it channel dependent LOG.info("TxRunner-{} [ Row Distribution -> {} ]", txRunnerId, expConfig.requestDistribution); LOG.info("TxRunner-{} [ Outstanding transactions -> {} ]", txRunnerId, expConfig.maxInFlight); LOG.info("TxRunner-{} [ Max Tx Size -> {} ]", txRunnerId, expConfig.maxTxSize); LOG.info("TxRunner-{} [ Commit delay -> {}:{} ]", txRunnerId, expConfig.commitDelay.timeValue, expConfig.commitDelay.timeUnit); LOG.info("TxRunner-{} [ % reads -> {} ]", txRunnerId, expConfig.percentReads); // Commit table client initialization CommitTable commitTable;// w w w . jav a2 s. com if (expConfig.isHBase()) { HBaseLogin.loginIfNeeded(expConfig.getLoginFlags()); HBaseCommitTableConfig hbaseCommitTableConfig = new HBaseCommitTableConfig(); hbaseCommitTableConfig.setTableName(expConfig.getHBaseCommitTable()); commitTable = new HBaseCommitTable(HBaseConfiguration.create(), hbaseCommitTableConfig); LOG.info("TxRunner-{} [ Using HBase Commit Table ]", txRunnerId); } else { commitTable = new NullCommitTable(); LOG.info("TxRunner-{} [ Using Null Commit Table ]", txRunnerId); } try { this.commitTableClient = commitTable.getClient().get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); e.printStackTrace(); throw e; } catch (ExecutionException e) { e.printStackTrace(); throw e; } // TSO Client initialization Configuration tsoConfig = new BaseConfiguration(); tsoConfig.setProperty(TSO_HOST_CONFKEY, expConfig.tsoHostPort.getHostText()); tsoConfig.setProperty(TSO_PORT_CONFKEY, expConfig.tsoHostPort.getPortOrDefault(1234)); tsoConfig.setProperty("request.timeout-ms", -1); // TODO ??? LOG.info("TxRunner-{} [ Connected to TSO in {} ]", txRunnerId, expConfig.tsoHostPort); this.tsoClient = TSOClient.newBuilder().withConfiguration(tsoConfig).build(); // Stat initialization String hostName = InetAddress.getLocalHost().getHostName(); this.timestampTimer = metrics.timer(name("tx_runner", Integer.toString(txRunnerId), hostName, "timestamp")); this.commitTimer = metrics.timer(name("tx_runner", Integer.toString(txRunnerId), hostName, "commit")); this.abortTimer = metrics.timer(name("tx_runner", Integer.toString(txRunnerId), hostName, "abort")); this.errorCounter = metrics.counter(name("tx_runner", Integer.toString(txRunnerId), hostName, "errors")); }
From source file:com.ibm.research.govsci.graph.BlueprintsBase.java
/** * Full constructor that takes an engine, a url, and a map for a configuration * /*w ww . j a v a 2s . c o m*/ * Configuration parameters should be the exact names that the database uses. This * is mainly for setting very specific parameters for neo4j, but it also works for * defining a username and password for connecting to an OreintDB database. * * @param engine name of the engine * @param dburl url of the database for the engine * @param config parameters for the engine */ public BlueprintsBase(String engine, String dburl, Map<String, String> config) { startConstructor(); String eng = engine.toLowerCase().trim(); dbengine = eng; log.debug("Requested database: {} url: {}", eng, dburl); if (eng.equals(Engine.NEO4J)) { log.info("Opening neo4j graph at: {}", dburl); kigraph = new Neo4jGraph(dburl, config); tgraph = (TransactionalGraph) kigraph; igraph = (IndexableGraph) kigraph; } else if (eng.equals(Engine.REXSTER)) { log.warn("Configuration parameters passed to RexsterGraph - Ignored"); log.info("Opening rexster graph at: {}", dburl); kigraph = new RexsterGraph(dburl); igraph = (IndexableGraph) kigraph; } else if (eng.equals(Engine.TINKERGRAPH)) { if (config != null) { log.warn("Configuration parameters passed to TinkerGraph - Ignored"); } log.info("creating new tinkergraph with url: {}", dburl); if (dburl == null) { kigraph = new TinkerGraph(); } else { kigraph = new TinkerGraph(dburl); } igraph = (IndexableGraph) kigraph; } else if (eng.equals(Engine.NEO4JBATCH)) { log.info("Opening neo4j batch graph at: {}", dburl); if (config == null) { kigraph = new Neo4jBatchGraph(dburl); } else { kigraph = new Neo4jBatchGraph(dburl, config); } igraph = (IndexableGraph) kigraph; } else if (eng.equals(Engine.ORIENTDB)) { String username = null; String password = null; if (config != null) { username = config.get("username"); password = config.get("password"); } if (username != null && password != null) { kigraph = new OrientGraph(dburl, username, password); } else { kigraph = new OrientGraph(dburl); } tgraph = (TransactionalGraph) kigraph; igraph = (IndexableGraph) kigraph; } else if (eng.equals(Engine.TITAN)) { Configuration conf = null; TitanGraph g; if (config != null) { conf = new BaseConfiguration(); for (Entry<String, String> e : config.entrySet()) { conf.setProperty(e.getKey(), e.getValue()); } } if (conf != null) { g = TitanFactory.open(conf); } else { g = TitanFactory.open(dburl); } kigraph = (KeyIndexableGraph) g; tgraph = (TransactionalGraph) g; } else { log.error("Undefined database engine: {}", eng); System.exit(-1); } finishConstructor(); }
From source file:com.linkedin.pinot.broker.routing.RoutingTableTest.java
@Test public void testTimeBoundaryRegression() throws Exception { final FakePropertyStore propertyStore = new FakePropertyStore(); final OfflineSegmentZKMetadata offlineSegmentZKMetadata = new OfflineSegmentZKMetadata(); offlineSegmentZKMetadata.setTimeUnit(TimeUnit.DAYS); offlineSegmentZKMetadata.setEndTime(1234L); propertyStore.setContents(//from ww w. ja v a 2s.c o m ZKMetadataProvider.constructPropertyStorePathForSegment("myTable_OFFLINE", "someSegment_0"), offlineSegmentZKMetadata.toZNRecord()); final ExternalView offlineExternalView = new ExternalView("myTable_OFFLINE"); offlineExternalView.setState("someSegment_0", "Server_1.2.3.4_1234", "ONLINE"); final MutableBoolean timeBoundaryUpdated = new MutableBoolean(false); HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(propertyStore, null, new BaseConfiguration()) { @Override protected ExternalView fetchExternalView(String table) { return offlineExternalView; } @Override protected void updateTimeBoundary(String tableName, ExternalView externalView) { if (tableName.equals("myTable_OFFLINE")) { timeBoundaryUpdated.setValue(true); } } }; routingTable.setBrokerMetrics(new BrokerMetrics(new MetricsRegistry())); Assert.assertFalse(timeBoundaryUpdated.booleanValue()); final ArrayList<InstanceConfig> instanceConfigList = new ArrayList<>(); instanceConfigList.add(new InstanceConfig("Server_1.2.3.4_1234")); TableConfig myTableOfflineConfig = generateTableConfig("myTable_OFFLINE"); TableConfig myTableRealtimeConfig = generateTableConfig("myTable_REALTIME"); routingTable.markDataResourceOnline(myTableOfflineConfig, offlineExternalView, instanceConfigList); routingTable.markDataResourceOnline(myTableRealtimeConfig, new ExternalView("myTable_REALTIME"), new ArrayList<InstanceConfig>()); Assert.assertTrue(timeBoundaryUpdated.booleanValue()); }
From source file:eu.cognitum.readandwrite.App.java
public static SailRepository createTitanConnection(String ip, String keyspace) throws RepositoryException { // note: delete Titan Cassandra's keyspace manually String backend = "cassandra"; Configuration conf = new BaseConfiguration(); conf.setProperty("storage.backend", backend); conf.setProperty("storage.hostname", ip); conf.setProperty("storage.keyspace", keyspace); conf.setProperty("cache.db-cache", "true"); TitanGraph g = TitanFactory.open(conf); String indexedPatterns = "p,c,pc"; if (null == g.getType(GraphSail.INFERRED)) { g.makeKey(GraphSail.INFERRED).dataType(Boolean.class); }/* www.j a v a 2 s. co m*/ if (null == g.getType(GraphSail.KIND)) { g.makeKey(GraphSail.KIND).dataType(String.class); } if (null == g.getType(GraphSail.LANG)) { g.makeKey(GraphSail.LANG).dataType(String.class); } if (null == g.getType(GraphSail.TYPE)) { g.makeKey(GraphSail.TYPE).dataType(String.class); } if (null == g.getType(GraphSail.VALUE)) { g.makeKey(GraphSail.VALUE).dataType(String.class).unique(); } for (String pattern : indexedPatterns.split(",")) { if (null == g.getType(pattern)) { g.makeKey(pattern).dataType(String.class); } } SailRepository sr = new SailRepository(new GraphSail(g, indexedPatterns)); sr.initialize(); return sr; }
From source file:co.turnus.analysis.bottlenecks.AlgorithmicBottlenecksCliLauncher.java
private static Configuration parseCommandLine(CommandLine cmd) throws ParseException { Configuration config = new BaseConfiguration(); StringBuffer s = new StringBuffer(); config.setProperty(VERBOSE, cmd.hasOption("v")); if (!cmd.hasOption("t")) { s.append("Trace project directory not specified. "); } else {/*from ww w . j a va 2 s . c o m*/ String fileName = cmd.getOptionValue("t", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Trace project does not exists. "); } else { config.setProperty(TRACE_PROJECT, fileName); } } if (!cmd.hasOption("w")) { s.append("Profiling weights file not specified. "); } else { String fileName = cmd.getOptionValue("w", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Profiling weights file does not exists. "); } else { config.setProperty(PROFILING_WEIGHTS, fileName); } } if (!cmd.hasOption("o")) { s.append("Output directory not specified. "); } else { String fileName = cmd.getOptionValue("o", ""); File file = new File(fileName); if (file == null || !file.exists()) { s.append("Output directory does not exists. "); } else { config.setProperty(OUTPUT_PATH, fileName); } } if (cmd.hasOption("xls")) { String fileName = cmd.getOptionValue("xls", ""); if (fileName == null || fileName.isEmpty()) { s.append("XLS file name is not correct. "); } else { config.setProperty(XLS, fileName); } } if (cmd.hasOption("i")) { config.setProperty(IMPACT_ANALYSIS_RUN, true); String[] values = cmd.getOptionValues("i"); if (values.length < 3) { s.append("No enought parameters for the impact analysis. "); } else { try { int intValue = Integer.parseInt(values[0]); config.setProperty(IMPACT_ANALYSIS_ACTIONS, intValue); } catch (Exception e) { s.append("The number of actions for the impact analysis should be an integer value. "); } try { int intValue = Integer.parseInt(values[1]); config.setProperty(IMPACT_ANALYSIS_POINTS, intValue); } catch (Exception e) { s.append("The number of points for the impact analysis should be an integer value. "); } String value = values[2]; if (value.equals("a")) { config.setProperty(IMPACT_ANALYSIS_ACTORLEVEL, true); } else if (value.equals("c")) { config.setProperty(IMPACT_ANALYSIS_ACTORLEVEL, false); } else { s.append("The impact analysis granularity is not correct. "); } } } else { config.setProperty(IMPACT_ANALYSIS_RUN, false); } String error = s.toString(); if (!error.isEmpty()) { throw new ParseException(error); } return config; }