Java Code Examples for org.apache.commons.configuration.Configuration#setProperty()

The following examples show how to use org.apache.commons.configuration.Configuration#setProperty() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: atlas   File: AtlasJanusDatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void initializationFailureShouldThrowRuntimeException() throws AtlasException {
    Configuration cfg = AtlasJanusGraphDatabase.getConfiguration();
    Map<String, Object> cfgBackup = new HashMap<>();
    Iterator<String> keys = cfg.getKeys();
    while(keys.hasNext()) {
        String key = keys.next();
        cfgBackup.put(key, cfg.getProperty(key));
    }

    try {
        cfg.clear();
        initJanusGraph(cfg);

        fail("Should have thrown an exception!");
    }
    catch (RuntimeException ex) {
        assertTrue(true);
        for (Map.Entry<String, Object> entry : cfgBackup.entrySet()) {
            cfg.setProperty(entry.getKey(), entry.getValue());
        }
    }
}
 
Example 2
Source Project: distributedlog   File: TestConfUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testLoadConfiguration() {
    Configuration conf1 = new CompositeConfiguration();
    conf1.setProperty("key1", "value1");
    conf1.setProperty("key2", "value2");
    conf1.setProperty("key3", "value3");

    Configuration conf2 = new CompositeConfiguration();
    conf2.setProperty("bkc.key1", "bkc.value1");
    conf2.setProperty("bkc.key4", "bkc.value4");

    assertEquals("value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals(null, conf1.getString("key4"));

    ConfUtils.loadConfiguration(conf1, conf2, "bkc.");

    assertEquals("bkc.value1", conf1.getString("key1"));
    assertEquals("value2", conf1.getString("key2"));
    assertEquals("value3", conf1.getString("key3"));
    assertEquals("bkc.value4", conf1.getString("key4"));
    assertEquals(null, conf1.getString("bkc.key1"));
    assertEquals(null, conf1.getString("bkc.key4"));
}
 
Example 3
public void shouldAllowGraphsLargerThanMemory() throws InterruptedException {
        int vertexCount = 300000;
//        TinkerGraph graph = newGratefulDeadGraphWithSpecializedElements();
        Configuration configuration = TinkerGraph.EMPTY_CONFIGURATION();
//        configuration.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_ONDISK_OVERFLOW_ENABLED, false);
        configuration.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_ONDISK_OVERFLOW_ENABLED, true);
        TinkerGraph graph = TinkerGraph.open(
                configuration,
                Arrays.asList(Song.factory, Artist.factory),
                Arrays.asList(FollowedBy.factory, SungBy.factory, WrittenBy.factory)
        );

        for (long i = 0; i < vertexCount; i++) {
            if (i % 50000 == 0) {
                System.out.println(i + " vertices created");
                Thread.sleep(1000); // in lieu of other application usage
            }
            Vertex v = graph.addVertex(Song.label);
//            v.property(Song.NAME, UUID.randomUUID().toString());
//            v.property(Song.SONG_TYPE, UUID.randomUUID().toString());
            v.property(Song.TEST_PROP, new int[200]);
        }
        graph.close();
    }
 
Example 4
@Test
public void testWithConfig() {
  Configuration config = new PropertiesConfiguration();
  final int workers = 5;
  final int runners = 2;

  config.setProperty(ResourceManager.QUERY_RUNNER_CONFIG_KEY, runners);
  config.setProperty(ResourceManager.QUERY_WORKER_CONFIG_KEY, workers);

  UnboundedResourceManager rm = new UnboundedResourceManager(config);
  assertEquals(rm.getNumQueryWorkerThreads(), workers);
  assertEquals(rm.getNumQueryRunnerThreads(), runners);
  assertEquals(rm.getTableThreadsHardLimit(), runners + workers);
  assertEquals(rm.getTableThreadsSoftLimit(), runners + workers);

  SchedulerGroupAccountant accountant = mock(SchedulerGroupAccountant.class);
  when(accountant.totalReservedThreads()).thenReturn(3);
  assertTrue(rm.canSchedule(accountant));

  when(accountant.totalReservedThreads()).thenReturn(workers + runners + 2);
  assertFalse(rm.canSchedule(accountant));
}
 
Example 5
public static void create(String sandboxName) {
    Configuration configuration;
    try {
        configuration = ApplicationProperties.get();

        String newStorageDir = System.getProperty("atlas.data") +
                File.separatorChar + "storage" +
                File.separatorChar + sandboxName;

        configuration.setProperty("atlas.graph.storage.directory", newStorageDir);


        String newIndexerDir = System.getProperty("atlas.data") +
                File.separatorChar + "index" +
                File.separatorChar + sandboxName;

        configuration.setProperty("atlas.graph.index.search.directory", newIndexerDir);


        LOG.debug("New Storage dir : {}", newStorageDir);
        LOG.debug("New Indexer dir : {}", newIndexerDir);
    } catch (AtlasException ignored) {}
}
 
Example 6
@Override
public void onBootEvent(BootEvent event) {
  if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
    return;
  }

  TransportClientConfig.setRestTransportClientCls(EdgeRestTransportClient.class);
  TransportConfig.setRestServerVerticle(EdgeRestServerVerticle.class);

  String defaultExecutor = DynamicPropertyFactory.getInstance()
      .getStringProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, null)
      .get();
  if (defaultExecutor != null) {
    LOGGER.info("Edge service default executor is {}.", defaultExecutor);
    return;
  }

  // change default to reactive mode
  Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
  configuration.setProperty(ExecutorManager.KEY_EXECUTORS_DEFAULT, ExecutorManager.EXECUTOR_REACTIVE);
  LOGGER.info("Set ReactiveExecutor to be edge service default executor.");
}
 
Example 7
@Test
public void shouldPersistWithRelativePath() {
    final String graphLocation = TestHelper.convertToRelative(TinkerGraphTest.class,
            new File(TestHelper.makeTestDataDirectory(TinkerGraphTest.class)))  + "shouldPersistToGryoRelative.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example 8
@Override
protected void overrideServerConf(Configuration configuration) {
  configuration.setProperty(CommonConstants.Server.CONFIG_OF_REALTIME_OFFHEAP_ALLOCATION, true);
  configuration.setProperty(CommonConstants.Server.CONFIG_OF_REALTIME_OFFHEAP_DIRECT_ALLOCATION, _isDirectAlloc);
  if (_isConsumerDirConfigured) {
    configuration.setProperty(CommonConstants.Server.CONFIG_OF_CONSUMER_DIR, CONSUMER_DIRECTORY);
  }
  if (_enableSplitCommit) {
    configuration.setProperty(CommonConstants.Server.CONFIG_OF_ENABLE_SPLIT_COMMIT, true);
    configuration.setProperty(CommonConstants.Server.CONFIG_OF_ENABLE_COMMIT_END_WITH_METADATA, true);
  }
  configuration.setProperty(CommonConstants.Server.CONFIG_OF_INSTANCE_RELOAD_CONSUMING_SEGMENT, true);
}
 
Example 9
Source Project: distributedlog   File: ConfUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Load configurations with prefixed <i>section</i> from source configuration <i>srcConf</i> into
 * target configuration <i>targetConf</i>.
 *
 * @param targetConf
 *          Target Configuration
 * @param srcConf
 *          Source Configuration
 * @param section
 *          Section Key
 */
public static void loadConfiguration(Configuration targetConf, Configuration srcConf, String section) {
    Iterator confKeys = srcConf.getKeys();
    while (confKeys.hasNext()) {
        Object keyObject = confKeys.next();
        if (!(keyObject instanceof String)) {
            continue;
        }
        String key = (String) keyObject;
        if (key.startsWith(section)) {
            targetConf.setProperty(key.substring(section.length()), srcConf.getProperty(key));
        }
    }
}
 
Example 10
void initNotificationService() throws AtlasException, InterruptedException {
    Configuration applicationProperties = ApplicationProperties.get();

    applicationProperties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));

    kafkaServer           = new EmbeddedKafkaServer(applicationProperties);
    kafkaNotification     = new KafkaNotification(applicationProperties);
    notificationInterface = kafkaNotification;

    kafkaServer.start();
    kafkaNotification.start();

    Thread.sleep(2000);
}
 
Example 11
Source Project: distributedlog   File: ConfUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Load configurations with prefixed <i>section</i> from source configuration <i>srcConf</i> into
 * target configuration <i>targetConf</i>.
 *
 * @param targetConf
 *          Target Configuration
 * @param srcConf
 *          Source Configuration
 * @param section
 *          Section Key
 */
public static void loadConfiguration(Configuration targetConf, Configuration srcConf, String section) {
    Iterator confKeys = srcConf.getKeys();
    while (confKeys.hasNext()) {
        Object keyObject = confKeys.next();
        if (!(keyObject instanceof String)) {
            continue;
        }
        String key = (String) keyObject;
        if (key.startsWith(section)) {
            targetConf.setProperty(key.substring(section.length()), srcConf.getProperty(key));
        }
    }
}
 
Example 12
Source Project: atlas   File: AtlasJanusGraphDatabase.java    License: Apache License 2.0 5 votes vote down vote up
private static void startLocalSolr() {
    if (isEmbeddedSolr()) {
        try {
            LocalSolrRunner.start();

            Configuration configuration = ApplicationProperties.get();
            configuration.clearProperty(SOLR_ZOOKEEPER_URL);
            configuration.setProperty(SOLR_ZOOKEEPER_URL, LocalSolrRunner.getZookeeperUrls());
        } catch (Exception e) {
            throw new RuntimeException("Failed to start embedded solr cloud server. Aborting!", e);
        }
    }
}
 
Example 13
@Override
public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list");
    final TinkerGraph graph = TinkerGraph.open(conf);
    final int len = input.readInt();
    final byte[] bytes = input.readBytes(len);
    try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) {
        GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph);
    } catch (Exception io) {
        throw new RuntimeException(io);
    }

    return graph;
}
 
Example 14
@Override
public void storeState(Configuration configuration) {
    super.storeState(configuration);

    // store class name for reflection on spark executor
    configuration.setProperty(VERTEX_PROGRAM, this.getClass().getName());
}
 
Example 15
@BeforeClass
public void setup() throws Exception {
    Configuration properties = ApplicationProperties.get();
    properties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));

    kafkaNotification = new KafkaNotification(properties);
    kafkaNotification.start();
}
 
Example 16
public Configuration build() {
    // create configuration instance
    Configuration configuration = new BaseConfiguration();
    // identifier
    configuration.setProperty(Neo4JIdentifierConfigurationKey, identifier != null ? identifier : UUID.randomUUID().toString());
    // url
    configuration.setProperty(Neo4JUrlConfigurationKey, "bolt://" + hostname + ":" + port);
    // hostname
    configuration.setProperty(Neo4JHostnameConfigurationKey, hostname);
    // port
    configuration.setProperty(Neo4JPortConfigurationKey, port);
    // username
    configuration.setProperty(Neo4JUsernameConfigurationKey, username);
    // password
    configuration.setProperty(Neo4JPasswordConfigurationKey, password);
    // database
    configuration.setProperty(Neo4JDatabaseConfigurationKey, database);
    // readonly
    configuration.setProperty(Neo4JReadonlyConfigurationKey, readonly);
    // graphName
    configuration.setProperty(Neo4JGraphNameConfigurationKey, graphName);
    // vertex id provider
    configuration.setProperty(Neo4JVertexIdProviderClassNameConfigurationKey, vertexIdProviderClassName != null ? vertexIdProviderClassName : elementIdProviderClassName);
    // edge id provider
    configuration.setProperty(Neo4JEdgeIdProviderClassNameConfigurationKey, edgeIdProviderClassName != null ? edgeIdProviderClassName : elementIdProviderClassName);
    // property id provider
    configuration.setProperty(Neo4JPropertyIdProviderClassNameConfigurationKey, propertyIdProviderClassName != null ? propertyIdProviderClassName : elementIdProviderClassName);
    // return configuration
    return configuration;
}
 
Example 17
@Test
public void testBootstrapTableWithPartition() {
  Map<String, Map<String, String>> currentAssignment = new TreeMap<>();
  for (String segmentName : SEGMENTS) {
    List<String> instancesAssigned = _segmentAssignmentWithPartition
        .assignSegment(segmentName, currentAssignment, _instancePartitionsMapWithPartition);
    currentAssignment
        .put(segmentName, SegmentAssignmentUtils.getInstanceStateMap(instancesAssigned, SegmentStateModel.ONLINE));
  }

  // Bootstrap table should reassign all segments based on their alphabetical order within the partition
  Configuration rebalanceConfig = new BaseConfiguration();
  rebalanceConfig.setProperty(RebalanceConfigConstants.BOOTSTRAP, true);
  Map<String, Map<String, String>> newAssignment = _segmentAssignmentWithPartition
      .rebalanceTable(currentAssignment, _instancePartitionsMapWithPartition, rebalanceConfig);
  assertEquals(newAssignment.size(), NUM_SEGMENTS);
  int numSegmentsPerPartition = NUM_SEGMENTS / NUM_PARTITIONS;
  String[][] partitionIdToSegmentsMap = new String[NUM_PARTITIONS][numSegmentsPerPartition];
  for (int i = 0; i < NUM_SEGMENTS; i++) {
    partitionIdToSegmentsMap[i % NUM_PARTITIONS][i / NUM_PARTITIONS] = SEGMENTS.get(i);
  }
  String[][] partitionIdToSortedSegmentsMap = new String[NUM_PARTITIONS][numSegmentsPerPartition];
  for (int i = 0; i < NUM_PARTITIONS; i++) {
    String[] sortedSegments = new String[numSegmentsPerPartition];
    System.arraycopy(partitionIdToSegmentsMap[i], 0, sortedSegments, 0, numSegmentsPerPartition);
    Arrays.sort(sortedSegments);
    partitionIdToSortedSegmentsMap[i] = sortedSegments;
  }
  for (int i = 0; i < NUM_PARTITIONS; i++) {
    for (int j = 0; j < numSegmentsPerPartition; j++) {
      assertEquals(newAssignment.get(partitionIdToSortedSegmentsMap[i][j]),
          currentAssignment.get(partitionIdToSegmentsMap[i][j]));
    }
  }
}
 
Example 18
@Override
public void saveConfiguration(Configuration c) {
  c.setProperty(ConfKeys.VERSION_CHECK_ON_STARTUP, checkCombo.isSelected());
}
 
Example 19
@Test(expected = IllegalStateException.class)
public void shouldRequireGraphFormatIfLocationIsSet() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, TestHelper.makeTestDataDirectory(TinkerGraphTest.class));
    TinkerGraph.open(conf);
}
 
Example 20
@Test
public void testGetResultParameters() throws Exception {
    File confFile = temp.newFile("props.cfg");
    FileUtils.writeLines(confFile, Arrays.asList(
            "processor.test.param.mime=image/jpeg",
            "processor.test.onExits=0, >10, 2\\,3, *",
            "processor.test.onExit.0.param.file=ERR_0\\:$${input.file.name}",
            "processor.test.onExit.>10.param.file=ERR_>10\\:$${input.file.name}",
            "processor.test.onExit.>10.stop=false",
            "processor.test.onExit.2,3.param.file=ERR_2\\,3\\:$${input.file.name}",
            "processor.test.onExit.*.param.file=ERR_*\\:$${input.file.name}",
            "processor.test.onSkip.param.file=SKIPPED\\:$${input.file.name}"
    ));
    PropertiesConfiguration pconf = new PropertiesConfiguration(confFile);
    String processorId = "processor.test";
    Configuration conf = pconf.subset(processorId);
    conf.setProperty("id", processorId);
    GenericExternalProcess gep = new GenericExternalProcess(conf);
    gep.addInputFile(confFile);
    ProcessResult result = ProcessResult.getResultParameters(conf, gep.getParameters().getMap(), false, 0, null);
    assertEquals("image/jpeg", result.getParameters().get(processorId + ".param.mime"));
    assertEquals("ERR_0:props", result.getParameters().get(processorId + ".param.file"));
    assertEquals(Integer.valueOf(0), result.getExit().getExitCode());
    assertFalse(result.getExit().isStop());
    assertFalse(result.getExit().isSkip());

    result = ProcessResult.getResultParameters(conf, gep.getParameters().getMap(), false, 3, null);
    assertEquals("image/jpeg", result.getParameters().get(processorId + ".param.mime"));
    assertEquals("ERR_2,3:props", result.getParameters().get(processorId + ".param.file"));
    assertEquals(Integer.valueOf(3), result.getExit().getExitCode());
    assertTrue(result.getExit().isStop());
    assertFalse(result.getExit().isSkip());

    result = ProcessResult.getResultParameters(conf, gep.getParameters().getMap(), false, 11, null);
    assertEquals("image/jpeg", result.getParameters().get(processorId + ".param.mime"));
    assertEquals("ERR_>10:props", result.getParameters().get(processorId + ".param.file"));
    assertEquals(Integer.valueOf(11), result.getExit().getExitCode());
    assertFalse(result.getExit().isStop());
    assertFalse(result.getExit().isSkip());

    result = ProcessResult.getResultParameters(conf, gep.getParameters().getMap(), false, -1, null);
    assertEquals("image/jpeg", result.getParameters().get(processorId + ".param.mime"));
    assertEquals("ERR_*:props", result.getParameters().get(processorId + ".param.file"));
    assertEquals(Integer.valueOf(-1), result.getExit().getExitCode());
    assertTrue(result.getExit().isStop());
    assertFalse(result.getExit().isSkip());

    result = ProcessResult.getResultParameters(conf, gep.getParameters().getMap(), true, 0, null);
    assertEquals("image/jpeg", result.getParameters().get(processorId + ".param.mime"));
    assertEquals("SKIPPED:props", result.getParameters().get(processorId + ".param.file"));
    assertFalse(result.getExit().isStop());
    assertTrue(result.getExit().isSkip());
}