repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/AbstractRegistryCenterTestExecutionListener.java
/* * 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.test.check; import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import java.util.HashSet; import java.util.Set; import org.junit.platform.engine.TestSource; import org.junit.platform.engine.support.descriptor.ClassSource; import org.junit.platform.launcher.TestExecutionListener; import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestPlan; import static org.apache.dubbo.common.constants.CommonConstants.ThirdPartyProperty.ZOOKEEPER_CONFIG_ENABLE_EMBEDDED; /** * The abstract implementation provides the basic methods. <p></p> * {@link #needRegistryCenter(TestPlan)}: checks if current {@link TestPlan} need registry center. */ public abstract class AbstractRegistryCenterTestExecutionListener implements TestExecutionListener { /** * The registry center should start * if we want to run the test cases in the given package. */ private static final Set<String> PACKAGE_NAME = new HashSet<>(); /** * Use embedded zookeeper or not. */ private static boolean enableEmbeddedZookeeper; static { // dubbo-config module PACKAGE_NAME.add("org.apache.dubbo.config"); // dubbo-test module PACKAGE_NAME.add("org.apache.dubbo.test"); // dubbo-registry PACKAGE_NAME.add("org.apache.dubbo.registry"); // dubbo-remoting-zookeeper PACKAGE_NAME.add("org.apache.dubbo.remoting.zookeeper"); // dubbo-metadata-report-zookeeper PACKAGE_NAME.add("org.apache.dubbo.metadata.store.zookeeper"); enableEmbeddedZookeeper = Boolean.valueOf(SystemPropertyConfigUtils.getSystemProperty(ZOOKEEPER_CONFIG_ENABLE_EMBEDDED, "true")); } /** * Checks if current {@link TestPlan} need registry center. */ public boolean needRegistryCenter(TestPlan testPlan) { return testPlan.getRoots().stream() .flatMap(testIdentifier -> testPlan.getChildren(testIdentifier).stream()) .filter(testIdentifier -> testIdentifier.getSource().isPresent()) .filter(testIdentifier -> supportEmbeddedZookeeper(testIdentifier)) .count() > 0; } /** * Checks if current {@link TestIdentifier} need registry center. */ public boolean needRegistryCenter(TestIdentifier testIdentifier) { return supportEmbeddedZookeeper(testIdentifier); } /** * Checks if the current {@link TestIdentifier} need embedded zookeeper. */ private boolean supportEmbeddedZookeeper(TestIdentifier testIdentifier) { if (!enableEmbeddedZookeeper) { return false; } TestSource testSource = testIdentifier.getSource().orElse(null); if (testSource instanceof ClassSource) { String packageName = ((ClassSource) testSource).getJavaClass().getPackage().getName(); for (String pkgName : PACKAGE_NAME) { if (packageName.contains(pkgName)) { return true; } } } return false; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterFinished.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/RegistryCenterFinished.java
/* * 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.test.check; import org.apache.dubbo.test.check.registrycenter.GlobalRegistryCenter; import org.junit.platform.launcher.TestPlan; /** * The entrance to terminate the mocked registry center. */ public class RegistryCenterFinished extends AbstractRegistryCenterTestExecutionListener { @Override public void testPlanExecutionFinished(TestPlan testPlan) { super.testPlanExecutionFinished(testPlan); try { if (needRegistryCenter(testPlan)) { GlobalRegistryCenter.shutdown(); } } catch (Throwable cause) { throw new IllegalStateException("Failed to terminate zookeeper instance in unit test", cause); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/DubboTestChecker.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/DubboTestChecker.java
/* * 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.test.check; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.rpc.model.FrameworkModel; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.junit.platform.engine.TestExecutionResult; import org.junit.platform.engine.TestSource; import org.junit.platform.engine.support.descriptor.ClassSource; import org.junit.platform.engine.support.descriptor.MethodSource; import org.junit.platform.launcher.TestExecutionListener; import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestPlan; /** * A test listener to check unclosed threads of test. * * <pre> * Usages: * # enable thread checking * mvn test -DcheckThreads=true * * # change thread dump wait time (ms) * mvn test -DcheckThreads=true -DthreadDumpWaitTime=5000 * * # print test reports of all sub modules to single file * mvn test -DcheckThreads=true -DthreadDumpWaitTime=5000 -DreportFile=/path/test-check-report.txt * </pre> */ public class DubboTestChecker implements TestExecutionListener { private static final String CONFIG_CHECK_MODE = "checkMode"; private static final String CONFIG_CHECK_THREADS = "checkThreads"; private static final String CONFIG_THREAD_DUMP_WAIT_TIME = "threadDumpWaitTime"; private static final String CONFIG_FORCE_DESTROY = "forceDestroy"; private static final String CONFIG_REPORT_FILE = "reportFile"; private static final String MODE_CLASS = "class"; private static final String MODE_METHOD = "method"; private static final Logger logger = LoggerFactory.getLogger(DubboTestChecker.class); /** * check mode: * class - check after class execution finished * method - check after method execution finished */ private String checkMode; /** * whether check unclosed threads */ private boolean checkThreads; /** * sleep time before dump threads */ private long threadDumpWaitTimeMs; /** * whether force destroy dubbo engine, default value is true. */ private boolean forceDestroyDubboAfterClass; /** * Check report file */ private File reportFile; /** * thread -> stacktrace */ private Map<Thread, StackTraceElement[]> unclosedThreadMap = new ConcurrentHashMap<>(); // test class name -> thread list private Map<String, List<Thread>> unclosedThreadsOfTestMap = new ConcurrentHashMap<>(); private String identifier; private PrintWriter reportWriter; private String projectDir; private FileOutputStream reportFileOut; @Override public void testPlanExecutionStarted(TestPlan testPlan) { try { init(System.getProperties()); } catch (IOException e) { throw new IllegalStateException("Test checker init failed", e); } } public void init(Properties properties) throws IOException { if (properties == null) { properties = new Properties(); } // log prefix identifier = "[" + this.getClass().getSimpleName() + "] "; // checkMode: class/method checkMode = StringUtils.lowerCase(properties.getProperty(CONFIG_CHECK_MODE, MODE_CLASS)); // checkThreads: true/false checkThreads = Boolean.parseBoolean(properties.getProperty(CONFIG_CHECK_THREADS, "false")); // threadDumpWaitTime threadDumpWaitTimeMs = Long.parseLong(properties.getProperty(CONFIG_THREAD_DUMP_WAIT_TIME, "5000")); // force destroy dubbo forceDestroyDubboAfterClass = Boolean.parseBoolean(properties.getProperty(CONFIG_FORCE_DESTROY, "true")); // project dir projectDir = new File(".").getCanonicalPath(); // report file String reportFileCanonicalPath = ""; String defaultReportDir = "target/"; String defaultReportFileName = "test-check-report.txt"; if (checkThreads) { String reportFilePath = properties.getProperty(CONFIG_REPORT_FILE, defaultReportDir + defaultReportFileName); this.reportFile = new File(reportFilePath); if (reportFile.isDirectory()) { reportFile.mkdirs(); reportFile = new File(reportFile, defaultReportFileName); } reportFileOut = new FileOutputStream(this.reportFile); reportWriter = new PrintWriter(reportFileOut); reportFileCanonicalPath = reportFile.getCanonicalPath(); } log("Project dir: " + projectDir); log(String.format( "Dubbo test checker configs: checkMode=%s, checkThreads=%s, threadDumpWaitTimeMs=%s, forceDestroy=%s, reportFile=%s", checkMode, checkThreads, threadDumpWaitTimeMs, forceDestroyDubboAfterClass, reportFileCanonicalPath)); flushReportFile(); } @Override public void testPlanExecutionFinished(TestPlan testPlan) { // print all unclosed threads if (checkThreads) { printThreadCheckingSummaryReport(); } else { log("Thread checking is disabled, use -DcheckThreads=true to check unclosed threads."); } if (reportWriter != null) { reportWriter.close(); } } private void printThreadCheckingSummaryReport() { log("===== Thread Checking Summary Report ======"); log("Project dir: " + projectDir); log("Total found " + unclosedThreadMap.size() + " unclosed threads in " + unclosedThreadsOfTestMap.size() + " tests."); log(""); unclosedThreadsOfTestMap.forEach((testClassName, threads) -> { printUnclosedThreads(threads, testClassName); }); flushReportFile(); } private void flushReportFile() { try { if (reportWriter != null) { reportWriter.flush(); } if (reportFileOut != null) { reportFileOut.getFD().sync(); } } catch (IOException e) { e.printStackTrace(); } } public Map<Thread, StackTraceElement[]> getUnclosedThreadMap() { return unclosedThreadMap; } @Override public void executionStarted(TestIdentifier testIdentifier) { TestSource testSource = testIdentifier.getSource().orElse(null); if (testSource instanceof ClassSource) { // ClassSource source = (ClassSource) testSource; // log("Run test class: " + source.getClassName()); } else if (testSource instanceof MethodSource) { MethodSource source = (MethodSource) testSource; log("Run test method: " + source.getClassName() + "#" + source.getMethodName()); } } @Override public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { TestSource testSource = testIdentifier.getSource().orElse(null); String testClassName; if (testSource instanceof MethodSource) { if (!StringUtils.contains(checkMode, MODE_METHOD)) { return; } MethodSource methodSource = (MethodSource) testSource; testClassName = methodSource.getClassName(); // log("Finish test method: " + methodSource.getClassName() + "#" + methodSource.getMethodName()); } else if (testSource instanceof ClassSource) { if (forceDestroyDubboAfterClass) { // make sure destroy dubbo engine FrameworkModel.destroyAll(); } if (!StringUtils.contains(checkMode, MODE_CLASS)) { return; } ClassSource source = (ClassSource) testSource; testClassName = source.getClassName(); // log("Finish test class: " + source.getClassName()); } else { return; } if (checkThreads) { checkUnclosedThreads(testClassName, threadDumpWaitTimeMs); } } public Map<Thread, StackTraceElement[]> checkUnclosedThreads(String testClassName, long waitMs) { // wait for shutdown log("Wait " + waitMs + "ms to check threads of " + testClassName + " ..."); try { Thread.sleep(waitMs); } catch (InterruptedException e) { } Map<Thread, StackTraceElement[]> threadStacks = Thread.getAllStackTraces(); List<Thread> unclosedThreads = threadStacks.keySet().stream() .filter(thread -> !StringUtils.startsWithAny( thread.getName(), "Reference Handler", "Finalizer", "Signal Dispatcher", "Attach Listener", "process reaper", "main" // jvm , "surefire-forkedjvm-" // surefire plugin )) .filter(thread -> !unclosedThreadMap.containsKey(thread)) .collect(Collectors.toList()); unclosedThreads.sort(Comparator.comparing(Thread::getName)); if (unclosedThreads.size() > 0) { for (Thread thread : unclosedThreads) { unclosedThreadMap.put(thread, threadStacks.get(thread)); } unclosedThreadsOfTestMap.put(testClassName, unclosedThreads); printUnclosedThreads(unclosedThreads, testClassName); } // return new unclosed thread map Map<Thread, StackTraceElement[]> unclosedThreadMap = new LinkedHashMap<>(); for (Thread thread : unclosedThreads) { unclosedThreadMap.put(thread, threadStacks.get(thread)); } return unclosedThreadMap; } private void printUnclosedThreads(List<Thread> threads, String testClassName) { if (threads.size() > 0) { log("Found " + threads.size() + " unclosed threads in test: " + testClassName); for (Thread thread : threads) { StackTraceElement[] stackTrace = unclosedThreadMap.get(thread); log(getFullStacktrace(thread, stackTrace)); } flushReportFile(); } } private void log(String msg) { // logger.info(identifier + msg); String s = identifier + msg; if (reportWriter != null) { reportWriter.println(s); } } public static String getFullStacktrace(Thread thread, StackTraceElement[] stackTrace) { StringBuilder sb = new StringBuilder("Thread: \"" + thread.getName() + "\"" + " Id=" + thread.getId()); sb.append(' ').append(thread.getState()); sb.append('\n'); if (stackTrace == null) { stackTrace = thread.getStackTrace(); } for (StackTraceElement ste : stackTrace) { sb.append(" at ").append(ste.toString()); sb.append('\n'); } return sb.toString(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/exception/DubboTestException.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/exception/DubboTestException.java
/* * 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.test.check.exception; /** * Define a specified exception when test. */ public class DubboTestException extends RuntimeException { /** * Constructs a new {@link DubboTestException} with the specified detail message. * * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. */ public DubboTestException(String message) { super(message); } /** * Constructs a new {@link DubboTestException} with the specified detail message and cause. * * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). * (A null value is permitted, and indicates that the cause is nonexistent or unknown.) */ public DubboTestException(String message, Throwable cause) { super(message, cause); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Processor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Processor.java
/* * 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.test.check.registrycenter; import org.apache.dubbo.test.check.exception.DubboTestException; /** * Define the processor to execute {@link Process} with the {@link org.apache.dubbo.test.check.registrycenter.Initializer.Context} */ public interface Processor { /** * Process the command with the global context. * * @param context the global context. * @throws DubboTestException when any exception occurred. */ void process(Context context) throws DubboTestException; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/GlobalRegistryCenter.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/GlobalRegistryCenter.java
/* * 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.test.check.registrycenter; /** * The global registry center. */ public class GlobalRegistryCenter { /** * The default static registry center instance. */ private static final RegistryCenter INSTANCE = new ZookeeperRegistryCenter(); /** * Start the registry center. * * @throws Exception when an exception occurred */ public static void startup() throws Exception { INSTANCE.startup(); } /** * Reset the registry center. * * @throws Exception when an exception occurred */ public static void reset() throws Exception { INSTANCE.reset(); } /** * Stop the registry center. * * @throws Exception when an exception occurred */ public static void shutdown() throws Exception { INSTANCE.shutdown(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Context.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Context.java
/* * 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.test.check.registrycenter; /** * The global context to store all initialized variables. */ public interface Context {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Config.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Config.java
/* * 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.test.check.registrycenter; /** * Define the config to obtain the */ public interface Config { /** * Returns the default connection address in single registry center. */ default String getConnectionAddress() { return getConnectionAddress1(); } /** * Returns the first connection address in multiple registry center. */ String getConnectionAddress1(); /** * Returns the second connection address in multiple registry center. */ String getConnectionAddress2(); /** * Returns the default connection address key in single registry center. * <h3>How to use</h3> * <pre> * System.getProperty({@link #getConnectionAddressKey()}) * </pre> */ String getConnectionAddressKey(); /** * Returns the first connection address key in multiple registry center. * <h3>How to use</h3> * <pre> * System.getProperty({@link #getConnectionAddressKey1()}) * </pre> */ String getConnectionAddressKey1(); /** * Returns the second connection address key in multiple registry center. * <h3>How to use</h3> * <pre> * System.getProperty({@link #getConnectionAddressKey2()}) * </pre> */ String getConnectionAddressKey2(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/RegistryCenter.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/RegistryCenter.java
/* * 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.test.check.registrycenter; import org.apache.dubbo.test.check.exception.DubboTestException; /** * The registry center. */ public interface RegistryCenter { /** * Start the registry center. * * @throws DubboTestException when an exception occurred */ void startup() throws DubboTestException; /** * Reset the registry center after ut exited. * @throws DubboTestException when an exception occurred */ void reset() throws DubboTestException; /** * Stop the registry center. * * @throws DubboTestException when an exception occurred */ void shutdown() throws DubboTestException; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/ZookeeperRegistryCenter.java
/* * 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.test.check.registrycenter; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; import org.apache.dubbo.test.check.registrycenter.initializer.ConfigZookeeperInitializer; import org.apache.dubbo.test.check.registrycenter.initializer.DownloadZookeeperInitializer; import org.apache.dubbo.test.check.registrycenter.initializer.UnpackZookeeperInitializer; import org.apache.dubbo.test.check.registrycenter.initializer.ZookeeperInitializer; import org.apache.dubbo.test.check.registrycenter.processor.ResetZookeeperProcessor; import org.apache.dubbo.test.check.registrycenter.processor.StartZookeeperUnixProcessor; import org.apache.dubbo.test.check.registrycenter.processor.StartZookeeperWindowsProcessor; import org.apache.dubbo.test.check.registrycenter.processor.StopZookeeperUnixProcessor; import org.apache.dubbo.test.check.registrycenter.processor.StopZookeeperWindowsProcessor; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_IO_TMPDIR; import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_OS_NAME; import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.USER_HOME; /** * Build the registry center with embedded zookeeper, which is run by a new process. */ class ZookeeperRegistryCenter implements RegistryCenter { public ZookeeperRegistryCenter() { this.initializers = new ArrayList<>(); this.initializers.add(new DownloadZookeeperInitializer()); this.initializers.add(new UnpackZookeeperInitializer()); this.initializers.add(new ConfigZookeeperInitializer()); // start processor this.put(OS.Unix, Command.Start, new StartZookeeperUnixProcessor()); this.put(OS.Windows, Command.Start, new StartZookeeperWindowsProcessor()); // reset processor Processor resetProcessor = new ResetZookeeperProcessor(); this.put(OS.Unix, Command.Reset, resetProcessor); this.put(OS.Windows, Command.Reset, resetProcessor); // stop processor this.put(OS.Unix, Command.Stop, new StopZookeeperUnixProcessor()); this.put(OS.Windows, Command.Stop, new StopZookeeperWindowsProcessor()); // initialize the global context if (OS.Unix.equals(os)) { this.context = new ZookeeperContext(); } else { this.context = new ZookeeperWindowsContext(); } // initialize the context this.context.setUnpackedDirectory(UNPACKED_DIRECTORY); this.context.setSourceFile(TARGET_FILE_PATH); } private static final Logger logger = LoggerFactory.getLogger(ZookeeperRegistryCenter.class); /** * The JVM arguments to set the embedded zookeeper directory. */ private static final String CONFIG_EMBEDDED_ZOOKEEPER_DIRECTORY = "embeddedZookeeperPath"; /** * The OS type. */ private static OS os = getOS(); /** * All of {@link ZookeeperInitializer} instances. */ private List<Initializer> initializers; /** * The global context of zookeeper. */ private ZookeeperContext context; /** * To store all processor instances. */ private Map<OS, Map<Command, Processor>> processors = new HashMap<>(); /** * The default unpacked directory. */ private static final String UNPACKED_DIRECTORY = "apache-zookeeper-bin"; /** * The target name of zookeeper binary file. */ private static final String TARGET_ZOOKEEPER_FILE_NAME = UNPACKED_DIRECTORY + ".tar.gz"; /** * The path of target zookeeper binary file. */ private static final Path TARGET_FILE_PATH = getTargetFilePath(); /** * The {@link #INITIALIZED} for flagging the {@link #startup()} method is called or not. */ private static final AtomicBoolean INITIALIZED = new AtomicBoolean(false); /** * Returns the directory to store zookeeper binary archive. * <p>The priorities to obtain the directory are as follows:</p> * <p>1. Use System.getProperty({@link #CONFIG_EMBEDDED_ZOOKEEPER_DIRECTORY}) if not null or empty</p> * <p>2. Use System.getProperty(user.home) if not null or empty</p> * <p>3. Use System.getProperty(java.io.tmpdir)</p> */ private static String getEmbeddedZookeeperDirectory() { String directory; // Use System.getProperty({@link #CONFIG_EMBEDDED_ZOOKEEPER_DIRECTORY}) directory = System.getProperty(CONFIG_EMBEDDED_ZOOKEEPER_DIRECTORY); logger.info(String.format("The customized directory is %s to store zookeeper binary archive.", directory)); if (StringUtils.isNotEmpty(directory)) { return directory; } // Use System.getProperty(user.home) logger.info(String.format("The user home is %s to store zookeeper binary archive.", directory)); directory = SystemPropertyConfigUtils.getSystemProperty(USER_HOME); logger.info(String.format("user.home is %s", directory)); if (StringUtils.isEmpty(directory)) { // Use default temporary directory directory = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_JAVA_IO_TMPDIR); logger.info(String.format("The temporary directory is %s to store zookeeper binary archive.", directory)); } Assert.notEmptyString(directory, "The directory to store zookeeper binary archive cannot be null or empty."); return directory + File.separator + ".tmp" + File.separator + "zookeeper"; } /** * Returns the target file path. */ private static Path getTargetFilePath() { String zookeeperDirectory = getEmbeddedZookeeperDirectory(); Path targetFilePath = Paths.get(zookeeperDirectory, TARGET_ZOOKEEPER_FILE_NAME); logger.info("Target file's absolute directory: " + targetFilePath); return targetFilePath; } /** * Returns the Operating System. */ private static OS getOS() { String osName = SystemPropertyConfigUtils.getSystemProperty(SYSTEM_OS_NAME).toLowerCase(); OS os = OS.Unix; if (osName.contains("windows")) { os = OS.Windows; } return os; } /** * Store all initialized processor instances. * * @param os the {@link OS} type. * @param command the {@link Command} to execute. * @param processor the {@link Processor} to run. */ private void put(OS os, Command command, Processor processor) { Map<Command, Processor> commandProcessorMap = this.processors.get(os); if (commandProcessorMap == null) { commandProcessorMap = new HashMap<>(); this.processors.put(os, commandProcessorMap); } commandProcessorMap.put(command, processor); } /** * Gets the {@link Processor} with the given {@link OS} type and {@link Command}. * * @param os the {@link OS} type. * @param command the {@link Command} to execute. * @return the {@link Processor} to run. */ private Processor get(OS os, Command command) { Map<Command, Processor> commandProcessorMap = this.processors.get(os); Objects.requireNonNull(commandProcessorMap, "The command with the OS cannot be null"); Processor processor = commandProcessorMap.get(command); Objects.requireNonNull(processor, "The processor cannot be null"); return processor; } /** * {@inheritDoc} */ @Override public void startup() throws DubboTestException { if (!INITIALIZED.get()) { // global look, make sure only one thread can initialize the zookeeper instances. synchronized (ZookeeperRegistryCenter.class) { if (!INITIALIZED.get()) { for (Initializer initializer : this.initializers) { initializer.initialize(this.context); } // add shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown())); INITIALIZED.set(true); } } } this.get(os, Command.Start).process(this.context); } /** * {@inheritDoc} */ @Override public void reset() throws DubboTestException { this.get(os, Command.Reset).process(this.context); } /** * {@inheritDoc} */ @Override public void shutdown() throws DubboTestException { this.get(os, Command.Stop).process(this.context); } /** * The type of OS. */ enum OS { Windows, Unix } /** * The commands to support the zookeeper. */ enum Command { Start, Reset, Stop } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Initializer.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/Initializer.java
/* * 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.test.check.registrycenter; import org.apache.dubbo.test.check.exception.DubboTestException; /** * The purpose of this class is to do initialization when we build {@link RegistryCenter}. */ public interface Initializer { /** * Initialize the global context. * @param context the global context to be initialized. * @throws DubboTestException when any exception occurred. */ void initialize(Context context) throws DubboTestException; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/UnpackZookeeperInitializer.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/UnpackZookeeperInitializer.java
/* * 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.test.check.registrycenter.initializer; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.utils.IOUtils; /** * Unpack the downloaded zookeeper binary archive. */ public class UnpackZookeeperInitializer extends ZookeeperInitializer { private static final Logger logger = LoggerFactory.getLogger(UnpackZookeeperInitializer.class); /** * Unpack the zookeeper binary file. * * @param context the global context of zookeeper. * @param clientPort the client port * @throws DubboTestException when an exception occurred */ private void unpack(ZookeeperContext context, int clientPort) throws DubboTestException { File sourceFile = context.getSourceFile().toFile(); Path targetPath = Paths.get(context.getSourceFile().getParent().toString(), String.valueOf(clientPort)); // check if it's unpacked. if (targetPath.toFile() != null && targetPath.toFile().isDirectory()) { logger.info(String.format("The file has been unpacked, target path:%s", targetPath.toString())); return; } try (FileInputStream fileInputStream = new FileInputStream(sourceFile); GzipCompressorInputStream gzipCompressorInputStream = new GzipCompressorInputStream(fileInputStream); TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(gzipCompressorInputStream, "UTF-8")) { File targetFile = targetPath.toFile(); TarArchiveEntry entry; while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) { if (entry.isDirectory()) { continue; } File curFile = new File(targetFile, entry.getName()); File parent = curFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } try (FileOutputStream outputStream = new FileOutputStream(curFile)) { IOUtils.copy(tarArchiveInputStream, outputStream); } } } catch (IOException e) { throw new DubboTestException(String.format("Failed to unpack the zookeeper binary file"), e); } } @Override protected void doInitialize(ZookeeperContext context) throws DubboTestException { for (int clientPort : context.getClientPorts()) { this.unpack(context, clientPort); // get the file name, just like apache-zookeeper-{version}-bin // the version we maybe unknown if the zookeeper archive binary file is copied by user self. Path parentPath = Paths.get(context.getSourceFile().getParent().toString(), String.valueOf(clientPort)); if (!Files.exists(parentPath) || !parentPath.toFile().isDirectory() || parentPath.toFile().listFiles().length != 1) { throw new IllegalStateException("There is something wrong in unpacked file!"); } // rename directory File sourceFile = parentPath.toFile().listFiles()[0]; File targetFile = Paths.get(parentPath.toString(), context.getUnpackedDirectory()) .toFile(); sourceFile.renameTo(targetFile); if (!Files.exists(targetFile.toPath()) || !targetFile.isDirectory()) { throw new IllegalStateException(String.format( "Failed to rename the directory. source directory: %s, target directory: %s", sourceFile.toPath().toString(), targetFile.toPath().toString())); } // get the bin path Path zookeeperBin = Paths.get(targetFile.toString(), "bin"); // update file permission for (File file : zookeeperBin.toFile().listFiles()) { file.setExecutable(true, false); file.setReadable(true, false); file.setWritable(false, false); } } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java
/* * 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.test.check.registrycenter.initializer; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Properties; /** * Update the config file of zookeeper. */ public class ConfigZookeeperInitializer extends ZookeeperInitializer { private static final Logger logger = LoggerFactory.getLogger(ConfigZookeeperInitializer.class); /** * Update the config file with the given client port and admin server port. * * @param clientPort the client port * @param adminServerPort the admin server port * @throws DubboTestException when an exception occurred */ private void updateConfig(ZookeeperContext context, int clientPort, int adminServerPort) throws DubboTestException { Path zookeeperConf = Paths.get( context.getSourceFile().getParent().toString(), String.valueOf(clientPort), context.getUnpackedDirectory(), "conf"); File zooSample = Paths.get(zookeeperConf.toString(), "zoo_sample.cfg").toFile(); int availableAdminServerPort = NetUtils.getAvailablePort(adminServerPort); Properties properties = new Properties(); try { // use Files.newInputStream instead of new FileInputStream try (InputStream is = Files.newInputStream(zooSample.toPath())) { properties.load(is); } properties.setProperty("clientPort", String.valueOf(clientPort)); properties.setProperty("admin.serverPort", String.valueOf(availableAdminServerPort)); Path dataDir = Paths.get(zookeeperConf.getParent().toString(), "data"); if (!Files.exists(dataDir)) { try { logger.info("It is creating the data directory..."); Files.createDirectories(dataDir); } catch (IOException e) { throw new RuntimeException( String.format( "Failed to create the data directory to save zookeeper binary file, file path:%s", context.getSourceFile()), e); } } properties.setProperty("dataDir", dataDir.toString()); FileOutputStream oFile = null; try { oFile = new FileOutputStream( Paths.get(zookeeperConf.toString(), "zoo.cfg").toFile()); properties.store(oFile, ""); } finally { try { oFile.close(); } catch (IOException e) { throw new DubboTestException("Failed to close file", e); } } logger.info("The configuration information of zoo.cfg are as below,\n" + "which located in " + zooSample.getAbsolutePath() + "\n" + propertiesToString(properties)); } catch (IOException e) { throw new DubboTestException(String.format("Failed to update %s file", zooSample), e); } File log4j = Paths.get(zookeeperConf.toString(), "log4j.properties").toFile(); try { // use Files.newInputStream instead of new FileInputStream try (InputStream is = Files.newInputStream(log4j.toPath())) { properties.load(is); } Path logDir = Paths.get(zookeeperConf.getParent().toString(), "logs"); if (!Files.exists(logDir)) { try { logger.info("It is creating the log directory..."); Files.createDirectories(logDir); } catch (IOException e) { throw new RuntimeException( String.format( "Failed to create the log directory to save zookeeper binary file, file path:%s", context.getSourceFile()), e); } } properties.setProperty("zookeeper.log.dir", logDir.toString()); FileOutputStream oFile = null; try { oFile = new FileOutputStream( Paths.get(zookeeperConf.toString(), "log4j.properties").toFile()); properties.store(oFile, ""); } finally { try { oFile.close(); } catch (IOException e) { throw new DubboTestException("Failed to close file", e); } } logger.info("The configuration information of log4j.properties are as below,\n" + "which located in " + log4j.getAbsolutePath() + "\n" + propertiesToString(properties)); } catch (IOException e) { throw new DubboTestException(String.format("Failed to update %s file", zooSample), e); } } /** * Convert the {@link Properties} instance to {@link String}. * * @param properties the properties to convert. * @return the string converted from {@link Properties} instance. */ private String propertiesToString(Properties properties) { StringBuilder builder = new StringBuilder(); for (Object key : properties.keySet()) { builder.append(key); builder.append(": "); builder.append(properties.get(key)); builder.append("\n"); } return builder.toString(); } @Override protected void doInitialize(ZookeeperContext context) throws DubboTestException { for (int i = 0; i < context.getClientPorts().length; i++) { this.updateConfig(context, context.getClientPorts()[i], context.getAdminServerPorts()[i]); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ZookeeperInitializer.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ZookeeperInitializer.java
/* * 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.test.check.registrycenter.initializer; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.Context; import org.apache.dubbo.test.check.registrycenter.Initializer; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.util.concurrent.atomic.AtomicBoolean; /** * The implementation of {@link Initializer} to initialize zookeeper. */ public abstract class ZookeeperInitializer implements Initializer { /** * The {@link #INITIALIZED} for checking the {@link #initialize(Context)} method is called or not. */ private final AtomicBoolean INITIALIZED = new AtomicBoolean(false); @Override public void initialize(Context context) throws DubboTestException { if (!this.INITIALIZED.compareAndSet(false, true)) { return; } this.doInitialize((ZookeeperContext) context); } /** * Initialize the global context for zookeeper. * * @param context the global context for zookeeper. * @throws DubboTestException when any exception occurred. */ protected abstract void doInitialize(ZookeeperContext context) throws DubboTestException; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/DownloadZookeeperInitializer.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/DownloadZookeeperInitializer.java
/* * 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.test.check.registrycenter.initializer; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.DefaultAsyncHttpClient; import org.asynchttpclient.DefaultAsyncHttpClientConfig; import org.asynchttpclient.Response; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_DOWNLOAD_ZK_FILE; /** * Download zookeeper binary archive. */ public class DownloadZookeeperInitializer extends ZookeeperInitializer { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(DownloadZookeeperInitializer.class); /** * The zookeeper binary file name format. */ private static final String ZOOKEEPER_FILE_NAME_FORMAT = "apache-zookeeper-%s-bin.tar.gz"; /** * The url format for zookeeper binary file. */ private static final String ZOOKEEPER_BINARY_URL_FORMAT = "https://archive.apache.org/dist/zookeeper/zookeeper-%s/" + ZOOKEEPER_FILE_NAME_FORMAT; /** * The temporary directory. */ private static final String TEMPORARY_DIRECTORY = "zookeeper"; /** * The timeout when download zookeeper binary archive file. */ private static final int REQUEST_TIMEOUT = 180 * 1000; /** * The timeout when connect the download url. */ private static final int CONNECT_TIMEOUT = 60 * 1000; /** * Returns {@code true} if the file exists with the given file path, otherwise {@code false}. * * @param filePath the file path to check. */ private boolean checkFile(Path filePath) { return Files.exists(filePath) && filePath.toFile().isFile(); } @Override protected void doInitialize(ZookeeperContext context) throws DubboTestException { // checks the zookeeper binary file exists or not if (checkFile(context.getSourceFile())) { return; } String zookeeperFileName = String.format(ZOOKEEPER_FILE_NAME_FORMAT, context.getVersion()); Path temporaryFilePath; try { temporaryFilePath = Paths.get( Files.createTempDirectory("").getParent().toString(), TEMPORARY_DIRECTORY, zookeeperFileName); } catch (IOException e) { throw new RuntimeException( String.format("Cannot create the temporary directory, file path: %s", TEMPORARY_DIRECTORY), e); } // create the temporary directory path. try { Files.createDirectories(temporaryFilePath.getParent()); } catch (IOException e) { throw new RuntimeException( String.format( "Failed to create the temporary directory to save zookeeper binary file, file path:%s", temporaryFilePath.getParent()), e); } // download zookeeper binary file in temporary directory. String zookeeperBinaryUrl = String.format(ZOOKEEPER_BINARY_URL_FORMAT, context.getVersion(), context.getVersion()); try { logger.info("It is beginning to download the zookeeper binary archive, it will take several minutes..." + "\nThe zookeeper binary archive file will be download from " + zookeeperBinaryUrl + "," + "\nwhich will be saved in " + temporaryFilePath.toString() + "," + "\nalso it will be renamed to 'apache-zookeeper-bin.tar.gz' and moved into " + context.getSourceFile() + ".\n"); this.download(zookeeperBinaryUrl, temporaryFilePath); } catch (Exception e) { throw new RuntimeException( String.format( "Download zookeeper binary archive failed, download url:%s, file path:%s." + "\nOr you can do something to avoid this problem as below:" + "\n1. Download zookeeper binary archive manually regardless of the version" + "\n2. Rename the downloaded file named 'apache-zookeeper-{version}-bin.tar.gz' to 'apache-zookeeper-bin.tar.gz'" + "\n3. Put the renamed file in %s, you maybe need to create the directory if necessary.\n", zookeeperBinaryUrl, temporaryFilePath, context.getSourceFile()), e); } // check downloaded zookeeper binary file in temporary directory. if (!checkFile(temporaryFilePath)) { throw new IllegalArgumentException(String.format( "There are some unknown problem occurred when downloaded the zookeeper binary archive file, file path:%s", temporaryFilePath)); } // create target directory if necessary if (!Files.exists(context.getSourceFile())) { try { Files.createDirectories(context.getSourceFile().getParent()); } catch (IOException e) { throw new IllegalArgumentException( String.format( "Failed to create target directory, the directory path: %s", context.getSourceFile().getParent()), e); } } // copy the downloaded zookeeper binary file into the target file path try { Files.copy(temporaryFilePath, context.getSourceFile(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new IllegalArgumentException( String.format( "Failed to copy file, the source file path: %s, the target file path: %s", temporaryFilePath, context.getSourceFile()), e); } // checks the zookeeper binary file exists or not again if (!checkFile(context.getSourceFile())) { throw new IllegalArgumentException(String.format( "The zookeeper binary archive file doesn't exist, file path:%s", context.getSourceFile())); } } /** * Download the file with the given url. * * @param url the url to download. * @param targetPath the target path to save the downloaded file. */ private void download(String url, Path targetPath) throws ExecutionException, InterruptedException, IOException, TimeoutException { AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(new DefaultAsyncHttpClientConfig.Builder() .setConnectTimeout(CONNECT_TIMEOUT) .setRequestTimeout(REQUEST_TIMEOUT) .setMaxRequestRetry(1) .build()); Future<Response> responseFuture = asyncHttpClient .prepareGet(url) .execute(new AsyncCompletionHandler<Response>() { @Override public Response onCompleted(Response response) { logger.info("Download zookeeper binary archive file successfully! download url: " + url); return response; } @Override public void onThrowable(Throwable t) { logger.warn( TESTING_REGISTRY_FAILED_TO_DOWNLOAD_ZK_FILE, "", "", "Failed to download the file, download url: " + url, t); super.onThrowable(t); } }); // Future timeout should 2 times as equal as REQUEST_TIMEOUT, because it will retry 1 time. Response response = responseFuture.get(REQUEST_TIMEOUT * 2, TimeUnit.MILLISECONDS); Files.copy(response.getResponseBodyAsStream(), targetPath, StandardCopyOption.REPLACE_EXISTING); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ResetZookeeperProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ResetZookeeperProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.Context; import org.apache.dubbo.test.check.registrycenter.Processor; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.util.concurrent.TimeUnit; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.RetryNTimes; /** * Create {@link Process} to reset zookeeper. */ public class ResetZookeeperProcessor implements Processor { @Override public void process(Context context) throws DubboTestException { ZookeeperContext zookeeperContext = (ZookeeperContext) context; for (int clientPort : zookeeperContext.getClientPorts()) { CuratorFramework client; try { CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("127.0.0.1:" + clientPort) .retryPolicy(new RetryNTimes(1, 1000)); client = builder.build(); client.start(); boolean connected = client.blockUntilConnected(1000, TimeUnit.MILLISECONDS); if (!connected) { // close CuratorFramework to stop re-connection. client.close(); throw new IllegalStateException("zookeeper not connected"); } client.delete().deletingChildrenIfNeeded().forPath("/dubbo"); } catch (Exception e) { throw new DubboTestException(e.getMessage(), e); } } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/KillProcessWindowsProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/KillProcessWindowsProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; import java.io.IOException; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.Executor; import org.apache.commons.exec.PumpStreamHandler; /** * Create a {@link org.apache.dubbo.test.check.registrycenter.Processor} to kill pid on Windows OS. */ public class KillProcessWindowsProcessor extends ZookeeperWindowsProcessor { private static final Logger logger = LoggerFactory.getLogger(KillProcessWindowsProcessor.class); @Override protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { for (int clientPort : context.getClientPorts()) { Integer pid = context.getPid(clientPort); if (pid == null) { logger.info("There is no PID of zookeeper instance with the port " + clientPort); continue; } logger.info(String.format("Kill the pid %d of the zookeeper with port %d", pid, clientPort)); Executor executor = new DefaultExecutor(); executor.setExitValues(null); executor.setStreamHandler(new PumpStreamHandler(null, null, null)); CommandLine cmdLine = new CommandLine("cmd.exe"); cmdLine.addArgument("/c"); cmdLine.addArgument("taskkill /PID " + pid + " -t -f"); try { executor.execute(cmdLine); // clear pid context.removePid(clientPort); } catch (IOException e) { throw new DubboTestException( String.format("Failed to kill the pid %d of zookeeper with port %d", pid, clientPort), e); } } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperUnixProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperUnixProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; /** * Create {@link Process} to start zookeeper on Unix OS. */ public class StartZookeeperUnixProcessor extends ZookeeperUnixProcessor { private static final Logger logger = LoggerFactory.getLogger(StartZookeeperUnixProcessor.class); /** * The pattern for checking if zookeeper instances started. */ private static final Pattern PATTERN_STARTED = Pattern.compile(".*STARTED.*"); @Override protected Process doProcess(ZookeeperContext context, int clientPort) throws DubboTestException { logger.info(String.format("The zookeeper-%d is starting...", clientPort)); List<String> commands = new ArrayList<>(); Path zookeeperBin = Paths.get( context.getSourceFile().getParent().toString(), String.valueOf(clientPort), context.getUnpackedDirectory(), "bin"); commands.add(Paths.get(zookeeperBin.toString(), "zkServer.sh") .toAbsolutePath() .toString()); commands.add("start"); commands.add(Paths.get(zookeeperBin.getParent().toString(), "conf", "zoo.cfg") .toAbsolutePath() .toString()); try { return new ProcessBuilder() .directory(zookeeperBin.getParent().toFile()) .command(commands) .inheritIO() .redirectOutput(ProcessBuilder.Redirect.PIPE) .start(); } catch (IOException e) { throw new DubboTestException(String.format("Failed to start zookeeper-%d", clientPort), e); } } @Override protected Pattern getPattern() { return PATTERN_STARTED; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperUnixProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperUnixProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.Context; import org.apache.dubbo.test.check.registrycenter.Processor; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.regex.Pattern; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_START_ZOOKEEPER; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER; /** * The abstract implementation of {@link Processor} is to provide some common methods on Unix OS. */ public abstract class ZookeeperUnixProcessor implements Processor { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(ZookeeperUnixProcessor.class); @Override public void process(Context context) throws DubboTestException { ZookeeperContext zookeeperContext = (ZookeeperContext) context; for (int clientPort : zookeeperContext.getClientPorts()) { Process process = this.doProcess(zookeeperContext, clientPort); this.logErrorStream(process.getErrorStream()); this.awaitProcessReady(process.getInputStream()); // kill the process try { process.destroy(); } catch (Throwable cause) { logger.warn( TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER, "", "", String.format("Failed to kill the process, with client port %s !", clientPort), cause); } } } /** * Prints the error log after run {@link Process}. * * @param errorStream the error stream. */ private void logErrorStream(final InputStream errorStream) { try (final BufferedReader reader = new BufferedReader(new InputStreamReader(errorStream))) { String line; while ((line = reader.readLine()) != null) { logger.error(TESTING_REGISTRY_FAILED_TO_START_ZOOKEEPER, "", "", line); } } catch (IOException e) { /* eat quietly */ } } /** * Wait until the server is started successfully. * * @param inputStream the log after run {@link Process}. * @throws DubboTestException if cannot match the given pattern. */ private void awaitProcessReady(final InputStream inputStream) throws DubboTestException { final StringBuilder log = new StringBuilder(); try (final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; while ((line = reader.readLine()) != null) { if (this.getPattern().matcher(line).matches()) { return; } log.append('\n').append(line); } } catch (IOException e) { throw new DubboTestException("Failed to read the log after executed process.", e); } throw new DubboTestException("Ready pattern not found in log, log: " + log); } /** * Use {@link Process} to handle the command. * * @param context the global zookeeper context. * @param clientPort the client port of zookeeper. * @return the instance of {@link Process}. * @throws DubboTestException when any exception occurred. */ protected abstract Process doProcess(ZookeeperContext context, int clientPort) throws DubboTestException; /** * Gets the pattern to check the server is ready or not. * * @return the pattern for checking. */ protected abstract Pattern getPattern(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperWindowsProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/ZookeeperWindowsProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.Context; import org.apache.dubbo.test.check.registrycenter.Processor; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; /** * The abstract implementation of {@link Processor} is to provide some common methods on Windows OS. */ public abstract class ZookeeperWindowsProcessor implements Processor { @Override public void process(Context context) throws DubboTestException { ZookeeperWindowsContext zookeeperWindowsContext = (ZookeeperWindowsContext) context; this.doProcess(zookeeperWindowsContext); } /** * Use {@link Process} to handle the command. * * @param context the global zookeeper context. * @throws DubboTestException when any exception occurred. */ protected abstract void doProcess(ZookeeperWindowsContext context) throws DubboTestException; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StartZookeeperWindowsProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.Processor; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.TimeUnit; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.Executor; /** * Create {@link Process} to start zookeeper on Windows OS. */ public class StartZookeeperWindowsProcessor extends ZookeeperWindowsProcessor { private static final Logger logger = LoggerFactory.getLogger(StartZookeeperWindowsProcessor.class); /** * The {@link Processor} to find the pid of zookeeper instance. */ private final Processor findPidProcessor = new FindPidWindowsProcessor(); /** * The {@link Processor} to kill the pid of zookeeper instance. */ private final Processor killPidProcessor = new KillProcessWindowsProcessor(); @Override protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { // find pid and save into global context. this.findPidProcessor.process(context); // kill pid of zookeeper instance if exists this.killPidProcessor.process(context); for (int clientPort : context.getClientPorts()) { logger.info(String.format("The zookeeper-%d is starting...", clientPort)); Path zookeeperBin = Paths.get( context.getSourceFile().getParent().toString(), String.valueOf(clientPort), context.getUnpackedDirectory(), "bin"); Executor executor = new DefaultExecutor(); executor.setExitValues(null); executor.setWatchdog(context.getWatchdog()); CommandLine cmdLine = new CommandLine("cmd.exe"); cmdLine.addArgument("/c"); cmdLine.addArgument(Paths.get(zookeeperBin.toString(), "zkServer.cmd") .toAbsolutePath() .toString()); context.getExecutorService().submit(() -> executor.execute(cmdLine)); } try { // TODO: Help me to optimize the ugly sleep. // sleep to wait all of zookeeper instances are started successfully. // The best way is to check the output log with the specified keywords, // however, there maybe keep waiting for check when any exception occurred, // because the output stream will be blocked to wait for continuous data without any break TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { // ignored } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/FindPidWindowsProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/FindPidWindowsProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.Executor; import org.apache.commons.exec.PumpStreamHandler; /** * Create a {@link org.apache.dubbo.test.check.registrycenter.Processor} to find pid on Windows OS. */ public class FindPidWindowsProcessor extends ZookeeperWindowsProcessor { private static final Logger logger = LoggerFactory.getLogger(FindPidWindowsProcessor.class); @Override protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { for (int clientPort : context.getClientPorts()) { this.findPid(context, clientPort); } } /** * Find the pid of zookeeper instance. * * @param context the global context. * @param clientPort the client port of zookeeper instance. */ private void findPid(ZookeeperWindowsContext context, int clientPort) { logger.info(String.format("Find the pid of the zookeeper with port %d", clientPort)); Executor executor = new DefaultExecutor(); executor.setExitValues(null); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream ins = new ByteArrayOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(ins.toByteArray()); executor.setStreamHandler(new PumpStreamHandler(out, null, in)); CommandLine cmdLine = new CommandLine("cmd.exe"); cmdLine.addArgument("/c"); cmdLine.addArgument("netstat -ano | findstr " + clientPort); try { executor.execute(cmdLine); String result = out.toString(); logger.info(String.format("Find result: %s", result)); if (StringUtils.isNotEmpty(result)) { String[] values = result.split("\\r\\n"); // values sample: // Protocol Local address Foreign address Status PID // TCP 127.0.0.1:2182 127.0.0.1:56672 ESTABLISHED 4020 // TCP 127.0.0.1:56672 127.0.0.1:2182 ESTABLISHED 1980 // TCP 127.0.0.1:56692 127.0.0.1:2182 ESTABLISHED 1980 // TCP 127.0.0.1:56723 127.0.0.1:2182 ESTABLISHED 1980 // TCP [::]:2182 [::]:0 LISTENING 4020 if (values != null && values.length > 0) { for (int i = 0; i < values.length; i++) { List<String> segments = Arrays.stream(values[i].trim().split(" ")) .filter(str -> !"".equals(str)) .collect(Collectors.toList()); // segments sample: // TCP // 127.0.0.1:2182 // 127.0.0.1:56672 // ESTABLISHED // 4020 if (segments != null && segments.size() == 5) { if (this.check(segments.get(1), clientPort)) { int pid = Integer.valueOf( segments.get(segments.size() - 1).trim()); context.register(clientPort, pid); return; } } } } } } catch (IOException e) { throw new DubboTestException( String.format("Failed to find the PID of zookeeper with port %d", clientPort), e); } } /** * Checks if segment is valid ip and port pair. * * @param segment the segment to check * @param clientPort the client port of zookeeper instance * @return {@code true} if segment is valid pair of ip and port, otherwise {@code false} */ private boolean check(String segment, int clientPort) { return ("[::]:" + clientPort).equalsIgnoreCase(segment) || ("0.0.0.0:" + clientPort).equalsIgnoreCase(segment) || ("127.0.0.1:" + clientPort).equalsIgnoreCase(segment); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperWindowsProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperWindowsProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.Processor; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperWindowsContext; /** * Create {@link Process} to stop zookeeper on Windows OS. */ public class StopZookeeperWindowsProcessor extends ZookeeperWindowsProcessor { private static final Logger logger = LoggerFactory.getLogger(StopZookeeperWindowsProcessor.class); /** * The {@link Processor} to find the pid of zookeeper instance. */ private final Processor findPidProcessor = new FindPidWindowsProcessor(); /** * The {@link Processor} to kill the pid of zookeeper instance. */ private final Processor killPidProcessor = new KillProcessWindowsProcessor(); @Override protected void doProcess(ZookeeperWindowsContext context) throws DubboTestException { logger.info("All of zookeeper instances are stopping..."); // find pid and save into global context. this.findPidProcessor.process(context); // kill pid of zookeeper instance if exists this.killPidProcessor.process(context); // destroy all resources context.destroy(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperUnixProcessor.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/processor/StopZookeeperUnixProcessor.java
/* * 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.test.check.registrycenter.processor; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.test.check.exception.DubboTestException; import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; /** * Create {@link Process} to stop zookeeper on Unix OS. */ public class StopZookeeperUnixProcessor extends ZookeeperUnixProcessor { private static final Logger logger = LoggerFactory.getLogger(StopZookeeperUnixProcessor.class); /** * The pattern for checking if the zookeeper instance stopped. */ private static final Pattern PATTERN_STOPPED = Pattern.compile(".*STOPPED.*"); @Override protected Process doProcess(ZookeeperContext context, int clientPort) throws DubboTestException { logger.info(String.format("The zookeeper-%d is stopping...", clientPort)); List<String> commands = new ArrayList<>(); Path zookeeperBin = Paths.get( context.getSourceFile().getParent().toString(), String.valueOf(clientPort), context.getUnpackedDirectory(), "bin"); commands.add(Paths.get(zookeeperBin.toString(), "zkServer.sh") .toAbsolutePath() .toString()); commands.add("stop"); try { return new ProcessBuilder() .directory(zookeeperBin.getParent().toFile()) .command(commands) .inheritIO() .redirectOutput(ProcessBuilder.Redirect.PIPE) .start(); } catch (IOException e) { throw new DubboTestException(String.format("Failed to stop zookeeper-%d", clientPort), e); } } @Override protected Pattern getPattern() { return PATTERN_STOPPED; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperConfig.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperConfig.java
/* * 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.test.check.registrycenter.config; import org.apache.dubbo.test.check.registrycenter.Config; /** * The zookeeper config in registry center. */ public class ZookeeperConfig implements Config { /** * The system properties config key with zookeeper port. */ private static final String ZOOKEEPER_PORT_KEY = "zookeeper.port"; /** * The system properties config key with first zookeeper port. */ private static final String ZOOKEEPER_PORT_1_KEY = "zookeeper.port.1"; /** * The system properties config key with second zookeeper port. */ private static final String ZOOKEEPER_PORT_2_KEY = "zookeeper.port.2"; /** * The system properties config key with zookeeper connection address. */ private static final String ZOOKEEPER_CONNECTION_ADDRESS_KEY = "zookeeper.connection.address"; /** * The system properties config key with first zookeeper connection address. */ private static final String ZOOKEEPER_CONNECTION_ADDRESS_1_KEY = "zookeeper.connection.address.1"; /** * The system properties config key with second zookeeper connection address. */ private static final String ZOOKEEPER_CONNECTION_ADDRESS_2_KEY = "zookeeper.connection.address.2"; /** * The default first client port of zookeeper. */ public static final int DEFAULT_CLIENT_PORT_1 = 2181; /** * The default second client port of zookeeper. */ public static final int DEFAULT_CLIENT_PORT_2 = 2182; /** * The default client ports of zookeeper. */ private static final int[] CLIENT_PORTS = new int[2]; /** * The default admin server ports of zookeeper. */ private static final int[] DEFAULT_ADMIN_SERVER_PORTS = new int[] {18081, 18082}; /** * The default version of zookeeper. */ private static final String DEFAULT_ZOOKEEPER_VERSION = "3.6.0"; /** * The format for zookeeper connection address. */ private static final String CONNECTION_ADDRESS_FORMAT = "zookeeper://127.0.0.1:%d"; // initialize the client ports of zookeeper. static { // There are two client ports // The priority of the one is that get it from system properties config // with the key of {@link #ZOOKEEPER_PORT_1_KEY} first, and then {@link #ZOOKEEPER_PORT_KEY}, // finally use {@link #DEFAULT_CLIENT_PORT_1} as default port // The priority of the other is that get it from system properties config with the key of {@link // #ZOOKEEPER_PORT_2_KEY} first, // and then use {@link #DEFAULT_CLIENT_PORT_2} as default port int port1 = DEFAULT_CLIENT_PORT_1; int port2 = DEFAULT_CLIENT_PORT_2; String portConfig1 = System.getProperty(ZOOKEEPER_PORT_1_KEY, System.getProperty(ZOOKEEPER_PORT_KEY)); if (portConfig1 != null) { try { port1 = Integer.parseInt(portConfig1); } catch (NumberFormatException e) { port1 = DEFAULT_CLIENT_PORT_1; } } String portConfig2 = System.getProperty(ZOOKEEPER_PORT_2_KEY); if (portConfig2 != null) { try { port2 = Integer.parseInt(portConfig2); } catch (NumberFormatException e) { port2 = DEFAULT_CLIENT_PORT_2; } } if (port1 == port2) { throw new IllegalArgumentException( String.format("The client ports %d and %d of zookeeper cannot be same!", port1, port2)); } CLIENT_PORTS[0] = port1; CLIENT_PORTS[1] = port2; // set system properties config System.setProperty(ZOOKEEPER_CONNECTION_ADDRESS_KEY, String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[0])); System.setProperty( ZOOKEEPER_CONNECTION_ADDRESS_1_KEY, String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[0])); System.setProperty( ZOOKEEPER_CONNECTION_ADDRESS_2_KEY, String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[1])); } @Override public String getConnectionAddress1() { return String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[0]); } @Override public String getConnectionAddress2() { return String.format(CONNECTION_ADDRESS_FORMAT, CLIENT_PORTS[1]); } @Override public String getConnectionAddressKey() { return ZOOKEEPER_CONNECTION_ADDRESS_KEY; } @Override public String getConnectionAddressKey1() { return ZOOKEEPER_CONNECTION_ADDRESS_1_KEY; } @Override public String getConnectionAddressKey2() { return ZOOKEEPER_CONNECTION_ADDRESS_2_KEY; } /** * Returns the zookeeper's version. */ public String getVersion() { return DEFAULT_ZOOKEEPER_VERSION; } /** * Returns the client ports of zookeeper. */ public int[] getClientPorts() { return CLIENT_PORTS; } /** * Returns the admin server ports of zookeeper. */ public int[] getAdminServerPorts() { return DEFAULT_ADMIN_SERVER_PORTS; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperRegistryCenterConfig.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/config/ZookeeperRegistryCenterConfig.java
/* * 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.test.check.registrycenter.config; import org.apache.dubbo.test.check.registrycenter.Config; /** * Define the zookeeper global config for registry center. */ public class ZookeeperRegistryCenterConfig { /** * Define the {@link Config} instance. */ private static final Config CONFIG = new ZookeeperConfig(); /** * Returns the connection address in single registry center. */ public static String getConnectionAddress() { return CONFIG.getConnectionAddress(); } /** * Returns the first connection address in multiple registry centers. */ public static String getConnectionAddress1() { return CONFIG.getConnectionAddress1(); } /** * Returns the second connection address in multiple registry centers. */ public static String getConnectionAddress2() { return CONFIG.getConnectionAddress2(); } /** * Returns the default connection address key in single registry center. * <h3>How to use</h3> * <pre> * System.getProperty({@link ZookeeperRegistryCenterConfig#getConnectionAddressKey()}) * </pre> */ public static String getConnectionAddressKey() { return CONFIG.getConnectionAddressKey(); } /** * Returns the first connection address key in multiple registry center. * <h3>How to use</h3> * <pre> * System.getProperty({@link ZookeeperRegistryCenterConfig#getConnectionAddressKey1()}) * </pre> */ public static String getConnectionAddressKey1() { return CONFIG.getConnectionAddressKey1(); } /** * Returns the second connection address key in multiple registry center. * <h3>How to use</h3> * <pre> * System.getProperty({@link ZookeeperRegistryCenterConfig#getConnectionAddressKey2()}) * </pre> */ public static String getConnectionAddressKey2() { return CONFIG.getConnectionAddressKey2(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperWindowsContext.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperWindowsContext.java
/* * 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.test.check.registrycenter.context; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.apache.commons.exec.ExecuteWatchdog; /** * The global context for zookeeper on Windows OS. */ public class ZookeeperWindowsContext extends ZookeeperContext { /** * The default executor service to manage the lifecycle of zookeeper. */ private final ExecutorService DEFAULT_EXECUTOR_SERVICE = new ThreadPoolExecutor( 2, 2, 0, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), new NamedInternalThreadFactory("mocked-zookeeper", true), new ThreadPoolExecutor.AbortPolicy()); /** * Define the default {@link ExecuteWatchdog} for terminating all registered zookeeper processes. */ private final ExecuteWatchdog WATCHDOG = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); /** * Set it to TRUE when using WatchDog. */ private boolean usedWatchDog = false; /** * The map to store the pair of clientPort and PID. */ private Map<Integer, Integer> processIds = new HashMap<>(); /** * Register the process id of zookeeper. * * @param clientPort the client port of zookeeper. * @param pid the process id of zookeeper instance. */ public void register(int clientPort, int pid) { this.processIds.put(clientPort, pid); } /** * Returns the pid of zookeeper instance with the given client port. * * @param clientPort the client port of zookeeper instance. * @return the pid of zookeeper instance. */ public Integer getPid(int clientPort) { return this.processIds.get(clientPort); } /** * Remove the registered pid with the given client port. * @param clientPort the client port of zookeeper instance. */ public void removePid(int clientPort) { this.processIds.remove(clientPort); } /** * Returns the default executor service to manage the lifecycle of zookeeper. */ public ExecutorService getExecutorService() { return DEFAULT_EXECUTOR_SERVICE; } /** * Returns the {@link ExecuteWatchdog}. */ public ExecuteWatchdog getWatchdog() { usedWatchDog = true; return WATCHDOG; } /** * Destroy all registered resources. */ public void destroy() { this.processIds.clear(); // check WatchDog used flag to avoid hanging at destroyProcess when WatchDog is not used. if (usedWatchDog) { this.WATCHDOG.destroyProcess(); } try { DEFAULT_EXECUTOR_SERVICE.shutdownNow(); } catch (SecurityException | NullPointerException ex) { return; } try { DEFAULT_EXECUTOR_SERVICE.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperContext.java
dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/context/ZookeeperContext.java
/* * 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.test.check.registrycenter.context; import org.apache.dubbo.test.check.registrycenter.Context; import org.apache.dubbo.test.check.registrycenter.config.ZookeeperConfig; import java.nio.file.Path; /** * The global context for zookeeper. */ public class ZookeeperContext implements Context { /** * The config of zookeeper. */ private ZookeeperConfig config = new ZookeeperConfig(); /** * The the source file path of downloaded zookeeper binary archive. */ private Path sourceFile; /** * The directory after unpacked zookeeper archive binary file. */ private String unpackedDirectory; /** * Sets the source file path of downloaded zookeeper binary archive. */ public void setSourceFile(Path sourceFile) { this.sourceFile = sourceFile; } /** * Returns the source file path of downloaded zookeeper binary archive. */ public Path getSourceFile() { return this.sourceFile; } /** * Returns the directory after unpacked zookeeper archive binary file. */ public String getUnpackedDirectory() { return unpackedDirectory; } /** * Sets the directory after unpacked zookeeper archive binary file. */ public void setUnpackedDirectory(String unpackedDirectory) { this.unpackedDirectory = unpackedDirectory; } /** * Returns the zookeeper's version. */ public String getVersion() { return config.getVersion(); } /** * Returns the client ports of zookeeper. */ public int[] getClientPorts() { return config.getClientPorts(); } /** * Returns the admin server ports of zookeeper. */ public int[] getAdminServerPorts() { return config.getAdminServerPorts(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java
dubbo-test/dubbo-test-modules/src/test/java/org/apache/dubbo/dependency/FileTest.java
/* * 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.dependency; import org.apache.dubbo.common.constants.CommonConstants; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class FileTest { private static final List<Pattern> ignoredModules = new LinkedList<>(); private static final List<Pattern> ignoredArtifacts = new LinkedList<>(); private static final List<Pattern> ignoredModulesInDubboAll = new LinkedList<>(); private static final List<Pattern> ignoredModulesInDubboAllShade = new LinkedList<>(); static { ignoredModules.add(Pattern.compile("dubbo-apache-release")); ignoredModules.add(Pattern.compile("dubbo-all-shaded")); ignoredModules.add(Pattern.compile("dubbo-dependencies-all")); ignoredModules.add(Pattern.compile("dubbo-parent")); ignoredModules.add(Pattern.compile("dubbo-core-spi")); ignoredModules.add(Pattern.compile("dubbo-demo.*")); ignoredModules.add(Pattern.compile("dubbo-annotation-processor")); ignoredModules.add(Pattern.compile("dubbo-config-spring6")); ignoredModules.add(Pattern.compile("dubbo-spring6-security")); ignoredModules.add(Pattern.compile("dubbo-spring-boot-3-autoconfigure")); ignoredModules.add(Pattern.compile("dubbo-plugin-loom.*")); ignoredModules.add(Pattern.compile("dubbo-mutiny.*")); ignoredModules.add(Pattern.compile("dubbo-mcp")); ignoredArtifacts.add(Pattern.compile("dubbo-demo.*")); ignoredArtifacts.add(Pattern.compile("dubbo-test.*")); ignoredArtifacts.add(Pattern.compile("dubbo-annotation-processor")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-all-shaded")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-bom")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-compiler")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-dependencies.*")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-distribution")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-metadata-processor")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-native.*")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-config-spring6.*")); ignoredModulesInDubboAll.add(Pattern.compile(".*spring-boot.*")); ignoredModulesInDubboAll.add(Pattern.compile("dubbo-maven-plugin")); ignoredModulesInDubboAllShade.add(Pattern.compile("dubbo-spring6-security")); ignoredModulesInDubboAllShade.add(Pattern.compile("dubbo-plugin-loom")); ignoredModulesInDubboAllShade.add(Pattern.compile("dubbo-mcp")); ignoredModulesInDubboAllShade.add(Pattern.compile("dubbo-mutiny")); } @Test void checkDubboBom() throws DocumentException { File baseFile = getBaseFile(); List<File> poms = new LinkedList<>(); readPoms(baseFile, poms); SAXReader reader = new SAXReader(); List<String> artifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); String dubboBomPath = "dubbo-distribution" + File.separator + "dubbo-bom" + File.separator + "pom.xml"; Document dubboBom = reader.read(new File(getBaseFile(), dubboBomPath)); List<String> artifactIdsInDubboBom = dubboBom .getRootElement() .element("dependencyManagement") .element("dependencies") .elements("dependency") .stream() .map(ele -> ele.elementText("artifactId")) .collect(Collectors.toList()); List<String> expectedArtifactIds = new LinkedList<>(artifactIds); expectedArtifactIds.removeAll(artifactIdsInDubboBom); expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); Assertions.assertTrue( expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-bom. Found modules: " + expectedArtifactIds); } @Test void checkArtifacts() throws DocumentException, IOException { File baseFile = getBaseFile(); List<File> poms = new LinkedList<>(); readPoms(baseFile, poms); SAXReader reader = new SAXReader(); List<String> artifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); List<String> artifactIdsInRoot = IOUtils.readLines( this.getClass() .getClassLoader() .getResource(CommonConstants.DUBBO_VERSIONS_KEY + "/.artifacts") .openStream(), StandardCharsets.UTF_8); artifactIdsInRoot.removeIf(s -> s.startsWith("#")); List<String> expectedArtifactIds = new LinkedList<>(artifactIds); expectedArtifactIds.removeAll(artifactIdsInRoot); expectedArtifactIds.removeIf(artifactId -> ignoredArtifacts.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); Assertions.assertTrue( expectedArtifactIds.isEmpty(), "Newly created modules must be added to .artifacts (in project root). Found modules: " + expectedArtifactIds); } @Test void checkDubboDependenciesAll() throws DocumentException { File baseFile = getBaseFile(); List<File> poms = new LinkedList<>(); readPoms(baseFile, poms); SAXReader reader = new SAXReader(); List<String> artifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .filter(doc -> !Objects.equals("pom", doc.elementText("packaging"))) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); String dubboDependenciesAllPath = "dubbo-test" + File.separator + "dubbo-dependencies-all" + File.separator + "pom.xml"; Document dubboDependenciesAll = reader.read(new File(getBaseFile(), dubboDependenciesAllPath)); List<String> artifactIdsInDubboDependenciesAll = dubboDependenciesAll.getRootElement().element("dependencies").elements("dependency").stream() .map(ele -> ele.elementText("artifactId")) .collect(Collectors.toList()); List<String> expectedArtifactIds = new LinkedList<>(artifactIds); expectedArtifactIds.removeAll(artifactIdsInDubboDependenciesAll); expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); Assertions.assertTrue( expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-dependencies-all. Found modules: " + expectedArtifactIds); } @Test void checkDubboAllDependencies() throws DocumentException { File baseFile = getBaseFile(); List<File> poms = new LinkedList<>(); readPoms(baseFile, poms); SAXReader reader = new SAXReader(); List<String> artifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); Assertions.assertEquals(poms.size(), artifactIds.size()); List<String> deployedArtifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .filter(doc -> !Objects.equals("pom", doc.elementText("packaging"))) .filter(doc -> Objects.isNull(doc.element("properties")) || (!Objects.equals("true", doc.element("properties").elementText("skip_maven_deploy")) && !Objects.equals( "true", doc.element("properties").elementText("maven.deploy.skip")))) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml"; Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath)); List<String> artifactIdsInDubboAll = dubboAll.getRootElement().element("dependencies").elements("dependency").stream() .map(ele -> ele.elementText("artifactId")) .collect(Collectors.toList()); List<String> expectedArtifactIds = new LinkedList<>(deployedArtifactIds); expectedArtifactIds.removeAll(artifactIdsInDubboAll); expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); Assertions.assertTrue( expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + expectedArtifactIds); List<String> unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll); unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId)); unexpectedArtifactIds.removeAll(deployedArtifactIds); Assertions.assertTrue( unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + unexpectedArtifactIds); unexpectedArtifactIds = new LinkedList<>(); for (String artifactId : artifactIdsInDubboAll) { if (!artifactIds.contains(artifactId)) { continue; } if (ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { unexpectedArtifactIds.add(artifactId); } if (ignoredModulesInDubboAll.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { unexpectedArtifactIds.add(artifactId); } } Assertions.assertTrue( unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml). Found modules: " + unexpectedArtifactIds); } @Test void checkDubboAllShade() throws DocumentException { File baseFile = getBaseFile(); List<File> poms = new LinkedList<>(); readPoms(baseFile, poms); SAXReader reader = new SAXReader(); List<String> artifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); Assertions.assertEquals(poms.size(), artifactIds.size()); List<String> deployedArtifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .filter(doc -> Objects.isNull(doc.element("properties")) || (!Objects.equals("true", doc.element("properties").elementText("skip_maven_deploy")) && !Objects.equals( "true", doc.element("properties").elementText("maven.deploy.skip")))) .filter(doc -> !Objects.equals("pom", doc.elementText("packaging"))) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml"; Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath)); List<String> artifactIdsInDubboAll = dubboAll.getRootElement().element("build").element("plugins").elements("plugin").stream() .filter(ele -> ele.elementText("artifactId").equals("maven-shade-plugin")) .map(ele -> ele.element("executions")) .map(ele -> ele.elements("execution")) .flatMap(Collection::stream) .filter(ele -> ele.elementText("phase").equals("package")) .map(ele -> ele.element("configuration")) .map(ele -> ele.element("artifactSet")) .map(ele -> ele.element("includes")) .map(ele -> ele.elements("include")) .flatMap(Collection::stream) .map(Element::getText) .filter(artifactId -> artifactId.startsWith("org.apache.dubbo:")) .map(artifactId -> artifactId.substring("org.apache.dubbo:".length())) .collect(Collectors.toList()); List<String> expectedArtifactIds = new LinkedList<>(deployedArtifactIds); expectedArtifactIds.removeAll(artifactIdsInDubboAll); expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); Assertions.assertTrue( expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + expectedArtifactIds); List<String> unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll); unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId)); unexpectedArtifactIds.removeAll(deployedArtifactIds); Assertions.assertTrue( unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); unexpectedArtifactIds = new LinkedList<>(); for (String artifactId : artifactIdsInDubboAll) { if (!artifactIds.contains(artifactId)) { continue; } if (ignoredModulesInDubboAllShade.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { continue; } if (ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { unexpectedArtifactIds.add(artifactId); } if (ignoredModulesInDubboAll.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { unexpectedArtifactIds.add(artifactId); } } Assertions.assertTrue( unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all (dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); } @Test void checkDubboAllNettyShade() throws DocumentException { File baseFile = getBaseFile(); List<File> poms = new LinkedList<>(); readPoms(baseFile, poms); SAXReader reader = new SAXReader(); List<String> artifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); Assertions.assertEquals(poms.size(), artifactIds.size()); List<String> deployedArtifactIds = poms.stream() .map(f -> { try { return reader.read(f); } catch (DocumentException e) { throw new RuntimeException(e); } }) .map(Document::getRootElement) .filter(doc -> Objects.isNull(doc.element("properties")) || (!Objects.equals("true", doc.element("properties").elementText("skip_maven_deploy")) && !Objects.equals( "true", doc.element("properties").elementText("maven.deploy.skip")))) .filter(doc -> !Objects.equals("pom", doc.elementText("packaging"))) .map(doc -> doc.elementText("artifactId")) .sorted() .collect(Collectors.toList()); String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml"; Document dubboAll = reader.read(new File(getBaseFile(), dubboAllPath)); List<String> artifactIdsInDubboAll = dubboAll.getRootElement().element("build").element("plugins").elements("plugin").stream() .filter(ele -> ele.elementText("artifactId").equals("maven-shade-plugin")) .map(ele -> ele.element("executions")) .map(ele -> ele.elements("execution")) .flatMap(Collection::stream) .filter(ele -> ele.elementText("phase").equals("package")) .map(ele -> ele.element("configuration")) .map(ele -> ele.element("artifactSet")) .map(ele -> ele.element("includes")) .map(ele -> ele.elements("include")) .flatMap(Collection::stream) .map(Element::getText) .filter(artifactId -> artifactId.startsWith("org.apache.dubbo:")) .map(artifactId -> artifactId.substring("org.apache.dubbo:".length())) .collect(Collectors.toList()); List<String> expectedArtifactIds = new LinkedList<>(deployedArtifactIds); expectedArtifactIds.removeAll(artifactIdsInDubboAll); expectedArtifactIds.removeIf(artifactId -> ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); expectedArtifactIds.removeIf(artifactId -> ignoredModulesInDubboAll.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())); Assertions.assertTrue( expectedArtifactIds.isEmpty(), "Newly created modules must be added to dubbo-all-shaded (dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml in shade plugin). Found modules: " + expectedArtifactIds); List<String> unexpectedArtifactIds = new LinkedList<>(artifactIdsInDubboAll); unexpectedArtifactIds.removeIf(artifactId -> !artifactIds.contains(artifactId)); unexpectedArtifactIds.removeAll(deployedArtifactIds); Assertions.assertTrue( unexpectedArtifactIds.isEmpty(), "Undeploy dependencies should not be added to dubbo-all-shaded (dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); unexpectedArtifactIds = new LinkedList<>(); for (String artifactId : artifactIdsInDubboAll) { if (!artifactIds.contains(artifactId)) { continue; } if (ignoredModulesInDubboAllShade.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { continue; } if (ignoredModules.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { unexpectedArtifactIds.add(artifactId); } if (ignoredModulesInDubboAll.stream() .anyMatch(pattern -> pattern.matcher(artifactId).matches())) { unexpectedArtifactIds.add(artifactId); } } Assertions.assertTrue( unexpectedArtifactIds.isEmpty(), "Unexpected dependencies should not be added to dubbo-all-shaded (dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml in shade plugin). Found modules: " + unexpectedArtifactIds); } @Test void checkDubboTransform() throws DocumentException { File baseFile = getBaseFile(); List<String> spis = new LinkedList<>(); readSPI(baseFile, spis); String dubboAllPath = "dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml"; String dubboAllShadedPath = "dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml"; String dubboCoreSPIPath = "dubbo-distribution" + File.separator + "dubbo-core-spi" + File.separator + "pom.xml"; SAXReader reader = new SAXReader(); Document dubboAll = reader.read(new File(baseFile, dubboAllPath)); Document dubboAllShaded = reader.read(new File(baseFile, dubboAllShadedPath)); Document dubboCoreSPI = reader.read(new File(baseFile, dubboCoreSPIPath)); List<String> transformsInDubboAll = dubboAll.getRootElement().element("build").element("plugins").elements("plugin").stream() .filter(ele -> ele.elementText("artifactId").equals("maven-shade-plugin")) .map(ele -> ele.element("executions")) .map(ele -> ele.elements("execution")) .flatMap(Collection::stream) .filter(ele -> ele.elementText("phase").equals("package")) .map(ele -> ele.element("configuration")) .map(ele -> ele.element("transformers")) .map(ele -> ele.elements("transformer")) .flatMap(Collection::stream) .map(ele -> ele.elementText("resource")) .map(String::trim) .map(resource -> resource.substring(resource.lastIndexOf("/") + 1)) .collect(Collectors.toList()); List<String> transformsInDubboAllShaded = dubboAllShaded.getRootElement().element("build").element("plugins").elements("plugin").stream() .filter(ele -> ele.elementText("artifactId").equals("maven-shade-plugin")) .map(ele -> ele.element("executions")) .map(ele -> ele.elements("execution")) .flatMap(Collection::stream) .filter(ele -> ele.elementText("phase").equals("package")) .map(ele -> ele.element("configuration")) .map(ele -> ele.element("transformers")) .map(ele -> ele.elements("transformer")) .flatMap(Collection::stream) .map(ele -> ele.elementText("resource")) .map(String::trim) .map(resource -> resource.substring(resource.lastIndexOf("/") + 1)) .collect(Collectors.toList()); List<String> transformsInDubboCoreSPI = dubboCoreSPI.getRootElement().element("build").element("plugins").elements("plugin").stream() .filter(ele -> ele.elementText("artifactId").equals("maven-shade-plugin")) .map(ele -> ele.element("executions")) .map(ele -> ele.elements("execution")) .flatMap(Collection::stream) .filter(ele -> ele.elementText("phase").equals("package")) .map(ele -> ele.element("configuration")) .map(ele -> ele.element("transformers")) .map(ele -> ele.elements("transformer")) .flatMap(Collection::stream) .map(ele -> ele.elementText("resource")) .map(String::trim) .map(resource -> resource.substring(resource.lastIndexOf("/") + 1)) .collect(Collectors.toList()); List<String> expectedSpis = new LinkedList<>(spis); expectedSpis.removeAll(transformsInDubboAll); Assertions.assertTrue( expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis); List<String> unexpectedSpis = new LinkedList<>(transformsInDubboAll); unexpectedSpis.removeAll(spis); Assertions.assertTrue( unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-all(dubbo-distribution" + File.separator + "dubbo-all" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis); expectedSpis = new LinkedList<>(spis); expectedSpis.removeAll(transformsInDubboAllShaded); Assertions.assertTrue( expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-all-shaded(dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis); unexpectedSpis = new LinkedList<>(transformsInDubboAllShaded); unexpectedSpis.removeAll(spis); Assertions.assertTrue( unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-all-shaded(dubbo-distribution" + File.separator + "dubbo-all-shaded" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis); expectedSpis = new LinkedList<>(spis); expectedSpis.removeAll(transformsInDubboCoreSPI); Assertions.assertTrue( expectedSpis.isEmpty(), "Newly created SPI interface must be added to dubbo-core-spi(dubbo-distribution" + File.separator + "dubbo-core-spi" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + expectedSpis); unexpectedSpis = new LinkedList<>(transformsInDubboCoreSPI); unexpectedSpis.removeAll(spis); Assertions.assertTrue( unexpectedSpis.isEmpty(), "Class without `@SPI` declaration should not be added to dubbo-core-spi(dubbo-distribution" + File.separator + "dubbo-core-spi" + File.separator + "pom.xml in shade plugin) to being transformed. Found spis: " + unexpectedSpis); } @Test void checkSpiFiles() { File baseFile = getBaseFile(); List<String> spis = new LinkedList<>(); readSPI(baseFile, spis); Map<File, String> spiResources = new HashMap<>(); readSPIResource(baseFile, spiResources); Map<File, String> copyOfSpis = new HashMap<>(spiResources); copyOfSpis.entrySet().removeIf(entry -> spis.contains(entry.getValue())); Assertions.assertTrue( copyOfSpis.isEmpty(), "Newly created spi profiles must have a valid class declared with `@SPI`. Found spi profiles: " + copyOfSpis.keySet()); List<File> unexpectedSpis = new LinkedList<>(); readSPIUnexpectedResource(baseFile, unexpectedSpis); String commonSpiPath = "dubbo-common" + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "META-INF" + File.separator + "services" + File.separator; unexpectedSpis.removeIf(file -> { String path = file.getAbsolutePath(); return path.contains(commonSpiPath + "org.apache.dubbo.common.extension.LoadingStrategy")
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
true
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/UserService.java
dubbo-common/src/test/java/com/service/UserService.java
/* * 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 com.service; public interface UserService extends Service<Params, User> {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/DemoService4.java
dubbo-common/src/test/java/com/service/DemoService4.java
/* * 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 com.service; public abstract class DemoService4<T, R, Param extends DemoService5<T, R, Param>> { public DemoService4() {} public DemoService5<T, R, Param> getWrapper() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/Service.java
dubbo-common/src/test/java/com/service/Service.java
/* * 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 com.service; public interface Service<P, V> { V get(P params); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/DemoService1.java
dubbo-common/src/test/java/com/service/DemoService1.java
/* * 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 com.service; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Vector; import com.pojo.Demo1; import com.pojo.Demo2; import com.pojo.Demo4; import com.pojo.Demo5; import com.pojo.Demo6; import com.pojo.Demo7; import com.pojo.Demo8; import com.pojo.DemoException1; import com.pojo.DemoException3; public interface DemoService1<T extends Demo8> { Demo1 getDemo1(); void setDemo2(Demo2 demo2); List<Demo4> getDemo4s(); List<HashSet<LinkedList<Set<Vector<Map<? extends Demo5, ? super Demo6>>>>>> getDemo5s(); List<Demo7>[] getDemo7s(); List<T> getTs(); void echo1() throws DemoException1; void echo2() throws DemoException3; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/Params.java
dubbo-common/src/test/java/com/service/Params.java
/* * 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 com.service; import java.io.Serializable; import java.util.Map; public class Params implements Serializable { private static final long serialVersionUID = 1L; private Map<String, String> params; public Params(Map<String, String> params) { this.params = params; } public String get(String key) { return params.get(key); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/DemoService2.java
dubbo-common/src/test/java/com/service/DemoService2.java
/* * 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 com.service; public interface DemoService2 extends DemoService1 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/User.java
dubbo-common/src/test/java/com/service/User.java
/* * 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 com.service; import java.io.Serializable; public class User implements Serializable { private static final long serialVersionUID = 1L; private int id; private String name; public User(int id, String name) { super(); this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "User [id=" + id + ", name=" + name + "]"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/DemoService5.java
dubbo-common/src/test/java/com/service/DemoService5.java
/* * 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 com.service; public abstract class DemoService5<T, R, Children extends DemoService5<T, R, Children>> {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/service/deep1/deep2/deep3/DemoService3.java
dubbo-common/src/test/java/com/service/deep1/deep2/deep3/DemoService3.java
/* * 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 com.service.deep1.deep2.deep3; public interface DemoService3 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo5.java
dubbo-common/src/test/java/com/pojo/Demo5.java
/* * 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 com.pojo; public class Demo5 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo2.java
dubbo-common/src/test/java/com/pojo/Demo2.java
/* * 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 com.pojo; public class Demo2 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo3.java
dubbo-common/src/test/java/com/pojo/Demo3.java
/* * 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 com.pojo; public class Demo3 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo8.java
dubbo-common/src/test/java/com/pojo/Demo8.java
/* * 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 com.pojo; public class Demo8 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/DemoException3.java
dubbo-common/src/test/java/com/pojo/DemoException3.java
/* * 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 com.pojo; public class DemoException3 extends DemoException2 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Simple.java
dubbo-common/src/test/java/com/pojo/Simple.java
/* * 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 com.pojo; public class Simple {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo6.java
dubbo-common/src/test/java/com/pojo/Demo6.java
/* * 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 com.pojo; public class Demo6 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/DemoException1.java
dubbo-common/src/test/java/com/pojo/DemoException1.java
/* * 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 com.pojo; public class DemoException1 extends Exception {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo1.java
dubbo-common/src/test/java/com/pojo/Demo1.java
/* * 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 com.pojo; public class Demo1 { private Simple simple; public Simple getSimple() { return simple; } public void setSimple(Simple simple) { this.simple = simple; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo4.java
dubbo-common/src/test/java/com/pojo/Demo4.java
/* * 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 com.pojo; public class Demo4 extends Demo3 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/DemoException2.java
dubbo-common/src/test/java/com/pojo/DemoException2.java
/* * 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 com.pojo; public class DemoException2 extends Exception {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/com/pojo/Demo7.java
dubbo-common/src/test/java/com/pojo/Demo7.java
/* * 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 com.pojo; public class Demo7 {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/MetadataTest.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/MetadataTest.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.common.ClassExtendsMap; import org.apache.dubbo.metadata.definition.common.ColorEnum; import org.apache.dubbo.metadata.definition.common.OuterClass; 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 org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** * TypeDefinitionBuilder * <p> * 16/9/22. */ class MetadataTest { @BeforeAll public static void setup() { TypeDefinitionBuilder.initBuilders(FrameworkModel.defaultModel()); } /** * */ @Test void testInnerClassType() { TypeDefinitionBuilder builder = new TypeDefinitionBuilder(); TypeDefinition td = builder.build(OuterClass.InnerClass.class, OuterClass.InnerClass.class); Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.OuterClass.InnerClass", td.getType()); Assertions.assertEquals(1, td.getProperties().size()); Assertions.assertNotNull(td.getProperties().get("name")); ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class); Assertions.assertEquals(TestService.class.getName(), sd.getCanonicalName()); Assertions.assertEquals( TestService.class.getMethods().length, sd.getMethods().size()); boolean containsType = false; for (TypeDefinition type : sd.getTypes()) { if (type.getType().equals("org.apache.dubbo.metadata.definition.common.OuterClass.InnerClass")) { containsType = true; break; } } Assertions.assertTrue(containsType); } /** * */ @Test void testRawMap() { TypeDefinitionBuilder builder = new TypeDefinitionBuilder(); TypeDefinition td = builder.build(ResultWithRawCollections.class, ResultWithRawCollections.class); Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.ResultWithRawCollections", td.getType()); Assertions.assertEquals(2, td.getProperties().size()); Assertions.assertEquals("java.util.Map", td.getProperties().get("map")); Assertions.assertEquals("java.util.List", td.getProperties().get("list")); ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class); Assertions.assertEquals(TestService.class.getName(), sd.getCanonicalName()); Assertions.assertEquals( TestService.class.getMethods().length, sd.getMethods().size()); boolean containsType = false; for (TypeDefinition type : sd.getTypes()) { if (type.getType().equals("org.apache.dubbo.metadata.definition.common.ResultWithRawCollections")) { containsType = true; break; } } Assertions.assertTrue(containsType); } @Test void testEnum() { TypeDefinitionBuilder builder = new TypeDefinitionBuilder(); TypeDefinition td = builder.build(ColorEnum.class, ColorEnum.class); Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.ColorEnum", td.getType()); Assertions.assertEquals(3, td.getEnums().size()); Assertions.assertTrue(td.getEnums().contains("RED")); Assertions.assertTrue(td.getEnums().contains("YELLOW")); Assertions.assertTrue(td.getEnums().contains("BLUE")); ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class); Assertions.assertEquals(TestService.class.getName(), sd.getCanonicalName()); Assertions.assertEquals( TestService.class.getMethods().length, sd.getMethods().size()); boolean containsType = false; for (TypeDefinition type : sd.getTypes()) { if (type.getType().equals("org.apache.dubbo.metadata.definition.common.ColorEnum")) { containsType = true; break; } } Assertions.assertTrue(containsType); } @Test void testExtendsMap() { TypeDefinitionBuilder builder = new TypeDefinitionBuilder(); TypeDefinition td = builder.build(ClassExtendsMap.class, ClassExtendsMap.class); Assertions.assertEquals("org.apache.dubbo.metadata.definition.common.ClassExtendsMap", td.getType()); Assertions.assertEquals(0, td.getProperties().size()); ServiceDefinition sd = MetadataUtils.generateMetadata(TestService.class); Assertions.assertEquals(TestService.class.getName(), sd.getCanonicalName()); Assertions.assertEquals( TestService.class.getMethods().length, sd.getMethods().size()); boolean containsType = false; for (TypeDefinition type : sd.getTypes()) { if (type.getType().equals("org.apache.dubbo.metadata.definition.common.ClassExtendsMap")) { containsType = true; break; } } Assertions.assertFalse(containsType); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/DefaultTypeBuilderTest.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/DefaultTypeBuilderTest.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.builder.DefaultTypeBuilder; import org.apache.dubbo.rpc.model.FrameworkModel; import java.util.HashMap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class DefaultTypeBuilderTest { @Test void testInnerClass() { TypeDefinitionBuilder.initBuilders(FrameworkModel.defaultModel()); Assertions.assertEquals( String.class.getName(), DefaultTypeBuilder.build(String.class, new HashMap<>()).getType()); DefaultTypeBuilderTest innerObject = new DefaultTypeBuilderTest() {}; Assertions.assertEquals( DefaultTypeBuilderTest.class.getName() + "$1", DefaultTypeBuilder.build(innerObject.getClass(), new HashMap<>()) .getType()); TypeDefinitionBuilder.BUILDERS = null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilderTest.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilderTest.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.builder.TypeBuilder; import org.apache.dubbo.rpc.model.FrameworkModel; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class TypeDefinitionBuilderTest { @Test void testSortTypeBuilder() { TypeDefinitionBuilder.initBuilders(FrameworkModel.defaultModel()); TypeBuilder tb = TypeDefinitionBuilder.BUILDERS.get(0); Assertions.assertTrue(tb instanceof TestTypeBuilder); tb = TypeDefinitionBuilder.BUILDERS.get(TypeDefinitionBuilder.BUILDERS.size() - 1); Assertions.assertTrue(tb instanceof Test3TypeBuilder); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/Test3TypeBuilder.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/Test3TypeBuilder.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.builder.TypeBuilder; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import java.lang.reflect.Type; import java.util.Map; /** * test for sort */ public class Test3TypeBuilder implements TypeBuilder { // it is smaller than the implements of TypeBuilder @Override public int getPriority() { return 10; } @Override public boolean accept(Class<?> clazz) { return false; } @Override public TypeDefinition build(Type type, Class<?> clazz, Map<String, TypeDefinition> typeCache) { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuilderTest.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/ServiceDefinitionBuilderTest.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.definition.model.MethodDefinition; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import org.apache.dubbo.metadata.definition.service.ComplexObject; import org.apache.dubbo.metadata.definition.service.DemoService; import org.apache.dubbo.rpc.model.FrameworkModel; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** * 2018/11/6 */ class ServiceDefinitionBuilderTest { private static FrameworkModel frameworkModel; @BeforeAll public static void setup() { frameworkModel = new FrameworkModel(); TypeDefinitionBuilder.initBuilders(frameworkModel); } @AfterAll public static void clear() { frameworkModel.destroy(); } @Test void testBuilderComplexObject() { TypeDefinitionBuilder.initBuilders(FrameworkModel.defaultModel()); FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(DemoService.class); checkComplexObjectAsParam(fullServiceDefinition); } void checkComplexObjectAsParam(FullServiceDefinition fullServiceDefinition) { Assertions.assertTrue(fullServiceDefinition .getAnnotations() .contains( "@org.apache.dubbo.metadata.definition.service.annotation.MockTypeAnnotation(value=666)") // JDK 17 style || fullServiceDefinition .getAnnotations() .contains("@org.apache.dubbo.metadata.definition.service.annotation.MockTypeAnnotation(666)")); List<MethodDefinition> methodDefinitions = fullServiceDefinition.getMethods(); MethodDefinition complexCompute = null; MethodDefinition findComplexObject = null; MethodDefinition testAnnotation = null; for (MethodDefinition methodDefinition : methodDefinitions) { if ("complexCompute".equals(methodDefinition.getName())) { complexCompute = methodDefinition; } else if ("findComplexObject".equals(methodDefinition.getName())) { findComplexObject = methodDefinition; } else if ("testAnnotation".equals(methodDefinition.getName())) { testAnnotation = methodDefinition; } } Assertions.assertTrue(Arrays.equals( complexCompute.getParameterTypes(), new String[] {String.class.getName(), ComplexObject.class.getName()})); Assertions.assertEquals(complexCompute.getReturnType(), String.class.getName()); Assertions.assertTrue(Arrays.equals(findComplexObject.getParameterTypes(), new String[] { String.class.getName(), "int", "long", String[].class.getCanonicalName(), "java.util.List<java.lang.Integer>", ComplexObject.TestEnum.class.getCanonicalName() })); Assertions.assertEquals(findComplexObject.getReturnType(), ComplexObject.class.getCanonicalName()); Assertions.assertTrue( (testAnnotation .getAnnotations() .contains( "@org.apache.dubbo.metadata.definition.service.annotation.MockMethodAnnotation(value=777)") && testAnnotation .getAnnotations() .contains( "@org.apache.dubbo.metadata.definition.service.annotation.MockMethodAnnotation2(value=888)")) // JDK 17 style || (testAnnotation .getAnnotations() .contains( "@org.apache.dubbo.metadata.definition.service.annotation.MockMethodAnnotation(777)") && testAnnotation .getAnnotations() .contains( "@org.apache.dubbo.metadata.definition.service.annotation.MockMethodAnnotation2(888)"))); Assertions.assertEquals(testAnnotation.getReturnType(), "void"); List<TypeDefinition> typeDefinitions = fullServiceDefinition.getTypes(); TypeDefinition topTypeDefinition = null; TypeDefinition innerTypeDefinition = null; TypeDefinition inner2TypeDefinition = null; TypeDefinition inner3TypeDefinition = null; TypeDefinition listTypeDefinition = null; for (TypeDefinition typeDefinition : typeDefinitions) { if (typeDefinition.getType().equals(ComplexObject.class.getCanonicalName())) { topTypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals(ComplexObject.InnerObject.class.getCanonicalName())) { innerTypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals(ComplexObject.InnerObject2.class.getCanonicalName())) { inner2TypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals(ComplexObject.InnerObject3.class.getCanonicalName())) { inner3TypeDefinition = typeDefinition; } else if (typeDefinition.getType().equals("java.util.List<java.lang.Integer>")) { listTypeDefinition = typeDefinition; } } Assertions.assertEquals("long", topTypeDefinition.getProperties().get("v")); Assertions.assertEquals( "java.util.Map<java.lang.String,java.lang.String>", topTypeDefinition.getProperties().get("maps")); Assertions.assertEquals( ComplexObject.InnerObject.class.getCanonicalName(), topTypeDefinition.getProperties().get("innerObject")); Assertions.assertEquals( "java.util.List<java.lang.Integer>", topTypeDefinition.getProperties().get("intList")); Assertions.assertEquals( "java.lang.String[]", topTypeDefinition.getProperties().get("strArrays")); Assertions.assertEquals( "org.apache.dubbo.metadata.definition.service.ComplexObject.InnerObject3[]", topTypeDefinition.getProperties().get("innerObject3")); Assertions.assertEquals( "org.apache.dubbo.metadata.definition.service.ComplexObject.TestEnum", topTypeDefinition.getProperties().get("testEnum")); Assertions.assertEquals( "java.util.Set<org.apache.dubbo.metadata.definition.service.ComplexObject.InnerObject2>", topTypeDefinition.getProperties().get("innerObject2")); Assertions.assertSame( "java.lang.String", innerTypeDefinition.getProperties().get("innerA")); Assertions.assertSame("int", innerTypeDefinition.getProperties().get("innerB")); Assertions.assertSame( "java.lang.String", inner2TypeDefinition.getProperties().get("innerA2")); Assertions.assertSame("int", inner2TypeDefinition.getProperties().get("innerB2")); Assertions.assertSame( "java.lang.String", inner3TypeDefinition.getProperties().get("innerA3")); Assertions.assertEquals( Integer.class.getCanonicalName(), listTypeDefinition.getItems().get(0)); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/MetadataUtils.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/MetadataUtils.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.model.MethodDefinition; import org.apache.dubbo.metadata.definition.model.ServiceDefinition; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import org.apache.dubbo.metadata.definition.util.ClassUtils; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.List; /** * generate metadata * <p> * 2017-4-17 14:33:24 */ public class MetadataUtils { /** * com.taobao.hsf.metadata.store.MetadataInfoStoreServiceRedis.publishClassInfo(ServiceMetadata) 生成元数据的代码 */ public static ServiceDefinition generateMetadata(Class<?> interfaceClass) { ServiceDefinition sd = new ServiceDefinition(); sd.setCanonicalName(interfaceClass.getCanonicalName()); sd.setCodeSource(ClassUtils.getCodeSource(interfaceClass)); TypeDefinitionBuilder builder = new TypeDefinitionBuilder(); List<Method> methods = ClassUtils.getPublicNonStaticMethods(interfaceClass); for (Method method : methods) { MethodDefinition md = new MethodDefinition(); md.setName(method.getName()); Class<?>[] paramTypes = method.getParameterTypes(); Type[] genericParamTypes = method.getGenericParameterTypes(); String[] parameterTypes = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) { try { TypeDefinition td = builder.build(genericParamTypes[i], paramTypes[i]); parameterTypes[i] = td.getType(); } catch (Exception e) { parameterTypes[i] = paramTypes[i].getName(); } } md.setParameterTypes(parameterTypes); try { TypeDefinition td = builder.build(method.getGenericReturnType(), method.getReturnType()); md.setReturnType(td.getType()); } catch (Exception e) { md.setReturnType(method.getReturnType().getName()); } sd.getMethods().add(md); } sd.setTypes(builder.getTypeDefinitions()); return sd; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/TestTypeBuilder.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/TestTypeBuilder.java
/* * 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.metadata.definition; import org.apache.dubbo.metadata.definition.builder.TypeBuilder; import org.apache.dubbo.metadata.definition.model.TypeDefinition; import java.lang.reflect.Type; import java.util.Map; /** * test for sort */ public class TestTypeBuilder implements TypeBuilder { // it is smaller than the implements of TypeBuilder @Override public int getPriority() { return -3; } @Override public boolean accept(Class<?> clazz) { return false; } @Override public TypeDefinition build(Type type, Class<?> clazz, Map<String, TypeDefinition> typeCache) { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/ComplexObject.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/ComplexObject.java
/* * 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.metadata.definition.service; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; /** * for test */ public class ComplexObject { public ComplexObject() {} 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); this.setStrArrays(var3); this.setTestEnum(testEnum); this.setV(l); InnerObject2 io21 = new InnerObject2(); io21.setInnerA2(var1 + "_21"); io21.setInnerB2(var2 + 100000); InnerObject2 io22 = new InnerObject2(); io22.setInnerA2(var1 + "_22"); io22.setInnerB2(var2 + 200000); this.setInnerObject2(new HashSet<InnerObject2>(Arrays.asList(io21, io22))); InnerObject3 io31 = new InnerObject3(); io31.setInnerA3(var1 + "_31"); InnerObject3 io32 = new InnerObject3(); io32.setInnerA3(var1 + "_32"); InnerObject3 io33 = new InnerObject3(); io33.setInnerA3(var1 + "_33"); this.setInnerObject3(new InnerObject3[] {io31, io32, io33}); this.maps = new HashMap<>(4); this.maps.put(var1 + "_k1", var1 + "_v1"); this.maps.put(var1 + "_k2", var1 + "_v2"); } private InnerObject innerObject; private Set<InnerObject2> innerObject2; private InnerObject3[] innerObject3; private String[] strArrays; private List<Integer> intList; private long v; private TestEnum testEnum; private Map<String, String> maps; public InnerObject getInnerObject() { return innerObject; } public void setInnerObject(InnerObject innerObject) { this.innerObject = innerObject; } public String[] getStrArrays() { return strArrays; } public void setStrArrays(String[] strArrays) { this.strArrays = strArrays; } public List<Integer> getIntList() { return intList; } public void setIntList(List<Integer> intList) { this.intList = intList; } public long getV() { return v; } public void setV(long v) { this.v = v; } public TestEnum getTestEnum() { return testEnum; } public void setTestEnum(TestEnum testEnum) { this.testEnum = testEnum; } public Set<InnerObject2> getInnerObject2() { return innerObject2; } public void setInnerObject2(Set<InnerObject2> innerObject2) { this.innerObject2 = innerObject2; } public InnerObject3[] getInnerObject3() { return innerObject3; } public void setInnerObject3(InnerObject3[] innerObject3) { this.innerObject3 = innerObject3; } public Map<String, String> getMaps() { return maps; } public void setMaps(Map<String, String> maps) { this.maps = maps; } @Override public String toString() { return "ComplexObject{" + "innerObject=" + innerObject + ", innerObject2=" + innerObject2 + ", innerObject3=" + Arrays.toString(innerObject3) + ", strArrays=" + Arrays.toString(strArrays) + ", intList=" + intList + ", v=" + v + ", testEnum=" + testEnum + ", maps=" + maps + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ComplexObject)) return false; ComplexObject that = (ComplexObject) o; return getV() == that.getV() && Objects.equals(getInnerObject(), that.getInnerObject()) && Objects.equals(getInnerObject2(), that.getInnerObject2()) && Arrays.equals(getInnerObject3(), that.getInnerObject3()) && Arrays.equals(getStrArrays(), that.getStrArrays()) && Objects.equals(getIntList(), that.getIntList()) && getTestEnum() == that.getTestEnum() && Objects.equals(getMaps(), that.getMaps()); } @Override public int hashCode() { int result = Objects.hash(getInnerObject(), getInnerObject2(), getIntList(), getV(), getTestEnum(), getMaps()); result = 31 * result + Arrays.hashCode(getInnerObject3()); result = 31 * result + Arrays.hashCode(getStrArrays()); return result; } public enum TestEnum { VALUE1, VALUE2 } public static class InnerObject { String innerA; int innerB; public String getInnerA() { return innerA; } public void setInnerA(String innerA) { this.innerA = innerA; } public int getInnerB() { return innerB; } public void setInnerB(int innerB) { this.innerB = innerB; } @Override public String toString() { return "InnerObject{" + "innerA='" + innerA + '\'' + ", innerB=" + innerB + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InnerObject)) return false; InnerObject that = (InnerObject) o; return getInnerB() == that.getInnerB() && Objects.equals(getInnerA(), that.getInnerA()); } @Override public int hashCode() { return Objects.hash(getInnerA(), getInnerB()); } } public static class InnerObject2 { String innerA2; int innerB2; public String getInnerA2() { return innerA2; } public void setInnerA2(String innerA2) { this.innerA2 = innerA2; } public int getInnerB2() { return innerB2; } public void setInnerB2(int innerB2) { this.innerB2 = innerB2; } @Override public String toString() { return "InnerObject{" + "innerA='" + innerA2 + '\'' + ", innerB=" + innerB2 + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InnerObject2)) return false; InnerObject2 that = (InnerObject2) o; return getInnerB2() == that.getInnerB2() && Objects.equals(getInnerA2(), that.getInnerA2()); } @Override public int hashCode() { return Objects.hash(getInnerA2(), getInnerB2()); } } public static class InnerObject3 { String innerA3; public String getInnerA3() { return innerA3; } public void setInnerA3(String innerA3) { this.innerA3 = innerA3; } @Override public String toString() { return "InnerObject3{" + "innerA3='" + innerA3 + '\'' + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InnerObject3)) return false; InnerObject3 that = (InnerObject3) o; return Objects.equals(getInnerA3(), that.getInnerA3()); } @Override public int hashCode() { return Objects.hash(getInnerA3()); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/DemoService.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/DemoService.java
/* * 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.metadata.definition.service; import org.apache.dubbo.metadata.definition.service.annotation.MockMethodAnnotation; import org.apache.dubbo.metadata.definition.service.annotation.MockMethodAnnotation2; import org.apache.dubbo.metadata.definition.service.annotation.MockTypeAnnotation; import java.util.List; /** * for test */ @MockTypeAnnotation(666) public interface DemoService { String complexCompute(String input, ComplexObject co); ComplexObject findComplexObject( String var1, int var2, long l, String[] var3, List<Integer> var4, ComplexObject.TestEnum testEnum); @MockMethodAnnotation(777) @MockMethodAnnotation2(888) void testAnnotation(boolean flag); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/annotation/MockTypeAnnotation.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/annotation/MockTypeAnnotation.java
/* * 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.metadata.definition.service.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface MockTypeAnnotation { int value(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/annotation/MockMethodAnnotation.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/annotation/MockMethodAnnotation.java
/* * 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.metadata.definition.service.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MockMethodAnnotation { int value(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/annotation/MockMethodAnnotation2.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/service/annotation/MockMethodAnnotation2.java
/* * 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.metadata.definition.service.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MockMethodAnnotation2 { int value(); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/TestService.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/TestService.java
/* * 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.metadata.definition.common; /** * 16/9/22. */ public interface TestService { /** * * @param innerClass * @return */ void m1(OuterClass.InnerClass innerClass); /** * * @param a */ void m2(int[] a); /** * * @param s1 * @return */ ResultWithRawCollections m3(String s1); /** * * @param color */ void m4(ColorEnum color); /** * * @param s1 * @return */ ClassExtendsMap m5(String s1); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/OuterClass.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/OuterClass.java
/* * 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.metadata.definition.common; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 16/9/22. */ public class OuterClass { private static final Logger logger = LoggerFactory.getLogger(OuterClass.class); public static class InnerClass { private String name; public InnerClass() { logger.debug("I am inner class"); } public String getName() { return name; } public void setName(String name) { this.name = name; } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/ClassExtendsMap.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/ClassExtendsMap.java
/* * 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.metadata.definition.common; import java.util.HashMap; public class ClassExtendsMap extends HashMap<String, Object> { private static final long serialVersionUID = 5108356684263812575L; private ClassExtendsMap resultMap; public ClassExtendsMap() {} public ClassExtendsMap getResultMap() { return resultMap; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/ResultWithRawCollections.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/ResultWithRawCollections.java
/* * 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.metadata.definition.common; import java.util.List; import java.util.Map; @SuppressWarnings("rawtypes") public class ResultWithRawCollections { private Map map; private List list; public ResultWithRawCollections() {} public ResultWithRawCollections(Map map, List list) { this.map = map; this.list = list; } public List getList() { return list; } public void setList(List list) { this.list = list; } public Map getMap() { return map; } public void setMap(Map map) { this.map = map; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/ColorEnum.java
dubbo-common/src/test/java/org/apache/dubbo/metadata/definition/common/ColorEnum.java
/* * 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.metadata.definition.common; public enum ColorEnum { RED, YELLOW, BLUE }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoService1Impl.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoService1Impl.java
/* * 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.rpc.support; import org.apache.dubbo.common.stream.StreamObserver; public class DemoService1Impl implements DemoService1 { @Override public StreamObserver<String> sayHello(StreamObserver<String> request) { request.onNext("BI_STREAM"); return request; } @Override public void sayHello(String msg, StreamObserver<String> request) { request.onNext(msg); request.onNext("SERVER_STREAM"); request.onCompleted(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoService1.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoService1.java
/* * 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.rpc.support; import org.apache.dubbo.common.stream.StreamObserver; public interface DemoService1 { StreamObserver<String> sayHello(StreamObserver<String> request); void sayHello(String msg, StreamObserver<String> request); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoServiceImpl.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoServiceImpl.java
/* * 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.rpc.support; public class DemoServiceImpl implements DemoService { @Override public String sayHello(String name) { return "hello " + name; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoService.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/DemoService.java
/* * 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.rpc.support; public interface DemoService { String sayHello(String name); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/ProtocolUtilsTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/ProtocolUtilsTest.java
/* * 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.rpc.support; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class ProtocolUtilsTest { @Test void testGetServiceKey() { final String serviceName = "com.abc.demoService"; final int port = 1001; assertServiceKey(port, serviceName, "1.0.0", "group"); assertServiceKey(port, serviceName, "1.0.0", ""); assertServiceKey(port, serviceName, "1.0.0", null); assertServiceKey(port, serviceName, "0.0", "group"); assertServiceKey(port, serviceName, "0_0_0", "group"); assertServiceKey(port, serviceName, "0.0.0", "group"); assertServiceKey(port, serviceName, "", "group"); assertServiceKey(port, serviceName, null, "group"); assertServiceKey(port, serviceName, "", ""); assertServiceKey(port, serviceName, "", null); assertServiceKey(port, serviceName, null, ""); assertServiceKey(port, serviceName, null, null); assertServiceKey(port, serviceName, "", " "); assertServiceKey(port, serviceName, " ", ""); assertServiceKey(port, serviceName, " ", " "); } private void assertServiceKey(int port, String serviceName, String serviceVersion, String serviceGroup) { Assertions.assertEquals( serviceKeyOldImpl(port, serviceName, serviceVersion, serviceGroup), ProtocolUtils.serviceKey(port, serviceName, serviceVersion, serviceGroup)); } /** * 来自 ProtocolUtils.serviceKey(int, String, String, String) 老版本的实现,用于对比测试! */ private static String serviceKeyOldImpl(int port, String serviceName, String serviceVersion, String serviceGroup) { StringBuilder buf = new StringBuilder(); if (serviceGroup != null && serviceGroup.length() > 0) { buf.append(serviceGroup); buf.append('/'); } buf.append(serviceName); if (serviceVersion != null && serviceVersion.length() > 0 && !"0.0.0".equals(serviceVersion)) { buf.append(':'); buf.append(serviceVersion); } buf.append(':'); buf.append(port); return buf.toString(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/MockScopeModelDestroyListener.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/MockScopeModelDestroyListener.java
/* * 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.rpc.support; import org.apache.dubbo.rpc.model.ScopeModel; import org.apache.dubbo.rpc.model.ScopeModelDestroyListener; public class MockScopeModelDestroyListener implements ScopeModelDestroyListener { private boolean destroyed = false; private ScopeModel scopeModel; @Override public void onDestroy(ScopeModel scopeModel) { this.destroyed = true; this.scopeModel = scopeModel; } public boolean isDestroyed() { return destroyed; } public ScopeModel getScopeModel() { return scopeModel; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/support/MockScopeModelAware.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/support/MockScopeModelAware.java
/* * 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.rpc.support; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModel; import org.apache.dubbo.rpc.model.ScopeModelAccessor; import org.apache.dubbo.rpc.model.ScopeModelAware; public class MockScopeModelAware implements ScopeModelAware, ScopeModelAccessor { private ScopeModel scopeModel; private FrameworkModel frameworkModel; private ApplicationModel applicationModel; private ModuleModel moduleModel; @Override public ScopeModel getScopeModel() { return scopeModel; } @Override public FrameworkModel getFrameworkModel() { return frameworkModel; } @Override public ApplicationModel getApplicationModel() { return applicationModel; } @Override public ModuleModel getModuleModel() { return moduleModel; } @Override public void setScopeModel(ScopeModel scopeModel) { this.scopeModel = scopeModel; } @Override public void setFrameworkModel(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; } @Override public void setApplicationModel(ApplicationModel applicationModel) { this.applicationModel = applicationModel; } @Override public void setModuleModel(ModuleModel moduleModel) { this.moduleModel = moduleModel; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/service/ServiceDescriptorInternalCacheTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/service/ServiceDescriptorInternalCacheTest.java
/* * 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.rpc.service; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class ServiceDescriptorInternalCacheTest { @Test void genericService() { Assertions.assertNotNull(ServiceDescriptorInternalCache.genericService()); Assertions.assertEquals( GenericService.class, ServiceDescriptorInternalCache.genericService().getServiceInterfaceClass()); } @Test void echoService() { Assertions.assertNotNull(ServiceDescriptorInternalCache.echoService()); Assertions.assertEquals( EchoService.class, ServiceDescriptorInternalCache.echoService().getServiceInterfaceClass()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/service/GenericExceptionTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/service/GenericExceptionTest.java
/* * 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.rpc.service; import org.apache.dubbo.common.utils.JsonUtils; import java.io.IOException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class GenericExceptionTest { @Test void jsonSupport() throws IOException { { GenericException src = new GenericException(); String s = JsonUtils.toJson(src); GenericException dst = JsonUtils.toJavaObject(s, GenericException.class); Assertions.assertEquals(src.getExceptionClass(), dst.getExceptionClass()); Assertions.assertEquals(src.getExceptionMessage(), dst.getExceptionMessage()); Assertions.assertEquals(src.getMessage(), dst.getMessage()); Assertions.assertEquals(src.getExceptionMessage(), dst.getExceptionMessage()); } { GenericException src = new GenericException(this.getClass().getSimpleName(), "test"); String s = JsonUtils.toJson(src); GenericException dst = JsonUtils.toJavaObject(s, GenericException.class); Assertions.assertEquals(src.getExceptionClass(), dst.getExceptionClass()); Assertions.assertEquals(src.getExceptionMessage(), dst.getExceptionMessage()); Assertions.assertEquals(src.getMessage(), dst.getMessage()); Assertions.assertEquals(src.getExceptionMessage(), dst.getExceptionMessage()); } { Throwable throwable = new Throwable("throwable"); GenericException src = new GenericException(throwable); String s = JsonUtils.toJson(src); GenericException dst = JsonUtils.toJavaObject(s, GenericException.class); Assertions.assertEquals(src.getExceptionClass(), dst.getExceptionClass()); Assertions.assertEquals(src.getExceptionMessage(), dst.getExceptionMessage()); Assertions.assertEquals(src.getMessage(), dst.getMessage()); Assertions.assertEquals(src.getExceptionMessage(), dst.getExceptionMessage()); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.config.Environment; import org.apache.dubbo.common.extension.ExtensionScope; import org.apache.dubbo.common.extension.SPI; import java.util.concurrent.locks.Lock; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * {@link ScopeModelUtil} */ class ScopeModelUtilTest { private FrameworkModel frameworkModel; private ApplicationModel applicationModel; private ModuleModel moduleModel; @BeforeEach public void setUp() { frameworkModel = new FrameworkModel(); applicationModel = frameworkModel.newApplication(); moduleModel = applicationModel.newModule(); } @AfterEach public void reset() { frameworkModel.destroy(); } @Test void test() { Assertions.assertEquals(ScopeModelUtil.getFrameworkModel(null), FrameworkModel.defaultModel()); Assertions.assertEquals(ScopeModelUtil.getFrameworkModel(frameworkModel), frameworkModel); Assertions.assertEquals(ScopeModelUtil.getFrameworkModel(applicationModel), frameworkModel); Assertions.assertEquals(ScopeModelUtil.getFrameworkModel(moduleModel), frameworkModel); Assertions.assertThrows( IllegalArgumentException.class, () -> ScopeModelUtil.getFrameworkModel(new MockScopeModel(null, null))); Assertions.assertEquals(ScopeModelUtil.getApplicationModel(null), ApplicationModel.defaultModel()); Assertions.assertEquals(ScopeModelUtil.getApplicationModel(applicationModel), applicationModel); Assertions.assertEquals(ScopeModelUtil.getApplicationModel(moduleModel), applicationModel); Assertions.assertThrows( IllegalArgumentException.class, () -> ScopeModelUtil.getApplicationModel(frameworkModel)); Assertions.assertEquals( ScopeModelUtil.getModuleModel(null), ApplicationModel.defaultModel().getDefaultModule()); Assertions.assertEquals(ScopeModelUtil.getModuleModel(moduleModel), moduleModel); Assertions.assertThrows(IllegalArgumentException.class, () -> ScopeModelUtil.getModuleModel(frameworkModel)); Assertions.assertThrows(IllegalArgumentException.class, () -> ScopeModelUtil.getModuleModel(applicationModel)); Assertions.assertEquals(ScopeModelUtil.getOrDefault(null, SPIDemo1.class), FrameworkModel.defaultModel()); Assertions.assertEquals(ScopeModelUtil.getOrDefault(null, SPIDemo2.class), ApplicationModel.defaultModel()); Assertions.assertEquals( ScopeModelUtil.getOrDefault(null, SPIDemo3.class), ApplicationModel.defaultModel().getDefaultModule()); Assertions.assertThrows( IllegalArgumentException.class, () -> ScopeModelUtil.getOrDefault(null, SPIDemo4.class)); Assertions.assertEquals( ScopeModelUtil.getExtensionLoader(SPIDemo1.class, null), FrameworkModel.defaultModel().getExtensionLoader(SPIDemo1.class)); Assertions.assertEquals( ScopeModelUtil.getExtensionLoader(SPIDemo2.class, null), ApplicationModel.defaultModel().getExtensionLoader(SPIDemo2.class)); Assertions.assertEquals( ScopeModelUtil.getExtensionLoader(SPIDemo3.class, null), ApplicationModel.defaultModel().getDefaultModule().getExtensionLoader(SPIDemo3.class)); Assertions.assertThrows( IllegalArgumentException.class, () -> ScopeModelUtil.getExtensionLoader(SPIDemo4.class, null)); } @SPI(scope = ExtensionScope.FRAMEWORK) interface SPIDemo1 {} @SPI(scope = ExtensionScope.APPLICATION) interface SPIDemo2 {} @SPI(scope = ExtensionScope.MODULE) interface SPIDemo3 {} interface SPIDemo4 {} class MockScopeModel extends ScopeModel { public MockScopeModel(ScopeModel parent, ExtensionScope scope) { super(parent, scope, false); } @Override protected void onDestroy() {} @Override public Environment modelEnvironment() { return null; } @Override protected Lock acquireDestroyLock() { return null; } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloReply.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloReply.java
/* * 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.rpc.model; import com.google.protobuf.Message; public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 { @Override protected FieldAccessorTable internalGetFieldAccessorTable() { return null; } @Override protected Message.Builder newBuilderForType(BuilderParent builderParent) { return null; } @Override public Message.Builder newBuilderForType() { return null; } @Override public Message.Builder toBuilder() { return null; } @Override public Message getDefaultInstanceForType() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/FrameworkModelTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/FrameworkModelTest.java
/* * 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.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; /** * {@link FrameworkModel} */ class FrameworkModelTest { @Test void testInitialize() { FrameworkModel.destroyAll(); FrameworkModel frameworkModel = new FrameworkModel(); Assertions.assertNull(frameworkModel.getParent()); Assertions.assertEquals(frameworkModel.getScope(), ExtensionScope.FRAMEWORK); Assertions.assertNotNull(frameworkModel.getInternalId()); Assertions.assertTrue(FrameworkModel.getAllInstances().contains(frameworkModel)); Assertions.assertEquals(FrameworkModel.defaultModel(), frameworkModel); Assertions.assertNotNull(frameworkModel.getExtensionDirector()); Assertions.assertNotNull(frameworkModel.getBeanFactory()); Assertions.assertTrue(frameworkModel.getClassLoaders().contains(ScopeModel.class.getClassLoader())); Assertions.assertNotNull(frameworkModel.getServiceRepository()); ApplicationModel applicationModel = frameworkModel.getInternalApplicationModel(); Assertions.assertNotNull(applicationModel); Assertions.assertTrue(frameworkModel.getAllApplicationModels().contains(applicationModel)); Assertions.assertFalse(frameworkModel.getApplicationModels().contains(applicationModel)); frameworkModel.destroy(); } @Test void testDefaultModel() { FrameworkModel frameworkModel = FrameworkModel.defaultModel(); Assertions.assertTrue(FrameworkModel.getAllInstances().contains(frameworkModel)); String desc = frameworkModel.getDesc(); Assertions.assertEquals(desc, "Dubbo Framework[" + frameworkModel.getInternalId() + "]"); frameworkModel.destroy(); } @Test void testApplicationModel() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.defaultApplication(); ApplicationModel internalApplicationModel = frameworkModel.getInternalApplicationModel(); Assertions.assertEquals(frameworkModel.getDefaultAppModel(), applicationModel); Assertions.assertTrue(frameworkModel.getAllApplicationModels().contains(applicationModel)); Assertions.assertTrue(frameworkModel.getAllApplicationModels().contains(internalApplicationModel)); Assertions.assertTrue(frameworkModel.getApplicationModels().contains(applicationModel)); Assertions.assertFalse(frameworkModel.getApplicationModels().contains(internalApplicationModel)); frameworkModel.removeApplication(applicationModel); Assertions.assertFalse(frameworkModel.getAllApplicationModels().contains(applicationModel)); Assertions.assertFalse(frameworkModel.getApplicationModels().contains(applicationModel)); frameworkModel.destroy(); } @Test void destroyAll() { FrameworkModel frameworkModel = new FrameworkModel(); frameworkModel.defaultApplication(); frameworkModel.newApplication(); FrameworkModel.destroyAll(); Assertions.assertTrue(FrameworkModel.getAllInstances().isEmpty()); Assertions.assertTrue(frameworkModel.isDestroyed()); try { frameworkModel.defaultApplication(); Assertions.fail("Cannot create new application after framework model destroyed"); } catch (Exception e) { Assertions.assertEquals("FrameworkModel is destroyed", e.getMessage(), StringUtils.toString(e)); } try { frameworkModel.newApplication(); Assertions.fail("Cannot create new application after framework model destroyed"); } catch (Exception e) { Assertions.assertEquals("FrameworkModel is destroyed", e.getMessage(), StringUtils.toString(e)); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/FrameworkServiceRepositoryTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/FrameworkServiceRepositoryTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.support.DemoService; import org.apache.dubbo.rpc.support.DemoServiceImpl; import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.apache.dubbo.common.BaseServiceMetadata.interfaceFromServiceKey; import static org.apache.dubbo.common.BaseServiceMetadata.versionFromServiceKey; /** * {@link FrameworkServiceRepository} */ class FrameworkServiceRepositoryTest { private FrameworkModel frameworkModel; private ApplicationModel applicationModel; private ModuleModel moduleModel; @BeforeEach public void setUp() { frameworkModel = new FrameworkModel(); applicationModel = frameworkModel.newApplication(); moduleModel = applicationModel.newModule(); } @AfterEach public void reset() { frameworkModel.destroy(); } @Test void test() { FrameworkServiceRepository frameworkServiceRepository = frameworkModel.getServiceRepository(); ModuleServiceRepository moduleServiceRepository = moduleModel.getServiceRepository(); ServiceMetadata serviceMetadata = new ServiceMetadata(DemoService.class.getName(), "GROUP", "1.0.0", DemoService.class); ServiceDescriptor serviceDescriptor = moduleServiceRepository.registerService(DemoService.class); String serviceKey = serviceMetadata.getServiceKey(); ProviderModel providerModel = new ProviderModel( serviceKey, new DemoServiceImpl(), serviceDescriptor, moduleModel, serviceMetadata, ClassUtils.getClassLoader(DemoService.class)); frameworkServiceRepository.registerProvider(providerModel); ProviderModel lookupExportedService = frameworkServiceRepository.lookupExportedService(serviceKey); Assertions.assertEquals(lookupExportedService, providerModel); List<ProviderModel> allProviderModels = frameworkServiceRepository.allProviderModels(); Assertions.assertEquals(allProviderModels.size(), 1); Assertions.assertEquals(allProviderModels.get(0), providerModel); String keyWithoutGroup = keyWithoutGroup(serviceKey); ProviderModel exportedServiceWithoutGroup = frameworkServiceRepository.lookupExportedServiceWithoutGroup(keyWithoutGroup); Assertions.assertEquals(exportedServiceWithoutGroup, providerModel); List<ProviderModel> providerModels = frameworkServiceRepository.lookupExportedServicesWithoutGroup(keyWithoutGroup); Assertions.assertEquals(providerModels.size(), 1); Assertions.assertEquals(providerModels.get(0), providerModel); ConsumerModel consumerModel = new ConsumerModel( serviceMetadata.getServiceKey(), new DemoServiceImpl(), serviceDescriptor, moduleModel, serviceMetadata, null, ClassUtils.getClassLoader(DemoService.class)); moduleServiceRepository.registerConsumer(consumerModel); List<ConsumerModel> consumerModels = frameworkServiceRepository.allConsumerModels(); Assertions.assertEquals(consumerModels.size(), 1); Assertions.assertEquals(consumerModels.get(0), consumerModel); frameworkServiceRepository.unregisterProvider(providerModel); Assertions.assertNull(frameworkServiceRepository.lookupExportedService(serviceKey)); Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(keyWithoutGroup)); } private static String keyWithoutGroup(String serviceKey) { String interfaceName = interfaceFromServiceKey(serviceKey); String version = versionFromServiceKey(serviceKey); if (StringUtils.isEmpty(version)) { return interfaceName; } return interfaceName + ":" + version; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleServiceRepositoryTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleServiceRepositoryTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.rpc.support.DemoService; import org.apache.dubbo.rpc.support.DemoServiceImpl; import java.util.List; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * {@link ModuleServiceRepository} */ class ModuleServiceRepositoryTest { private FrameworkModel frameworkModel; private ApplicationModel applicationModel; private ModuleModel moduleModel; @BeforeEach public void setUp() { frameworkModel = new FrameworkModel(); applicationModel = frameworkModel.newApplication(); moduleModel = applicationModel.newModule(); } @AfterEach public void reset() { frameworkModel.destroy(); } @Test void test() { ModuleServiceRepository moduleServiceRepository = new ModuleServiceRepository(moduleModel); Assertions.assertEquals(moduleServiceRepository.getModuleModel(), moduleModel); ModuleServiceRepository repository = moduleModel.getServiceRepository(); // 1.test service ServiceMetadata serviceMetadata = new ServiceMetadata(DemoService.class.getName(), null, null, DemoService.class); ServiceDescriptor serviceDescriptor = repository.registerService(DemoService.class); ServiceDescriptor lookupServiceResult = repository.lookupService(DemoService.class.getName()); Assertions.assertEquals(lookupServiceResult, serviceDescriptor); List<ServiceDescriptor> allServices = repository.getAllServices(); Assertions.assertEquals(1, allServices.size()); Assertions.assertEquals(allServices.get(0), serviceDescriptor); ServiceDescriptor serviceDescriptor1 = repository.registerService(DemoService.class.getSimpleName(), DemoService.class); Assertions.assertEquals(serviceDescriptor1, serviceDescriptor); // 2.test consumerModule ConsumerModel consumerModel = new ConsumerModel( serviceMetadata.getServiceKey(), new DemoServiceImpl(), serviceDescriptor, moduleModel, serviceMetadata, null, ClassUtils.getClassLoader(DemoService.class)); repository.registerConsumer(consumerModel); List<ConsumerModel> allReferredServices = repository.getReferredServices(); Assertions.assertEquals(1, allReferredServices.size()); Assertions.assertEquals(allReferredServices.get(0), consumerModel); List<ConsumerModel> referredServices = repository.lookupReferredServices(DemoService.class.getName()); Assertions.assertEquals(1, referredServices.size()); Assertions.assertEquals(referredServices.get(0), consumerModel); ConsumerModel referredService = repository.lookupReferredServices(DemoService.class.getName()).get(0); Assertions.assertEquals(referredService, consumerModel); // 3.test providerModel ProviderModel providerModel = new ProviderModel( DemoService.class.getName(), new DemoServiceImpl(), serviceDescriptor, moduleModel, serviceMetadata, ClassUtils.getClassLoader(DemoService.class)); repository.registerProvider(providerModel); List<ProviderModel> allExportedServices = repository.getExportedServices(); Assertions.assertEquals(1, allExportedServices.size()); Assertions.assertEquals(allExportedServices.get(0), providerModel); ProviderModel exportedService = repository.lookupExportedService(DemoService.class.getName()); Assertions.assertEquals(exportedService, providerModel); List<ProviderModel> providerModels = frameworkModel.getServiceRepository().allProviderModels(); Assertions.assertEquals(1, providerModels.size()); Assertions.assertEquals(providerModels.get(0), providerModel); // 4.test destroy repository.destroy(); Assertions.assertTrue(repository.getAllServices().isEmpty()); Assertions.assertTrue(repository.getReferredServices().isEmpty()); Assertions.assertTrue(repository.getExportedServices().isEmpty()); Assertions.assertTrue( frameworkModel.getServiceRepository().allProviderModels().isEmpty()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/Person.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/Person.java
/* * 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.rpc.model; import java.util.Arrays; public class Person { byte oneByte = 123; private String name = "name1"; private int age = 11; private String[] value = {"value1", "value2"}; public String getName() { return name; } public void setName(String name) { this.name = name; } public byte getOneByte() { return oneByte; } public void setOneByte(byte b) { this.oneByte = b; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String[] getValue() { return value; } public void setValue(String[] value) { this.value = value; } @Override public String toString() { return String.format("Person name(%s) age(%d) byte(%s) [value=%s]", name, age, oneByte, Arrays.toString(value)); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + Arrays.hashCode(value); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Person other = (Person) obj; if (age != other.age) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (!Arrays.equals(value, other.value)) return false; return true; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloRequest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloRequest.java
/* * 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.rpc.model; import com.google.protobuf.Message; public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 { @Override protected FieldAccessorTable internalGetFieldAccessorTable() { return null; } @Override protected Message.Builder newBuilderForType(BuilderParent builderParent) { return null; } @Override public Message.Builder newBuilderForType() { return null; } @Override public Message.Builder toBuilder() { return null; } @Override public Message getDefaultInstanceForType() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelAwareExtensionProcessorTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelAwareExtensionProcessorTest.java
/* * 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.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; import org.junit.jupiter.api.Test; /** * {@link ScopeModelAwareExtensionProcessor} */ class ScopeModelAwareExtensionProcessorTest { private FrameworkModel frameworkModel; private ApplicationModel applicationModel; private ModuleModel moduleModel; @BeforeEach public void setUp() { frameworkModel = new FrameworkModel(); applicationModel = frameworkModel.newApplication(); moduleModel = applicationModel.newModule(); } @AfterEach public void reset() { frameworkModel.destroy(); } @Test void testInitialize() { ScopeModelAwareExtensionProcessor processor1 = new ScopeModelAwareExtensionProcessor(frameworkModel); Assertions.assertEquals(processor1.getFrameworkModel(), frameworkModel); Assertions.assertEquals(processor1.getScopeModel(), frameworkModel); Assertions.assertNull(processor1.getApplicationModel()); Assertions.assertNull(processor1.getModuleModel()); ScopeModelAwareExtensionProcessor processor2 = new ScopeModelAwareExtensionProcessor(applicationModel); Assertions.assertEquals(processor2.getApplicationModel(), applicationModel); Assertions.assertEquals(processor2.getScopeModel(), applicationModel); Assertions.assertEquals(processor2.getFrameworkModel(), frameworkModel); Assertions.assertNull(processor2.getModuleModel()); ScopeModelAwareExtensionProcessor processor3 = new ScopeModelAwareExtensionProcessor(moduleModel); Assertions.assertEquals(processor3.getModuleModel(), moduleModel); Assertions.assertEquals(processor3.getScopeModel(), moduleModel); Assertions.assertEquals(processor2.getApplicationModel(), applicationModel); Assertions.assertEquals(processor2.getFrameworkModel(), frameworkModel); } @Test void testPostProcessAfterInitialization() throws Exception { ScopeModelAwareExtensionProcessor processor = new ScopeModelAwareExtensionProcessor(moduleModel); MockScopeModelAware mockScopeModelAware = new MockScopeModelAware(); Object object = processor.postProcessAfterInitialization( mockScopeModelAware, mockScopeModelAware.getClass().getName()); Assertions.assertEquals(object, mockScopeModelAware); Assertions.assertEquals(mockScopeModelAware.getScopeModel(), moduleModel); Assertions.assertEquals(mockScopeModelAware.getFrameworkModel(), frameworkModel); Assertions.assertEquals(mockScopeModelAware.getApplicationModel(), applicationModel); Assertions.assertEquals(mockScopeModelAware.getModuleModel(), moduleModel); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ReflectionServiceDescriptorTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ReflectionServiceDescriptorTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.metadata.definition.TypeDefinitionBuilder; import org.apache.dubbo.rpc.support.DemoService; import org.apache.dubbo.rpc.support.DemoService1; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.mockito.Mockito.when; class ReflectionServiceDescriptorTest { private final ReflectionServiceDescriptor service = new ReflectionServiceDescriptor(DemoService.class); @Test void addMethod() { ReflectionServiceDescriptor service2 = new ReflectionServiceDescriptor(DemoService.class); MethodDescriptor method = Mockito.mock(MethodDescriptor.class); when(method.getMethodName()).thenReturn("sayHello2"); service2.addMethod(method); Assertions.assertEquals(1, service2.getMethods("sayHello2").size()); } @Test void testStreamRpcTypeException() { try { new ReflectionServiceDescriptor(DemoService1.class); } catch (IllegalStateException e) { Assertions.assertTrue(e.getMessage().contains("Stream method could not be overloaded.")); } } @Test void getFullServiceDefinition() { TypeDefinitionBuilder.initBuilders(new FrameworkModel()); Assertions.assertNotNull(service.getFullServiceDefinition("demoService")); } @Test void getInterfaceName() { Assertions.assertEquals(DemoService.class.getName(), service.getInterfaceName()); } @Test void getServiceInterfaceClass() { Assertions.assertEquals(DemoService.class, service.getServiceInterfaceClass()); } @Test void getAllMethods() { Assertions.assertFalse(service.getAllMethods().isEmpty()); } @Test void getMethod() { String desc = ReflectUtils.getDesc(String.class); Assertions.assertNotNull(service.getMethod("sayHello", desc)); } @Test void testGetMethod() { Assertions.assertNotNull(service.getMethod("sayHello", new Class[] {String.class})); } @Test void getMethods() { Assertions.assertEquals(1, service.getMethods("sayHello").size()); } @Test void testEquals() { ReflectionServiceDescriptor service2 = new ReflectionServiceDescriptor(DemoService.class); ReflectionServiceDescriptor service3 = new ReflectionServiceDescriptor(DemoService.class); Assertions.assertEquals(service2, service3); } @Test void testHashCode() { ReflectionServiceDescriptor service2 = new ReflectionServiceDescriptor(DemoService.class); ReflectionServiceDescriptor service3 = new ReflectionServiceDescriptor(DemoService.class); Assertions.assertEquals(service2.hashCode(), service3.hashCode()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/User.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/User.java
/* * 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.rpc.model; import java.util.Objects; /** * this class has no nullary constructor and some field is primitive */ public class User { private int age; private String name; public User(int age, String name) { this.age = age; this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return String.format("User name(%s) age(%d) ", name, age); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; User user = (User) o; if (name == null) { if (user.name != null) { return false; } } else if (!name.equals(user.name)) { return false; } return Objects.equals(age, user.age); } @Override public int hashCode() { return Objects.hash(age, name); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.utils.StringUtils; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.stream.Collectors; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class ScopeModelTest { @Test void testCreateOnDestroy() throws InterruptedException { FrameworkModel.destroyAll(); FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); List<Throwable> errors = new ArrayList<>(); applicationModel.addDestroyListener(scopeModel -> { try { try { applicationModel.getDefaultModule(); Assertions.fail("Cannot create new module after application model destroyed"); } catch (Exception e) { Assertions.assertEquals("ApplicationModel is destroyed", e.getMessage(), StringUtils.toString(e)); } try { applicationModel.newModule(); Assertions.fail("Cannot create new module after application model destroyed"); } catch (Exception e) { Assertions.assertEquals("ApplicationModel is destroyed", e.getMessage(), StringUtils.toString(e)); } } catch (Throwable e) { errors.add(e); } }); CountDownLatch latch = new CountDownLatch(1); frameworkModel.addDestroyListener(scopeModel -> { try { try { frameworkModel.defaultApplication(); Assertions.fail("Cannot create new application after framework model destroyed"); } catch (Exception e) { Assertions.assertEquals("FrameworkModel is destroyed", e.getMessage(), StringUtils.toString(e)); } try { frameworkModel.newApplication(); Assertions.fail("Cannot create new application after framework model destroyed"); } catch (Exception e) { Assertions.assertEquals("FrameworkModel is destroyed", e.getMessage(), StringUtils.toString(e)); } try { ApplicationModel.defaultModel(); Assertions.fail("Cannot create new application after framework model destroyed"); } catch (Exception e) { Assertions.assertEquals("FrameworkModel is destroyed", e.getMessage(), StringUtils.toString(e)); } try { FrameworkModel.defaultModel().defaultApplication(); Assertions.fail("Cannot create new application after framework model destroyed"); } catch (Exception e) { Assertions.assertEquals("FrameworkModel is destroyed", e.getMessage(), StringUtils.toString(e)); } } catch (Throwable ex) { errors.add(ex); } finally { latch.countDown(); } }); // destroy frameworkModel frameworkModel.destroy(); latch.await(); String errorMsg = null; for (Throwable throwable : errors) { errorMsg = StringUtils.toString(throwable); errorMsg += "\n"; } Assertions.assertEquals(0, errors.size(), "Error occurred while destroy FrameworkModel: " + errorMsg); // destroy all FrameworkModel FrameworkModel.destroyAll(); List<String> remainFrameworks = FrameworkModel.getAllInstances().stream().map(m -> m.getDesc()).collect(Collectors.toList()); Assertions.assertEquals( 0, FrameworkModel.getAllInstances().size(), "FrameworkModel is not completely destroyed: " + remainFrameworks); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/SerializablePerson.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/SerializablePerson.java
/* * 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.rpc.model; import java.io.Serializable; import java.util.Arrays; public class SerializablePerson implements Serializable { private static final long serialVersionUID = 1L; byte oneByte = 123; private String name = "name1"; private int age = 11; private String[] value = {"value1", "value2"}; public String getName() { return name; } public void setName(String name) { this.name = name; } public byte getOneByte() { return oneByte; } public void setOneByte(byte b) { this.oneByte = b; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String[] getValue() { return value; } public void setValue(String[] value) { this.value = value; } @Override public String toString() { return String.format("Person name(%s) age(%d) byte(%s) [value=%s]", name, age, oneByte, Arrays.toString(value)); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + Arrays.hashCode(value); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SerializablePerson other = (SerializablePerson) obj; if (age != other.age) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (!Arrays.equals(value, other.value)) return false; return true; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ApplicationModelTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ApplicationModelTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; import org.apache.dubbo.common.config.ConfigurationCache; import org.apache.dubbo.common.extension.ExtensionScope; 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 java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** * {@link ApplicationModel} */ class ApplicationModelTest { @Test void testInitialize() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); Assertions.assertEquals(applicationModel.getParent(), frameworkModel); Assertions.assertEquals(applicationModel.getScope(), ExtensionScope.APPLICATION); Assertions.assertEquals(applicationModel.getFrameworkModel(), frameworkModel); Assertions.assertFalse(applicationModel.isInternal()); Assertions.assertTrue(frameworkModel.getApplicationModels().contains(applicationModel)); Assertions.assertNotNull(applicationModel.getInternalId()); Assertions.assertNotNull(applicationModel.getExtensionDirector()); Assertions.assertNotNull(applicationModel.getBeanFactory()); Assertions.assertTrue(applicationModel.getClassLoaders().contains(ScopeModel.class.getClassLoader())); Assertions.assertNotNull(applicationModel.getInternalModule()); Assertions.assertNotNull(applicationModel.getApplicationServiceRepository()); ScopeBeanFactory applicationModelBeanFactory = applicationModel.getBeanFactory(); Assertions.assertNotNull(applicationModelBeanFactory.getBean(ShutdownHookCallbacks.class)); Assertions.assertNotNull(applicationModelBeanFactory.getBean(FrameworkStatusReportService.class)); Assertions.assertNotNull(applicationModelBeanFactory.getBean(ConfigurationCache.class)); frameworkModel.destroy(); } @Test void testDefaultApplication() { ApplicationModel applicationModel = ApplicationModel.defaultModel(); FrameworkModel frameworkModel = applicationModel.getFrameworkModel(); Assertions.assertFalse(applicationModel.isInternal()); Assertions.assertEquals(frameworkModel.defaultApplication(), applicationModel); Assertions.assertTrue(frameworkModel.getApplicationModels().contains(applicationModel)); String desc = applicationModel.getDesc(); Assertions.assertEquals(desc, "Dubbo Application[" + applicationModel.getInternalId() + "](unknown)"); frameworkModel.destroy(); } @Test void testModule() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel defaultModule = applicationModel.getDefaultModule(); ModuleModel internalModule = applicationModel.getInternalModule(); Assertions.assertTrue(applicationModel.getModuleModels().contains(defaultModule)); Assertions.assertTrue(applicationModel.getModuleModels().contains(internalModule)); Assertions.assertTrue(applicationModel.getPubModuleModels().contains(defaultModule)); Assertions.assertFalse(applicationModel.getPubModuleModels().contains(internalModule)); applicationModel.removeModule(defaultModule); Assertions.assertFalse(applicationModel.getModuleModels().contains(defaultModule)); Assertions.assertFalse(applicationModel.getPubModuleModels().contains(defaultModule)); frameworkModel.destroy(); } @Test void testOfNullable() { ApplicationModel applicationModel = ApplicationModel.ofNullable(null); Assertions.assertEquals(ApplicationModel.defaultModel(), applicationModel); applicationModel.getFrameworkModel().destroy(); FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel1 = frameworkModel.newApplication(); ApplicationModel applicationModel2 = ApplicationModel.ofNullable(applicationModel1); Assertions.assertEquals(applicationModel1, applicationModel2); frameworkModel.destroy(); } @Test void testDestroy() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); applicationModel.getDefaultModule(); applicationModel.newModule(); MockScopeModelDestroyListener destroyListener = new MockScopeModelDestroyListener(); applicationModel.addDestroyListener(destroyListener); applicationModel.destroy(); Assertions.assertFalse(frameworkModel.getApplicationModels().contains(applicationModel)); Assertions.assertTrue(applicationModel.getModuleModels().isEmpty()); Assertions.assertTrue(destroyListener.isDestroyed()); Assertions.assertEquals(destroyListener.getScopeModel(), applicationModel); Assertions.assertNull(applicationModel.getApplicationServiceRepository()); Assertions.assertTrue(applicationModel.isDestroyed()); // trigger frameworkModel.tryDestroy() Assertions.assertTrue(frameworkModel.isDestroyed()); try { applicationModel.getDefaultModule(); Assertions.fail("Cannot create new module after application model destroyed"); } catch (Exception e) { Assertions.assertEquals("ApplicationModel is destroyed", e.getMessage(), StringUtils.toString(e)); } try { applicationModel.newModule(); Assertions.fail("Cannot create new module after application model destroyed"); } catch (Exception e) { Assertions.assertEquals("ApplicationModel is destroyed", e.getMessage(), StringUtils.toString(e)); } } @Test void testCopyOnWriteArrayListIteratorAndRemove() throws InterruptedException { List<Integer> cur = new ArrayList<>(); for (int i = 0; i < 10000; i++) { cur.add(i); } List<Integer> myList = new CopyOnWriteArrayList<>(cur); List<Thread> threads = new ArrayList<>(); int threadNum = 20; CountDownLatch endLatch = new CountDownLatch(threadNum); for (int i = 0; i < 20; i++) { threads.add(new Thread(() -> { for (Integer number : myList) { if (number % 2 == 0) { myList.remove(number); } } endLatch.countDown(); })); } threads.forEach(Thread::start); endLatch.await(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; 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; /** * {@link ModuleModel} */ class ModuleModelTest { @Test void testInitialize() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); Assertions.assertEquals(moduleModel.getParent(), applicationModel); Assertions.assertEquals(moduleModel.getScope(), ExtensionScope.MODULE); Assertions.assertEquals(moduleModel.getApplicationModel(), applicationModel); Assertions.assertTrue(applicationModel.getPubModuleModels().contains(moduleModel)); Assertions.assertNotNull(moduleModel.getInternalId()); Assertions.assertFalse(moduleModel.isLifeCycleManagedExternally()); Assertions.assertNotNull(moduleModel.getExtensionDirector()); Assertions.assertNotNull(moduleModel.getBeanFactory()); Assertions.assertTrue(moduleModel.getClassLoaders().contains(ScopeModel.class.getClassLoader())); Assertions.assertNotNull(moduleModel.getServiceRepository()); Assertions.assertNotNull(moduleModel.getConfigManager()); ScopeBeanFactory moduleModelBeanFactory = moduleModel.getBeanFactory(); Assertions.assertNotNull(moduleModelBeanFactory.getBean(ConfigurationCache.class)); frameworkModel.destroy(); } @Test void testModelEnvironment() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); ModuleEnvironment modelEnvironment = moduleModel.modelEnvironment(); Assertions.assertNotNull(modelEnvironment); frameworkModel.destroy(); } @Test void testDestroy() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); MockScopeModelDestroyListener destroyListener = new MockScopeModelDestroyListener(); moduleModel.addDestroyListener(destroyListener); moduleModel.destroy(); Assertions.assertTrue(destroyListener.isDestroyed()); Assertions.assertEquals(destroyListener.getScopeModel(), moduleModel); Assertions.assertFalse(applicationModel.getPubModuleModels().contains(moduleModel)); Assertions.assertNull(moduleModel.getServiceRepository()); Assertions.assertTrue(moduleModel.isDestroyed()); // trigger tryDestroy Assertions.assertTrue(applicationModel.isDestroyed()); Assertions.assertTrue(frameworkModel.isDestroyed()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ServiceRepositoryTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ServiceRepositoryTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.rpc.support.DemoService; import org.apache.dubbo.rpc.support.DemoServiceImpl; import java.util.Collection; import java.util.List; import java.util.Set; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * {@link ServiceRepository} */ class ServiceRepositoryTest { private FrameworkModel frameworkModel; private ApplicationModel applicationModel; private ModuleModel moduleModel; @BeforeEach public void setUp() { frameworkModel = new FrameworkModel(); applicationModel = frameworkModel.newApplication(); moduleModel = applicationModel.newModule(); } @AfterEach public void reset() { frameworkModel.destroy(); } @Test void test() { // verify BuiltinService Set<BuiltinServiceDetector> builtinServices = applicationModel .getExtensionLoader(BuiltinServiceDetector.class) .getSupportedExtensionInstances(); ModuleServiceRepository moduleServiceRepository = applicationModel.getInternalModule().getServiceRepository(); List<ServiceDescriptor> allServices = moduleServiceRepository.getAllServices(); Assertions.assertEquals(allServices.size(), builtinServices.size()); ModuleServiceRepository repository = moduleModel.getServiceRepository(); ServiceMetadata serviceMetadata = new ServiceMetadata(DemoService.class.getName(), null, null, DemoService.class); ServiceDescriptor serviceDescriptor = repository.registerService(DemoService.class); // registerConsumer ConsumerModel consumerModel = new ConsumerModel( serviceMetadata.getServiceKey(), new DemoServiceImpl(), serviceDescriptor, moduleModel, serviceMetadata, null, ClassUtils.getClassLoader(DemoService.class)); repository.registerConsumer(consumerModel); // registerProvider ProviderModel providerModel = new ProviderModel( DemoService.class.getName(), new DemoServiceImpl(), serviceDescriptor, moduleModel, serviceMetadata, ClassUtils.getClassLoader(DemoService.class)); repository.registerProvider(providerModel); // verify allProviderModels, allConsumerModels ServiceRepository serviceRepository = applicationModel.getApplicationServiceRepository(); Collection<ProviderModel> providerModels = serviceRepository.allProviderModels(); Assertions.assertEquals(providerModels.size(), 1); Assertions.assertTrue(providerModels.contains(providerModel)); Collection<ConsumerModel> consumerModels = serviceRepository.allConsumerModels(); Assertions.assertEquals(consumerModels.size(), 1); Assertions.assertTrue(consumerModels.contains(consumerModel)); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ReflectionMethodDescriptorTest.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ReflectionMethodDescriptorTest.java
/* * 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.rpc.model; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.rpc.model.MethodDescriptor.RpcType; import org.apache.dubbo.rpc.support.DemoService; import java.lang.reflect.Type; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; class ReflectionMethodDescriptorTest { private final ReflectionMethodDescriptor method; { try { method = new ReflectionMethodDescriptor(DemoService.class.getDeclaredMethod("sayHello", String.class)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } } @Test void getMethodName() { Assertions.assertEquals("sayHello", method.getMethodName()); } @Test void getMethod() { Assertions.assertEquals("sayHello", method.getMethod().getName()); } @Test void getCompatibleParamSignatures() { Assertions.assertArrayEquals(new String[] {String.class.getName()}, method.getCompatibleParamSignatures()); } @Test void getParameterClasses() { Assertions.assertArrayEquals(new Class[] {String.class}, method.getParameterClasses()); } @Test void getParamDesc() { Assertions.assertEquals(ReflectUtils.getDesc(String.class), method.getParamDesc()); } @Test void getReturnClass() { Assertions.assertEquals(String.class, method.getReturnClass()); } @Test void getReturnTypes() { Assertions.assertArrayEquals(new Type[] {String.class, String.class}, method.getReturnTypes()); } @Test void getRpcType() { Assertions.assertEquals(RpcType.UNARY, method.getRpcType()); } @Test void isGeneric() { Assertions.assertFalse(method.isGeneric()); } @Test void addAttribute() { String attr = "attr"; method.addAttribute(attr, attr); Assertions.assertEquals(attr, method.getAttribute(attr)); } @Test void testEquals() { try { MethodDescriptor method2 = new ReflectionMethodDescriptor(DemoService.class.getDeclaredMethod("sayHello", String.class)); method.addAttribute("attr", "attr"); method2.addAttribute("attr", "attr"); Assertions.assertEquals(method, method2); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } } @Test void testHashCode() { try { MethodDescriptor method2 = new ReflectionMethodDescriptor(DemoService.class.getDeclaredMethod("sayHello", String.class)); method.addAttribute("attr", "attr"); method2.addAttribute("attr", "attr"); Assertions.assertEquals(method.hashCode(), method2.hashCode()); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/Phone.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/Phone.java
/* * 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.rpc.model.person; import java.io.Serializable; public class Phone implements Serializable { private static final long serialVersionUID = 4399060521859707703L; private String country; private String area; private String number; private String extensionNumber; public Phone() {} public Phone(String country, String area, String number, String extensionNumber) { this.country = country; this.area = area; this.number = number; this.extensionNumber = extensionNumber; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getArea() { return area; } public void setArea(String area) { this.area = area; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getExtensionNumber() { return extensionNumber; } public void setExtensionNumber(String extensionNumber) { this.extensionNumber = extensionNumber; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((area == null) ? 0 : area.hashCode()); result = prime * result + ((country == null) ? 0 : country.hashCode()); result = prime * result + ((extensionNumber == null) ? 0 : extensionNumber.hashCode()); result = prime * result + ((number == null) ? 0 : number.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Phone other = (Phone) obj; if (area == null) { if (other.area != null) return false; } else if (!area.equals(other.area)) return false; if (country == null) { if (other.country != null) return false; } else if (!country.equals(other.country)) return false; if (extensionNumber == null) { if (other.extensionNumber != null) return false; } else if (!extensionNumber.equals(other.extensionNumber)) return false; if (number == null) { if (other.number != null) return false; } else if (!number.equals(other.number)) return false; return true; } @Override public String toString() { StringBuilder sb = new StringBuilder(); if (country != null && country.length() > 0) { sb.append(country); sb.append('-'); } if (area != null && area.length() > 0) { sb.append(area); sb.append('-'); } if (number != null && number.length() > 0) { sb.append(number); } if (extensionNumber != null && extensionNumber.length() > 0) { sb.append('-'); sb.append(extensionNumber); } return sb.toString(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/PersonInfo.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/PersonInfo.java
/* * 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.rpc.model.person; import java.io.Serializable; import java.util.List; public class PersonInfo implements Serializable { private static final long serialVersionUID = 7443011149612231882L; List<Phone> phones; Phone fax; FullAddress fullAddress; String mobileNo; String name; boolean male; boolean female; String department; String jobTitle; String homepageUrl; public List<Phone> getPhones() { return phones; } public void setPhones(List<Phone> phones) { this.phones = phones; } public boolean isMale() { return male; } public void setMale(boolean male) { this.male = male; } public boolean isFemale() { return female; } public void setFemale(boolean female) { this.female = female; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public Phone getFax() { return fax; } public void setFax(Phone fax) { this.fax = fax; } public FullAddress getFullAddress() { return fullAddress; } public void setFullAddress(FullAddress fullAddress) { this.fullAddress = fullAddress; } public String getHomepageUrl() { return homepageUrl; } public void setHomepageUrl(String homepageUrl) { this.homepageUrl = homepageUrl; } public String getJobTitle() { return jobTitle; } public void setJobTitle(String jobTitle) { this.jobTitle = jobTitle; } public String getMobileNo() { return mobileNo; } public void setMobileNo(String mobileNo) { this.mobileNo = mobileNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((department == null) ? 0 : department.hashCode()); result = prime * result + ((fax == null) ? 0 : fax.hashCode()); result = prime * result + (female ? 1231 : 1237); result = prime * result + ((fullAddress == null) ? 0 : fullAddress.hashCode()); result = prime * result + ((homepageUrl == null) ? 0 : homepageUrl.hashCode()); result = prime * result + ((jobTitle == null) ? 0 : jobTitle.hashCode()); result = prime * result + (male ? 1231 : 1237); result = prime * result + ((mobileNo == null) ? 0 : mobileNo.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((phones == null) ? 0 : phones.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; PersonInfo other = (PersonInfo) obj; if (department == null) { if (other.department != null) return false; } else if (!department.equals(other.department)) return false; if (fax == null) { if (other.fax != null) return false; } else if (!fax.equals(other.fax)) return false; if (female != other.female) return false; if (fullAddress == null) { if (other.fullAddress != null) return false; } else if (!fullAddress.equals(other.fullAddress)) return false; if (homepageUrl == null) { if (other.homepageUrl != null) return false; } else if (!homepageUrl.equals(other.homepageUrl)) return false; if (jobTitle == null) { if (other.jobTitle != null) return false; } else if (!jobTitle.equals(other.jobTitle)) return false; if (male != other.male) return false; if (mobileNo == null) { if (other.mobileNo != null) return false; } else if (!mobileNo.equals(other.mobileNo)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (phones == null) { if (other.phones != null) return false; } else if (!phones.equals(other.phones)) return false; return true; } @Override public String toString() { return "PersonInfo [phones=" + phones + ", fax=" + fax + ", fullAddress=" + fullAddress + ", mobileNo=" + mobileNo + ", name=" + name + ", male=" + male + ", female=" + female + ", department=" + department + ", jobTitle=" + jobTitle + ", homepageUrl=" + homepageUrl + "]"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/BigPerson.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/BigPerson.java
/* * 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.rpc.model.person; import java.io.Serializable; public class BigPerson implements Serializable { private static final long serialVersionUID = 1L; String personId; String loginName; PersonStatus status; String email; String personName; PersonInfo infoProfile; public BigPerson() {} public BigPerson(String id) { this.personId = id; } public String getPersonId() { return personId; } public void setPersonId(String personId) { this.personId = personId; } public PersonInfo getInfoProfile() { return infoProfile; } public void setInfoProfile(PersonInfo infoProfile) { this.infoProfile = infoProfile; } public String getEmail() { return this.email; } public void setEmail(String email) { this.email = email; } public String getLoginName() { return this.loginName; } public void setLoginName(String loginName) { this.loginName = loginName; } public PersonStatus getStatus() { return this.status; } public void setStatus(PersonStatus status) { this.status = status; } public String getPersonName() { return personName; } public void setPersonName(String personName) { this.personName = personName; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((email == null) ? 0 : email.hashCode()); result = prime * result + ((infoProfile == null) ? 0 : infoProfile.hashCode()); result = prime * result + ((loginName == null) ? 0 : loginName.hashCode()); result = prime * result + ((personName == null) ? 0 : personName.hashCode()); result = prime * result + ((personId == null) ? 0 : personId.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; BigPerson other = (BigPerson) obj; if (email == null) { if (other.email != null) return false; } else if (!email.equals(other.email)) return false; if (infoProfile == null) { if (other.infoProfile != null) return false; } else if (!infoProfile.equals(other.infoProfile)) return false; if (loginName == null) { if (other.loginName != null) return false; } else if (!loginName.equals(other.loginName)) return false; if (personName == null) { if (other.personName != null) return false; } else if (!personName.equals(other.personName)) return false; if (personId == null) { if (other.personId != null) return false; } else if (!personId.equals(other.personId)) return false; if (status != other.status) return false; return true; } @Override public String toString() { return "BigPerson [personId=" + personId + ", loginName=" + loginName + ", status=" + status + ", email=" + email + ", personName=" + personName + ", infoProfile=" + infoProfile + "]"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/FullAddress.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/FullAddress.java
/* * 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.rpc.model.person; import java.io.Serializable; public class FullAddress implements Serializable { private static final long serialVersionUID = 5163979984269419831L; private String countryId; private String countryName; private String provinceName; private String cityId; private String cityName; private String streetAddress; private String zipCode; public FullAddress() {} public FullAddress(String countryId, String provinceName, String cityId, String streetAddress, String zipCode) { this.countryId = countryId; this.countryName = countryId; this.provinceName = provinceName; this.cityId = cityId; this.cityName = cityId; this.streetAddress = streetAddress; this.zipCode = zipCode; } public FullAddress( String countryId, String countryName, String provinceName, String cityId, String cityName, String streetAddress, String zipCode) { this.countryId = countryId; this.countryName = countryName; this.provinceName = provinceName; this.cityId = cityId; this.cityName = cityName; this.streetAddress = streetAddress; this.zipCode = zipCode; } public String getCountryId() { return countryId; } public void setCountryId(String countryId) { this.countryId = countryId; } public String getCountryName() { return countryName; } public void setCountryName(String countryName) { this.countryName = countryName; } public String getProvinceName() { return provinceName; } public void setProvinceName(String provinceName) { this.provinceName = provinceName; } public String getCityId() { return cityId; } public void setCityId(String cityId) { this.cityId = cityId; } public String getCityName() { return cityName; } public void setCityName(String cityName) { this.cityName = cityName; } public String getStreetAddress() { return streetAddress; } public void setStreetAddress(String streetAddress) { this.streetAddress = streetAddress; } public String getZipCode() { return zipCode; } public void setZipCode(String zipCode) { this.zipCode = zipCode; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((cityId == null) ? 0 : cityId.hashCode()); result = prime * result + ((cityName == null) ? 0 : cityName.hashCode()); result = prime * result + ((countryId == null) ? 0 : countryId.hashCode()); result = prime * result + ((countryName == null) ? 0 : countryName.hashCode()); result = prime * result + ((provinceName == null) ? 0 : provinceName.hashCode()); result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode()); result = prime * result + ((zipCode == null) ? 0 : zipCode.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; FullAddress other = (FullAddress) obj; if (cityId == null) { if (other.cityId != null) return false; } else if (!cityId.equals(other.cityId)) return false; if (cityName == null) { if (other.cityName != null) return false; } else if (!cityName.equals(other.cityName)) return false; if (countryId == null) { if (other.countryId != null) return false; } else if (!countryId.equals(other.countryId)) return false; if (countryName == null) { if (other.countryName != null) return false; } else if (!countryName.equals(other.countryName)) return false; if (provinceName == null) { if (other.provinceName != null) return false; } else if (!provinceName.equals(other.provinceName)) return false; if (streetAddress == null) { if (other.streetAddress != null) return false; } else if (!streetAddress.equals(other.streetAddress)) return false; if (zipCode == null) { if (other.zipCode != null) return false; } else if (!zipCode.equals(other.zipCode)) return false; return true; } @Override public String toString() { StringBuilder sb = new StringBuilder(); if (countryName != null && countryName.length() > 0) { sb.append(countryName); } if (provinceName != null && provinceName.length() > 0) { sb.append(' '); sb.append(provinceName); } if (cityName != null && cityName.length() > 0) { sb.append(' '); sb.append(cityName); } if (streetAddress != null && streetAddress.length() > 0) { sb.append(' '); sb.append(streetAddress); } return sb.toString(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/PersonStatus.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/person/PersonStatus.java
/* * 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.rpc.model.person; public enum PersonStatus { ENABLED, DISABLED }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/media/Image.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/media/Image.java
/* * 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.rpc.model.media; public class Image implements java.io.Serializable { private static final long serialVersionUID = 1L; public String uri; public String title; // Can be null public int width; public int height; public Size size; public Image() {} public Image(String uri, String title, int width, int height, Size size) { this.height = height; this.title = title; this.uri = uri; this.width = width; this.size = size; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Image image = (Image) o; if (height != image.height) return false; if (width != image.width) return false; if (size != image.size) return false; if (title != null ? !title.equals(image.title) : image.title != null) return false; if (uri != null ? !uri.equals(image.uri) : image.uri != null) return false; return true; } @Override public int hashCode() { int result = uri != null ? uri.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + width; result = 31 * result + height; result = 31 * result + (size != null ? size.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Image "); sb.append("uri=").append(uri); sb.append(", title=").append(title); sb.append(", width=").append(width); sb.append(", height=").append(height); sb.append(", size=").append(size); sb.append(']'); return sb.toString(); } public String getUri() { return uri; } public void setUri(String uri) { this.uri = uri; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public Size getSize() { return size; } public void setSize(Size size) { this.size = size; } public enum Size { SMALL, LARGE } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/media/Media.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/model/media/Media.java
/* * 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.rpc.model.media; import java.util.List; @SuppressWarnings("serial") public class Media implements java.io.Serializable { public String uri; public String title; // Can be unset. public int width; public int height; public String format; public long duration; public long size; public int bitrate; // Can be unset. public boolean hasBitrate; public List<String> persons; public Player player; public String copyright; // Can be unset. public Media() {} public Media( String uri, String title, int width, int height, String format, long duration, long size, int bitrate, boolean hasBitrate, List<String> persons, Player player, String copyright) { this.uri = uri; this.title = title; this.width = width; this.height = height; this.format = format; this.duration = duration; this.size = size; this.bitrate = bitrate; this.hasBitrate = hasBitrate; this.persons = persons; this.player = player; this.copyright = copyright; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Media media = (Media) o; if (bitrate != media.bitrate) return false; if (duration != media.duration) return false; if (hasBitrate != media.hasBitrate) return false; if (height != media.height) return false; if (size != media.size) return false; if (width != media.width) return false; if (copyright != null ? !copyright.equals(media.copyright) : media.copyright != null) return false; if (format != null ? !format.equals(media.format) : media.format != null) return false; if (persons != null ? !persons.equals(media.persons) : media.persons != null) return false; if (player != media.player) return false; if (title != null ? !title.equals(media.title) : media.title != null) return false; if (uri != null ? !uri.equals(media.uri) : media.uri != null) return false; return true; } @Override public int hashCode() { int result = uri != null ? uri.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + width; result = 31 * result + height; result = 31 * result + (format != null ? format.hashCode() : 0); result = 31 * result + (int) (duration ^ (duration >>> 32)); result = 31 * result + (int) (size ^ (size >>> 32)); result = 31 * result + bitrate; result = 31 * result + (hasBitrate ? 1 : 0); result = 31 * result + (persons != null ? persons.hashCode() : 0); result = 31 * result + (player != null ? player.hashCode() : 0); result = 31 * result + (copyright != null ? copyright.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Media "); sb.append("uri=").append(uri); sb.append(", title=").append(title); sb.append(", width=").append(width); sb.append(", height=").append(height); sb.append(", format=").append(format); sb.append(", duration=").append(duration); sb.append(", size=").append(size); sb.append(", hasBitrate=").append(hasBitrate); sb.append(", bitrate=").append(String.valueOf(bitrate)); sb.append(", persons=").append(persons); sb.append(", player=").append(player); sb.append(", copyright=").append(copyright); sb.append(']'); return sb.toString(); } public String getUri() { return uri; } public void setUri(String uri) { this.uri = uri; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public long getDuration() { return duration; } public void setDuration(long duration) { this.duration = duration; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } public int getBitrate() { return bitrate; } public void setBitrate(int bitrate) { this.bitrate = bitrate; this.hasBitrate = true; } public List<String> getPersons() { return persons; } public void setPersons(List<String> persons) { this.persons = persons; } public Player getPlayer() { return player; } public void setPlayer(Player player) { this.player = player; } public String getCopyright() { return copyright; } public void setCopyright(String copyright) { this.copyright = copyright; } public enum Player { JAVA, FLASH } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2ExecutorSupport.java
dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2ExecutorSupport.java
/* * 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.rpc.executor; import java.util.concurrent.Executor; public class Mock2ExecutorSupport implements ExecutorSupport { @Override public Executor getExecutor(Object data) { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false