use of com.tencent.polaris.client.pb.RateLimitProto.RateLimit.Builder in project polaris-java by polarismesh.
the class LocalTest method before.
@Before
public void before() {
try {
namingServer = NamingServer.startNamingServer(10081);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
ServiceKey serviceKey = new ServiceKey(Consts.NAMESPACE_TEST, Consts.LOCAL_LIMIT_SERVICE);
namingServer.getNamingService().addService(serviceKey);
Builder rateLimitBuilder = RateLimit.newBuilder();
Rule.Builder ruleBuilder1 = Rule.newBuilder();
ruleBuilder1.setType(Type.LOCAL);
ruleBuilder1.setPriority(UInt32Value.newBuilder().setValue(1).build());
ruleBuilder1.setAction(StringValue.newBuilder().setValue("reject").build());
ruleBuilder1.setAmountMode(AmountMode.GLOBAL_TOTAL);
ruleBuilder1.addAmounts(Amount.newBuilder().setMaxAmount(UInt32Value.newBuilder().setValue(9998).build()).setValidDuration(Duration.newBuilder().setSeconds(1).build()));
ruleBuilder1.setRevision(StringValue.newBuilder().setValue("11111").build());
rateLimitBuilder.addRules(ruleBuilder1.build());
Rule.Builder ruleBuilder2 = Rule.newBuilder();
ruleBuilder2.setType(Type.LOCAL);
ruleBuilder2.setPriority(UInt32Value.newBuilder().setValue(0).build());
ruleBuilder2.setAction(StringValue.newBuilder().setValue("reject").build());
ruleBuilder2.setAmountMode(AmountMode.GLOBAL_TOTAL);
ruleBuilder2.putLabels(Consts.LABEL_METHOD, MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue(Consts.METHOD_CASH).build()).build());
ruleBuilder2.addAmounts(Amount.newBuilder().setMaxAmount(UInt32Value.newBuilder().setValue(1998).build()).setValidDuration(Duration.newBuilder().setSeconds(1).build()));
ruleBuilder2.setRevision(StringValue.newBuilder().setValue("22222").build());
rateLimitBuilder.addRules(ruleBuilder2.build());
Rule.Builder ruleBuilder3 = Rule.newBuilder();
ruleBuilder3.setType(Type.LOCAL);
ruleBuilder3.setPriority(UInt32Value.newBuilder().setValue(0).build());
ruleBuilder3.setAction(StringValue.newBuilder().setValue("reject").build());
ruleBuilder3.setAmountMode(AmountMode.GLOBAL_TOTAL);
ruleBuilder3.putLabels(Consts.LABEL_METHOD, MatchString.newBuilder().setType(MatchStringType.EXACT).setValue(StringValue.newBuilder().setValue(Consts.METHOD_PAY).build()).build());
ruleBuilder3.addAmounts(Amount.newBuilder().setMaxAmount(UInt32Value.newBuilder().setValue(998).build()).setValidDuration(Duration.newBuilder().setSeconds(1).build()));
ruleBuilder3.setRevision(StringValue.newBuilder().setValue("33333").build());
rateLimitBuilder.addRules(ruleBuilder3.build());
rateLimitBuilder.setRevision(StringValue.newBuilder().setValue("xxxxxxx").build());
namingServer.getNamingService().setRateLimit(serviceKey, rateLimitBuilder.build());
}
Aggregations