Skip to content

Commit

Permalink
Enum param support (#44)
Browse files Browse the repository at this point in the history
* support enum param

* modify version to v1.3.8

* 1. Support group to zookeeper,redis registration center.
2. Fixed some bugs.

* add enum test

* add the jar file under dist
  • Loading branch information
ningyu1 committed Dec 18, 2018
1 parent b6c7b24 commit c181cf3
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 28 deletions.
Binary file not shown.
Binary file added dist/jmeter-plugins-dubbo-1.3.8.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.ningyu</groupId>
<artifactId>jmeter-plugins-dubbo</artifactId>
<version>1.3.7</version>
<version>1.3.8</version>

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
Expand Down
Expand Up @@ -59,6 +59,7 @@ public class DubboSampleGui extends AbstractSamplerGui {
private JComboBox<String> registryProtocolText;
private JComboBox<String> rpcProtocolText;
private JTextField addressText;
private JTextField registryGroupText;
private JTextField timeoutText;
private JTextField versionText;
private JTextField retriesText;
Expand Down Expand Up @@ -102,18 +103,23 @@ private void init() {
protocolLable.setLabelFor(registryProtocolText);
ph.add(protocolLable);
ph.add(registryProtocolText);
ph.add(makeHelper("Registry center address protocol, The 'none' is direct connection. "));
registrySettings.add(ph);
//Address
JPanel ah = new HorizontalPanel();
JLabel addressLable = new JLabel("Address:", SwingConstants.RIGHT);
addressText = new JTextField(textColumns);
addressLable.setLabelFor(addressText);
JLabel addressHelpLable = new JLabel();
addressHelpLable.setIcon(new ImageIcon(getClass().getResource("/images/help.png")));
addressHelpLable.setToolTipText("Use the registry to allow multiple addresses, Use direct connection to allow only one address! Multiple address format: ip1:port1,ip2:port2 . Direct address format: ip:port . ");
ah.add(addressLable);
ah.add(addressText);
ah.add(addressHelpLable);
ah.add(makeHelper("Use the registry to allow multiple addresses, Use direct connection to allow only one address! Multiple address format: ip1:port1,ip2:port2 . Direct address format: ip:port . "));
JLabel registryGroupLable = new JLabel("Group:", SwingConstants.RIGHT);
registryGroupText = new JTextField();
registryGroupLable.setLabelFor(registryGroupText);
ah.add(registryGroupLable);
ah.add(registryGroupText);
ah.add(makeHelper("Service registration grouping, cross-group services will not affect each other, and can not be called each other, suitable for environmental isolation."));

registrySettings.add(ah);
//Selection Interface
JPanel sh = new HorizontalPanel();
Expand All @@ -129,7 +135,11 @@ public void itemStateChanged(ItemEvent e) {
interfaceList.addPropertyChangeListener("model", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
doChange(interfaceList.getSelectedItem().toString());
if (interfaceList.getSelectedItem() != null) {
doChange(interfaceList.getSelectedItem().toString());
} else {
methodList.setModel(new DefaultComboBoxModel<String>(new String[]{}));
}
}
});
jButton.addActionListener(new ActionListener() {
Expand All @@ -153,7 +163,9 @@ public void itemStateChanged(ItemEvent e) {
methodList.addPropertyChangeListener("model", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
methodText.setText(methodList.getSelectedItem().toString());
if (methodList.getSelectedItem() != null) {
methodText.setText(methodList.getSelectedItem().toString());
}
}
});
sh.add(methodList);
Expand All @@ -170,11 +182,12 @@ public void propertyChange(PropertyChangeEvent evt) {
rpcProtocolLable.setLabelFor(rpcProtocolText);
rpcPh.add(rpcProtocolLable);
rpcPh.add(rpcProtocolText);
rpcPh.add(makeHelper("RPC protocol name."));
protocolSettings.add(rpcPh);

//Consumer Settings
JPanel consumerSettings = new VerticalPanel();
consumerSettings.setBorder(BorderFactory.createTitledBorder("Consumer Settings"));
consumerSettings.setBorder(BorderFactory.createTitledBorder("Consumer&Service Settings"));
JPanel h = new HorizontalPanel();
//Timeout
JLabel timeoutLable = new JLabel(" Timeout:", SwingConstants.RIGHT);
Expand All @@ -183,40 +196,46 @@ public void propertyChange(PropertyChangeEvent evt) {
timeoutLable.setLabelFor(timeoutText);
h.add(timeoutLable);
h.add(timeoutText);
h.add(makeHelper("Invoking timeout(ms)"));
//Version
JLabel versionLable = new JLabel("Version:", SwingConstants.RIGHT);
versionText = new JTextField(textColumns);
versionText.setText(DubboSample.DEFAULT_VERSION);
versionLable.setLabelFor(versionText);
h.add(versionLable);
h.add(versionText);
h.add(makeHelper("Service version."));
//Retries
JLabel retriesLable = new JLabel("Retries:", SwingConstants.RIGHT);
retriesText = new JTextField(textColumns);
retriesText.setText(DubboSample.DEFAULT_RETRIES);
retriesLable.setLabelFor(retriesText);
h.add(retriesLable);
h.add(retriesText);
h.add(makeHelper("The retry count for RPC, not including the first invoke. Please set it to 0 if don't need to retry."));
//Cluster
JLabel clusterLable = new JLabel("Cluster:", SwingConstants.RIGHT);
clusterText = new JTextField(textColumns);
clusterText.setText(DubboSample.DEFAULT_CLUSTER);
clusterLable.setLabelFor(clusterText);
h.add(clusterLable);
h.add(clusterText);
h.add(makeHelper("failover/failfast/failsafe/failback/forking are available."));
//Group
JLabel groupLable = new JLabel("Group:", SwingConstants.RIGHT);
groupText = new JTextField(textColumns);
groupLable.setLabelFor(groupText);
h.add(groupLable);
h.add(groupText);
h.add(makeHelper("The group of the service providers. It can distinguish services when it has multiple implements."));
//Connections
JLabel connectionsLable = new JLabel("Connections:", SwingConstants.RIGHT);
connectionsText = new JTextField(textColumns);
connectionsText.setText(DubboSample.DEFAULT_CONNECTIONS);
connectionsLable.setLabelFor(connectionsText);
h.add(connectionsLable);
h.add(connectionsText);
h.add(makeHelper("The maximum connections of every provider. For short connection such as rmi, http and hessian, it's connection limit, but for long connection such as dubbo, it's connection count."));
consumerSettings.add(h);

JPanel hp1 = new HorizontalPanel();
Expand All @@ -226,12 +245,14 @@ public void propertyChange(PropertyChangeEvent evt) {
asyncLable.setLabelFor(asyncText);
hp1.add(asyncLable);
hp1.add(asyncText);
hp1.add(makeHelper("Asynchronous execution, not reliable. It does not block the execution thread just only ignores the return value."));
//Loadbalance
JLabel loadbalanceLable = new JLabel("Loadbalance:", SwingConstants.RIGHT);
loadbalanceText = new JComboBox<String>(new String[]{"random", "roundrobin", "leastactive", "consistenthash"});
loadbalanceLable.setLabelFor(loadbalanceText);
hp1.add(loadbalanceLable);
hp1.add(loadbalanceText);
hp1.add(makeHelper("Strategy of load balance, random, roundrobin and leastactive are available."));
consumerSettings.add(hp1);

//Interface Settings
Expand All @@ -244,6 +265,7 @@ public void propertyChange(PropertyChangeEvent evt) {
interfaceLable.setLabelFor(interfaceText);
ih.add(interfaceLable);
ih.add(interfaceText);
ih.add(makeHelper("The service interface name."));
interfaceSettings.add(ih);
//Method
JPanel mh = new HorizontalPanel();
Expand All @@ -252,6 +274,7 @@ public void propertyChange(PropertyChangeEvent evt) {
methodLable.setLabelFor(methodText);
mh.add(methodLable);
mh.add(methodText);
mh.add(makeHelper("The service method name"));
interfaceSettings.add(mh);

//表格panel
Expand Down Expand Up @@ -303,6 +326,13 @@ public void actionPerformed(ActionEvent arg0) {
add(settingPanel,BorderLayout.CENTER);
}

public JLabel makeHelper(String tooltip) {
JLabel helpLable = new JLabel();
helpLable.setIcon(new ImageIcon(getClass().getResource("/images/help.png")));
helpLable.setToolTipText(tooltip);
return helpLable;
}

/**
* this method sets the Sample's data into the gui
*/
Expand All @@ -312,6 +342,7 @@ public void configure(TestElement element) {
log.debug("sample赋值给gui");
DubboSample sample = (DubboSample) element;
registryProtocolText.setSelectedItem(sample.getRegistryProtocol());
registryGroupText.setText(sample.getRegistryGroup());
rpcProtocolText.setSelectedItem(sample.getRpcProtocol());
addressText.setText(sample.getAddress());
versionText.setText(sample.getVersion());
Expand Down Expand Up @@ -361,6 +392,7 @@ public void modifyTestElement(TestElement element) {
super.configureTestElement(element);
DubboSample sample = (DubboSample) element;
sample.setRegistryProtocol(registryProtocolText.getSelectedItem().toString());
sample.setRegistryGroup(registryGroupText.getText());
sample.setRpcProtocol(rpcProtocolText.getSelectedItem().toString());
sample.setAddress(addressText.getText());
sample.setTimeout(timeoutText.getText());
Expand Down Expand Up @@ -418,6 +450,7 @@ public void clearGui() {
log.debug("清空gui数据");
super.clearGui();
registryProtocolText.setSelectedIndex(0);
registryGroupText.setText("");
rpcProtocolText.setSelectedIndex(0);
addressText.setText("");
timeoutText.setText(DubboSample.DEFAULT_TIMEOUT);
Expand Down Expand Up @@ -452,12 +485,15 @@ private void doChange(String key) {
//set method
String[] items = method.split(",");
methodList.setModel(new DefaultComboBoxModel<String>(items));
} else {
methodList.setModel(new DefaultComboBoxModel<String>(new String[]{}));
}
}

private void doConfirm(ActionEvent event, JAutoCompleteComboBox<String> interfaceList) {
String protocol = registryProtocolText.getSelectedItem().toString();
String address = addressText.getText();
String group = registryGroupText.getText();
if (StringUtils.isBlank(address)) {
JOptionPane.showMessageDialog(this.getParent(), "Address can't be empty!", "error", JOptionPane.ERROR_MESSAGE);
return;
Expand All @@ -466,7 +502,7 @@ private void doConfirm(ActionEvent event, JAutoCompleteComboBox<String> interfac
if (result == JOptionPane.YES_OPTION) {
List<String> list = new ArrayList<String>();
try {
list = ProviderService.get(address).getProviders(protocol, address);
list = ProviderService.get(address).getProviders(protocol, address, group);
JOptionPane.showMessageDialog(this.getParent(), "Get provider list to finish! Check if the log has errors.", "info", JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(this.getParent(), e.getMessage(), "error", JOptionPane.ERROR_MESSAGE);
Expand Down
Expand Up @@ -57,6 +57,7 @@ public class DubboSample extends AbstractSampler {
private static final long serialVersionUID = -6794913295411458705L;

public static String FIELD_DUBBO_REGISTRY_PROTOCOL = "FIELD_DUBBO_REGISTRY_PROTOCOL";
public static String FIELD_DUBBO_REGISTRY_GROUP = "FIELD_DUBBO_REGISTRY_GROUP";
public static String FIELD_DUBBO_RPC_PROTOCOL = "FIELD_DUBBO_RPC_PROTOCOL";
public static String FIELD_DUBBO_ADDRESS = "FIELD_DUBBO_ADDRESS";
public static String FIELD_DUBBO_TIMEOUT = "FIELD_DUBBO_TIMEOUT";
Expand Down Expand Up @@ -93,6 +94,22 @@ public String getRegistryProtocol() {
public void setRegistryProtocol(String registryProtocol) {
this.setProperty(new StringProperty(FIELD_DUBBO_REGISTRY_PROTOCOL, org.springframework.util.StringUtils.trimAllWhitespace(registryProtocol)));
}

/**
* get Registry Group
* @return the group
*/
public String getRegistryGroup() {
return this.getPropertyAsString(FIELD_DUBBO_REGISTRY_GROUP);
}

/**
* set Registry Group
* @param registryGroup the group to set
*/
public void setRegistryGroup(String registryGroup) {
this.setProperty(new StringProperty(FIELD_DUBBO_REGISTRY_GROUP, org.springframework.util.StringUtils.trimAllWhitespace(registryGroup)));
}

/**
* get RPC protocol
Expand Down Expand Up @@ -375,24 +392,29 @@ private Object callDubbo(SampleResult res) {
String rpcProtocol = getRpcProtocol().replaceAll("://", "");
// get registry protocol
String protocol = getRegistryProtocol();
// get registry group
String registryGroup = getRegistryGroup();
switch (protocol) {
case Constants.REGISTRY_ZOOKEEPER:
registry = new RegistryConfig();
registry.setProtocol(Constants.REGISTRY_ZOOKEEPER);
registry.setGroup(registryGroup);
registry.setAddress(address);
reference.setRegistry(registry);
reference.setProtocol(rpcProtocol);
break;
case Constants.REGISTRY_MULTICAST:
registry = new RegistryConfig();
registry.setProtocol(Constants.REGISTRY_MULTICAST);
registry.setGroup(registryGroup);
registry.setAddress(address);
reference.setRegistry(registry);
reference.setProtocol(rpcProtocol);
break;
case Constants.REGISTRY_REDIS:
registry = new RegistryConfig();
registry.setProtocol(Constants.REGISTRY_REDIS);
registry.setGroup(registryGroup);
registry.setAddress(address);
reference.setRegistry(registry);
reference.setProtocol(rpcProtocol);
Expand Down
Expand Up @@ -59,21 +59,21 @@ public Map<String, URL> findByService(String serviceName) {
return providerUrls == null ? null : providerUrls.get(serviceName);
}

public List<String> getProviders(String protocol, String address) throws RuntimeException {
if (protocol.equals("zookeeper")){
return executeRegistry(protocol, address);
public List<String> getProviders(String protocol, String address, String group) throws RuntimeException {
if (protocol.equals("zookeeper") || protocol.equals("redis")){
return executeRegistry(protocol, address, group);
// } else if (protocol.equals("none")) {
// return executeTelnet();
} else {
throw new RuntimeException("Registry Protocol please use zookeeper!");
throw new RuntimeException("Registry Protocol please use zookeeper or redis!");
}
}

private List<String> executeTelnet() throws RuntimeException {
throw new RuntimeException();
}

private List<String> executeRegistry(String protocol, String address) throws RuntimeException {
private List<String> executeRegistry(String protocol, String address, String group) throws RuntimeException {
ReferenceConfig reference = new ReferenceConfig();
// set application
reference.setApplication(DubboSample.application);
Expand All @@ -82,30 +82,21 @@ private List<String> executeRegistry(String protocol, String address) throws Run
case Constants.REGISTRY_ZOOKEEPER:
registry = new RegistryConfig();
registry.setProtocol(Constants.REGISTRY_ZOOKEEPER);
registry.setAddress(address);
reference.setRegistry(registry);
break;
case Constants.REGISTRY_MULTICAST:
registry = new RegistryConfig();
registry.setProtocol(Constants.REGISTRY_MULTICAST);
registry.setGroup(group);
registry.setAddress(address);
reference.setRegistry(registry);
break;
case Constants.REGISTRY_REDIS:
registry = new RegistryConfig();
registry.setProtocol(Constants.REGISTRY_REDIS);
registry.setAddress(address);
reference.setRegistry(registry);
break;
case Constants.REGISTRY_SIMPLE:
registry = new RegistryConfig();
registry.setGroup(group);
registry.setAddress(address);
reference.setRegistry(registry);
break;
}
reference.setInterface("com.alibaba.dubbo.registry.RegistryService");
try {
ReferenceConfigCache cache = ReferenceConfigCache.getCache(address, new ReferenceConfigCache.KeyGenerator() {
ReferenceConfigCache cache = ReferenceConfigCache.getCache(address + "_" + group, new ReferenceConfigCache.KeyGenerator() {
public String generateKey(ReferenceConfig<?> referenceConfig) {
return referenceConfig.toString();
}
Expand All @@ -114,7 +105,7 @@ public String generateKey(ReferenceConfig<?> referenceConfig) {
if (registryService == null) {
throw new RuntimeException("Can't get the interface list, please check if the address is wrong!");
}
RegistryServerSync registryServerSync = RegistryServerSync.get(address);
RegistryServerSync registryServerSync = RegistryServerSync.get(address + "_" + group);
registryService.subscribe(RegistryServerSync.SUBSCRIBE, registryServerSync);
List<String> ret = new ArrayList<String>();
providerUrls = registryServerSync.getRegistryCache().get(com.alibaba.dubbo.common.Constants.PROVIDERS_CATEGORY);
Expand Down
Expand Up @@ -19,6 +19,8 @@
import com.google.common.reflect.TypeToken;
import io.github.ningyu.jmeter.plugin.dubbo.sample.MethodArgument;
import org.apache.commons.lang3.StringUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
Expand All @@ -30,6 +32,8 @@
*/
public class ClassUtils {

private static final Logger log = LoggingManager.getLoggerForClass();

private static final String TYPE_NAME_PREFIX = "class ";

public static String getClassName(Type type) {
Expand Down Expand Up @@ -214,7 +218,16 @@ public static void parseParameter(List<String> paramterTypeList,
} catch (ClassNotFoundException e) {
//不是jdk或者lib下的类,使用通用map格式反序列化值
paramterTypeList.add(arg.getParamType());
parameterValuesList.add(isBlank(arg.getParamValue()) ? null : JsonUtils.formJson(arg.getParamValue(), new TypeToken<HashMap<String,Object>>() {}.getType()));
Object obj = null;
if (!isBlank(arg.getParamValue())) {
//使用通用map格式反序列化值
obj = JsonUtils.formJson(arg.getParamValue(), new TypeToken<HashMap<String, Object>>() {}.getType());
if (obj == null) {
//枚举类型的类走字符串序列化
obj = JsonUtils.formJson(arg.getParamValue(), String.class);
}
}
parameterValuesList.add(obj);
}
}
}
Expand Down

0 comments on commit c181cf3

Please sign in to comment.