private Injector createInjector(final Config config, final Optional<LeaderFinder<URIMetadata>> leaderFinder) { final SharedResourcesBroker<ThrottlingServerScopes> topLevelBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, ThrottlingServerScopes.GLOBAL.defaultScopeInstance());
@Test public void test() throws Exception { URL prefix = getClass().getResource("/configStore"); Config config = ConfigFactory.parseMap(ImmutableMap.of( ConfigClientBasedPolicyFactory.CONFIG_KEY_URI_PREFIX_KEY, "simple-" + prefix.toString() )); SharedResourcesBroker<ThrottlingServerScopes> broker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker( ConfigFactory.empty(), ThrottlingServerScopes.GLOBAL.defaultScopeInstance()); ConfigClientBasedPolicyFactory policyFactory = new ConfigClientBasedPolicyFactory(); ThrottlingPolicy policy = policyFactory.createPolicy(new SharedLimiterKey("ConfigBasedPolicyTest/resource1"), broker, config); Assert.assertEquals(policy.getClass(), QPSPolicy.class); Assert.assertEquals(((QPSPolicy) policy).getQps(), 100); policy = policyFactory.createPolicy(new SharedLimiterKey("ConfigBasedPolicyTest/resource2"), broker, config); Assert.assertEquals(policy.getClass(), CountBasedPolicy.class); Assert.assertEquals(((CountBasedPolicy) policy).getCount(), 50); }
private Injector createInjector(final Config config, final Optional<LeaderFinder<URIMetadata>> leaderFinder) { final SharedResourcesBroker<ThrottlingServerScopes> topLevelBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, ThrottlingServerScopes.GLOBAL.defaultScopeInstance());