com.alibaba.dubbo.registry.common.route.RouteRuleUtils Java Examples

The following examples show how to use com.alibaba.dubbo.registry.common.route.RouteRuleUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #2
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #3
Source File: RouteRuleUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #4
Source File: RouteRuleUtilsTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #5
Source File: RouteRuleUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #6
Source File: RouteRuleUtilsTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #7
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #8
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #9
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_filterServiceByRule()throws Exception {
     List<String> services = new ArrayList<String>();
     services.add("com.alibaba.MemberService");
     services.add("com.alibaba.ViewCacheService");
     services.add("com.alibaba.PC2Service");
     services.add("service2");
     
     Route route = new Route();
     route.setMatchRule("service=com.alibaba.*,AuthService&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
     route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
     RouteRule rr = RouteRule.parse(route);
     Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
     assertEquals(3,changedService.size());
}
 
Example #10
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
 public void test_filterServiceByRule2()throws Exception {
  List<String> services = new ArrayList<String>();
  services.add("com.alibaba.MemberService");
  services.add("com.alibaba.ViewCacheService");
  services.add("com.alibaba.PC2Service");
  services.add("service2");
  
  Route route = new Route();
  route.setMatchRule("service=com.alibaba.PC2Service&service!=com.alibaba.DomainService,com.alibaba.ViewCacheService&consumer.host!=127.0.0.1,15.11.57.6&consumer.version = 2.0.0&consumer.version != 1.0.0");
  route.setFilterRule("provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020");
  RouteRule rr = RouteRule.parse(route);
  Collection<String> changedService = RouteRuleUtils.filterServiceByRule(services, rr);
  assertEquals(2,changedService.size());
}
 
Example #11
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void test_isMatchCondition()throws Exception {
    Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>();
    Map<String, String> valueParams = new HashMap<String, String>();
    Map<String, String> kv = new HashMap<String, String>();
    
    boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    {
        // key1
        Set<String> matches   = new HashSet<String>();
        matches.add("value1_1");
        matches.add("value1_2");
        matches.add("value1_3");
        Set<String> unmatches = new HashSet<String>();
        unmatches.add("v1_1");
        unmatches.add("v1_2");
        unmatches.add("v1_3");
        
        RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key1", p);
        
        // key2 
        matches   = new HashSet<String>();
        matches.add("value2_1");
        matches.add("value2_2");
        matches.add("value2_3");
        unmatches = new HashSet<String>();
        unmatches.add("v2_1");
        unmatches.add("v2_2");
        unmatches.add("v2_3");
        
        p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key2", p);
    }
    
    kv.put("kkk", "vvv");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "vvvXXX");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "value1_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key2", "value2_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    kv.put("key1", "v1_2");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
}
 
Example #12
Source File: RouteRuleUtilsTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@Test
public void test_isMatchCondition()throws Exception {
    Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>();
    Map<String, String> valueParams = new HashMap<String, String>();
    Map<String, String> kv = new HashMap<String, String>();
    
    boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    {
        // key1
        Set<String> matches   = new HashSet<String>();
        matches.add("value1_1");
        matches.add("value1_2");
        matches.add("value1_3");
        Set<String> unmatches = new HashSet<String>();
        unmatches.add("v1_1");
        unmatches.add("v1_2");
        unmatches.add("v1_3");
        
        RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key1", p);
        
        // key2 
        matches   = new HashSet<String>();
        matches.add("value2_1");
        matches.add("value2_2");
        matches.add("value2_3");
        unmatches = new HashSet<String>();
        unmatches.add("v2_1");
        unmatches.add("v2_2");
        unmatches.add("v2_3");
        
        p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key2", p);
    }
    
    kv.put("kkk", "vvv");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "vvvXXX");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "value1_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key2", "value2_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    kv.put("key1", "v1_2");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
}
 
Example #13
Source File: RouteRuleUtilsTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@Test
public void test_isMatchCondition()throws Exception {
    Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>();
    Map<String, String> valueParams = new HashMap<String, String>();
    Map<String, String> kv = new HashMap<String, String>();
    
    boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    {
        // key1
        Set<String> matches   = new HashSet<String>();
        matches.add("value1_1");
        matches.add("value1_2");
        matches.add("value1_3");
        Set<String> unmatches = new HashSet<String>();
        unmatches.add("v1_1");
        unmatches.add("v1_2");
        unmatches.add("v1_3");
        
        RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key1", p);
        
        // key2 
        matches   = new HashSet<String>();
        matches.add("value2_1");
        matches.add("value2_2");
        matches.add("value2_3");
        unmatches = new HashSet<String>();
        unmatches.add("v2_1");
        unmatches.add("v2_2");
        unmatches.add("v2_3");
        
        p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key2", p);
    }
    
    kv.put("kkk", "vvv");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "vvvXXX");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "value1_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key2", "value2_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    kv.put("key1", "v1_2");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
}
 
Example #14
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void test_isMatchCondition()throws Exception {
    Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>();
    Map<String, String> valueParams = new HashMap<String, String>();
    Map<String, String> kv = new HashMap<String, String>();
    
    boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    {
        // key1
        Set<String> matches   = new HashSet<String>();
        matches.add("value1_1");
        matches.add("value1_2");
        matches.add("value1_3");
        Set<String> unmatches = new HashSet<String>();
        unmatches.add("v1_1");
        unmatches.add("v1_2");
        unmatches.add("v1_3");
        
        RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key1", p);
        
        // key2 
        matches   = new HashSet<String>();
        matches.add("value2_1");
        matches.add("value2_2");
        matches.add("value2_3");
        unmatches = new HashSet<String>();
        unmatches.add("v2_1");
        unmatches.add("v2_2");
        unmatches.add("v2_3");
        
        p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key2", p);
    }
    
    kv.put("kkk", "vvv");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "vvvXXX");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "value1_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key2", "value2_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    kv.put("key1", "v1_2");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
}
 
Example #15
Source File: RouteRuleUtilsTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void test_isMatchCondition()throws Exception {
    Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>();
    Map<String, String> valueParams = new HashMap<String, String>();
    Map<String, String> kv = new HashMap<String, String>();
    
    boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    {
        // key1
        Set<String> matches   = new HashSet<String>();
        matches.add("value1_1");
        matches.add("value1_2");
        matches.add("value1_3");
        Set<String> unmatches = new HashSet<String>();
        unmatches.add("v1_1");
        unmatches.add("v1_2");
        unmatches.add("v1_3");
        
        RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key1", p);
        
        // key2 
        matches   = new HashSet<String>();
        matches.add("value2_1");
        matches.add("value2_2");
        matches.add("value2_3");
        unmatches = new HashSet<String>();
        unmatches.add("v2_1");
        unmatches.add("v2_2");
        unmatches.add("v2_3");
        
        p = new RouteRule.MatchPair(matches, unmatches);
        condition.put("key2", p);
    }
    
    kv.put("kkk", "vvv");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "vvvXXX");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key1", "value1_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
    
    kv.put("key2", "value2_1");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertTrue(output);
    
    kv.put("key1", "v1_2");
    output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv);
    assertFalse(output);
}