List of usage examples for org.apache.commons.configuration BaseConfiguration BaseConfiguration
BaseConfiguration
From source file:com.linkedin.pinot.routing.builder.KafkaLowLevelConsumerRoutingTableBuilderTest.java
@Test public void testAllOnlineRoutingTable() { final int ITERATIONS = 1000; Random random = new Random(); KafkaLowLevelConsumerRoutingTableBuilder routingTableBuilder = new KafkaLowLevelConsumerRoutingTableBuilder(); routingTableBuilder.init(new BaseConfiguration()); long totalNanos = 0L; for (int i = 0; i < ITERATIONS; i++) { int instanceCount = random.nextInt(12) + 3; // 3 to 14 instances int partitionCount = random.nextInt(8) + 4; // 4 to 11 partitions int replicationFactor = random.nextInt(3) + 3; // 3 to 5 replicas // Generate instances String[] instanceNames = new String[instanceCount]; for (int serverInstanceId = 0; serverInstanceId < instanceCount; serverInstanceId++) { instanceNames[serverInstanceId] = "Server_localhost_" + serverInstanceId; }/*ww w . j a v a 2 s . c o m*/ // Generate partitions String[][] segmentNames = new String[partitionCount][]; int totalSegmentCount = 0; for (int partitionId = 0; partitionId < partitionCount; partitionId++) { int segmentCount = random.nextInt(32); // 0 to 31 segments in partition segmentNames[partitionId] = new String[segmentCount]; for (int sequenceNumber = 0; sequenceNumber < segmentCount; sequenceNumber++) { segmentNames[partitionId][sequenceNumber] = new LLCSegmentName("table", partitionId, sequenceNumber, System.currentTimeMillis()).getSegmentName(); } totalSegmentCount += segmentCount; } // Generate instance configurations List<InstanceConfig> instanceConfigs = new ArrayList<InstanceConfig>(); for (String instanceName : instanceNames) { InstanceConfig instanceConfig = new InstanceConfig(instanceName); instanceConfigs.add(instanceConfig); instanceConfig.getRecord().setSimpleField(CommonConstants.Helix.IS_SHUTDOWN_IN_PROGRESS, "false"); } // Generate a random external view ExternalView externalView = new ExternalView("table_REALTIME"); int[] segmentCountForInstance = new int[instanceCount]; int maxSegmentCountOnInstance = 0; for (int partitionId = 0; partitionId < segmentNames.length; partitionId++) { String[] segments = segmentNames[partitionId]; // Assign each segment for this partition for (int replicaId = 0; replicaId < replicationFactor; ++replicaId) { for (int segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) { int instanceIndex = -1; int randomOffset = random.nextInt(instanceCount); // Pick the first random instance that has fewer than maxSegmentCountOnInstance segments assigned to it for (int j = 0; j < instanceCount; j++) { int potentialInstanceIndex = (j + randomOffset) % instanceCount; if (segmentCountForInstance[potentialInstanceIndex] < maxSegmentCountOnInstance) { instanceIndex = potentialInstanceIndex; break; } } // All replicas have exactly maxSegmentCountOnInstance, pick a replica and increment the max if (instanceIndex == -1) { maxSegmentCountOnInstance++; instanceIndex = randomOffset; } // Increment the segment count for the instance segmentCountForInstance[instanceIndex]++; // Add the segment to the external view externalView.setState(segmentNames[partitionId][segmentIndex], instanceNames[instanceIndex], "ONLINE"); } } } // Create routing tables long startTime = System.nanoTime(); List<ServerToSegmentSetMap> routingTables = routingTableBuilder .computeRoutingTableFromExternalView("table_REALTIME", externalView, instanceConfigs); long endTime = System.nanoTime(); totalNanos += endTime - startTime; // Check that all routing tables generated match all segments, with no duplicates for (ServerToSegmentSetMap routingTable : routingTables) { Set<String> assignedSegments = new HashSet<String>(); for (String server : routingTable.getServerSet()) { for (String segment : routingTable.getSegmentSet(server)) { assertFalse(assignedSegments.contains(segment)); assignedSegments.add(segment); } } assertEquals(assignedSegments.size(), totalSegmentCount); } } LOGGER.warn("Routing table building avg ms: " + totalNanos / (ITERATIONS * 1000000.0)); }
From source file:edu.cwru.sepia.agent.ScriptedGoalAgentTest.java
@BeforeClass public static void loadTemplates() throws Exception { State.StateBuilder builder = new State.StateBuilder(); state = builder.build();//from w ww. j a va2 s.c om templates = TypeLoader.loadFromFile("../Sepia/data/templates.xml", player, state); System.out.println("Sucessfully loaded templates"); builder.setSize(15, 15); for (Template<?> t : templates) { builder.addTemplate(t); } { Unit u = ((UnitTemplate) builder.getTemplate(player, "Peasant")).produceInstance(state); u.setXPosition(5); u.setYPosition(5); founder = u; builder.addUnit(u, u.getXPosition(), u.getYPosition()); } { ResourceNode rn = new ResourceNode(new ResourceNodeType("GOLD_MINE", new ResourceType("GOLD")), 2, 2, 70000, state.nextTargetId()); builder.addResource(rn); } { ResourceNode rn = new ResourceNode(new ResourceNodeType("TREE", new ResourceType("WOOD")), 1, 1, 70000, state.nextTargetId()); builder.addResource(rn); } planner = new SimplePlanner(state); model = new SimpleModel(state, null, new BaseConfiguration()); }
From source file:co.turnus.analysis.profiler.orcc.code.OrccStaticProfilerOptions.java
public static Configuration getConfiguration(ILaunchConfiguration configuration, String mode) { Configuration conf = new BaseConfiguration(); try {//from w ww.j a va2 s . com conf.setProperty(VERBOSE, mode.equals("debug")); String stmp = configuration.getAttribute(ORCC_PROJECT, ""); conf.setProperty(ORCC_PROJECT, stmp); stmp = configuration.getAttribute(ORCC_XDF, ""); conf.setProperty(ORCC_XDF, stmp); stmp = configuration.getAttribute(VERSIONER, GitVersioner.NAME); conf.setProperty(VERSIONER, stmp); // set the output path stmp = configuration.getAttribute(OUTPUT_PATH_CUSTOM_USE, false) ? configuration.getAttribute(OUTPUT_PATH_CUSTOM_VALUE, "") : ""; setOutputPath(conf, stmp); } catch (Exception e) { throw new TurnusRuntimeException("Error parsing the launch configuration options", e); } return conf; }
From source file:com.comcast.viper.flume2storm.spout.FlumeSpoutTest.java
@BeforeClass public static void configure() { // First Event Sender configuration eventSender1Config = new BaseConfiguration(); eventSender1Config.addProperty(SimpleConnectionParameters.HOSTNAME, "localhost"); eventSender1Config.addProperty(SimpleConnectionParameters.PORT, 7001); // Second Event Sender configuration eventSender2Config = new BaseConfiguration(); eventSender2Config.addProperty(SimpleConnectionParameters.HOSTNAME, "localhost"); eventSender2Config.addProperty(SimpleConnectionParameters.PORT, 7002); // Flume Spout configuration flumeSpoutConfig = new BaseConfiguration(); flumeSpoutConfig.addProperty(FlumeSpoutConfiguration.LOCATION_SERVICE_FACTORY_CLASS, SimpleLocationServiceFactory.class.getName()); flumeSpoutConfig.addProperty(FlumeSpoutConfiguration.SERVICE_PROVIDER_SERIALIZATION_CLASS, SimpleServiceProviderSerialization.class.getName()); flumeSpoutConfig.addProperty(FlumeSpoutConfiguration.EVENT_RECEPTOR_FACTORY_CLASS, SimpleEventReceptorFactory.class.getName()); }
From source file:com.cedarsoft.configuration.xml.ConfigurationAccessTest.java
License:asdf
@Before public void setUp() throws Exception { configuration = new BaseConfiguration(); }
From source file:co.turnus.trace.impl.SimpleTraceLoader.java
@Override public Trace load(TraceProject project) { TraceFactory f = new SimpleTraceFactory(); // create the configuration for this factory Configuration fConf = new BaseConfiguration(); fConf.setProperty(SENS_FSM, getOption(SENS_FSM, true)); fConf.setProperty(SENS_TOKENS, getOption(SENS_TOKENS, true)); fConf.setProperty(SENS_GUARD, getOption(SENS_GUARD, true)); fConf.setProperty(SENS_PORT, getOption(SENS_PORT, true)); fConf.setProperty(SENS_STATEVAR, getOption(SENS_STATEVAR, true)); f.setConfiguration(fConf);// w w w .ja v a2 s . c o m return new XmlTraceReader(project, f).read(); }
From source file:com.cedarsoft.configuration.xml.ConfigBindingGuiceTest.java
License:asdf
@Before public void setUp() throws Exception { injector = Guice.createInjector(new AbstractModule() { @Override//from ww w .j ava 2 s. co m protected void configure() { bind(Configuration.class).toInstance(new BaseConfiguration()); bind(MyBean.class).toProvider(new Provider<MyBean>() { @Inject Configuration configuration; @Override @Nonnull public MyBean get() { MyBean myBean = new MyBean(); BeanAdapter<MyBean> beanAdapter = new BeanAdapter<MyBean>(myBean, true); ConfigurationAccess<String> configurationAccess = new ConfigurationAccess<String>( configuration, String.class, MyBean.PROPERTY_VALUE, "theDefaultValue"); ConfigurationBinding.bind(configurationAccess, beanAdapter.getValueModel(MyBean.PROPERTY_VALUE)); return myBean; } }).in(Scopes.SINGLETON); } }); }
From source file:com.comcast.viper.flume2storm.sink.StormSinkConfigurationTest.java
/** * Test {@link StormSinkConfiguration#from(Configuration)} * * @throws F2SConfigurationException/*from ww w .j a v a 2 s . co m*/ * If the configuration is invalid */ @Test public void testFromConfiguration() throws F2SConfigurationException { int batchSize = 200; String locationServiceFactoryClassName = SimpleLocationServiceFactory.class.getCanonicalName(); String serviceProviderSerializationClassName = SimpleServiceProviderSerialization.class.getCanonicalName(); String eventSenderFactoryClassName = SimpleEventSenderFactory.class.getCanonicalName(); String connectionParametersFactoryClassName = SimpleConnectionParametersFactory.class.getCanonicalName(); Configuration config = new BaseConfiguration(); config.addProperty(StormSinkConfiguration.BATCH_SIZE, batchSize); config.addProperty(StormSinkConfiguration.LOCATION_SERVICE_FACTORY_CLASS, locationServiceFactoryClassName); config.addProperty(StormSinkConfiguration.SERVICE_PROVIDER_SERIALIZATION_CLASS, serviceProviderSerializationClassName); config.addProperty(StormSinkConfiguration.EVENT_SENDER_FACTORY_CLASS, eventSenderFactoryClassName); config.addProperty(StormSinkConfiguration.CONNECTION_PARAMETERS_FACTORY_CLASS, connectionParametersFactoryClassName); StormSinkConfiguration stormSinkConfiguration = StormSinkConfiguration.from(config); Assert.assertEquals(batchSize, stormSinkConfiguration.getBatchSize()); Assert.assertEquals(locationServiceFactoryClassName, stormSinkConfiguration.getLocationServiceFactoryClassName()); Assert.assertEquals(serviceProviderSerializationClassName, stormSinkConfiguration.getServiceProviderSerializationClassName()); Assert.assertEquals(eventSenderFactoryClassName, stormSinkConfiguration.getEventSenderFactoryClassName()); Assert.assertEquals(connectionParametersFactoryClassName, stormSinkConfiguration.getConnectionParametersFactoryClassName()); }
From source file:com.feedzai.fos.impl.r.RIntegrationTest.java
@Test public void addModel() throws Exception { BaseConfiguration configuration = new BaseConfiguration(); Map<String, String> properties = new HashMap<>(); List<Attribute> attributes = getAttributes(); String suuid = "d9556c14-97f1-40f6-9514-f6fb339474af"; UUID uuid = UUID.fromString(suuid); ModelConfig modelConfig = new ModelConfig(attributes, properties); modelConfig.setProperty("UUID", suuid); 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, "svm"); modelConfig.setProperty(RModelConfig.TRAIN_FUNCTION_ARGUMENTS, "probability = TRUE"); modelConfig.setProperty(RModelConfig.PREDICT_FUNCTION_ARGUMENTS, "probability = TRUE"); modelConfig.setProperty(RModelConfig.PREDICT_RESULT_TRANSFORM, "r <- attr(r, 'probabilities')"); configuration.setProperty(FosConfig.FACTORY_NAME, RManagerFactory.class.getName()); FosConfig config = new FosConfig(configuration); RManagerConfig rManagerConfig = new RManagerConfig(config); RManager rManager = new RManager(rManagerConfig); rManager.trainFile(modelConfig, getCwd() + "/credit-a.arff"); rManager.addModel(modelConfig,//from ww w. j av a 2 s . c o m new ModelDescriptor(ModelDescriptor.Format.BINARY, getCwd() + "/credit-a.arff.model")); 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.springrts.springls.ServerConfiguration.java
private static Configuration createDefaults() { Configuration configuration = new BaseConfiguration(); configuration.setProperty(PORT, 8200); configuration.setProperty(NAT_PORT, 8201); configuration.setProperty(LAN_MODE, false); configuration.setProperty(STATISTICS_STORE, false); configuration.setProperty(LAN_ADMIN_USERNAME, "admin"); configuration.setProperty(LAN_ADMIN_PASSWORD, "admin"); configuration.setProperty(CHANNELS_LOG_REGEX, "^%%%%%%%$"); // match no channel configuration.setProperty(ENGINE_VERSION, "*"); // all versions configuration.setProperty(LOBBY_PROTOCOL_VERSION, "0.35"); configuration.setProperty(USE_DATABASE, false); return configuration; }