org.apache.commons.configuration.MapConfiguration Java Examples
The following examples show how to use
org.apache.commons.configuration.MapConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetricsHelperTest.java From incubator-pinot with Apache License 2.0 | 6 votes |
@Test public void testMetricsHelperRegistration() { listenerOneOkay = false; listenerTwoOkay = false; Map<String, String> configKeys = new HashMap<String, String>(); configKeys.put("pinot.broker.metrics.metricsRegistryRegistrationListeners", ListenerOne.class.getName() + "," + ListenerTwo.class.getName()); Configuration configuration = new MapConfiguration(configKeys); MetricsRegistry registry = new MetricsRegistry(); // Initialize the MetricsHelper and create a new timer MetricsHelper.initializeMetrics(configuration.subset("pinot.broker.metrics")); MetricsHelper.registerMetricsRegistry(registry); MetricsHelper.newTimer(registry, new MetricName(MetricsHelperTest.class, "dummy"), TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS); // Check that the two listeners fired assertTrue(listenerOneOkay); assertTrue(listenerTwoOkay); }
Example #2
Source File: AbstractCodahaleFixtureGenerator.java From cm_ext with Apache License 2.0 | 6 votes |
public AbstractCodahaleFixtureGenerator(String[] args, Options options) throws Exception { Preconditions.checkNotNull(args); Preconditions.checkNotNull(options); CommandLineParser parser = new DefaultParser(); try { CommandLine cmdLine = parser.parse(options, args); if (!cmdLine.getArgList().isEmpty()) { throw new ParseException("Unexpected extra arguments: " + cmdLine.getArgList()); } config = new MapConfiguration(Maps.<String, Object>newHashMap()); for (Option option : cmdLine.getOptions()) { config.addProperty(option.getLongOpt(), option.getValue()); } } catch (ParseException ex) { IOUtils.write("Error: " + ex.getMessage() + "\n", System.err); printUsageMessage(System.err, options); throw ex; } }
Example #3
Source File: HaltedTraverserStrategyTest.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test public void shouldReturnDetachedElements() { final Graph graph = TinkerFactory.createModern(); final GraphTraversalSource g = graph.traversal().withComputer().withStrategies(HaltedTraverserStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{ put(HaltedTraverserStrategy.HALTED_TRAVERSER_FACTORY, DetachedFactory.class.getCanonicalName()); }}))); g.V().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass())); g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(DetachedVertexProperty.class, vertexProperty.getClass())); g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass())); g.V().out().outE().forEachRemaining(edge -> assertEquals(DetachedEdge.class, edge.getClass())); g.V().out().outE().properties("weight").forEachRemaining(property -> assertEquals(DetachedProperty.class, property.getClass())); g.V().out().outE().values("weight").forEachRemaining(value -> assertEquals(Double.class, value.getClass())); g.V().out().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass())); g.V().out().out().path().forEachRemaining(path -> assertEquals(DetachedPath.class, path.getClass())); g.V().out().pageRank().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass())); g.V().out().pageRank().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass())); // should handle nested collections g.V().out().fold().next().forEach(vertex -> assertEquals(DetachedVertex.class, vertex.getClass())); }
Example #4
Source File: DynamicZookeeperConfigurationSourceTest.java From chassis with Apache License 2.0 | 6 votes |
@Before public void beforeClass() throws Exception { zookeeper = new TestingServer(SocketUtils.findAvailableTcpPort()); curatorFramework = CuratorFrameworkFactory.newClient(zookeeper.getConnectString(), new RetryOneTime(1000)); curatorFramework.start(); curatorFramework.create().forPath(CONFIG_BASE_PATH); Map<String, Object> defaults = new HashMap<>(); defaults.put(DEF_KEY1, DEF_VAL1); defaults.put(DEF_KEY2, DEF_VAL2); defaultConfiguration = new MapConfiguration(defaults); node = UUID.randomUUID().toString(); config = new ConcurrentCompositeConfiguration(); }
Example #5
Source File: ZookeeperConfigurationWriterTest.java From chassis with Apache License 2.0 | 6 votes |
@Test public void basePathExists_noOverwrite() throws Exception { Assert.assertNull(curatorFramework.checkExists().forPath(base)); try (CuratorFramework zkCurator = createCuratorFramework()) { ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false); writer.write(new MapConfiguration(props), new DefaultPropertyFilter()); Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1))); Assert.assertEquals(val2, new String(curatorFramework.getData().forPath(base + "/" + key2))); try { writer.write(new MapConfiguration(props), new DefaultPropertyFilter()); Assert.fail(); } catch (BootstrapException e) { //expected } } }
Example #6
Source File: InstallTest.java From juddi with Apache License 2.0 | 6 votes |
/** * Test of applyReplicationTokenChanges method, of class Install. */ @Test public void testApplyReplicationTokenChanges() throws Exception { System.out.println("applyReplicationTokenChanges"); InputStream fis = getClass().getClassLoader().getResourceAsStream("juddi_install_data/root_replicationConfiguration.xml"); ReplicationConfiguration replicationCfg = (ReplicationConfiguration) XmlUtils.unmarshal(fis, ReplicationConfiguration.class); Properties props = new Properties(); props.put(Property.JUDDI_NODE_ID, "uddi:a_custom_node"); props.put(Property.JUDDI_BASE_URL, "http://juddi.apache.org"); props.put(Property.JUDDI_BASE_URL_SECURE, "https://juddi.apache.org"); Configuration config = new MapConfiguration(props); String thisnode = "uddi:a_custom_node"; ReplicationConfiguration result = Install.applyReplicationTokenChanges(replicationCfg, config, thisnode); StringWriter sw = new StringWriter(); JAXB.marshal(result, sw); Assert.assertFalse(sw.toString().contains("${juddi.nodeId}")); Assert.assertFalse(sw.toString().contains("${juddi.server.baseurlsecure}")); Assert.assertFalse(sw.toString().contains("${juddi.server.baseurl}")); }
Example #7
Source File: ConfigurationHelper.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Loads configuration from system defined arguments, i.e. -Dapi.x.y.z=abc. */ public Configuration fromSystem() { MapConfiguration mapConfig = setupConfiguration(new MapConfiguration((Properties) System.getProperties().clone())); // Disables trimming so system properties that include whitespace (such as line.separator) will // be preserved. mapConfig.setTrimmingDisabled(true); return mapConfig; }
Example #8
Source File: TestLogConfigUtils.java From singer with Apache License 2.0 | 5 votes |
@Test public void testShadowKafkaProducerConfigs() throws ConfigurationException, IOException { LogConfigUtils.DEFAULT_SERVERSET_DIR = "target/serversets"; new File(LogConfigUtils.DEFAULT_SERVERSET_DIR).mkdirs(); Files.write(new File(LogConfigUtils.DEFAULT_SERVERSET_DIR+"/discovery.xyz.prod").toPath(), "xyz:9092".getBytes()); Files.write(new File(LogConfigUtils.DEFAULT_SERVERSET_DIR+"/discovery.test.prod").toPath(), "test:9092".getBytes()); Files.write(new File(LogConfigUtils.DEFAULT_SERVERSET_DIR+"/discovery.test2.prod").toPath(), "test2:9092".getBytes()); Map<String, Object> map = new HashMap<>(); map.put(SingerConfigDef.BROKER_SERVERSET_DEPRECATED, "/discovery/xyz/prod"); AbstractConfiguration config = new MapConfiguration(map); KafkaProducerConfig producerConfig = null; // without shadow mode activation regular serverset file should be sourced producerConfig = LogConfigUtils.parseProducerConfig(config); assertEquals(Arrays.asList("xyz:9092"), producerConfig.getBrokerLists()); // with shadow mode override should be sourced LogConfigUtils.SHADOW_MODE_ENABLED = true; LogConfigUtils.SHADOW_SERVERSET_MAPPING.put(LogConfigUtils.DEFAULT_SHADOW_SERVERSET, "discovery.test.prod"); producerConfig = LogConfigUtils.parseProducerConfig(config); assertEquals(Arrays.asList("test:9092"), producerConfig.getBrokerLists()); LogConfigUtils.SHADOW_SERVERSET_MAPPING.put("/discovery/xyz/prod", "discovery.test2.prod"); producerConfig = LogConfigUtils.parseProducerConfig(config); assertEquals(Arrays.asList("test2:9092"), producerConfig.getBrokerLists()); }
Example #9
Source File: MetricDescriptorGeneratorTool.java From cm_ext with Apache License 2.0 | 5 votes |
private AbstractMetricFixtureAdapter<?> newMetricFixtureAdapter( MapConfiguration config, OutputStream out, OutputStream err) throws IllegalAccessException, InstantiationException { Preconditions.checkNotNull(config); Preconditions.checkNotNull(out); Preconditions.checkNotNull(err); // All implementations of the MetricFixtureAdapter must have a no-argument // c'tor. LOG.info("Instantiating new metric fixture of class " + config.getString(OPT_ADAPTER_CLASS.getLongOpt())); Class<?> adapterClass = (Class<?>) config.getProperty(ADAPTER_CLASS_CONFIG); Preconditions.checkNotNull(adapterClass); return (AbstractMetricFixtureAdapter<?>) adapterClass.newInstance(); }
Example #10
Source File: CuratorFrameworkBuilderTest.java From chassis with Apache License 2.0 | 5 votes |
@Test public void buildWithConfiguration(){ HashMap<String, Object> map = new HashMap<>(); map.put(BootstrapConfigKeys.ZOOKEEPER_MAX_RETRIES.getPropertyName(), 1); MapConfiguration configuration = new MapConfiguration(map); try (CuratorFramework curatorFramework = new CuratorFrameworkBuilder(false).withZookeeper("localhost:2181").withConfiguration(configuration).build()) {} }
Example #11
Source File: ZookeeperConfigurationWriterTest.java From chassis with Apache License 2.0 | 5 votes |
@Test public void basePathExists_overwrite() throws Exception { Assert.assertNull(curatorFramework.checkExists().forPath(base)); try (CuratorFramework zkCurator = createCuratorFramework()) { ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, true); writer.write(new MapConfiguration(props), new DefaultPropertyFilter()); Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1))); Assert.assertEquals(val2, new String(curatorFramework.getData().forPath(base + "/" + key2))); String key3 = RandomUtils.nextInt() + ""; String val3 = RandomUtils.nextInt() + ""; String newVal1 = RandomUtils.nextInt() + ""; props.clear(); //updates key1 props.put(key1, newVal1); //adds key3 props.put(key3, val3); //key2 should be deleted writer.write(new MapConfiguration(props), new DefaultPropertyFilter()); Assert.assertEquals(newVal1, new String(curatorFramework.getData().forPath(base + "/" + key1))); Assert.assertEquals(val3, new String(curatorFramework.getData().forPath(base + "/" + key3))); Assert.assertNull(curatorFramework.checkExists().forPath(base + "/" + key2)); } }
Example #12
Source File: ZookeeperConfigurationWriterTest.java From chassis with Apache License 2.0 | 5 votes |
@Test public void partialBasePathExists() throws Exception { Assert.assertNull(curatorFramework.checkExists().forPath(base)); curatorFramework.create().forPath("/" + environmentName); Assert.assertNotNull(curatorFramework.checkExists().forPath("/" + environmentName)); try (CuratorFramework zkCurator = createCuratorFramework()) { ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false); writer.write(new MapConfiguration(props), new DefaultPropertyFilter()); Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1))); } }
Example #13
Source File: ZookeeperConfigurationWriterTest.java From chassis with Apache License 2.0 | 5 votes |
@Test public void noBasePathExists() throws Exception { Assert.assertNull(curatorFramework.checkExists().forPath(base)); try (CuratorFramework zkCurator = createCuratorFramework()) { ZookeeperConfigurationWriter writer = new ZookeeperConfigurationWriter(applicationName, environmentName, version, zkCurator, false); writer.write(new MapConfiguration(props), new DefaultPropertyFilter()); Assert.assertEquals(val1, new String(curatorFramework.getData().forPath(base + "/" + key1))); } }
Example #14
Source File: ClientContext.java From knox with Apache License 2.0 | 5 votes |
public ClientContext() { configuration = new MapConfiguration(new HashMap<>()); poolContext = new PoolContext(this); socketContext = new SocketContext(this); connectionContext = new ConnectionContext(this); kerberos = new KerberosContext(this); }
Example #15
Source File: ValidatorTest.java From mithqtt with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() { validator = new Validator(new MapConfiguration(new HashMap<>())); validator.clientIdPattern = Pattern.compile("^[ -~]+$"); validator.topicNamePattern = Pattern.compile("^[\\w_ /]*$"); validator.topicFilterPattern = Pattern.compile("^[\\w_ +#/]*$"); }
Example #16
Source File: RedisSyncSingleStorageImplTest.java From mithqtt with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() throws ConfigurationException { Map<String, Object> map = new HashMap<>(); map.put("redis.type", "single"); map.put("redis.address", "localhost"); map.put("mqtt.inflight.queue.size", 3); map.put("mqtt.qos2.queue.size", 3); map.put("mqtt.retain.queue.size", 3); MapConfiguration config = new MapConfiguration(map); redis = new RedisSyncSingleStorageImpl(); redis.init(config); }
Example #17
Source File: PropertyUtil.java From qaf with MIT License | 5 votes |
public void addAll(Map<String, ?> props) { boolean b = props.keySet().removeAll(System.getProperties().keySet()); if (b) { logger.trace("Found one or more system properties which will not modified"); } copy(new MapConfiguration(props)); }
Example #18
Source File: MetricCompactionStrategy.java From timely with Apache License 2.0 | 5 votes |
public static MetricAgeOffConfiguration newFromRequest(MajorCompactionRequest request, String majcIteratorName) { Configuration config = new MapConfiguration(request.getTableProperties()); String majcIteratorKey = Property.TABLE_ITERATOR_MAJC_PREFIX.getKey() + majcIteratorName; if (LOG.isTraceEnabled()) { LOG.trace("Using key lookup for iterator: {}", majcIteratorKey); } Configuration configAgeOff = config.subset((majcIteratorKey + ".opt")); if (null == configAgeOff.getString(DEFAULT_AGEOFF_KEY)) { throw new IllegalArgumentException( DEFAULT_AGEOFF_KEY_SUFFIX + " must be configured for " + majcIteratorKey); } PatriciaTrie<Long> ageoffs = new PatriciaTrie<>(); long configureMinAgeOff = Long.MAX_VALUE; long configureMaxAgeOff = Long.MIN_VALUE; @SuppressWarnings("unchecked") Iterator<String> keys = configAgeOff.getKeys(); while (keys.hasNext()) { String k = keys.next(); String v = configAgeOff.getString(k); if (k.startsWith((AGE_OFF_PREFIX))) { String name = k.substring(AGE_OFF_PREFIX.length()); if (LOG.isTraceEnabled()) { LOG.trace("Adding {} to Trie with value {}", name, Long.parseLong(v)); } long ageoff = Long.parseLong(v); configureMinAgeOff = Math.min(configureMinAgeOff, ageoff); configureMaxAgeOff = Math.max(configureMaxAgeOff, ageoff); ageoffs.put(name, ageoff); } } long defaultAgeOff = ageoffs.get(DEFAULT_AGEOFF_KEY_SUFFIX); return new MetricAgeOffConfiguration(ageoffs, defaultAgeOff); }
Example #19
Source File: TinkerGraphComputerProvider.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public GraphTraversalSource traversal(final Graph graph) { return graph.traversal().withStrategies(VertexProgramStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{ put(VertexProgramStrategy.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1); put(VertexProgramStrategy.GRAPH_COMPUTER, RANDOM.nextBoolean() ? GraphComputer.class.getCanonicalName() : TinkerGraphComputer.class.getCanonicalName()); }}))); }
Example #20
Source File: TestPriorityProperty.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void globalRefresh() { PriorityProperty<String> property = priorityPropertyManager.createPriorityProperty(String.class, null, null, keys); Assert.assertNull(property.getValue()); ConcurrentCompositeConfiguration config = (ConcurrentCompositeConfiguration) DynamicPropertyFactory .getBackingConfigurationSource(); config.addConfiguration(new MapConfiguration(Collections.singletonMap(high, "high-value"))); Assert.assertEquals("high-value", property.getValue()); }
Example #21
Source File: CassandraAuditRepositoryTest.java From atlas with Apache License 2.0 | 5 votes |
@BeforeClass public void setup() { try { EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra_test.yml"); eventRepository = new CassandraBasedAuditRepository(); Configuration atlasConf = new MapConfiguration(getClusterProperties()); ((CassandraBasedAuditRepository) eventRepository).setApplicationProperties(atlasConf); ((CassandraBasedAuditRepository) eventRepository).start(); ensureClusterCreation(); } catch (Exception ex) { throw new SkipException("setup: failed!", ex); } }
Example #22
Source File: TestLogConfigUtils.java From singer with Apache License 2.0 | 5 votes |
@Test public void testProducerBufferMemory() throws ConfigurationException { Map<String, Object> map = new HashMap<>(); map.put("bootstrap.servers", "localhost:9092"); map.put("buffer.memory", "2048"); AbstractConfiguration config = new MapConfiguration(map); try { KafkaProducerConfig producerConfig = LogConfigUtils.parseProducerConfig(config); assertEquals(2048, producerConfig.getBufferMemory()); } catch (ConfigurationException e) { // fail since no exception should be thrown throw e; } }
Example #23
Source File: TitanGraphDatabase.java From graphdb-benchmarks with Apache License 2.0 | 4 votes |
private static final Configuration generateBaseTitanConfiguration(GraphDatabaseType type, File dbPath, boolean batchLoading, BenchmarkConfiguration bench) { if (!GraphDatabaseType.TITAN_FLAVORS.contains(type)) { throw new IllegalArgumentException("must provide a Titan database type but got " + (type == null ? "null" : type.name())); } if (dbPath == null) { throw new IllegalArgumentException("the dbPath must not be null"); } if (!dbPath.exists() || !dbPath.canWrite() || !dbPath.isDirectory()) { throw new IllegalArgumentException("db path must exist as a directory and must be writeable"); } final Configuration conf = new MapConfiguration(new HashMap<String, String>()); final Configuration storage = conf.subset(GraphDatabaseConfiguration.STORAGE_NS.getName()); final Configuration ids = conf.subset(GraphDatabaseConfiguration.IDS_NS.getName()); final Configuration metrics = conf.subset(GraphDatabaseConfiguration.METRICS_NS.getName()); conf.addProperty(GraphDatabaseConfiguration.ALLOW_SETTING_VERTEX_ID.getName(), "true"); // storage NS config. FYI, storage.idauthority-wait-time is 300ms storage.addProperty(GraphDatabaseConfiguration.STORAGE_BACKEND.getName(), type.getBackend()); storage.addProperty(GraphDatabaseConfiguration.STORAGE_DIRECTORY.getName(), dbPath.getAbsolutePath()); storage.addProperty(GraphDatabaseConfiguration.STORAGE_BATCH.getName(), Boolean.toString(batchLoading)); storage.addProperty(GraphDatabaseConfiguration.BUFFER_SIZE.getName(), bench.getTitanBufferSize()); storage.addProperty(GraphDatabaseConfiguration.PAGE_SIZE.getName(), bench.getTitanPageSize()); // ids NS config ids.addProperty(GraphDatabaseConfiguration.IDS_BLOCK_SIZE.getName(), bench.getTitanIdsBlocksize()); // Titan metrics - https://github.com/thinkaurelius/titan/wiki/Titan-Performance-and-Monitoring metrics.addProperty(GraphDatabaseConfiguration.BASIC_METRICS.getName(), "true"); metrics.addProperty("prefix", type.getShortname()); if(bench.publishGraphiteMetrics()) { final Configuration graphite = metrics.subset(BenchmarkConfiguration.GRAPHITE); graphite.addProperty("hostname", bench.getGraphiteHostname()); graphite.addProperty(BenchmarkConfiguration.CSV_INTERVAL, bench.getCsvReportingInterval()); } if(bench.publishCsvMetrics()) { final Configuration csv = metrics.subset(GraphDatabaseConfiguration.METRICS_CSV_NS.getName()); csv.addProperty(GraphDatabaseConfiguration.METRICS_CSV_DIR.getName(), bench.getCsvDir().getAbsolutePath()); csv.addProperty(BenchmarkConfiguration.CSV_INTERVAL, bench.getCsvReportingInterval()); } return conf; }