add testcase
This commit is contained in:
parent
f7142c1151
commit
2119aa1bdd
@ -23,6 +23,7 @@ import com.alibaba.nacos.cmdb.service.CmdbReader;
|
||||
import com.alibaba.nacos.naming.boot.SpringContext;
|
||||
import com.alibaba.nacos.naming.core.Instance;
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -284,13 +285,4 @@ public class LabelSelector extends ExpressionSelector implements Selector {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws NacosException {
|
||||
|
||||
String expression = "CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B";
|
||||
expression = StringUtils.deleteWhitespace(expression);
|
||||
System.out.println(ExpressionInterpreter.getTerms(expression));
|
||||
|
||||
System.out.println(LabelSelector.parseExpression(expression));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.alibaba.nacos.naming.selector;
|
||||
|
||||
import com.alibaba.nacos.naming.exception.NacosException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Xs.Tao
|
||||
*/
|
||||
public class LabelSelectorTest {
|
||||
|
||||
private String expression = "CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B";
|
||||
|
||||
@Test
|
||||
public void parseExpression() throws NacosException {
|
||||
expression = StringUtils.deleteWhitespace(expression);
|
||||
List<String> terms =LabelSelector.ExpressionInterpreter.getTerms(expression);
|
||||
Assert.assertEquals(7,terms.size());
|
||||
Set<String> parseLables=LabelSelector.parseExpression(expression);
|
||||
Assert.assertEquals(2,parseLables.size());
|
||||
String[] labs=parseLables.toArray(new String[]{});
|
||||
Assert.assertEquals("A",labs[0]);
|
||||
Assert.assertEquals("B",labs[1]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user