com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair Java Examples

The following examples show how to use com.alibaba.dubbo.registry.common.route.RouteRule.MatchPair. 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: RouteRuleTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testParse_Simple() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.morgan.*");
    p.unmatches.add("com.alibaba.morgan.MemberService");
    whenParams.put("service", p);

    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.morgan.*&service!=com.alibaba.morgan.MemberService", "provider.host=10.16.26.51"));
}
 
Example #2
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testParse_Simple() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.morgan.*");
    p.unmatches.add("com.alibaba.morgan.MemberService");
    whenParams.put("service", p);

    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.morgan.*&service!=com.alibaba.morgan.MemberService", "provider.host=10.16.26.51"));
}
 
Example #3
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testParse_Simple() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.morgan.*");
    p.unmatches.add("com.alibaba.morgan.MemberService");
    whenParams.put("service", p);

    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.morgan.*&service!=com.alibaba.morgan.MemberService", "provider.host=10.16.26.51"));
}
 
Example #4
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testParse_Simple() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.morgan.*");
    p.unmatches.add("com.alibaba.morgan.MemberService");
    whenParams.put("service", p);

    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.morgan.*&service!=com.alibaba.morgan.MemberService", "provider.host=10.16.26.51"));
}
 
Example #5
Source File: RouteRuleTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testParse_Simple() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.morgan.*");
    p.unmatches.add("com.alibaba.morgan.MemberService");
    whenParams.put("service", p);

    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.morgan.*&service!=com.alibaba.morgan.MemberService", "provider.host=10.16.26.51"));
}
 
Example #6
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_empty() throws Exception {
	Map<String, RouteRule.MatchPair> condtion = RouteRule.parseRule(null);
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("");
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("    ");
    assertEquals(0, condtion.size());
}
 
Example #7
Source File: RouteRuleTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_AllRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    p.unmatches.add("com.alibaba.DomainService");
    p.unmatches.add("com.alibaba.ViewCacheService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    p.unmatches.add("15.11.57.6");
    whenParams.put("consumer.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("2.0.0");
    p.unmatches.add("1.0.0");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,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",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #8
Source File: RouteRuleTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_empty() throws Exception {
	Map<String, RouteRule.MatchPair> condtion = RouteRule.parseRule(null);
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("");
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("    ");
    assertEquals(0, condtion.size());
}
 
Example #9
Source File: RouteRuleTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_complex() throws Exception {
    Map<String, RouteRule.MatchPair> when = RouteRule.parseRule("when1=valueW1 ,valueW1 & when2 = valueW2,valueW3, valueW4 & when2 != valueWu,valueWv & when3!=valueWx,valueWy");
    Map<String, RouteRule.MatchPair> then = RouteRule.parseRule("then1 = valueT1 & then2 = valueT2,valueT3,   valueT4");
    
    Map<String, RouteRule.MatchPair> expectedWhen = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("valueW1");
    expectedWhen.put("when1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueW2");
    p.matches.add("valueW3");
    p.matches.add("valueW4");
    p.unmatches.add("valueWu");
    p.unmatches.add("valueWv");
    expectedWhen.put("when2", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("valueWx");
    p.unmatches.add("valueWy");
    expectedWhen.put("when3", p);
    
    assertEquals(expectedWhen, when);
    
    Map<String, RouteRule.MatchPair> expectedThen = new HashMap<String, RouteRule.MatchPair>();
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT1");
    expectedThen.put("then1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT2");
    p.matches.add("valueT3");
    p.matches.add("valueT4");
    expectedThen.put("then2", p);
    
    assertEquals(expectedThen, then);
}
 
Example #10
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void test_MatchPair_copy() throws Exception {
    MatchPair copy = pair.copy();
    assertEquals(pair, copy);
    
    copy.matches.remove("+a");
    assertFalse(pair.equals(copy));
    
    copy = pair.copy();
    copy.matches.add("+z");
    assertFalse(pair.equals(copy));
}
 
Example #11
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("127.0.0.1");
    p.matches.add("17.58.25.62");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.matches.add("1.0.0");
    p.matches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1,17.58.25.62&consumer.version = 1.0.0,1.0.6",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #12
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MisMatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.unmatches.add("com.alibaba.MemberService");
    p.unmatches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("1.0.0");
    p.unmatches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("morgan");
    p.unmatches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service!=com.alibaba.MemberService,AuthService&consumer.host!=127.0.0.1&consumer.version != 1.0.0,1.0.6",
            		"provider.application!=morgan,pc2&provider.host!=10.16.26.51&provider.port!=1020"));
}
 
Example #13
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_AllRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    p.unmatches.add("com.alibaba.DomainService");
    p.unmatches.add("com.alibaba.ViewCacheService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    p.unmatches.add("15.11.57.6");
    whenParams.put("consumer.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("2.0.0");
    p.unmatches.add("1.0.0");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,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",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #14
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("127.0.0.1");
    p.matches.add("17.58.25.62");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.matches.add("1.0.0");
    p.matches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1,17.58.25.62&consumer.version = 1.0.0,1.0.6",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #15
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_complex() throws Exception {
    Map<String, RouteRule.MatchPair> when = RouteRule.parseRule("when1=valueW1 ,valueW1 & when2 = valueW2,valueW3, valueW4 & when2 != valueWu,valueWv & when3!=valueWx,valueWy");
    Map<String, RouteRule.MatchPair> then = RouteRule.parseRule("then1 = valueT1 & then2 = valueT2,valueT3,   valueT4");
    
    Map<String, RouteRule.MatchPair> expectedWhen = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("valueW1");
    expectedWhen.put("when1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueW2");
    p.matches.add("valueW3");
    p.matches.add("valueW4");
    p.unmatches.add("valueWu");
    p.unmatches.add("valueWv");
    expectedWhen.put("when2", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("valueWx");
    p.unmatches.add("valueWy");
    expectedWhen.put("when3", p);
    
    assertEquals(expectedWhen, when);
    
    Map<String, RouteRule.MatchPair> expectedThen = new HashMap<String, RouteRule.MatchPair>();
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT1");
    expectedThen.put("then1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT2");
    p.matches.add("valueT3");
    p.matches.add("valueT4");
    expectedThen.put("then2", p);
    
    assertEquals(expectedThen, then);
}
 
Example #16
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void test_MatchPair_copy() throws Exception {
    MatchPair copy = pair.copy();
    assertEquals(pair, copy);
    
    copy.matches.remove("+a");
    assertFalse(pair.equals(copy));
    
    copy = pair.copy();
    copy.matches.add("+z");
    assertFalse(pair.equals(copy));
}
 
Example #17
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("127.0.0.1");
    p.matches.add("17.58.25.62");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.matches.add("1.0.0");
    p.matches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1,17.58.25.62&consumer.version = 1.0.0,1.0.6",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #18
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MisMatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.unmatches.add("com.alibaba.MemberService");
    p.unmatches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("1.0.0");
    p.unmatches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("morgan");
    p.unmatches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service!=com.alibaba.MemberService,AuthService&consumer.host!=127.0.0.1&consumer.version != 1.0.0,1.0.6",
            		"provider.application!=morgan,pc2&provider.host!=10.16.26.51&provider.port!=1020"));
}
 
Example #19
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_AllRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    p.unmatches.add("com.alibaba.DomainService");
    p.unmatches.add("com.alibaba.ViewCacheService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    p.unmatches.add("15.11.57.6");
    whenParams.put("consumer.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("2.0.0");
    p.unmatches.add("1.0.0");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,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",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #20
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_empty() throws Exception {
	Map<String, RouteRule.MatchPair> condtion = RouteRule.parseRule(null);
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("");
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("    ");
    assertEquals(0, condtion.size());
}
 
Example #21
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_complex() throws Exception {
    Map<String, RouteRule.MatchPair> when = RouteRule.parseRule("when1=valueW1 ,valueW1 & when2 = valueW2,valueW3, valueW4 & when2 != valueWu,valueWv & when3!=valueWx,valueWy");
    Map<String, RouteRule.MatchPair> then = RouteRule.parseRule("then1 = valueT1 & then2 = valueT2,valueT3,   valueT4");
    
    Map<String, RouteRule.MatchPair> expectedWhen = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("valueW1");
    expectedWhen.put("when1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueW2");
    p.matches.add("valueW3");
    p.matches.add("valueW4");
    p.unmatches.add("valueWu");
    p.unmatches.add("valueWv");
    expectedWhen.put("when2", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("valueWx");
    p.unmatches.add("valueWy");
    expectedWhen.put("when3", p);
    
    assertEquals(expectedWhen, when);
    
    Map<String, RouteRule.MatchPair> expectedThen = new HashMap<String, RouteRule.MatchPair>();
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT1");
    expectedThen.put("then1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT2");
    p.matches.add("valueT3");
    p.matches.add("valueT4");
    expectedThen.put("then2", p);
    
    assertEquals(expectedThen, then);
}
 
Example #22
Source File: RouteRuleTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("127.0.0.1");
    p.matches.add("17.58.25.62");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.matches.add("1.0.0");
    p.matches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1,17.58.25.62&consumer.version = 1.0.0,1.0.6",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #23
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void test_MatchPair_copy() throws Exception {
    MatchPair copy = pair.copy();
    assertEquals(pair, copy);
    
    copy.matches.remove("+a");
    assertFalse(pair.equals(copy));
    
    copy = pair.copy();
    copy.matches.add("+z");
    assertFalse(pair.equals(copy));
}
 
Example #24
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MisMatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.unmatches.add("com.alibaba.MemberService");
    p.unmatches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("1.0.0");
    p.unmatches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("morgan");
    p.unmatches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service!=com.alibaba.MemberService,AuthService&consumer.host!=127.0.0.1&consumer.version != 1.0.0,1.0.6",
            		"provider.application!=morgan,pc2&provider.host!=10.16.26.51&provider.port!=1020"));
}
 
Example #25
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_AllRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    p.unmatches.add("com.alibaba.DomainService");
    p.unmatches.add("com.alibaba.ViewCacheService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    p.unmatches.add("15.11.57.6");
    whenParams.put("consumer.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("2.0.0");
    p.unmatches.add("1.0.0");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,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",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #26
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_empty() throws Exception {
	Map<String, RouteRule.MatchPair> condtion = RouteRule.parseRule(null);
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("");
    assertEquals(0, condtion.size());
    
    condtion = RouteRule.parseRule("    ");
    assertEquals(0, condtion.size());
}
 
Example #27
Source File: RouteRuleTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParseRule_complex() throws Exception {
    Map<String, RouteRule.MatchPair> when = RouteRule.parseRule("when1=valueW1 ,valueW1 & when2 = valueW2,valueW3, valueW4 & when2 != valueWu,valueWv & when3!=valueWx,valueWy");
    Map<String, RouteRule.MatchPair> then = RouteRule.parseRule("then1 = valueT1 & then2 = valueT2,valueT3,   valueT4");
    
    Map<String, RouteRule.MatchPair> expectedWhen = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("valueW1");
    expectedWhen.put("when1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueW2");
    p.matches.add("valueW3");
    p.matches.add("valueW4");
    p.unmatches.add("valueWu");
    p.unmatches.add("valueWv");
    expectedWhen.put("when2", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("valueWx");
    p.unmatches.add("valueWy");
    expectedWhen.put("when3", p);
    
    assertEquals(expectedWhen, when);
    
    Map<String, RouteRule.MatchPair> expectedThen = new HashMap<String, RouteRule.MatchPair>();
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT1");
    expectedThen.put("then1", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("valueT2");
    p.matches.add("valueT3");
    p.matches.add("valueT4");
    expectedThen.put("then2", p);
    
    assertEquals(expectedThen, then);
}
 
Example #28
Source File: RouteRuleTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void test_MatchPair_copy() throws Exception {
    MatchPair copy = pair.copy();
    assertEquals(pair, copy);
    
    copy.matches.remove("+a");
    assertFalse(pair.equals(copy));
    
    copy = pair.copy();
    copy.matches.add("+z");
    assertFalse(pair.equals(copy));
}
 
Example #29
Source File: RouteRuleTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.matches.add("com.alibaba.MemberService");
    p.matches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("127.0.0.1");
    p.matches.add("17.58.25.62");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.matches.add("1.0.0");
    p.matches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.matches.add("morgan");
    p.matches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.matches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1,17.58.25.62&consumer.version = 1.0.0,1.0.6",
            		"provider.application=morgan,pc2&provider.host=10.16.26.51&provider.port=1020"));
}
 
Example #30
Source File: RouteRuleTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testParse_MisMatchRight() throws Exception {
    final Map<String, RouteRule.MatchPair> whenParams = new HashMap<String, RouteRule.MatchPair>();
    final Map<String, RouteRule.MatchPair> thenParams = new HashMap<String, RouteRule.MatchPair>();
    
    RouteRule.MatchPair p = new RouteRule.MatchPair();
    p.unmatches.add("com.alibaba.MemberService");
    p.unmatches.add("AuthService");
    whenParams.put("service", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("127.0.0.1");
    whenParams.put("consumer.host", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("1.0.0");
    p.unmatches.add("1.0.6");
    whenParams.put("consumer.version", p);

    p = new RouteRule.MatchPair();
    p.unmatches.add("morgan");
    p.unmatches.add("pc2");
    thenParams.put("provider.application", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("10.16.26.51");
    thenParams.put("provider.host", p);
    
    p = new RouteRule.MatchPair();
    p.unmatches.add("1020");
    thenParams.put("provider.port", p);
    
    assertEquals(RouteRule.createFromCondition(whenParams, thenParams),
            RouteRule.parse("service!=com.alibaba.MemberService,AuthService&consumer.host!=127.0.0.1&consumer.version != 1.0.0,1.0.6",
            		"provider.application!=morgan,pc2&provider.host!=10.16.26.51&provider.port!=1020"));
}