private static void initializeHystrixSettings() { hystrixConfig = ConfigurationManager.getConfigInstance(); hystrixConfig.setProperty(CORE_SIZE_CONFIG, "20"); hystrixConfig.setProperty(MAX_QUEUE_SIZE_CONFIG, "20"); hystrixConfig.setProperty(QUEUE_REJECTION_THRESHOLD_CONFIG, "10"); hystrixConfig.setProperty(COLLAPSER_TIMER_DELAY, "50"); }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { AbstractConfiguration conf = WebConfig.getConfig(); for (Iterator<String> it = conf.getKeys(); it.hasNext(); ) { String key = it.next(); String value = conf.getString(key); request.setAttribute(key, value); } chain.doFilter(request, response); }
@Before public void setUp() { AbstractConfiguration.setDefaultListDelimiter(','); clearSystemProperties(); this.configurationHelper = new ConfigurationHelper(); this.test1Properties = new HashMap<String, String>() { { this.put("a.b.c", "efgh"); this.put("a.b.d", "1234"); } }; this.test3Properties = new HashMap<String, String>() { { this.put("a.b.c", "jklm"); this.put("e.f.h", "90123"); // The value in the file is "foo,bar" but AbstractConfiguration.getString(key) only // returns // the first item in a collection. this.put("i.j.k", "foo"); } }; }
@Test public void testFromSystem_containsListValues() throws Exception { AbstractConfiguration.setDefaultListDelimiter('|'); Map<String, String> properties = Maps.newHashMap(); properties.put("testProperty", "b,bee"); for (Entry<String, String> entry : properties.entrySet()) { System.setProperty(entry.getKey(), entry.getValue()); } Splitter splitter = Splitter.on(','); Configuration systemConfiguration = configurationHelper.fromSystem(); for (Entry<String, String> entry : properties.entrySet()) { String[] actualValues = systemConfiguration.getStringArray(entry.getKey()); String[] expectedValues; if ("line.separator".equals(entry.getKey())) { expectedValues = new String[] {SystemUtils.LINE_SEPARATOR}; } else { expectedValues = splitter.splitToList(entry.getValue()).toArray(new String[0]); } assertArrayEquals( String.format("Values for key %s do not match", entry.getKey()), expectedValues, actualValues); } }
/** * Asserts that reading list values from a properties file works properly when the default list * delimiter is modified. */ @Test public void testFromFile_listValuesWithDefaultDelimiterChanged() throws Exception { AbstractConfiguration.setDefaultListDelimiter('|'); Configuration configuration = configurationHelper.fromFile( ConfigurationHelperTest.class.getResource("props/test3.properties")); assertPropertiesEquals(test3Properties, configuration); String[] stringArray = configuration.getStringArray("i.j.k"); assertArrayEquals(new String[] {"foo", "bar"}, stringArray); }
@Test public void testDataStorage() throws IllegalDataStorageTypeException, IllegalDataStorageException { DataStorage dataStorage = DataStorageManager.newDataStorage("test"); assert dataStorage instanceof TestDataStorage; // get eagle.storage.type (value: test) from src/test/resources/config.properties DataStorage dataStorage2 = DataStorageManager.getDataStorageByEagleConfig(); assert dataStorage2 instanceof TestDataStorage; AbstractConfiguration configuration = new CombinedConfiguration(); configuration.addProperty(DataStorageManager.EAGLE_STORAGE_TYPE, "test"); DataStorage dataStorage3 = DataStorageManager.newDataStorage(configuration); assert dataStorage3 instanceof TestDataStorage; Properties properties = new Properties(); properties.put(DataStorageManager.EAGLE_STORAGE_TYPE, "test"); DataStorage dataStorage4 = DataStorageManager.newDataStorage(properties); assert dataStorage4 instanceof TestDataStorage; }
public static void addApplicationContext(ConfigurableApplicationContext context) { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); config.clearProperty(APPLICATION_CONTEXT); config.setProperty(APPLICATION_CONTEXT, context); }
public void processQueries(String instanceName, String xmlFile) { XMLConfiguration config = null; /** clear'em out */ if (collectionQueries.get(instanceName) != null) { collectionQueries.get(instanceName).clear(); } if (relationshipQueries.get(instanceName) != null) { relationshipQueries.get(instanceName).clear(); } if (jdbcDriver != null) { jdbcDriver = null; } if (validationQuery != null) { validationQuery = null; } if (url != null) { url = null; } try { /** * use strange ethiopic unicode character so that it never delimits the properties * * <p>This is a workaround becuase config.setDelimiterParsingDisabled(true) doesn't disable * parsing */ AbstractConfiguration.setDefaultListDelimiter('\u12BF'); config = new XMLConfiguration(xmlFile); config.setDelimiterParsingDisabled(true); Map<String, String> instanceCollectionQueryMap = new TreeMap<String, String>(); Map<String, String> instanceRelationshipQueryMap = new TreeMap<String, String>(); Map<String, String> instanceAttributeQueryMap = new TreeMap<String, String>(); @SuppressWarnings("unchecked") List<HierarchicalConfiguration> params = config.configurationsAt("configuration"); for (HierarchicalConfiguration param : params) { this.jdbcDriver = param.getString("driver"); this.validationQuery = param.getString("validationquery"); this.url = param.getString("url"); this.cycleTimeOffset = param.getInt("cycletimeoffset"); if (log.isDebugEnabled()) { log.debug("jdbcDriver:" + param.getString("driver")); log.debug("validationQuery:" + param.getString("validationquery")); log.debug("url:" + param.getString("url")); log.debug("cycleTimeOffset:" + param.getInt("cycletimeoffset")); } } @SuppressWarnings("unchecked") List<HierarchicalConfiguration> queries = config.configurationsAt("queries.query"); for (HierarchicalConfiguration sub : queries) { String name = sub.getString("name"); String type = sub.getString("type"); String sql = sub.getString("sql"); if (type.equalsIgnoreCase("collection")) { instanceCollectionQueryMap.put(name, sql); } else if (type.equalsIgnoreCase("relationship")) { instanceRelationshipQueryMap.put(name, sql); } else if (type.equalsIgnoreCase("attribute")) { instanceAttributeQueryMap.put(name, sql); } } collectionQueries.put(instanceName, instanceCollectionQueryMap); relationshipQueries.put(instanceName, instanceRelationshipQueryMap); attributeQueries.put(instanceName, instanceAttributeQueryMap); } catch (ConfigurationException e) { log.error(e); } }