3.0 service discovery metadata refactor (#9506)
This commit is contained in:
parent
32a083cfc3
commit
b2a4f612ec
|
|
@ -18,9 +18,9 @@ package org.apache.dubbo.rpc.cluster.filter;
|
|||
|
||||
import org.apache.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.rpc.Filter;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.apache.dubbo.rpc.Invocation;
|
||||
import org.apache.dubbo.rpc.Invoker;
|
||||
import org.apache.dubbo.rpc.Result;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.rpc.cluster.merger;
|
||||
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -20,14 +20,15 @@ package org.apache.dubbo.rpc.cluster.router.mesh.rule;
|
|||
import org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.DubboRoute;
|
||||
import org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.DubboRouteDetail;
|
||||
import org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.VirtualServiceRule;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
public class VirtualServiceRuleTest {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dubbo.rpc.RpcException;
|
|||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.cluster.Directory;
|
||||
import org.apache.dubbo.rpc.cluster.filter.DemoService;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.rpc.cluster.support;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.URLBuilder;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ import java.util.HashSet;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,31 +20,32 @@ package org.apache.dubbo.rpc.cluster.support.merger;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.URLBuilder;
|
||||
import org.apache.dubbo.rpc.cluster.ProviderURLMergeProcessor;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
|
||||
|
||||
public class DefaultProviderURLMergeProcessorTest {
|
||||
|
||||
|
|
|
|||
238
dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
vendored
Normal file
238
dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
vendored
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.common.cache;
|
||||
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.FileLock;
|
||||
import java.nio.channels.OverlappingFileLockException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Local file interaction class that can back different caches.
|
||||
*
|
||||
* All items in local file are of human friendly format.
|
||||
*/
|
||||
public class FileCacheStore {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FileCacheStore.class);
|
||||
|
||||
private static final int DEL = 0x7F;
|
||||
private static final char ESCAPE = '%';
|
||||
private static final Set<Character> ILLEGALS = new HashSet<Character>();
|
||||
private static final String SUFFIX = ".dubbo.cache";
|
||||
|
||||
private String fileName;
|
||||
private File basePath;
|
||||
private File cacheFile;
|
||||
private FileLock directoryLock;
|
||||
private File lockFile;
|
||||
|
||||
public FileCacheStore(String basePath, String fileName) throws IOException, PathNotExclusiveException {
|
||||
if (basePath == null) {
|
||||
basePath = System.getProperty("user.home") + "/.dubbo/";
|
||||
}
|
||||
this.basePath = new File(basePath);
|
||||
this.fileName = fileName;
|
||||
|
||||
this.cacheFile = getFile(fileName, SUFFIX);
|
||||
if (cacheFile != null && !cacheFile.exists()) {
|
||||
cacheFile.createNewFile();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> loadCache(int entrySize) throws IOException {
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(cacheFile))) {
|
||||
int count = 1;
|
||||
String line = reader.readLine();
|
||||
while (line != null && count <= entrySize) {
|
||||
// content has '=' need to be encoded before write
|
||||
if (!line.equals("") && !line.startsWith("#") && line.contains("=")) {
|
||||
String[] pairs = line.split("=");
|
||||
properties.put(pairs[0], pairs[1]);
|
||||
count++;
|
||||
}
|
||||
line = reader.readLine();
|
||||
}
|
||||
|
||||
if (count > entrySize) {
|
||||
logger.warn("Cache file was truncated for exceeding the maximum entry size " + entrySize);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn("Load cache failed ", e);
|
||||
throw e;
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
public File getFile(String cacheName, String suffix) throws PathNotExclusiveException {
|
||||
cacheName = safeName(cacheName);
|
||||
if (!cacheName.endsWith(suffix)) {
|
||||
cacheName = cacheName + suffix;
|
||||
}
|
||||
return getFile(cacheName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a file object for the given name
|
||||
*
|
||||
* @param name the file name
|
||||
* @return a file object
|
||||
*/
|
||||
public File getFile(String name) throws PathNotExclusiveException {
|
||||
synchronized (this) {
|
||||
File candidate = basePath;
|
||||
// ensure cache store path exists
|
||||
if (!candidate.isDirectory() && !candidate.mkdirs()) {
|
||||
throw new RuntimeException("Cache store path can't be created: " + candidate);
|
||||
}
|
||||
|
||||
try {
|
||||
tryFileLock(name);
|
||||
} catch (PathNotExclusiveException e) {
|
||||
logger.warn("Path '" + basePath
|
||||
+ "' is already used by an existing Dubbo process.\n"
|
||||
+ "Please specify another one explicitly.");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(basePath, name);
|
||||
for (File parent = file.getParentFile(); parent != null; parent = parent.getParentFile()) {
|
||||
if (basePath.equals(parent)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Attempted to access file outside the dubbo cache path");
|
||||
}
|
||||
|
||||
/**
|
||||
* sanitize a name for valid file or directory name
|
||||
*
|
||||
* @param name
|
||||
* @return sanitized version of name
|
||||
*/
|
||||
private static String safeName(String name) {
|
||||
int len = name.length();
|
||||
StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
char c = name.charAt(i);
|
||||
if (c <= ' ' || c >= DEL || (c >= 'A' && c <= 'Z') || ILLEGALS.contains(c) || c == ESCAPE) {
|
||||
sb.append(ESCAPE);
|
||||
sb.append(String.format("%04x", (int) c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void tryFileLock(String fileName) throws PathNotExclusiveException {
|
||||
lockFile = new File(basePath.getAbsoluteFile(), fileName + ".lock");
|
||||
lockFile.deleteOnExit();
|
||||
|
||||
FileLock dirLock;
|
||||
try {
|
||||
lockFile.createNewFile();
|
||||
if (!lockFile.exists()) {
|
||||
throw new AssertionError("Failed to create lock file " + lockFile);
|
||||
}
|
||||
FileChannel lockFileChannel = new RandomAccessFile(lockFile, "rw").getChannel();
|
||||
dirLock = lockFileChannel.tryLock();
|
||||
} catch (OverlappingFileLockException ofle) {
|
||||
dirLock = null;
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
||||
if (dirLock == null) {
|
||||
throw new PathNotExclusiveException(basePath.getAbsolutePath() + "/" + fileName + " is not exclusive.");
|
||||
}
|
||||
|
||||
this.directoryLock = dirLock;
|
||||
}
|
||||
|
||||
private void unlock() {
|
||||
if (directoryLock != null && directoryLock.isValid()) {
|
||||
try {
|
||||
directoryLock.release();
|
||||
directoryLock.channel().close();
|
||||
deleteFile(lockFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to release cache path's lock file:" + lockFile, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshCache(Map<String, String> properties, String comment) {
|
||||
if (CollectionUtils.isEmptyMap(properties)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(cacheFile, false), StandardCharsets.UTF_8))) {
|
||||
bw.write("#" + comment);
|
||||
bw.write("#" + new Date().toString());
|
||||
bw.newLine();
|
||||
for (Map.Entry<String, String> e : properties.entrySet()) {
|
||||
String key = e.getKey();
|
||||
String val = e.getValue();
|
||||
bw.write(key + "=" + val);
|
||||
bw.newLine();
|
||||
}
|
||||
bw.flush();
|
||||
} catch (IOException e) {
|
||||
logger.warn("Update cache error.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteFile(File f) {
|
||||
if (!f.delete()) {
|
||||
logger.debug("Failed to delete file " + f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
private static class PathNotExclusiveException extends Exception {
|
||||
public PathNotExclusiveException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PathNotExclusiveException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ public class CompositeConfiguration implements Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
//FIXME, consider change configList to SortedMap to replace this boolean status.
|
||||
//FIXME, consider changing configList to SortedMap to replace this boolean status.
|
||||
public boolean isDynamicIncluded() {
|
||||
return dynamicIncluded;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ public class ConfigurationUtils {
|
|||
public static Map<String, String> parseProperties(String content) throws IOException {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
logger.warn("You specified the config center, but there's not even one single config item in it.");
|
||||
logger.warn("Config center was specified, but no config item found.");
|
||||
} else {
|
||||
Properties properties = new Properties();
|
||||
properties.load(new StringReader(content));
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.config.configcenter.file;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
|
||||
import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
|
||||
|
|
@ -33,6 +30,10 @@ import org.apache.dubbo.common.utils.StringUtils;
|
|||
import org.apache.dubbo.rpc.model.ScopeModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModelUtil;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystem;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration {
|
|||
try {
|
||||
configuration.close();
|
||||
} catch (Exception e) {
|
||||
logger.warn("close dynamic configuration failed: " + e.getMessage(), e);
|
||||
logger.warn("close dynamic configuration " + configuration.getClass().getName() + "failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
configurations.clear();
|
||||
|
|
|
|||
|
|
@ -217,10 +217,6 @@ public interface CommonConstants {
|
|||
|
||||
String METADATA_KEY = "metadata-type";
|
||||
|
||||
String CONFIG_MAPPING_TYPE = "config";
|
||||
|
||||
String METADATA_MAPPING_TYPE = "metadata";
|
||||
|
||||
String DEFAULT_METADATA_STORAGE_TYPE = "local";
|
||||
|
||||
String REMOTE_METADATA_STORAGE_TYPE = "remote";
|
||||
|
|
|
|||
|
|
@ -96,11 +96,7 @@ public interface RegistryConstants {
|
|||
String SERVICE_REGISTRY_PROTOCOL = "service-discovery-registry";
|
||||
|
||||
/**
|
||||
* The parameter key of the subscribed service names for Service-Oriented Registry
|
||||
* <p>
|
||||
* If there is a multiple-values, the "comma" is the separator.
|
||||
*
|
||||
* @since 2.7.5
|
||||
* Specify registry level services consumer needs to subscribe to, multiple values should be separated using ",".
|
||||
*/
|
||||
String SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services";
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public abstract class AbstractDeployer<E extends ScopeModel> implements Deployer
|
|||
|
||||
protected AtomicBoolean initialized = new AtomicBoolean(false);
|
||||
|
||||
private List<DeployListener<E>> listeners = new ArrayList<>();
|
||||
protected List<DeployListener<E>> listeners = new ArrayList<>();
|
||||
|
||||
private E scopeModel;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,5 +25,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
|
|||
*/
|
||||
@SPI(scope = ExtensionScope.APPLICATION)
|
||||
public interface ApplicationDeployListener extends DeployListener<ApplicationModel> {
|
||||
default void onModuleStarted(ApplicationModel applicationModel) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ public interface ApplicationDeployer extends Deployer<ApplicationModel> {
|
|||
*/
|
||||
void prepareApplicationInstance();
|
||||
|
||||
/**
|
||||
* Register application instance and start internal services
|
||||
*/
|
||||
void prepareInternalModule();
|
||||
|
||||
/**
|
||||
* Pre-processing before destroy model
|
||||
*/
|
||||
|
|
@ -77,7 +82,7 @@ public interface ApplicationDeployer extends Deployer<ApplicationModel> {
|
|||
/**
|
||||
* check all module state and update application state
|
||||
*/
|
||||
void checkState();
|
||||
void checkState(ModuleModel moduleModel, DeployState moduleState);
|
||||
|
||||
/**
|
||||
* module state changed callbacks
|
||||
|
|
|
|||
|
|
@ -14,8 +14,14 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.registry.xds;
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
public interface XdsEnv {
|
||||
String getCluster();
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class JsonUtils {
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static Gson getGson() {
|
||||
return gson;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* LRU-2
|
||||
* </p>
|
||||
* When the data accessed for the first time, add it to history list. If the size of history list reaches max capacity, eliminate the earliest data (first in first out).
|
||||
* When the data already exists in the history list, and be accessed for the second time, then it will be put into cache.
|
||||
*
|
||||
* TODO, consider replacing with ConcurrentHashMap to improve performance under concurrency
|
||||
*/
|
||||
public class LRU2Cache<K, V> extends LinkedHashMap<K, V> {
|
||||
|
||||
private static final long serialVersionUID = -5167631809472116969L;
|
||||
|
||||
private static final float DEFAULT_LOAD_FACTOR = 0.75f;
|
||||
|
||||
private static final int DEFAULT_MAX_CAPACITY = 1000;
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private volatile int maxCapacity;
|
||||
|
||||
// as history list
|
||||
private PreCache<K, Boolean> preCache;
|
||||
|
||||
public LRU2Cache() {
|
||||
this(DEFAULT_MAX_CAPACITY);
|
||||
}
|
||||
|
||||
public LRU2Cache(int maxCapacity) {
|
||||
super(16, DEFAULT_LOAD_FACTOR, true);
|
||||
this.maxCapacity = maxCapacity;
|
||||
this.preCache = new PreCache<>(maxCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
|
||||
return size() > maxCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
lock.lock();
|
||||
try {
|
||||
return super.containsKey(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
lock.lock();
|
||||
try {
|
||||
return super.get(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (preCache.containsKey(key)) {
|
||||
// add it to cache
|
||||
preCache.remove(key);
|
||||
return super.put(key, value);
|
||||
} else {
|
||||
// add it to history list
|
||||
preCache.put(key, true);
|
||||
return value;
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
lock.lock();
|
||||
try {
|
||||
preCache.remove(key);
|
||||
return super.remove(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
lock.lock();
|
||||
try {
|
||||
return super.size();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
lock.lock();
|
||||
try {
|
||||
preCache.clear();
|
||||
super.clear();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxCapacity() {
|
||||
return maxCapacity;
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
preCache.setMaxCapacity(maxCapacity);
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
static class PreCache<K, V> extends LinkedHashMap<K, V> {
|
||||
|
||||
private volatile int maxCapacity;
|
||||
|
||||
public PreCache() {
|
||||
this(DEFAULT_MAX_CAPACITY);
|
||||
}
|
||||
|
||||
public PreCache(int maxCapacity) {
|
||||
super(16, DEFAULT_LOAD_FACTOR, true);
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
|
||||
return size() > maxCapacity;
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -20,12 +20,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* LRU-2
|
||||
* </p>
|
||||
* When the data accessed for the first time, add it to history list. If the size of history list reaches max capacity, eliminate the earliest data (first in first out).
|
||||
* When the data already exists in the history list, and be accessed for the second time, then it will be put into cache.
|
||||
*/
|
||||
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
|
||||
|
||||
private static final long serialVersionUID = -5167631809472116969L;
|
||||
|
|
@ -36,9 +30,6 @@ public class LRUCache<K, V> extends LinkedHashMap<K, V> {
|
|||
private final Lock lock = new ReentrantLock();
|
||||
private volatile int maxCapacity;
|
||||
|
||||
// as history list
|
||||
private PreCache<K, Boolean> preCache;
|
||||
|
||||
public LRUCache() {
|
||||
this(DEFAULT_MAX_CAPACITY);
|
||||
}
|
||||
|
|
@ -46,7 +37,6 @@ public class LRUCache<K, V> extends LinkedHashMap<K, V> {
|
|||
public LRUCache(int maxCapacity) {
|
||||
super(16, DEFAULT_LOAD_FACTOR, true);
|
||||
this.maxCapacity = maxCapacity;
|
||||
this.preCache = new PreCache<>(maxCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -78,15 +68,7 @@ public class LRUCache<K, V> extends LinkedHashMap<K, V> {
|
|||
public V put(K key, V value) {
|
||||
lock.lock();
|
||||
try {
|
||||
if (preCache.containsKey(key)) {
|
||||
// add it to cache
|
||||
preCache.remove(key);
|
||||
return super.put(key, value);
|
||||
} else {
|
||||
// add it to history list
|
||||
preCache.put(key, true);
|
||||
return value;
|
||||
}
|
||||
return super.put(key, value);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
|
@ -96,7 +78,6 @@ public class LRUCache<K, V> extends LinkedHashMap<K, V> {
|
|||
public V remove(Object key) {
|
||||
lock.lock();
|
||||
try {
|
||||
preCache.remove(key);
|
||||
return super.remove(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
|
@ -117,43 +98,26 @@ public class LRUCache<K, V> extends LinkedHashMap<K, V> {
|
|||
public void clear() {
|
||||
lock.lock();
|
||||
try {
|
||||
preCache.clear();
|
||||
super.clear();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void lock() {
|
||||
lock.lock();
|
||||
}
|
||||
|
||||
public void releaseLock() {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
public int getMaxCapacity() {
|
||||
return maxCapacity;
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
preCache.setMaxCapacity(maxCapacity);
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
static class PreCache<K, V> extends LinkedHashMap<K, V> {
|
||||
|
||||
private volatile int maxCapacity;
|
||||
|
||||
public PreCache() {
|
||||
this(DEFAULT_MAX_CAPACITY);
|
||||
}
|
||||
|
||||
public PreCache(int maxCapacity) {
|
||||
super(16, DEFAULT_LOAD_FACTOR, true);
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) {
|
||||
return size() > maxCapacity;
|
||||
}
|
||||
|
||||
public void setMaxCapacity(int maxCapacity) {
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ package org.apache.dubbo.common.utils;
|
|||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
|
|
|||
|
|
@ -16,14 +16,6 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.definition;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
|
||||
import org.apache.dubbo.metadata.definition.model.MethodDefinition;
|
||||
import org.apache.dubbo.metadata.definition.model.ServiceDefinition;
|
||||
|
|
@ -32,6 +24,14 @@ import org.apache.dubbo.metadata.definition.util.ClassUtils;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 2015/1/27.
|
||||
*/
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.definition;
|
||||
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder;
|
||||
import org.apache.dubbo.metadata.definition.builder.TypeBuilder;
|
||||
import org.apache.dubbo.metadata.definition.model.TypeDefinition;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -37,11 +37,10 @@ import java.util.Set;
|
|||
*/
|
||||
public class TypeDefinitionBuilder {
|
||||
private static final Logger logger = LoggerFactory.getLogger(TypeDefinitionBuilder.class);
|
||||
static final List<TypeBuilder> BUILDERS;
|
||||
public static List<TypeBuilder> BUILDERS;
|
||||
|
||||
static {
|
||||
ExtensionLoader<TypeBuilder> extensionLoader = ExtensionLoader.getExtensionLoader(TypeBuilder.class);
|
||||
Set<TypeBuilder> tbs = extensionLoader.getSupportedExtensionInstances();
|
||||
public static void initBuilders(FrameworkModel model) {
|
||||
Set<TypeBuilder> tbs = model.getExtensionLoader(TypeBuilder.class).getSupportedExtensionInstances();
|
||||
BUILDERS = new ArrayList<>(tbs);
|
||||
}
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.definition.builder;
|
||||
|
||||
import org.apache.dubbo.common.extension.ExtensionScope;
|
||||
import org.apache.dubbo.common.extension.SPI;
|
||||
import org.apache.dubbo.common.lang.Prioritized;
|
||||
import org.apache.dubbo.metadata.definition.model.TypeDefinition;
|
||||
|
|
@ -26,7 +27,7 @@ import java.util.Map;
|
|||
/**
|
||||
* 2015/1/27.
|
||||
*/
|
||||
@SPI
|
||||
@SPI(scope = ExtensionScope.FRAMEWORK)
|
||||
public interface TypeBuilder extends Prioritized {
|
||||
|
||||
/**
|
||||
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.apache.dubbo.metadata.definition.model;
|
||||
|
||||
import org.apache.dubbo.metadata.definition.util.ClassUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.dubbo.metadata.definition.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* 2015/1/27.
|
||||
*/
|
||||
|
|
@ -25,6 +25,7 @@ import org.apache.dubbo.common.logger.LoggerFactory;
|
|||
import org.apache.dubbo.common.resource.GlobalResourcesRepository;
|
||||
import org.apache.dubbo.common.utils.Assert;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.metadata.definition.TypeDefinitionBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -81,6 +82,9 @@ public class FrameworkModel extends ScopeModel {
|
|||
@Override
|
||||
protected void initialize() {
|
||||
super.initialize();
|
||||
|
||||
TypeDefinitionBuilder.initBuilders(this);
|
||||
|
||||
serviceRepository = new FrameworkServiceRepository(this);
|
||||
|
||||
ExtensionLoader<ScopeModelInitializer> initializerExtensionLoader = this.getExtensionLoader(ScopeModelInitializer.class);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ public class ModuleModel extends ScopeModel {
|
|||
if (applicationDeployer != null) {
|
||||
applicationDeployer.notifyModuleChanged(this, DeployState.PENDING);
|
||||
}
|
||||
this.internalModule = isInternal;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -188,6 +188,15 @@ public class ModuleServiceRepository {
|
|||
return Collections.unmodifiableList(serviceDescriptors);
|
||||
}
|
||||
|
||||
public ServiceDescriptor getService(String serviceName) {
|
||||
// TODO, may need to distinguish service by class loader.
|
||||
List<ServiceDescriptor> serviceDescriptors = services.get(serviceName);
|
||||
if (CollectionUtils.isEmpty(serviceDescriptors)) {
|
||||
return null;
|
||||
}
|
||||
return serviceDescriptors.get(0);
|
||||
}
|
||||
|
||||
public ServiceDescriptor lookupService(String interfaceName) {
|
||||
if (services.containsKey(interfaceName)) {
|
||||
List<ServiceDescriptor> serviceDescriptors = services.get(interfaceName);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public abstract class ScopeModel implements ExtensionAccessor {
|
|||
|
||||
private Map<String, Object> attributes;
|
||||
private final AtomicBoolean destroyed = new AtomicBoolean(false);
|
||||
protected boolean internalModule;
|
||||
|
||||
public ScopeModel(ScopeModel parent, ExtensionScope scope) {
|
||||
this.parent = parent;
|
||||
|
|
@ -227,6 +228,10 @@ public abstract class ScopeModel implements ExtensionAccessor {
|
|||
this.desc = buildDesc();
|
||||
}
|
||||
|
||||
public boolean isInternal() {
|
||||
return internalModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the describe string of this scope model
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,16 +17,21 @@
|
|||
package org.apache.dubbo.rpc.model;
|
||||
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
|
||||
import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentNavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
/**
|
||||
* ServiceModel and ServiceMetadata are to some extend duplicated with each other. We should merge them in the future.
|
||||
|
|
@ -37,11 +42,18 @@ public class ServiceDescriptor {
|
|||
// to accelerate search
|
||||
private final Map<String, List<MethodDescriptor>> methods = new HashMap<>();
|
||||
private final Map<String, Map<String, MethodDescriptor>> descToMethods = new HashMap<>();
|
||||
private ConcurrentNavigableMap<String, FullServiceDefinition> serviceDefinitions = new ConcurrentSkipListMap<>();
|
||||
|
||||
public ServiceDescriptor(Class<?> interfaceClass) {
|
||||
this.serviceInterfaceClass = interfaceClass;
|
||||
this.serviceName = interfaceClass.getName();
|
||||
initMethods();
|
||||
initServiceDefinition(interfaceClass);
|
||||
}
|
||||
|
||||
private void initServiceDefinition(Class<?> interfaceClass) {
|
||||
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, Collections.emptyMap());
|
||||
serviceDefinitions.put(serviceName, fullServiceDefinition);
|
||||
}
|
||||
|
||||
private void initMethods() {
|
||||
|
|
@ -116,6 +128,14 @@ public class ServiceDescriptor {
|
|||
return methods.get(methodName);
|
||||
}
|
||||
|
||||
public ConcurrentNavigableMap<String, FullServiceDefinition> getServiceDefinitions() {
|
||||
return serviceDefinitions;
|
||||
}
|
||||
|
||||
public FullServiceDefinition getServiceDefinition(String serviceName) {
|
||||
return serviceDefinitions.get(serviceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.apache.dubbo.common.status.reporter.FrameworkStatusReportService;
|
|||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.common;
|
||||
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.apache.dubbo.common.utils.StringUtils;
|
|||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModelAccessor;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.apache.dubbo.common.beans.model.FooBeanWithApplicationModel;
|
|||
import org.apache.dubbo.common.beans.model.FooBeanWithFrameworkModel;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
62
dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java
vendored
Normal file
62
dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.common.cache;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class FileCacheStoreTest {
|
||||
FileCacheStore cacheStore;
|
||||
|
||||
@Test
|
||||
public void testCache() throws Exception {
|
||||
String directoryPath = getDirectoryOfClassPath();
|
||||
String filePath = "test-cache.dubbo.cache";
|
||||
cacheStore = new FileCacheStore(directoryPath, filePath);
|
||||
Map<String, String> properties = cacheStore.loadCache(10);
|
||||
assertEquals(2, properties.size());
|
||||
|
||||
Map<String, String> newProperties = new HashMap<>();
|
||||
newProperties.put("newKey1", "newValue1");
|
||||
newProperties.put("newKey2", "newValue2");
|
||||
newProperties.put("newKey3", "newValue3");
|
||||
newProperties.put("newKey4", "newValue4");
|
||||
cacheStore = new FileCacheStore(directoryPath, "non-exit.dubbo.cache");
|
||||
cacheStore.refreshCache(newProperties, "test refresh cache");
|
||||
Map<String, String> propertiesLimitTo2 = cacheStore.loadCache(2);
|
||||
assertEquals(2, propertiesLimitTo2.size());
|
||||
|
||||
Map<String, String> propertiesLimitTo10 = cacheStore.loadCache(10);
|
||||
assertEquals(4, propertiesLimitTo10.size());
|
||||
}
|
||||
|
||||
private String getDirectoryOfClassPath() throws URISyntaxException {
|
||||
URL resource = this.getClass().getResource("/log4j.xml");
|
||||
String path = Paths.get(resource.toURI()).toFile().getAbsolutePath();
|
||||
int index = path.indexOf("log4j.xml");
|
||||
String directoryPath = path.substring(0, index);
|
||||
return directoryPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,12 +16,9 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.concurrent;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
|
@ -32,8 +29,12 @@ import java.util.concurrent.SynchronousQueue;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
|
||||
public class CompletableFutureTaskTest {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
|
|||
import org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.common.config;
|
||||
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
package org.apache.dubbo.common.config.configcenter.file;
|
||||
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.config.configcenter.file;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.apache.dubbo.common.extension.director.impl.TestModuleService;
|
|||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ import org.apache.dubbo.common.extension.wrapper.impl.DemoImpl;
|
|||
import org.apache.dubbo.common.lang.Prioritized;
|
||||
import org.apache.dubbo.common.url.component.ServiceConfigURL;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.extension.activate.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.common.extension.activate.ActivateExt1;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.Activate;
|
||||
|
||||
@Activate(group = "old_group")
|
||||
public class OldActivateExt1Impl2 implements ActivateExt1 {
|
||||
public String echo(String msg) {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.extension.activate.impl;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.Activate;
|
||||
import org.apache.dubbo.common.extension.activate.ActivateExt1;
|
||||
|
||||
import com.alibaba.dubbo.common.extension.Activate;
|
||||
|
||||
@Activate(group = "old_group")
|
||||
public class OldActivateExt1Impl3 implements ActivateExt1 {
|
||||
public String echo(String msg) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.apache.dubbo.common.extension.ExtensionInjector;
|
|||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.extension.director.FooFrameworkProvider;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.common.extension.support;
|
||||
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.common.lang;
|
||||
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.common.logger;
|
||||
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ package org.apache.dubbo.common.status;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.status.Status.Level.OK;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class StatusTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.status.reporter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ package org.apache.dubbo.common.status.support;
|
|||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.status.Status;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class LoadStatusCheckerTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(LoadStatusCheckerTest.class);
|
||||
|
|
|
|||
|
|
@ -20,13 +20,14 @@ package org.apache.dubbo.common.status.support;
|
|||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.status.Status;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.apache.dubbo.common.status.Status.Level.OK;
|
||||
import static org.apache.dubbo.common.status.Status.Level.WARN;
|
||||
import static org.hamcrest.CoreMatchers.anyOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class MemoryStatusCheckerTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MemoryStatusCheckerTest.class);
|
||||
|
|
|
|||
|
|
@ -18,16 +18,17 @@
|
|||
package org.apache.dubbo.common.status.support;
|
||||
|
||||
import org.apache.dubbo.common.status.Status;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class StatusUtilsTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.common.threadpool.manager;
|
|||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.common.utils;
|
|||
import org.apache.dubbo.common.extension.DubboInternalLoadingStrategy;
|
||||
import org.apache.dubbo.common.extension.director.FooAppProvider;
|
||||
import org.apache.dubbo.common.resource.GlobalResourcesRepository;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.apache.dubbo.common.config.InmemoryConfiguration;
|
|||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.threadpool.ThreadPool;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package org.apache.dubbo.common.utils;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class HolderTest {
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@ package org.apache.dubbo.common.utils;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class LRUCacheTest {
|
||||
public class LRU2CacheTest {
|
||||
@Test
|
||||
public void testCache() throws Exception {
|
||||
LRUCache<String, Integer> cache = new LRUCache<String, Integer>(3);
|
||||
LRU2Cache<String, Integer> cache = new LRU2Cache<String, Integer>(3);
|
||||
cache.put("one", 1);
|
||||
cache.put("two", 2);
|
||||
cache.put("three", 3);
|
||||
|
|
@ -63,7 +63,7 @@ public class LRUCacheTest {
|
|||
|
||||
@Test
|
||||
public void testCapacity() throws Exception {
|
||||
LRUCache<String, Integer> cache = new LRUCache<String, Integer>();
|
||||
LRU2Cache<String, Integer> cache = new LRU2Cache<String, Integer>();
|
||||
assertThat(cache.getMaxCapacity(), equalTo(1000));
|
||||
cache.setMaxCapacity(10);
|
||||
assertThat(cache.getMaxCapacity(), equalTo(10));
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import org.junit.jupiter.api.AfterEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ package org.apache.dubbo.common.utils;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class NamedThreadFactoryTest {
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@ package org.apache.dubbo.config;
|
|||
|
||||
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.config.context;
|
||||
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.apache.dubbo.config.ProtocolConfig;
|
|||
import org.apache.dubbo.config.ProviderConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.descriptor;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import org.apache.dubbo.common.stream.StreamObserver;
|
||||
import org.apache.dubbo.proto.HelloReply;
|
||||
import org.apache.dubbo.rpc.model.MethodDescriptor;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ import org.apache.dubbo.metadata.definition.common.ResultWithRawCollections;
|
|||
import org.apache.dubbo.metadata.definition.common.TestService;
|
||||
import org.apache.dubbo.metadata.definition.model.ServiceDefinition;
|
||||
import org.apache.dubbo.metadata.definition.model.TypeDefinition;
|
||||
import org.apache.dubbo.rpc.model.FrameworkModel;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
|
|
@ -35,6 +37,11 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
public class MetadataTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
TypeDefinitionBuilder.initBuilders(FrameworkModel.defaultModel());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
@ -32,8 +32,8 @@ public class ComplexObject {
|
|||
public ComplexObject() {
|
||||
}
|
||||
|
||||
public ComplexObject(String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum) {
|
||||
this.setInnerObject(new ComplexObject.InnerObject());
|
||||
public ComplexObject(String var1, int var2, long l, String[] var3, List<Integer> var4, TestEnum testEnum) {
|
||||
this.setInnerObject(new InnerObject());
|
||||
this.getInnerObject().setInnerA(var1);
|
||||
this.getInnerObject().setInnerB(var2);
|
||||
this.setIntList(var4);
|
||||
|
|
@ -23,6 +23,7 @@ import org.apache.dubbo.common.lang.ShutdownHookCallbacks;
|
|||
import org.apache.dubbo.common.status.reporter.FrameworkStatusReportService;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.rpc.support.MockScopeModelDestroyListener;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.model;
|
|||
|
||||
import org.apache.dubbo.common.extension.ExtensionScope;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
|
|||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.rpc.support.DemoService;
|
||||
import org.apache.dubbo.rpc.support.DemoServiceImpl;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.apache.dubbo.common.config.ConfigurationCache;
|
|||
import org.apache.dubbo.common.config.ModuleEnvironment;
|
||||
import org.apache.dubbo.common.extension.ExtensionScope;
|
||||
import org.apache.dubbo.rpc.support.MockScopeModelDestroyListener;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.model;
|
|||
|
||||
import org.apache.dubbo.rpc.support.DemoService;
|
||||
import org.apache.dubbo.rpc.support.DemoServiceImpl;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.rpc.model;
|
||||
|
||||
import org.apache.dubbo.rpc.support.MockScopeModelAware;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue