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

The following examples show how to use org.apache.commons.configuration2.Configuration#setProperty() . 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: PersistedInputOutputRDDIntegrateTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotHaveDanglingPersistedComputeRDDs() throws Exception {
    Spark.create("local[4]");
    final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDIntegrateTest.class, UUID.randomUUID().toString());
    final Configuration configuration = super.getBaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
    configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
    Graph graph = GraphFactory.open(configuration);
    ///
    assertEquals(6, graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)).V().out().count().next().longValue());
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(0, Spark.getContext().getPersistentRDDs().size());
    //
    assertEquals(2, graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)).V().out().out().count().next().longValue());
    assertFalse(Spark.hasRDD(Constants.getGraphLocation(rddName)));
    assertEquals(0, Spark.getContext().getPersistentRDDs().size());
    ///////
    Spark.close();
}
 
Example 2
Source File: SparkContextStorage.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<Vertex> head(final String location, final Class readerClass, final int totalLines) {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, location);
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, readerClass.getCanonicalName());
    try {
        if (InputRDD.class.isAssignableFrom(readerClass)) {
            return IteratorUtils.map(((InputRDD) readerClass.getConstructor().newInstance()).readGraphRDD(configuration, new JavaSparkContext(Spark.getContext())).take(totalLines).iterator(), tuple -> tuple._2().get());
        } else if (InputFormat.class.isAssignableFrom(readerClass)) {
            return IteratorUtils.map(new InputFormatRDD().readGraphRDD(configuration, new JavaSparkContext(Spark.getContext())).take(totalLines).iterator(), tuple -> tuple._2().get());
        }
    } catch (final Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    throw new IllegalArgumentException("The provided parserClass must be an " + InputFormat.class.getCanonicalName() + " or an " + InputRDD.class.getCanonicalName() + ": " + readerClass.getCanonicalName());
}
 
Example 3
Source File: TestConfigurationPropertiesFactoryBean.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
@Test
public void testMergeConfigurations() throws Exception
{
    final Configuration one = new BaseConfiguration();
    one.setProperty("foo", "bar");
    final String properties =
            "## some header \n" + "foo = bar1\n" + "bar = foo\n";

    final PropertiesConfiguration two = new PropertiesConfiguration();
    final PropertiesConfigurationLayout layout =
            new PropertiesConfigurationLayout();
    layout.load(two, new StringReader(properties));

    configurationFactory.setConfigurations(one, two);
    configurationFactory.afterPropertiesSet();
    final Properties props = configurationFactory.getObject();
    Assert.assertEquals("foo", props.getProperty("bar"));
    Assert.assertEquals("bar", props.getProperty("foo"));
}
 
Example 4
Source File: OutputRDDTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldWriteToArbitraryRDD() throws Exception {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern-v3d0.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, ExampleOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldWriteToArbitraryRDD"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    ////////
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
}
 
Example 5
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistWithRelativePath() {
    final String graphLocation = TestHelper.convertToRelative(TinkerGraphTest.class,
                                                              TestHelper.makeTestDataPath(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 6
Source File: GraphFactoryTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldOpenWithFactoryViaConcreteClass() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(Graph.GRAPH, MockGraphWithFactory.class.getName());
    GraphFactory.open(conf);
    final MockGraphWithFactory g = (MockGraphWithFactory) GraphFactory.open(conf);
    assertEquals(conf, g.getConf());
}
 
Example 7
Source File: DSWorkbenchTroopsFrame.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public void storeCustomProperties(Configuration pConfig) {
  pConfig.setProperty(getPropertyPrefix() + ".menu.visible", centerPanel.isMenuVisible());
  pConfig.setProperty(getPropertyPrefix() + ".alwaysOnTop", jTroopsInformationAlwaysOnTop.isSelected());

  int selectedIndex = jTroopsTabPane.getModel().getSelectedIndex();
  if (selectedIndex >= 0) {
    pConfig.setProperty(getPropertyPrefix() + ".tab.selection", selectedIndex);
  }


  TroopTableTab tab = ((TroopTableTab) jTroopsTabPane.getComponentAt(0));
  PropertyHelper.storeTableProperties(tab.getTroopTable(), pConfig, getPropertyPrefix());
}
 
Example 8
Source File: VertexProgramHelper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static void serialize(final Object object, final Configuration configuration, final String key) {
    try {
        configuration.setProperty(key, Base64.getEncoder().encodeToString(Serializer.serializeObject(object)));
    } catch (final IOException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
Example 9
Source File: GraphFactoryTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldOpenViaConfiguration() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(Graph.GRAPH, MockGraph.class.getName());
    conf.setProperty("keep", "it");
    GraphFactory.open(conf);
    final MockGraph g = (MockGraph) GraphFactory.open(conf);
    assertEquals(MockGraph.class.getName(), g.getConf().getString(Graph.GRAPH));
    assertEquals("it", g.getConf().getString("keep"));
}
 
Example 10
Source File: PageRankVertexProgram.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void storeState(final Configuration configuration) {
    VertexProgram.super.storeState(configuration);
    configuration.setProperty(ALPHA, this.alpha);
    configuration.setProperty(EPSILON, this.epsilon);
    configuration.setProperty(PROPERTY, this.property);
    configuration.setProperty(MAX_ITERATIONS, this.maxIterations);
    if (null != this.edgeTraversal)
        this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL);
    if (null != this.initialRankTraversal)
        this.initialRankTraversal.storeState(configuration, INITIAL_RANK_TRAVERSAL);
}
 
Example 11
Source File: DSWorkbenchAttackFrame.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public void storeCustomProperties(Configuration pConfig) {
    pConfig.setProperty(getPropertyPrefix() + ".menu.visible", centerPanel.isMenuVisible());
    pConfig.setProperty(getPropertyPrefix() + ".alwaysOnTop", jAttackFrameAlwaysOnTop.isSelected());

    int selectedIndex = jAttackTabPane.getModel().getSelectedIndex();
    if (selectedIndex >= 0) {
        pConfig.setProperty(getPropertyPrefix() + ".tab.selection", selectedIndex);
    }

    AttackTableTab tab = ((AttackTableTab) jAttackTabPane.getComponentAt(0));
    PropertyHelper.storeTableProperties(tab.getAttackTable(), pConfig, getPropertyPrefix());
}
 
Example 12
Source File: DSWorkbenchFormFrame.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
@Override
public void storeCustomProperties(Configuration pConfig) {
    pConfig.setProperty(getPropertyPrefix() + ".menu.visible", centerPanel.isMenuVisible());
    pConfig.setProperty(getPropertyPrefix() + ".alwaysOnTop", jAlwaysOnTop.isSelected());
    
    PropertyHelper.storeTableProperties(jFormsTable, pConfig, getPropertyPrefix());
}
 
Example 13
Source File: TestFileBasedConfigurationBuilder.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Tests whether a configuration can be created and associated with a file that does
 * not yet exist. Later the configuration is saved to this file.
 */
@Test
public void testCreateConfigurationNonExistingFileAndThenSave()
        throws ConfigurationException {
    final File outFile = ConfigurationAssert.getOutFile("save.properties");
    final Parameters parameters = new Parameters();
    final FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(
            PropertiesConfiguration.class, null, true).configure(parameters
            .properties().setFile(outFile));
    final Configuration config = builder.getConfiguration();
    config.setProperty(PROP, 1);
    builder.save();
    checkSavedConfig(outFile, 1);
    assertTrue("Could not remove test file", outFile.delete());
}
 
Example 14
Source File: GraphFactoryTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateAnEmptyGraphInstance() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(Graph.GRAPH, EmptyGraph.class.getName());
    final Graph graph = GraphFactory.open(conf);
    assertSame(EmptyGraph.instance(), graph);
}
 
Example 15
Source File: TinkerFactory.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Create the "the crew" graph which is a TinkerPop 3.x toy graph showcasing many 3.x features like meta-properties,
 * multi-properties and graph variables.
 */
public static TinkerGraph createTheCrew() {
    final Configuration conf = getNumberIdManagerConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name());
    final TinkerGraph g = TinkerGraph.open(conf);
    generateTheCrew(g);
    return g;
}
 
Example 16
Source File: TinkerIoRegistryV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: TinkerFactory.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static Configuration getNumberIdManagerConfiguration() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name());
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_EDGE_ID_MANAGER, TinkerGraph.DefaultIdManager.INTEGER.name());
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_VERTEX_PROPERTY_ID_MANAGER, TinkerGraph.DefaultIdManager.LONG.name());
    return conf;
}
 
Example 18
Source File: GraphFactoryTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void shouldThrowExceptionIfGraphKeyIsNotValidClassInConfiguration() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty(Graph.GRAPH, "not.a.real.class.that.is.a.SomeGraph");
    GraphFactory.open(conf);
}
 
Example 19
Source File: DSWorkbenchSOSRequestAnalyzer.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
@Override
public void storeCustomProperties(Configuration pConfig) {
    pConfig.setProperty(getPropertyPrefix() + ".menu.visible", centerPanel.isMenuVisible());
    pConfig.setProperty(getPropertyPrefix() + ".alwaysOnTop", jAlwaysOnTopBox.isSelected());
    PropertyHelper.storeTableProperties(jAttacksTable, pConfig, getPropertyPrefix());
}
 
Example 20
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@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);
}