getMethods(String interfaceName) throws ClassNotFoundException {
Class> clazz = Class.forName(interfaceName);
Method[] methods = clazz.getMethods();
return MethodCaches.cache(interfaceName, methods); // 缓存一份,方便下次调用
}
public void close() {
registry.destroy();
}
public boolean isAvailable() {
return registry.isAvailable();
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/handler/SendReceiveHandler.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.handler;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.TimeoutException;
import com.alibaba.dubbo.remoting.exchange.Request;
import com.alibaba.dubbo.remoting.exchange.Response;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.fastjson.JSON;
import com.mmc.dubbo.doe.context.ResponseDispatcher;
import lombok.extern.slf4j.Slf4j;
/**
* nio event listener.
* @author Joey
* @date 2018/6/7 10:55
*/
@Slf4j
public class SendReceiveHandler implements ChannelHandler {
@Override
public void connected(Channel channel) throws RemotingException {
log.info("SendReceiveHandler.connected");
}
@Override
public void disconnected(Channel channel) throws RemotingException {
log.info("SendReceiveHandler.disconnected");
}
@Override
public void sent(Channel channel, Object message) throws RemotingException {
log.info("SendReceiveHandler.sent");
if (message instanceof Request) {
Request req = (Request) message;
ResponseDispatcher.getDispatcher().register(req);
}
}
@Override
public void received(Channel channel, Object message) {
log.info("SendReceiveHandler.received({})", JSON.toJSONString(message));
if (message instanceof Response) {
Response res = (Response) message;
if (res.getStatus() == Response.OK) {
try {
if (res.getResult() instanceof RpcResult) {
ResponseDispatcher.getDispatcher().dispatch(res);
}
} catch (Exception e) {
log.error("callback invoke error .result:" + res.getResult() + ",url:" + channel.getUrl(), e);
}
} else if (res.getStatus() == Response.CLIENT_TIMEOUT || res.getStatus() == Response.SERVER_TIMEOUT) {
try {
TimeoutException te = new TimeoutException(res.getStatus() == Response.SERVER_TIMEOUT, channel, res.getErrorMessage());
// callbackCopy.caught(te);
} catch (Exception e) {
log.error("callback invoke error ,url:" + channel.getUrl(), e);
}
} else {
try {
RuntimeException re = new RuntimeException(res.getErrorMessage());
// callbackCopy.caught(re);
} catch (Exception e) {
log.error("callback invoke error ,url:" + channel.getUrl(), e);
}
}
}
}
@Override
public void caught(Channel channel, Throwable exception) throws RemotingException {
log.error("SendReceiveHandler.caught", exception);
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/handler/StreamHandler.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.handler;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.mmc.dubbo.doe.cache.RedisResolver;
import com.mmc.dubbo.doe.context.Const;
import com.mmc.dubbo.doe.dto.PomDTO;
import com.mmc.dubbo.doe.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* @author Joey
* @date 2018/6/29 20:20
*/
@Slf4j
public class StreamHandler implements Runnable {
private final String libPath;
private final RedisResolver redisResolver;
private final String requestId;
private final Process ps;
public StreamHandler(Process ps, RedisResolver redisResolver, String requestId, String libPath) {
this.ps = ps;
this.redisResolver = redisResolver;
this.requestId = requestId;
this.libPath = libPath;
}
/**
* When an object implementing interface Runnable is used
* to create a thread, starting the thread causes the object's
* run method to be called in that separately executing
* thread.
*
* The general contract of the method run is that it may
* take any action whatsoever.
*
* @see Thread#run()
*/
@Override
public void run() {
log.info("begin to put the message into redis.");
// 获取标准输出
BufferedReader readStdout = new BufferedReader(new InputStreamReader(ps.getInputStream()));
// 获取错误输出
BufferedReader readStderr = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
try {
// auto expire
String key = StringUtil.format(Const.DOE_DOWNLOAD_JAR_MESSAGE, requestId);
redisResolver.rPush(key, "");
redisResolver.expire(key, 15 * 60); // ten minute
String successLine;
String errorLine = null;
while (null != (successLine = readStdout.readLine()) || (errorLine = readStderr.readLine()) != null) {
if (StringUtils.isNotEmpty(successLine)) {
putToRedis(requestId, successLine);
}
if (StringUtils.isNotEmpty(errorLine)) {
putToRedis(requestId, errorLine);
}
}
log.info("finish download the jars to the path {}.", libPath);
} catch (Exception e) {
log.error("occur something wrong when download the jars.", e);
} finally {
try {
readStdout.close();
readStderr.close();
} catch (Exception e) {
log.error("occur something wrong when close resources", e);
}
}
}
private void putToRedis(String requestId, String message) {
log.info("{}|{}", requestId, message);
String key = StringUtil.format(Const.DOE_DOWNLOAD_JAR_MESSAGE, requestId);
redisResolver.rPush(key, message);
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/CaseModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import lombok.Data;
import java.util.Date;
import java.util.Map;
/**
* @author Joey
* @date 2018/6/28 10:42
*/
@Data
public class CaseModel {
/**
* case Id.
*/
private long caseId;
/**
* case group.
*/
private String caseGroup;
private String caseName;
private String caseDesc;
private String insertTime;
/**
* provider address.
*/
private String address;
private String interfaceName;
/**
* the method name with parameters.
*/
private String methodText;
private String providerKey;
private String methodKey;
/**
* parameters.
*/
private String json;
/**
* assert condition.
*/
private String condition;
/**
* expected result.
*/
private String expect;
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/MethodModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.mmc.dubbo.doe.util.StringUtil;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
/**
* @author Joey
* @date 2018/6/15 14:54
*/
public class MethodModel {
private final Method method;
private final String key;
public String getKey() {
return key;
}
public Method getMethod() {
return method;
}
public MethodModel(String key, Method method) {
this.key = key;
this.method = method;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(method.getName());
sb.append("(");
for (Parameter param : method.getParameters()) {
sb.append(param.getType().getName());
sb.append(" ");
sb.append(param.getName());
sb.append(", ");
}
sb.delete(sb.length() - 2, sb.length());
sb.append(")");
return sb.toString();
}
public String getMethodText() {
StringBuilder sb = new StringBuilder();
sb.append(method.getName());
sb.append("(");
for (Parameter param : method.getParameters()) {
sb.append(getShortType(param.getType().getName()));
sb.append(" ");
sb.append(param.getName());
sb.append(", ");
}
sb.delete(sb.length() - 2, sb.length());
sb.append(")");
return sb.toString();
}
private String getShortType(String name) {
if (StringUtils.isEmpty(name)) {
return name;
}
int index = name.lastIndexOf(".");
if (index > 0 && index < name.length()) {
name = name.substring(index + 1);
}
return name;
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/PointModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import lombok.Data;
/**
* ip and port.
*
* @author Joey
* @date 2018/7/18 10:17
*/
@Data
public class PointModel {
private String ip;
private int port;
public PointModel(String host, Integer port) {
this.ip = host;
this.port = port;
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/PomModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import com.alibaba.dubbo.common.utils.StringUtils;
/**
* @author Joey
* @date 2018/6/16 9:55
*/
public class PomModel {
private String groupId;
private String artifactId;
private String version;
private String scope;
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getArtifactId() {
return artifactId;
}
public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public boolean isBroken() {
return StringUtils.isEmpty(groupId) || StringUtils.isEmpty(artifactId) || StringUtils.isEmpty(version);
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/RegistryModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import lombok.Data;
/**
* @author Joey
* @date 2018/7/9 19:42
*/
@Data
public class RegistryModel {
private String registryKey;
private String registryDesc;
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/ServiceModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import lombok.Data;
/**
* interface wrapper.
*
* @author Joey
* @date 2018/6/18 17:51
*/
@Data
public class ServiceModel {
private String serviceName;
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/model/UrlModel.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.model;
import com.alibaba.dubbo.common.URL;
/**
* @author Joey
* @date 2018/6/15 17:56
*/
public class UrlModel {
private final String key;
private final URL url;
public UrlModel(String key, URL url) {
this.key = key;
this.url = url;
}
public String getKey() {
return key;
}
public URL getUrl() {
return url;
}
}
================================================
FILE: mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/service/CaseService.java
================================================
/*
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Founder. You shall not disclose such Confidential Information
* and shall use it only in accordance with the terms of the agreements
* you entered into with Founder.
*
*/
package com.mmc.dubbo.doe.service;
import com.mmc.dubbo.doe.dto.ResultDTO;
import com.mmc.dubbo.doe.model.CaseModel;
import java.util.List;
/**
* @author Joey
* @date 2018/6/29 15:21
*/
public interface CaseService {
/**
* save the case.
*
* @param model
* @return
*/
ResultDTO save(CaseModel model);
/**
* list all case.
*
* @return
*/
List