Skip to content

Commit

Permalink
test:fix test case (sofastack#874)
Browse files Browse the repository at this point in the history
* fix:do not re package the sofaruntimeexception
add clear method
  • Loading branch information
leizhiyuan authored Mar 5, 2020
1 parent 449c2f8 commit 6b7173a
Show file tree
Hide file tree
Showing 33 changed files with 345 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public AbstractProxyClientTransport(ClientTransportConfig transportConfig) {
ProviderInfo provider = transportConfig.getProviderInfo();
try {
proxy = buildProxy(transportConfig);
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_BUILD_PROXY), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static AddressHolder getAddressHolder(ConsumerBootstrap consumerBootstrap
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_ADDRESS_HOLDER, addressHolder));
}
return ext.getExtInstance(new Class[] { ConsumerBootstrap.class }, new Object[] { consumerBootstrap });
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_ADDRESS_HOLDER, addressHolder), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static Cluster getCluster(ConsumerBootstrap consumerBootstrap) {
}
return ext.getExtInstance(new Class[] { ConsumerBootstrap.class },
new Object[] { consumerBootstrap });
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_CLUSTER, cluster), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static ConnectionHolder getConnectionHolder(ConsumerBootstrap consumerBoo
connectionHolder));
}
return ext.getExtInstance(new Class[] { ConsumerBootstrap.class }, new Object[] { consumerBootstrap });
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_CONNECTION_HOLDER, connectionHolder),
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static LoadBalancer getLoadBalancer(ConsumerBootstrap consumerBootstrap)
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_LOAD_BALANCER, loadBalancer));
}
return ext.getExtInstance(new Class[] { ConsumerBootstrap.class }, new Object[] { consumerBootstrap });
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_LOAD_BALANCER, loadBalancer), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ public String queryAttribute(String property) {
oldValue = BeanUtils.getProperty(this, property, propertyClazz);
}
return oldValue == null ? null : oldValue.toString();
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_QUERY_ATTRIBUTE, property), e);
}
Expand Down Expand Up @@ -941,6 +943,8 @@ public boolean updateAttribute(String property, String newValueStr, boolean over
}
}
return changed;
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UPDATE_ATTRIBUTE, property, newValueStr),
e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public Class<?> getProxyClass() {
throw ExceptionUtils.buildRuntime("service.interfaceId",
"null", "interfaceId must be not null");
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_GET_PROXY_CLASS), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public T getExtInstance(Class[] argTypes, Object[] args) {
} else {
return ClassUtils.newInstanceWithArgs(clazz, argTypes, args);
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_CREATE_EXT_INSTANCE,
clazz.getCanonicalName()), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected FilterChain(List<Filter> filters, FilterInvoker lastInvoker, AbstractI
// cache this for filter when async respond
loadedFilters.add(filter);
}
} catch (SofaRpcRuntimeException e) {
LOGGER.error(LogCodes.getLog(LogCodes.ERROR_FILTER_CONSTRUCT), e);
throw e;
} catch (Exception e) {
LOGGER.error(LogCodes.getLog(LogCodes.ERROR_FILTER_CONSTRUCT), e);
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_FILTER_CONSTRUCT), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static <T> T buildProxy(String proxyType, Class<T> clazz, Invoker proxyIn
}
Proxy proxy = ext.getExtInstance();
return proxy.getProxy(clazz, proxyInvoker);
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Proxy", proxyType), e);
}
Expand All @@ -69,6 +71,8 @@ public static Invoker getInvoker(Object proxyObject, String proxyType) {
}
Proxy proxy = ext.getExtInstance();
return proxy.getInvoker(proxyObject);
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", proxyType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public static synchronized Registry getRegistry(RegistryConfig registryConfig) {
ALL_REGISTRIES.put(registryConfig, registry);
}
return registry;
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_LOAD_EXT, "Registry", protocol));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public synchronized static Server getServer(ServerConfig serverConfig) {
SERVER_MAP.put(serverConfig.getPort() + "", server);
}
return server;
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_GET_SERVER), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public synchronized static Tracer getTracer(String tracerName) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_FAIL_LOAD_TRACER_EXT, tracerName));
}
return ext.getExtInstance();
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_FAIL_LOAD_TRACER_EXT, tracerName), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ public Object invoke(Object self, Method thisMethod, Method proceed, Object[] ar
return sofaResponse.getAppResponse();
}
});
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException("", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ public T refer() {
consumerConfig.setConfigListener(null);
consumerConfig.setProviderInfoListener(null);
cnt.decrementAndGet(); // 发布失败不计数
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_BUILD_CONSUMER_PROXY), e);
if (e instanceof SofaRpcRuntimeException) {
throw (SofaRpcRuntimeException) e;
} else {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_BUILD_CONSUMER_PROXY), e);
}
}
if (consumerConfig.getOnAvailable() != null && cluster != null) {
cluster.checkStateChange(false); // 状态变化通知监听器
Expand All @@ -184,7 +188,7 @@ public T refer() {
}

/**
* for check fields and parameters of consumer config
* for check fields and parameters of consumer config
*/
protected void checkParameters() {

Expand Down Expand Up @@ -366,8 +370,7 @@ protected List<ProviderGroup> subscribeFromRegistries() {
}
}
} catch (SofaRpcRuntimeException e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUBSCRIBE_FROM_REGISTRY,
registryConfig.getId()), e);
throw e;
} catch (Throwable e) {
String appName = consumerConfig.getAppName();
if (LOGGER.isWarnEnabled(appName)) {
Expand Down Expand Up @@ -544,7 +547,11 @@ private void switchCluster() throws Exception {
if (newCluster != null) {
newCluster.destroy();
}
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SWITCH_CLUSTER_NEW), e);
if (e instanceof SofaRpcRuntimeException) {
throw e;
} else {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SWITCH_CLUSTER_NEW), e);
}
}
try { // 切换
cluster = newCluster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ private void doExport() {
}

} catch (SofaRpcRuntimeException e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REGISTER_PROCESSOR_TO_SERVER,
serverConfig.getId()), e);
throw e;
} catch (Exception e) {
LOGGER.errorWithApp(appName,
LogCodes.getLog(LogCodes.ERROR_REGISTER_PROCESSOR_TO_SERVER, serverConfig.getId()), e);
Expand All @@ -189,6 +188,9 @@ private void doExport() {
register();
} catch (Exception e) {
decrementCounter(hasExportedInCurrent);
if (e instanceof SofaRpcRuntimeException) {
throw e;
}
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_BUILD_PROVIDER_PROXY), e);
}

Expand Down Expand Up @@ -337,8 +339,7 @@ protected void register() {
try {
registry.register(providerConfig);
} catch (SofaRpcRuntimeException e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REGISTER_TO_REGISTRY,
registryConfig.getId()), e);
throw e;
} catch (Throwable e) {
String appName = providerConfig.getAppName();
if (LOGGER.isWarnEnabled(appName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public static void registerFallback(ConsumerConfig consumerConfig, Object fallba
FALLBACK_FACTORY_MAPPING.put(consumerConfig, new DefaultFallbackFactory<Object>(fallback));
}

public static void clearFallback() {
FALLBACK_FACTORY_MAPPING.clear();
}

public static void registerFallbackFactory(ConsumerConfig consumerConfig, FallbackFactory fallbackFactory) {
FALLBACK_FACTORY_MAPPING.put(consumerConfig, fallbackFactory);
}
Expand All @@ -48,6 +52,10 @@ public static void registerSetterFactory(ConsumerConfig consumerConfig, SetterFa
SETTER_FACTORY_MAPPING.put(consumerConfig, setterFactory);
}

public static void clearSetterFactory() {
SETTER_FACTORY_MAPPING.clear();
}

public static void registerGlobalFallbackFactory(FallbackFactory fallbackFactory) {
GLOBAL_FALLBACK_FACTORY = fallbackFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public void register(ProviderConfig config) {
LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
}
}
}catch (SofaRpcRuntimeException e){
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "consulRegistry", config.buildKey()), e);
}
Expand Down Expand Up @@ -219,8 +221,11 @@ public void unRegister(ProviderConfig config) {
}
} catch (Exception e) {
if (!RpcRunningState.isShuttingDown()) {
if ( e instanceof SofaRpcRuntimeException){
throw e;
}else{
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNREG_PROVIDER ,EXT_NAME), e);
}
}}
}
}

Expand Down Expand Up @@ -251,7 +256,9 @@ public List<ProviderGroup> subscribe(ConsumerConfig config) {
}

return Collections.singletonList(new ProviderGroup().addAll(providers));
} catch (Exception e) {
} catch (SofaRpcRuntimeException e){
throw e;
}catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUB_PROVIDER ,EXT_NAME), e);
}
}
Expand Down Expand Up @@ -376,7 +383,9 @@ private NewService.Check buildCheck(String serverHost, int serverPort) {
String address;
try {
address = new URL(properties.getHealthCheckProtocol(), host, port, properties.getHealthCheckPath()).toString();
} catch (Exception e) {
} catch (SofaRpcRuntimeException e){
throw e;
}catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_HEALTH_CHECK_URL ), e);
}
check.setHttp(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public void register(ProviderConfig config) {
}
providerInstances.put(config, instances);
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "NacosRegistry",
config.buildKey()), e);
Expand Down Expand Up @@ -223,7 +225,11 @@ public void unRegister(ProviderConfig config) {

} catch (Exception e) {
if (!RpcRunningState.isShuttingDown()) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNREG_PROVIDER, EXT_NAME), e);
if (e instanceof SofaRpcRuntimeException) {
throw (SofaRpcRuntimeException) e;
} else {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNREG_PROVIDER, EXT_NAME), e);
}
}
}
}
Expand Down Expand Up @@ -290,6 +296,8 @@ public void onEvent(Event event) {
List<ProviderInfo> providerInfos = NacosRegistryHelper.convertInstancesToProviders(allInstances);
List<ProviderInfo> matchProviders = RegistryUtils.matchProviderInfos(config, providerInfos);
return Collections.singletonList(new ProviderGroup().addAll(matchProviders));
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUB_PROVIDER, EXT_NAME), e);
}
Expand All @@ -310,7 +318,12 @@ public void unSubscribe(ConsumerConfig config) {
}
} catch (Exception e) {
if (!RpcRunningState.isShuttingDown()) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNSUB_LISTENER, EXT_NAME), e);

if (e instanceof SofaRpcRuntimeException) {
throw (SofaRpcRuntimeException) e;
} else {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNSUB_LISTENER, EXT_NAME), e);
}
}
}

Expand Down
Loading

0 comments on commit 6b7173a

Please sign in to comment.