Example usage for org.apache.commons.configuration Configuration setProperty

List of usage examples for org.apache.commons.configuration Configuration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration setProperty.

Prototype

void setProperty(String key, Object value);

Source Link

Document

Set a property, this will replace any previously set values.

Usage

From source file:org.apache.qpid.server.virtualhost.VirtualHostImplTest.java

private VirtualHost createVirtualHostUsingStoreType(String virtualHostName)
        throws ConfigurationException, Exception {
    Broker broker = BrokerTestHelper.createBrokerMock();
    _virtualHostRegistry = broker.getVirtualHostRegistry();

    Configuration config = new PropertiesConfiguration();
    config.setProperty("store.type", MemoryMessageStore.TYPE);
    VirtualHostConfiguration configuration = new VirtualHostConfiguration(virtualHostName, config, broker);
    VirtualHost host = new VirtualHostImpl(_virtualHostRegistry, mock(StatisticsGatherer.class),
            new SecurityManager(null), configuration);
    _virtualHostRegistry.registerVirtualHost(host);
    return host;/*from   w ww.j a  v a2  s  . co  m*/
}

From source file:org.apache.servicecomb.edge.core.EdgeBootListener.java

@Override
public void onBootEvent(BootEvent event) {
    if (!EventType.BEFORE_PRODUCER_PROVIDER.equals(event.getEventType())) {
        return;/*www . j  a v a 2s  .  c o m*/
    }

    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.");
}

From source file:org.apache.servicecomb.springboot.starter.transport.RestServletInitializer.java

@SuppressWarnings("try")
@Override//from w w  w. j  a v  a  2  s  .  c  o  m
public void onStartup(ServletContext servletContext) throws ServletException {
    if (getPort() == 0) {
        LOGGER.warn(
                "spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
        return;
    }

    // web container did not did listen now.
    // so mock to listen, and then close.
    try (ServerSocket ss = new ServerSocket(getPort(), 0, getAddress())) {
        if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
            // ensure the servlet will be instantiated
            Configuration configuration = (Configuration) DynamicPropertyFactory
                    .getBackingConfigurationSource();
            configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
        }

        ServletUtils.init(servletContext);
    } catch (IOException e) {
        throw new ServletException(e);
    }
}

From source file:org.apache.servicecomb.springboot.starter.transport.TestRestServletInitializer.java

@Before
public void setUp() throws Exception {
    Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
    configuration.clearProperty(ServletConfig.KEY_SERVLET_URL_PATTERN);
    configuration.setProperty(ServletConfig.SERVICECOMB_REST_ADDRESS, LISTEN_ADDRESS);

    PowerMockito.mockStatic(NetUtils.class);
    PowerMockito.when(NetUtils.parseIpPortFromURI(anyString()))
            .thenReturn(new IpPort(LISTEN_ADDRESS, TEST_PORT));
    PowerMockito.when(NetUtils.canTcpListen(anyObject(), anyInt())).thenReturn(false);
}

From source file:org.apache.servicecomb.springboot.starter.transport.TestRestServletInitializer.java

@Test
public void testOnStartup() throws Exception {
    Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
    String urlPattern = "/rest/*";
    configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, urlPattern);

    ServletContext servletContext = mock(ServletContext.class);
    Dynamic dynamic = mock(Dynamic.class);
    when(servletContext.addServlet(RestServletInjector.SERVLET_NAME, RestServlet.class)).thenReturn(dynamic);

    RestServletInitializer restServletInitializer = new RestServletInitializer();
    restServletInitializer.setPort(TEST_PORT);
    restServletInitializer.onStartup(servletContext);

    verify(dynamic).setAsyncSupported(true);
    verify(dynamic).addMapping(urlPattern);
    verify(dynamic).setLoadOnStartup(0);
}

From source file:org.apache.servicecomb.springboot2.starter.servlet.RestServletInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    if (factory.getPort() == 0) {
        LOGGER.warn(// w w  w  .jav  a 2s .com
                "spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
        return;
    }

    // web container did not did listen now.
    // so mock to listen, and then close.
    try (ServerSocket ss = new ServerSocket(factory.getPort(), 0, factory.getAddress())) {
        if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
            // ensure the servlet will be instantiated
            Configuration configuration = (Configuration) DynamicPropertyFactory
                    .getBackingConfigurationSource();
            configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
        }

        ServletUtils.init(servletContext);
    } catch (IOException e) {
        throw new ServletException(e);
    }
}

From source file:org.apache.tinkerpop.gremlin.AbstractGraphProvider.java

@Override
public Configuration newGraphConfiguration(final String graphName, final Class<?> test,
        final String testMethodName, final Map<String, Object> configurationOverrides,
        final LoadGraphWith.GraphData loadGraphWith) {
    final Configuration conf = new BaseConfiguration();
    getBaseConfiguration(graphName, test, testMethodName, loadGraphWith).entrySet().stream()
            .forEach(e -> conf.setProperty(e.getKey(), e.getValue()));

    // assign overrides but don't allow gremlin.graph setting to be overridden.  the test suite should
    // not be able to override that.
    configurationOverrides.entrySet().stream().filter(c -> !c.getKey().equals(Graph.GRAPH))
            .forEach(e -> conf.setProperty(e.getKey(), e.getValue()));
    return conf;/*from  w w w . ja v  a  2s.  c  o m*/
}

From source file:org.apache.tinkerpop.gremlin.driver.SettingsTest.java

@Test
public void shouldCreateFromConfiguration() {
    final Configuration conf = new BaseConfiguration();
    conf.setProperty("port", 8000);
    conf.setProperty("nioPoolSize", 16);
    conf.setProperty("workerPoolSize", 32);
    conf.setProperty("username", "user1");
    conf.setProperty("password", "password1");
    conf.setProperty("jaasEntry", "JaasIt");
    conf.setProperty("protocol", "protocol0");
    conf.setProperty("hosts", Arrays.asList("255.0.0.1", "255.0.0.2", "255.0.0.3"));
    conf.setProperty("serializer.className", "my.serializers.MySerializer");
    conf.setProperty("serializer.config.any", "thing");
    conf.setProperty("connectionPool.enableSsl", true);
    conf.setProperty("connectionPool.trustCertChainFile", "pem");
    conf.setProperty("connectionPool.minSize", 100);
    conf.setProperty("connectionPool.maxSize", 200);
    conf.setProperty("connectionPool.minSimultaneousUsagePerConnection", 300);
    conf.setProperty("connectionPool.maxSimultaneousUsagePerConnection", 400);
    conf.setProperty("connectionPool.maxInProcessPerConnection", 500);
    conf.setProperty("connectionPool.minInProcessPerConnection", 600);
    conf.setProperty("connectionPool.maxWaitForConnection", 700);
    conf.setProperty("connectionPool.maxContentLength", 800);
    conf.setProperty("connectionPool.reconnectInterval", 900);
    conf.setProperty("connectionPool.reconnectInitialDelay", 1000);
    conf.setProperty("connectionPool.resultIterationBatchSize", 1100);
    conf.setProperty("connectionPool.channelizer", "channelizer0");

    final Settings settings = Settings.from(conf);

    assertEquals(8000, settings.port);/*w ww  . j a v a  2 s  .  c  o  m*/
    assertEquals(16, settings.nioPoolSize);
    assertEquals(32, settings.workerPoolSize);
    assertEquals("user1", settings.username);
    assertEquals("password1", settings.password);
    assertEquals("JaasIt", settings.jaasEntry);
    assertEquals("protocol0", settings.protocol);
    assertEquals("my.serializers.MySerializer", settings.serializer.className);
    assertEquals("thing", settings.serializer.config.get("any"));
    assertEquals(true, settings.connectionPool.enableSsl);
    assertEquals("pem", settings.connectionPool.trustCertChainFile);
    assertEquals(100, settings.connectionPool.minSize);
    assertEquals(200, settings.connectionPool.maxSize);
    assertEquals(300, settings.connectionPool.minSimultaneousUsagePerConnection);
    assertEquals(400, settings.connectionPool.maxSimultaneousUsagePerConnection);
    assertEquals(500, settings.connectionPool.maxInProcessPerConnection);
    assertEquals(600, settings.connectionPool.minInProcessPerConnection);
    assertEquals(700, settings.connectionPool.maxWaitForConnection);
    assertEquals(800, settings.connectionPool.maxContentLength);
    assertEquals(900, settings.connectionPool.reconnectInterval);
    assertEquals(1000, settings.connectionPool.reconnectInitialDelay);
    assertEquals(1100, settings.connectionPool.resultIterationBatchSize);
    assertEquals("channelizer0", settings.connectionPool.channelizer);
}

From source file:org.apache.tinkerpop.gremlin.hadoop.process.computer.spark.io.InputOutputRDDTest.java

@Test
public void shouldReadFromWriteToArbitraryRDD() throws Exception {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer");
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_RDD,
            ExampleInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_RDD,
            ExampleOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, "hadoop-gremlin/target/test-output");
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    //////////from  ww w . j  a  v  a2 s .  c o m
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class).result(GraphComputer.ResultGraph.NEW)
            .persist(
                    GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(
                            GraphTraversalSource.build()
                                    .engine(ComputerTraversalEngine.build().computer(SparkGraphComputer.class)),
                            "gremlin-groovy", "g.V()")
                    .create(graph))
            .submit().get();
}

From source file:org.apache.tinkerpop.gremlin.hadoop.process.computer.spark.io.InputRDDTest.java

@Test
public void shouldReadFromArbitraryRDD() {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer");
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_RDD,
            ExampleInputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_FORMAT,
            GryoOutputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, "hadoop-gremlin/target/test-output");
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    /////////* w w  w . j a v  a 2s  .c om*/
    Graph graph = GraphFactory.open(configuration);
    assertEquals(Double.valueOf(123.0d), graph
            .traversal(GraphTraversalSource.computer(SparkGraphComputer.class)).V().values("age").sum().next());
    assertEquals(Long.valueOf(4l),
            graph.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)).V().count().next());
}