ThrottlingPropertiesConfiguration extends AbstractThrottlingConfiguration { @PostConstruct void initProps() { Assert.notNull(env, "env must not be null"); int defaultInterval = DEFAULT_INTERVAL; int defaultLimit = DEFAULT_LIMIT; List<String> propNames = new ArrayList<String>(); for (String propName : Tools.getAllKnownPropertyNames(env)) { if (propName.startsWith(PROPERTY_PREFIX)) { switch (propName) { case DEFAULT_INTERVAL_PROP: defaultInterval = Integer.valueOf(env.getProperty(DEFAULT_INTERVAL_PROP)); break; case DEFAULT_LIMIT_PROP: defaultLimit = Integer.valueOf(env.getProperty(DEFAULT_LIMIT_PROP)); break; default: propNames.add(propName); break; } } } addProperty(ThrottleScope.ANY_SOURCE_SYSTEM, ThrottleScope.ANY_SERVICE, defaultInterval, defaultLimit); for (String propName : propNames) { String[] nameParts = StringUtils.split(propName, ThrottleScope.THROTTLE_SEPARATOR); if (nameParts.length != 3) { throw new IllegalStateException("throttling property name must have exactly 3 parts, " + "e.g. 'throttling.crm.setActivityExt'"); } String propValue = env.getProperty(propName); String[] valueParts = StringUtils.split(propValue, ThrottleProps.PROP_VALUE_SEPARATOR); int limit = Integer.valueOf(valueParts[0]); int interval = defaultInterval; if (valueParts.length > 1) { interval = Integer.valueOf(valueParts[1]); } addProperty(nameParts[1], nameParts[2], interval, limit); } } @Autowired  ThrottlingPropertiesConfiguration(ConfigurableEnvironment env);   }
@Test public void testConf() { String prefix = ThrottlingPropertiesConfiguration.PROPERTY_PREFIX; Properties props = new Properties(); props.put(ThrottlingPropertiesConfiguration.DEFAULT_LIMIT_PROP, "5"); props.put(ThrottlingPropertiesConfiguration.DEFAULT_INTERVAL_PROP, "15"); props.put(prefix + "crm.op1", "10"); props.put(prefix + "crm.op2", "10/70"); props.put(prefix + "billing.*", "50"); props.put(prefix + "*.sendSms", "100"); props.put(prefix + "*.sendSms", "100/6"); env.getPropertySources().addFirst(new PropertiesPropertySource("throttling-test", props)); ThrottlingPropertiesConfiguration conf = new ThrottlingPropertiesConfiguration(env); conf.initProps(); assertThrottleProp(conf, "crm", "op1", 10, 15); assertThrottleProp(conf, "crm", "op2", 10, 70); assertThrottleProp(conf, "crm", ThrottleScope.ANY_SERVICE, 10, 15); assertThrottleProp(conf, "crm", "sendSms", 100, 6); assertThrottleProp(conf, "billing", ThrottleScope.ANY_SERVICE, 50, 15); assertThrottleProp(conf, "billing", "activateSubscriber", 50, 15); assertThrottleProp(conf, "billing", "sendSmsWithParams", 50, 15); assertThrottleProp(conf, ThrottleScope.ANY_SOURCE_SYSTEM, "sendSms", 100, 6); assertThrottleProp(conf, "erp", "createDeposit", 5, 15); }