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-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/ZipkinAutoConfiguration.java
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/ZipkinAutoConfiguration.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.spring.boot.autoconfigure.observability.zipkin; import org.apache.dubbo.spring.boot.autoconfigure.observability.annotation.ConditionalOnDubboTracingEnable; import org.apache.dubbo.spring.boot.autoconfigure.observability.zipkin.ZipkinConfigurations.BraveConfiguration; import org.apache.dubbo.spring.boot.autoconfigure.observability.zipkin.ZipkinConfigurations.OpenTelemetryConfiguration; import org.apache.dubbo.spring.boot.autoconfigure.observability.zipkin.ZipkinConfigurations.ReporterConfiguration; import org.apache.dubbo.spring.boot.autoconfigure.observability.zipkin.ZipkinConfigurations.SenderConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; import zipkin2.Span; import zipkin2.codec.BytesEncoder; import zipkin2.codec.SpanBytesEncoder; import zipkin2.reporter.Sender; import static org.apache.dubbo.spring.boot.autoconfigure.observability.ObservabilityUtils.DUBBO_TRACING_ZIPKIN_CONFIG_PREFIX; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; /** * {@link EnableAutoConfiguration Auto-configuration} for Zipkin. * <p> * It uses imports on {@link ZipkinConfigurations} to guarantee the correct configuration ordering. * Create Zipkin sender and exporter when you are using Boot < 3.0 or you are not using spring-boot-starter-actuator. * When you use SpringBoot 3.*, priority should be given to loading S3 related configurations. Dubbo related zipkin configurations are invalid. * * @since 3.2.1 */ @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) @AutoConfiguration( after = RestTemplateAutoConfiguration.class, afterName = "org.springframework.boot.actuate.autoconfigure.tracing.zipkin") @ConditionalOnClass(Sender.class) @Import({ SenderConfiguration.class, ReporterConfiguration.class, BraveConfiguration.class, OpenTelemetryConfiguration.class }) @ConditionalOnDubboTracingEnable public class ZipkinAutoConfiguration { @Bean @ConditionalOnProperty(prefix = DUBBO_TRACING_ZIPKIN_CONFIG_PREFIX, name = "endpoint") @ConditionalOnMissingBean public BytesEncoder<Span> spanBytesEncoder() { return SpanBytesEncoder.JSON_V2; } @Bean @ConditionalOnProperty(prefix = DUBBO_TRACING_ZIPKIN_CONFIG_PREFIX, name = "endpoint") @ConditionalOnMissingBean public zipkin2.reporter.BytesEncoder<Span> reporterBytesEncoder() { return zipkin2.reporter.SpanBytesEncoder.JSON_V2; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/ZipkinConfigurations.java
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/ZipkinConfigurations.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.spring.boot.autoconfigure.observability.zipkin; import org.apache.dubbo.config.nested.ExporterConfig; import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties; import org.apache.dubbo.spring.boot.autoconfigure.observability.zipkin.customizer.ZipkinRestTemplateBuilderCustomizer; import org.apache.dubbo.spring.boot.autoconfigure.observability.zipkin.customizer.ZipkinWebClientBuilderCustomizer; import java.util.concurrent.atomic.AtomicReference; import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.WebClient; import zipkin2.Span; import zipkin2.codec.BytesEncoder; import zipkin2.reporter.AsyncReporter; import zipkin2.reporter.Reporter; import zipkin2.reporter.Sender; import zipkin2.reporter.brave.ZipkinSpanHandler; import zipkin2.reporter.urlconnection.URLConnectionSender; import static org.apache.dubbo.spring.boot.autoconfigure.observability.ObservabilityUtils.DUBBO_TRACING_ZIPKIN_CONFIG_PREFIX; /** * Configurations for Zipkin. Those are imported by {@link ZipkinAutoConfiguration}. */ class ZipkinConfigurations { @Configuration(proxyBeanMethods = false) @ConditionalOnProperty(prefix = DUBBO_TRACING_ZIPKIN_CONFIG_PREFIX, name = "endpoint") @Import({ UrlConnectionSenderConfiguration.class, WebClientSenderConfiguration.class, RestTemplateSenderConfiguration.class }) static class SenderConfiguration {} @Configuration(proxyBeanMethods = false) @ConditionalOnClass(URLConnectionSender.class) @EnableConfigurationProperties(DubboConfigurationProperties.class) static class UrlConnectionSenderConfiguration { @Bean @ConditionalOnMissingBean(Sender.class) URLConnectionSender urlConnectionSender(DubboConfigurationProperties properties) { URLConnectionSender.Builder builder = URLConnectionSender.newBuilder(); ExporterConfig.ZipkinConfig zipkinConfig = properties.getTracing().getTracingExporter().getZipkinConfig(); builder.connectTimeout((int) zipkinConfig.getConnectTimeout().toMillis()); builder.readTimeout((int) zipkinConfig.getReadTimeout().toMillis()); builder.endpoint(zipkinConfig.getEndpoint()); return builder.build(); } } @Configuration(proxyBeanMethods = false) @ConditionalOnClass(RestTemplate.class) @EnableConfigurationProperties(DubboConfigurationProperties.class) static class RestTemplateSenderConfiguration { @Bean @ConditionalOnMissingBean(Sender.class) ZipkinRestTemplateSender restTemplateSender( DubboConfigurationProperties properties, ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers) { ExporterConfig.ZipkinConfig zipkinConfig = properties.getTracing().getTracingExporter().getZipkinConfig(); RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder() .setConnectTimeout(zipkinConfig.getConnectTimeout()) .setReadTimeout(zipkinConfig.getReadTimeout()); restTemplateBuilder = applyCustomizers(restTemplateBuilder, customizers); return new ZipkinRestTemplateSender(zipkinConfig.getEndpoint(), restTemplateBuilder.build()); } private RestTemplateBuilder applyCustomizers( RestTemplateBuilder restTemplateBuilder, ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers) { Iterable<ZipkinRestTemplateBuilderCustomizer> orderedCustomizers = () -> customizers.orderedStream().iterator(); RestTemplateBuilder currentBuilder = restTemplateBuilder; for (ZipkinRestTemplateBuilderCustomizer customizer : orderedCustomizers) { currentBuilder = customizer.customize(currentBuilder); } return currentBuilder; } } @Configuration(proxyBeanMethods = false) @ConditionalOnClass(WebClient.class) @EnableConfigurationProperties(DubboConfigurationProperties.class) static class WebClientSenderConfiguration { @Bean @ConditionalOnMissingBean(Sender.class) ZipkinWebClientSender webClientSender( DubboConfigurationProperties properties, ObjectProvider<ZipkinWebClientBuilderCustomizer> customizers) { ExporterConfig.ZipkinConfig zipkinConfig = properties.getTracing().getTracingExporter().getZipkinConfig(); WebClient.Builder builder = WebClient.builder(); customizers.orderedStream().forEach((customizer) -> customizer.customize(builder)); return new ZipkinWebClientSender(zipkinConfig.getEndpoint(), builder.build()); } } @Configuration(proxyBeanMethods = false) static class ReporterConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnBean(Sender.class) AsyncReporter<Span> spanReporter(Sender sender, zipkin2.reporter.BytesEncoder<Span> encoder) { return AsyncReporter.builder(sender).build(encoder); } } @Configuration(proxyBeanMethods = false) @ConditionalOnClass(ZipkinSpanHandler.class) static class BraveConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnBean(Reporter.class) ZipkinSpanHandler zipkinSpanHandler(Reporter<Span> spanReporter) { return (ZipkinSpanHandler) ZipkinSpanHandler.newBuilder(spanReporter).build(); } } @Configuration(proxyBeanMethods = false) @ConditionalOnClass(ZipkinSpanExporter.class) @ConditionalOnProperty(prefix = DUBBO_TRACING_ZIPKIN_CONFIG_PREFIX, name = "endpoint") @EnableConfigurationProperties(DubboConfigurationProperties.class) static class OpenTelemetryConfiguration { @Bean @ConditionalOnMissingBean ZipkinSpanExporter zipkinSpanExporter( DubboConfigurationProperties properties, BytesEncoder<Span> encoder, ObjectProvider<Sender> senders) { AtomicReference<Sender> senderRef = new AtomicReference<>(); senders.orderedStream().findFirst().ifPresent(senderRef::set); Sender sender = senderRef.get(); if (sender == null) { ExporterConfig.ZipkinConfig zipkinConfig = properties.getTracing().getTracingExporter().getZipkinConfig(); return ZipkinSpanExporter.builder() .setEncoder(encoder) .setEndpoint(zipkinConfig.getEndpoint()) .setReadTimeout(zipkinConfig.getReadTimeout()) .build(); } return ZipkinSpanExporter.builder() .setEncoder(encoder) .setSender(sender) .build(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/HttpSender.java
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/HttpSender.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.spring.boot.autoconfigure.observability.zipkin; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UncheckedIOException; import java.util.Collections; import java.util.List; import java.util.zip.GZIPOutputStream; import org.springframework.http.HttpHeaders; import org.springframework.util.unit.DataSize; import zipkin2.reporter.BytesMessageEncoder; import zipkin2.reporter.Call; import zipkin2.reporter.CheckResult; import zipkin2.reporter.ClosedSenderException; import zipkin2.reporter.Encoding; import zipkin2.reporter.Sender; /** * A Zipkin {@link Sender} that uses an HTTP client to send JSON spans. Supports automatic compression with gzip. */ abstract class HttpSender extends Sender { private static final DataSize MESSAGE_MAX_SIZE = DataSize.ofKilobytes(512); private volatile boolean closed; @Override public Encoding encoding() { return Encoding.JSON; } @Override public int messageMaxBytes() { return (int) MESSAGE_MAX_SIZE.toBytes(); } @Override public int messageSizeInBytes(List<byte[]> encodedSpans) { return encoding().listSizeInBytes(encodedSpans); } @Override public int messageSizeInBytes(int encodedSizeInBytes) { return encoding().listSizeInBytes(encodedSizeInBytes); } @Override public CheckResult check() { try { sendSpans(Collections.emptyList()).execute(); return CheckResult.OK; } catch (IOException | RuntimeException ex) { return CheckResult.failed(ex); } } @Override public void close() throws IOException { this.closed = true; } /** * The returned {@link HttpPostCall} will send span(s) as a POST to a zipkin endpoint * when executed. * * @param batchedEncodedSpans list of encoded spans as a byte array * @return an instance of a Zipkin {@link Call} which can be executed */ protected abstract HttpPostCall sendSpans(byte[] batchedEncodedSpans); @Override public Call<Void> sendSpans(List<byte[]> encodedSpans) { if (this.closed) { throw new ClosedSenderException(); } return sendSpans(BytesMessageEncoder.JSON.encode(encodedSpans)); } abstract static class HttpPostCall extends Call.Base<Void> { /** * Only use gzip compression on data which is bigger than this in bytes. */ private static final DataSize COMPRESSION_THRESHOLD = DataSize.ofKilobytes(1); private final byte[] body; HttpPostCall(byte[] body) { this.body = body; } protected byte[] getBody() { if (needsCompression()) { return compress(this.body); } return this.body; } protected byte[] getUncompressedBody() { return this.body; } protected HttpHeaders getDefaultHeaders() { HttpHeaders headers = new HttpHeaders(); headers.set("b3", "0"); headers.set("Content-Type", "application/json"); if (needsCompression()) { headers.set("Content-Encoding", "gzip"); } return headers; } private boolean needsCompression() { return this.body.length > COMPRESSION_THRESHOLD.toBytes(); } private byte[] compress(byte[] input) { ByteArrayOutputStream result = new ByteArrayOutputStream(); try (GZIPOutputStream gzip = new GZIPOutputStream(result)) { gzip.write(input); } catch (IOException ex) { throw new UncheckedIOException(ex); } return result.toByteArray(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/ZipkinRestTemplateSender.java
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/ZipkinRestTemplateSender.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.spring.boot.autoconfigure.observability.zipkin; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.web.client.RestTemplate; import zipkin2.reporter.Call; import zipkin2.reporter.Callback; class ZipkinRestTemplateSender extends HttpSender { private final String endpoint; private final RestTemplate restTemplate; ZipkinRestTemplateSender(String endpoint, RestTemplate restTemplate) { this.endpoint = endpoint; this.restTemplate = restTemplate; } @Override public HttpPostCall sendSpans(byte[] batchedEncodedSpans) { return new RestTemplateHttpPostCall(this.endpoint, batchedEncodedSpans, this.restTemplate); } private static class RestTemplateHttpPostCall extends HttpPostCall { private final String endpoint; private final RestTemplate restTemplate; RestTemplateHttpPostCall(String endpoint, byte[] body, RestTemplate restTemplate) { super(body); this.endpoint = endpoint; this.restTemplate = restTemplate; } @Override public Call<Void> clone() { return new RestTemplateHttpPostCall(this.endpoint, getUncompressedBody(), this.restTemplate); } @Override protected Void doExecute() { HttpEntity<byte[]> request = new HttpEntity<>(getBody(), getDefaultHeaders()); this.restTemplate.exchange(this.endpoint, HttpMethod.POST, request, Void.class); return null; } @Override protected void doEnqueue(Callback<Void> callback) { try { doExecute(); callback.onSuccess(null); } catch (Exception ex) { callback.onError(ex); } } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/customizer/ZipkinRestTemplateBuilderCustomizer.java
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/customizer/ZipkinRestTemplateBuilderCustomizer.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.spring.boot.autoconfigure.observability.zipkin.customizer; import org.springframework.boot.web.client.RestTemplateBuilder; /** * Callback interface that can be implemented by beans wishing to customize the * {@link RestTemplateBuilder} used to send spans to Zipkin. * * @since 3.2.0 */ @FunctionalInterface public interface ZipkinRestTemplateBuilderCustomizer { /** * Customize the rest template builder. * * @param restTemplateBuilder the {@code RestTemplateBuilder} to customize * @return the customized {@code RestTemplateBuilder} */ RestTemplateBuilder customize(RestTemplateBuilder restTemplateBuilder); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/customizer/ZipkinWebClientBuilderCustomizer.java
dubbo-spring-boot-project/dubbo-spring-boot-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/observability/zipkin/customizer/ZipkinWebClientBuilderCustomizer.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.spring.boot.autoconfigure.observability.zipkin.customizer; import org.springframework.web.reactive.function.client.WebClient; /** * Callback interface that can be implemented by beans wishing to customize the * {@link WebClient.Builder} used to send spans to Zipkin. * * @since 3.2.0 */ @FunctionalInterface public interface ZipkinWebClientBuilderCustomizer { /** * Customize the web client builder. * * @param webClientBuilder the {@code WebClient.Builder} to customize */ void customize(WebClient.Builder webClientBuilder); }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboEndpointTest.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/test/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboEndpointTest.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.spring.boot.actuate.endpoint; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.spring.boot.util.DubboUtils; import java.util.Map; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.apache.dubbo.common.Version.getVersion; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; /** * {@link DubboQosEndpoints} Test * * @see DubboQosEndpoints * @since 2.7.0 */ @ExtendWith(SpringExtension.class) @SpringBootTest( classes = {DubboQosEndpoints.class}, properties = {"dubbo.application.name = dubbo-demo-application"}) @EnableAutoConfiguration class DubboEndpointTest { @Autowired private DubboQosEndpoints dubboQosEndpoints; @BeforeEach public void init() { DubboBootstrap.reset(); } @AfterEach public void destroy() { DubboBootstrap.reset(); } @Test void testInvoke() { Map<String, Object> metadata = dubboQosEndpoints.invoke(); assertNotNull(metadata.get("timestamp")); Map<String, String> versions = (Map<String, String>) metadata.get("versions"); Map<String, String> urls = (Map<String, String>) metadata.get("urls"); assertFalse(versions.isEmpty()); assertFalse(urls.isEmpty()); assertEquals(getVersion(DubboUtils.class, "1.0.0"), versions.get("dubbo-spring-boot")); assertEquals(getVersion(), versions.get("dubbo")); assertEquals("https://github.com/apache/dubbo", urls.get("dubbo")); assertEquals("dev@dubbo.apache.org", urls.get("mailing-list")); assertEquals("https://github.com/apache/dubbo-spring-boot-project", urls.get("github")); assertEquals("https://github.com/apache/dubbo-spring-boot-project/issues", urls.get("issues")); assertEquals("https://github.com/apache/dubbo-spring-boot-project.git", urls.get("git")); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/mertics/DubboMetricsBinder.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/mertics/DubboMetricsBinder.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.spring.boot.actuate.mertics; import org.apache.dubbo.metrics.MetricsGlobalRegistry; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.composite.CompositeMeterRegistry; import org.springframework.beans.factory.DisposableBean; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener; public class DubboMetricsBinder implements ApplicationListener<ApplicationStartedEvent>, DisposableBean { private final MeterRegistry meterRegistry; public DubboMetricsBinder(MeterRegistry meterRegistry) { this.meterRegistry = meterRegistry; } @Override public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) { if (meterRegistry instanceof CompositeMeterRegistry) { MetricsGlobalRegistry.setCompositeRegistry((CompositeMeterRegistry) meterRegistry); } else { MetricsGlobalRegistry.getCompositeRegistry().add(meterRegistry); } } @Override public void destroy() {} }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/health/DubboHealthIndicatorProperties.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/health/DubboHealthIndicatorProperties.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.spring.boot.actuate.health; import org.apache.dubbo.common.status.StatusChecker; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.context.properties.ConfigurationProperties; import static org.apache.dubbo.spring.boot.actuate.health.DubboHealthIndicatorProperties.PREFIX; /** * Dubbo {@link HealthIndicator} Properties * * @see HealthIndicator * @since 2.7.0 */ @ConfigurationProperties(prefix = PREFIX, ignoreUnknownFields = false) public class DubboHealthIndicatorProperties { /** * The prefix of {@link DubboHealthIndicatorProperties} */ public static final String PREFIX = "management.health.dubbo"; private Status status = new Status(); public Status getStatus() { return status; } public void setStatus(Status status) { this.status = status; } /** * The nested class for {@link StatusChecker}'s names * <pre> * registry= org.apache.dubbo.registry.status.RegistryStatusChecker * spring= org.apache.dubbo.config.spring.status.SpringStatusChecker * datasource= org.apache.dubbo.config.spring.status.DataSourceStatusChecker * memory= org.apache.dubbo.common.status.support.MemoryStatusChecker * load= org.apache.dubbo.common.status.support.LoadStatusChecker * server= org.apache.dubbo.rpc.protocol.dubbo.status.ServerStatusChecker * threadpool= org.apache.dubbo.rpc.protocol.dubbo.status.ThreadPoolStatusChecker * </pre> * * @see StatusChecker */ public static class Status { /** * The defaults names of {@link StatusChecker} * <p> * The defaults : "memory", "load" */ private Set<String> defaults = new LinkedHashSet<>(Arrays.asList("memory", "load")); /** * The extra names of {@link StatusChecker} */ private Set<String> extras = new LinkedHashSet<>(); public Set<String> getDefaults() { return defaults; } public void setDefaults(Set<String> defaults) { this.defaults = defaults; } public Set<String> getExtras() { return extras; } public void setExtras(Set<String> extras) { this.extras = extras; } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/health/DubboHealthIndicator.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/health/DubboHealthIndicator.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.spring.boot.actuate.health; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.status.StatusChecker; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ModuleModel; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.util.StringUtils; /** * Dubbo {@link HealthIndicator} * * @see HealthIndicator * @since 2.7.0 */ public class DubboHealthIndicator extends AbstractHealthIndicator { @Autowired private DubboHealthIndicatorProperties dubboHealthIndicatorProperties; // @Autowired(required = false) private Map<String, ProtocolConfig> protocolConfigs = Collections.emptyMap(); // @Autowired(required = false) private Map<String, ProviderConfig> providerConfigs = Collections.emptyMap(); @Autowired private ConfigManager configManager; @Autowired private ApplicationModel applicationModel; @Override protected void doHealthCheck(Health.Builder builder) throws Exception { ExtensionLoader<StatusChecker> extensionLoader = applicationModel.getExtensionLoader(StatusChecker.class); Map<String, String> statusCheckerNamesMap = resolveStatusCheckerNamesMap(); boolean hasError = false; boolean hasUnknown = false; // Up first builder.up(); for (Map.Entry<String, String> entry : statusCheckerNamesMap.entrySet()) { String statusCheckerName = entry.getKey(); String source = entry.getValue(); StatusChecker checker = extensionLoader.getExtension(statusCheckerName); org.apache.dubbo.common.status.Status status = checker.check(); org.apache.dubbo.common.status.Status.Level level = status.getLevel(); if (!hasError && level.equals(org.apache.dubbo.common.status.Status.Level.ERROR)) { hasError = true; builder.down(); } if (!hasError && !hasUnknown && level.equals(org.apache.dubbo.common.status.Status.Level.UNKNOWN)) { hasUnknown = true; builder.unknown(); } Map<String, Object> detail = new LinkedHashMap<>(); detail.put("source", source); detail.put("status", status); builder.withDetail(statusCheckerName, detail); } } /** * Resolves the map of {@link StatusChecker}'s name and its' source. * * @return non-null {@link Map} */ protected Map<String, String> resolveStatusCheckerNamesMap() { Map<String, String> statusCheckerNamesMap = new LinkedHashMap<>(); statusCheckerNamesMap.putAll(resolveStatusCheckerNamesMapFromDubboHealthIndicatorProperties()); statusCheckerNamesMap.putAll(resolveStatusCheckerNamesMapFromProtocolConfigs()); statusCheckerNamesMap.putAll(resolveStatusCheckerNamesMapFromProviderConfig()); return statusCheckerNamesMap; } private Map<String, String> resolveStatusCheckerNamesMapFromDubboHealthIndicatorProperties() { DubboHealthIndicatorProperties.Status status = dubboHealthIndicatorProperties.getStatus(); Map<String, String> statusCheckerNamesMap = new LinkedHashMap<>(); for (String statusName : status.getDefaults()) { statusCheckerNamesMap.put(statusName, DubboHealthIndicatorProperties.PREFIX + ".status.defaults"); } for (String statusName : status.getExtras()) { statusCheckerNamesMap.put(statusName, DubboHealthIndicatorProperties.PREFIX + ".status.extras"); } return statusCheckerNamesMap; } private Map<String, String> resolveStatusCheckerNamesMapFromProtocolConfigs() { if (protocolConfigs.isEmpty()) { protocolConfigs = configManager.getConfigsMap(ProtocolConfig.class); } Map<String, String> statusCheckerNamesMap = new LinkedHashMap<>(); for (Map.Entry<String, ProtocolConfig> entry : protocolConfigs.entrySet()) { String beanName = entry.getKey(); ProtocolConfig protocolConfig = entry.getValue(); Set<String> statusCheckerNames = getStatusCheckerNames(protocolConfig); for (String statusCheckerName : statusCheckerNames) { String source = buildSource(beanName, protocolConfig); statusCheckerNamesMap.put(statusCheckerName, source); } } return statusCheckerNamesMap; } private Map<String, String> resolveStatusCheckerNamesMapFromProviderConfig() { if (providerConfigs.isEmpty()) { providerConfigs = new LinkedHashMap<>(); for (ModuleModel moduleModel : applicationModel.getModuleModels()) { providerConfigs.putAll(moduleModel.getConfigManager().getConfigsMap(ProviderConfig.class)); } } Map<String, String> statusCheckerNamesMap = new LinkedHashMap<>(); for (Map.Entry<String, ProviderConfig> entry : providerConfigs.entrySet()) { String beanName = entry.getKey(); ProviderConfig providerConfig = entry.getValue(); Set<String> statusCheckerNames = getStatusCheckerNames(providerConfig); for (String statusCheckerName : statusCheckerNames) { String source = buildSource(beanName, providerConfig); statusCheckerNamesMap.put(statusCheckerName, source); } } return statusCheckerNamesMap; } private Set<String> getStatusCheckerNames(ProtocolConfig protocolConfig) { String status = protocolConfig.getStatus(); return StringUtils.commaDelimitedListToSet(status); } private Set<String> getStatusCheckerNames(ProviderConfig providerConfig) { String status = providerConfig.getStatus(); return StringUtils.commaDelimitedListToSet(status); } private String buildSource(String beanName, Object bean) { return beanName + "@" + bean.getClass().getSimpleName() + ".getStatus()"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboConfigsMetadataEndpoint.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboConfigsMetadataEndpoint.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.spring.boot.actuate.endpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboConfigsMetadata; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; /** * Dubbo Configs Metadata {@link Endpoint} * * @since 2.7.0 */ @Endpoint(id = "dubboconfigs") public class DubboConfigsMetadataEndpoint extends AbstractDubboMetadata { @Autowired private DubboConfigsMetadata dubboConfigsMetadata; @ReadOperation public Map<String, Map<String, Map<String, Object>>> configs() { return dubboConfigsMetadata.configs(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboQosEndpoints.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboQosEndpoints.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.spring.boot.actuate.endpoint; import org.apache.dubbo.qos.command.ActuatorExecutor; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboMetadata; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.Selector; import org.springframework.lang.Nullable; /** * Dubbo Actuator {@link Endpoint} * * @see Endpoint * @since 3.3.0 */ @Endpoint(id = "dubbo") public class DubboQosEndpoints { @Autowired private ApplicationModel applicationModel; @Autowired private DubboMetadata dubboMetadata; @Autowired private DubboActuatorProperties dubboActuatorProperties; @ReadOperation public Map<String, Object> invoke() { return dubboMetadata.invoke(); } @ReadOperation public String handleCommand(@Selector String command, @Nullable String[] args) { if (dubboActuatorProperties.isEnabled(command.toLowerCase())) { ActuatorExecutor actuatorExecutor = applicationModel.getBeanFactory().getBean(ActuatorExecutor.class); return actuatorExecutor.execute(command, args); } else { return ("Invalid command or not enabled"); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboActuatorProperties.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboActuatorProperties.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.spring.boot.actuate.endpoint; import java.util.Map; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @Component @ConfigurationProperties(prefix = "management.endpoint") public class DubboActuatorProperties { private Map<String, Boolean> dubbo; public Map<String, Boolean> getDubbo() { return dubbo; } public void setDubbo(Map<String, Boolean> dubbo) { this.dubbo = dubbo; } public boolean isEnabled(String command) { if (StringUtils.hasText(command)) { Boolean enabled = dubbo.get(command + ".enabled"); return enabled != null && enabled; } else { return false; } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboServicesMetadataEndpoint.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboServicesMetadataEndpoint.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.spring.boot.actuate.endpoint; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboServicesMetadata; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; /** * {@link DubboService} Metadata {@link Endpoint} * * @since 2.7.0 */ @Endpoint(id = "dubboservices") public class DubboServicesMetadataEndpoint extends AbstractDubboMetadata { @Autowired private DubboServicesMetadata dubboServicesMetadata; @ReadOperation public Map<String, Map<String, Object>> services() { return dubboServicesMetadata.services(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboReferencesMetadataEndpoint.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboReferencesMetadataEndpoint.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.spring.boot.actuate.endpoint; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboReferencesMetadata; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; /** * {@link DubboReference} Metadata {@link Endpoint} * * @since 2.7.0 */ @Endpoint(id = "dubboreferences") public class DubboReferencesMetadataEndpoint extends AbstractDubboMetadata { @Autowired private DubboReferencesMetadata dubboReferencesMetadata; @ReadOperation public Map<String, Map<String, Object>> references() { return dubboReferencesMetadata.references(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboPropertiesMetadataEndpoint.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboPropertiesMetadataEndpoint.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.spring.boot.actuate.endpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboPropertiesMetadata; import java.util.SortedMap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; /** * Dubbo Properties {@link Endpoint} * * @since 2.7.0 */ @Endpoint(id = "dubboproperties") public class DubboPropertiesMetadataEndpoint extends AbstractDubboMetadata { @Autowired private DubboPropertiesMetadata dubboPropertiesMetadata; @ReadOperation public SortedMap<String, Object> properties() { return dubboPropertiesMetadata.properties(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboShutdownEndpoint.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboShutdownEndpoint.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.spring.boot.actuate.endpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboShutdownMetadata; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; /** * Dubbo Shutdown * * @since 2.7.0 */ @Endpoint(id = "dubboshutdown") public class DubboShutdownEndpoint extends AbstractDubboMetadata { @Autowired private DubboShutdownMetadata dubboShutdownMetadata; @WriteOperation public Map<String, Object> shutdown() throws Exception { return dubboShutdownMetadata.shutdown(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboConfigsMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboConfigsMetadata.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.spring.boot.actuate.endpoint.metadata; import org.apache.dubbo.config.AbstractConfig; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConsumerConfig; import org.apache.dubbo.config.MethodConfig; import org.apache.dubbo.config.ModuleConfig; import org.apache.dubbo.config.MonitorConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; import org.springframework.stereotype.Component; import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors; /** * Dubbo Configs Metadata * * @since 2.7.0 */ @Component public class DubboConfigsMetadata extends AbstractDubboMetadata { public Map<String, Map<String, Map<String, Object>>> configs() { Map<String, Map<String, Map<String, Object>>> configsMap = new LinkedHashMap<>(); addDubboConfigBeans(ApplicationConfig.class, configsMap); addDubboConfigBeans(ConsumerConfig.class, configsMap); addDubboConfigBeans(MethodConfig.class, configsMap); addDubboConfigBeans(ModuleConfig.class, configsMap); addDubboConfigBeans(MonitorConfig.class, configsMap); addDubboConfigBeans(ProtocolConfig.class, configsMap); addDubboConfigBeans(ProviderConfig.class, configsMap); addDubboConfigBeans(ReferenceConfig.class, configsMap); addDubboConfigBeans(RegistryConfig.class, configsMap); addDubboConfigBeans(ServiceConfig.class, configsMap); return configsMap; } private void addDubboConfigBeans( Class<? extends AbstractConfig> dubboConfigClass, Map<String, Map<String, Map<String, Object>>> configsMap) { Map<String, ? extends AbstractConfig> dubboConfigBeans = beansOfTypeIncludingAncestors(applicationContext, dubboConfigClass); String name = dubboConfigClass.getSimpleName(); Map<String, Map<String, Object>> beansMetadata = new TreeMap<>(); for (Map.Entry<String, ? extends AbstractConfig> entry : dubboConfigBeans.entrySet()) { String beanName = entry.getKey(); AbstractConfig configBean = entry.getValue(); Map<String, Object> configBeanMeta = resolveBeanMetadata(configBean); beansMetadata.put(beanName, configBeanMeta); } configsMap.put(name, beansMetadata); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.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.spring.boot.actuate.endpoint.metadata; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.ServiceBean; import java.util.LinkedHashMap; import java.util.Map; import org.springframework.stereotype.Component; /** * {@link DubboService} Metadata * * @since 2.7.0 */ @Component public class DubboServicesMetadata extends AbstractDubboMetadata { public Map<String, Map<String, Object>> services() { Map<String, ServiceBean> serviceBeansMap = getServiceBeansMap(); Map<String, Map<String, Object>> servicesMetadata = new LinkedHashMap<>(serviceBeansMap.size()); for (Map.Entry<String, ServiceBean> entry : serviceBeansMap.entrySet()) { String serviceBeanName = entry.getKey(); ServiceBean serviceBean = entry.getValue(); Map<String, Object> serviceBeanMetadata = resolveBeanMetadata(serviceBean); Object service = resolveServiceBean(serviceBeanName, serviceBean); if (service != null) { // Add Service implementation class serviceBeanMetadata.put("serviceClass", service.getClass().getName()); } servicesMetadata.put(serviceBeanName, serviceBeanMetadata); } return servicesMetadata; } private Object resolveServiceBean(String serviceBeanName, ServiceBean serviceBean) { int index = serviceBeanName.indexOf("#"); if (index > -1) { Class<?> interfaceClass = serviceBean.getInterfaceClass(); String serviceName = serviceBeanName.substring(index + 1); if (applicationContext.containsBean(serviceName)) { return applicationContext.getBean(serviceName, interfaceClass); } } return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.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.spring.boot.actuate.endpoint.metadata; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.springframework.beans.factory.annotation.InjectionMetadata; import org.springframework.stereotype.Component; /** * {@link DubboReference} Metadata * * @since 2.7.0 */ @Component public class DubboReferencesMetadata extends AbstractDubboMetadata { public Map<String, Map<String, Object>> references() { Map<String, Map<String, Object>> referencesMetadata = new HashMap<>(); ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor(); referencesMetadata.putAll(buildReferencesMetadata(beanPostProcessor.getInjectedFieldReferenceBeanMap())); referencesMetadata.putAll(buildReferencesMetadata(beanPostProcessor.getInjectedMethodReferenceBeanMap())); return referencesMetadata; } private Map<String, Map<String, Object>> buildReferencesMetadata( Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> injectedElementReferenceBeanMap) { Map<String, Map<String, Object>> referencesMetadata = new HashMap<>(); for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : injectedElementReferenceBeanMap.entrySet()) { InjectionMetadata.InjectedElement injectedElement = entry.getKey(); ReferenceBean<?> referenceBean = entry.getValue(); ReferenceConfig referenceConfig = referenceBean.getReferenceConfig(); Map<String, Object> beanMetadata = null; if (referenceConfig != null) { beanMetadata = resolveBeanMetadata(referenceConfig); // beanMetadata.put("invoker", resolveBeanMetadata(referenceBean.get())); } else { // referenceBean is not initialized beanMetadata = new LinkedHashMap<>(); } referencesMetadata.put(String.valueOf(injectedElement.getMember()), beanMetadata); } return referencesMetadata; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboShutdownMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboShutdownMetadata.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.spring.boot.actuate.endpoint.metadata; import org.apache.dubbo.config.ReferenceConfigBase; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.registry.support.RegistryManager; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * Dubbo Shutdown * * @since 2.7.0 */ @Component public class DubboShutdownMetadata extends AbstractDubboMetadata { @Autowired private ApplicationModel applicationModel; public Map<String, Object> shutdown() throws Exception { Map<String, Object> shutdownCountData = new LinkedHashMap<>(); // registries RegistryManager registryManager = applicationModel.getBeanFactory().getBean(RegistryManager.class); int registriesCount = registryManager.getRegistries().size(); // protocols int protocolsCount = getProtocolConfigsBeanMap().size(); shutdownCountData.put("registries", registriesCount); shutdownCountData.put("protocols", protocolsCount); // Service Beans Map<String, ServiceBean> serviceBeansMap = getServiceBeansMap(); if (!serviceBeansMap.isEmpty()) { for (ServiceBean serviceBean : serviceBeansMap.values()) { serviceBean.destroy(); } } shutdownCountData.put("services", serviceBeansMap.size()); // Reference Beans Collection<ReferenceConfigBase<?>> references = applicationModel.getDefaultModule().getConfigManager().getReferences(); for (ReferenceConfigBase<?> reference : references) { reference.destroy(); } shutdownCountData.put("references", references.size()); // Set Result to complete Map<String, Object> shutdownData = new TreeMap<>(); shutdownData.put("shutdown.count", shutdownCountData); return shutdownData; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/AbstractDubboMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/AbstractDubboMetadata.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.spring.boot.actuate.endpoint.metadata; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.net.URL; import java.util.Date; import java.util.LinkedHashMap; import java.util.Map; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors; import static org.springframework.util.ClassUtils.isPrimitiveOrWrapper; /** * Abstract Dubbo Metadata * * @since 2.7.0 */ public abstract class AbstractDubboMetadata implements ApplicationContextAware, EnvironmentAware { protected ApplicationContext applicationContext; protected ConfigurableEnvironment environment; private static boolean isSimpleType(Class<?> type) { return isPrimitiveOrWrapper(type) || type == String.class || type == BigDecimal.class || type == BigInteger.class || type == Date.class || type == URL.class || type == Class.class; } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } @Override public void setEnvironment(Environment environment) { if (environment instanceof ConfigurableEnvironment) { this.environment = (ConfigurableEnvironment) environment; } } protected Map<String, Object> resolveBeanMetadata(final Object bean) { final Map<String, Object> beanMetadata = new LinkedHashMap<>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod != null && isSimpleType(propertyDescriptor.getPropertyType())) { String name = Introspector.decapitalize(propertyDescriptor.getName()); Object value = readMethod.invoke(bean); if (value != null) { beanMetadata.put(name, value); } } } } catch (Exception e) { throw new RuntimeException(e); } return beanMetadata; } protected Map<String, ServiceBean> getServiceBeansMap() { return beansOfTypeIncludingAncestors(applicationContext, ServiceBean.class); } protected ReferenceAnnotationBeanPostProcessor getReferenceAnnotationBeanPostProcessor() { return DubboBeanUtils.getReferenceAnnotationBeanPostProcessor(applicationContext); } protected Map<String, ProtocolConfig> getProtocolConfigsBeanMap() { return beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboMetadata.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.spring.boot.actuate.endpoint.metadata; import org.apache.dubbo.common.Version; import org.apache.dubbo.spring.boot.util.DubboUtils; import java.util.LinkedHashMap; import java.util.Map; import org.springframework.stereotype.Component; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_GITHUB_URL; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_MAILING_LIST; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL; /** * Dubbo Metadata * @since 2.7.0 */ @Component public class DubboMetadata { public Map<String, Object> invoke() { Map<String, Object> metaData = new LinkedHashMap<>(); metaData.put("timestamp", System.currentTimeMillis()); Map<String, String> versions = new LinkedHashMap<>(); versions.put("dubbo-spring-boot", Version.getVersion(DubboUtils.class, "1.0.0")); versions.put("dubbo", Version.getVersion()); Map<String, String> urls = new LinkedHashMap<>(); urls.put("dubbo", DUBBO_GITHUB_URL); urls.put("mailing-list", DUBBO_MAILING_LIST); urls.put("github", DUBBO_SPRING_BOOT_GITHUB_URL); urls.put("issues", DUBBO_SPRING_BOOT_ISSUES_URL); urls.put("git", DUBBO_SPRING_BOOT_GIT_URL); metaData.put("versions", versions); metaData.put("urls", urls); return metaData; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboPropertiesMetadata.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboPropertiesMetadata.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.spring.boot.actuate.endpoint.metadata; import java.util.SortedMap; import org.springframework.stereotype.Component; import static org.apache.dubbo.config.spring.util.EnvironmentUtils.filterDubboProperties; /** * Dubbo Properties Metadata * * @since 2.7.0 */ @Component public class DubboPropertiesMetadata extends AbstractDubboMetadata { public SortedMap<String, Object> properties() { return (SortedMap) filterDubboProperties(environment); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/condition/CompatibleOnEnabledEndpointCondition.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/condition/CompatibleOnEnabledEndpointCondition.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.spring.boot.actuate.endpoint.condition; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.ClassUtils; import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_CLASS_NOT_FOUND; /** * {@link Conditional} that checks whether or not an endpoint is enabled, which is compatible with * org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnEnabledEndpointCondition * and org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnAvailableEndpointCondition * * @see CompatibleConditionalOnEnabledEndpoint * @since 2.7.7 */ class CompatibleOnEnabledEndpointCondition implements Condition { private static final ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(CompatibleOnEnabledEndpointCondition.class); // Spring Boot [2.0.0 , 2.2.x] static String CONDITION_CLASS_NAME_OLD = "org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnEnabledEndpointCondition"; // Spring Boot 2.2.0 + static String CONDITION_CLASS_NAME_NEW = "org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnAvailableEndpointCondition"; @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { ClassLoader classLoader = context.getClassLoader(); if (ClassUtils.isPresent(CONDITION_CLASS_NAME_OLD, classLoader)) { Class<?> cls = ClassUtils.resolveClassName(CONDITION_CLASS_NAME_OLD, classLoader); if (Condition.class.isAssignableFrom(cls)) { Condition condition = Condition.class.cast(BeanUtils.instantiateClass(cls)); return condition.matches(context, metadata); } } // Check by org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint if (ClassUtils.isPresent(CONDITION_CLASS_NAME_NEW, classLoader)) { return true; } // No condition class found LOGGER.warn( COMMON_CLASS_NOT_FOUND, "No condition class found", "", String.format("No condition class found, Dubbo Health Endpoint [%s] will not expose", metadata)); return false; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/condition/CompatibleConditionalOnEnabledEndpoint.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/condition/CompatibleConditionalOnEnabledEndpoint.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.spring.boot.actuate.endpoint.condition; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension; import org.springframework.context.annotation.Conditional; /** * {@link Conditional} that checks whether or not an endpoint is enabled, which is compatible with * org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint ([2.0.x, 2.2.x]) * org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint * * @see CompatibleOnEnabledEndpointCondition * @since 2.7.7 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) @Documented @Conditional(CompatibleOnEnabledEndpointCondition.class) public @interface CompatibleConditionalOnEnabledEndpoint { /** * The endpoint type that should be checked. Inferred when the return type of the * {@code @Bean} method is either an {@link Endpoint @Endpoint} or an * {@link EndpointExtension @EndpointExtension}. * * @return the endpoint type to check */ Class<?> endpoint() default Void.class; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/actuate/health/DubboHealthIndicatorTest.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/actuate/health/DubboHealthIndicatorTest.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.spring.boot.actuate.health; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.junit.jupiter.api.Assertions.assertEquals; /** * {@link DubboHealthIndicator} Test * * @see DubboHealthIndicator * @since 2.7.0 */ @ExtendWith(SpringExtension.class) @TestPropertySource( properties = { "dubbo.application.id = my-application-1", "dubbo.application.name = dubbo-demo-application-1", "dubbo.protocol.id = dubbo-protocol", "dubbo.protocol.name = dubbo", "dubbo.protocol.port = 12345", "dubbo.protocol.status = registry", "dubbo.provider.id = dubbo-provider", "dubbo.provider.status = server", "management.health.dubbo.status.defaults = memory", "management.health.dubbo.status.extras = load,threadpool" }) @SpringBootTest(classes = {DubboHealthIndicator.class, DubboHealthIndicatorTest.class}) @EnableConfigurationProperties(DubboHealthIndicatorProperties.class) @EnableDubboConfig class DubboHealthIndicatorTest { @Autowired private DubboHealthIndicator dubboHealthIndicator; @Test void testResolveStatusCheckerNamesMap() { Map<String, String> statusCheckerNamesMap = dubboHealthIndicator.resolveStatusCheckerNamesMap(); assertEquals(5, statusCheckerNamesMap.size()); assertEquals("dubbo-protocol@ProtocolConfig.getStatus()", statusCheckerNamesMap.get("registry")); assertEquals("dubbo-provider@ProviderConfig.getStatus()", statusCheckerNamesMap.get("server")); assertEquals("management.health.dubbo.status.defaults", statusCheckerNamesMap.get("memory")); assertEquals("management.health.dubbo.status.extras", statusCheckerNamesMap.get("load")); assertEquals("management.health.dubbo.status.extras", statusCheckerNamesMap.get("threadpool")); } @Test void testHealth() { Health health = dubboHealthIndicator.health(); assertEquals(Status.UNKNOWN, health.getStatus()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfigurationTest.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/test/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfigurationTest.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.spring.boot.actuate.autoconfigure; import org.apache.dubbo.common.BaseServiceMetadata; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboConfigsMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboPropertiesMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboQosEndpoints; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboReferencesMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboServicesMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboShutdownEndpoint; import java.util.Map; import java.util.SortedMap; import java.util.function.Supplier; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.client.RestTemplate; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** * {@link DubboEndpointAnnotationAutoConfiguration} Test * * @since 2.7.0 */ @ExtendWith(SpringExtension.class) @SpringBootTest( classes = { DubboEndpointAnnotationAutoConfigurationTest.class, DubboEndpointAnnotationAutoConfigurationTest.ConsumerConfiguration.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { "dubbo.service.version = 1.0.0", "dubbo.application.id = my-application", "dubbo.application.name = dubbo-demo-application", "dubbo.module.id = my-module", "dubbo.module.name = dubbo-demo-module", "dubbo.registry.id = my-registry", "dubbo.registry.address = N/A", "dubbo.protocol.id=my-protocol", "dubbo.protocol.name=dubbo", "dubbo.protocol.port=20880", "dubbo.provider.id=my-provider", "dubbo.provider.host=127.0.0.1", "dubbo.scan.basePackages = org.apache.dubbo.spring.boot.actuate.autoconfigure", "management.endpoint.dubbo.enabled = true", "management.endpoint.dubboshutdown.enabled = true", "management.endpoint.dubboconfigs.enabled = true", "management.endpoint.dubboservices.enabled = true", "management.endpoint.dubboreferences.enabled = true", "management.endpoint.dubboproperties.enabled = true", "management.endpoints.web.exposure.include = *", }) @EnableAutoConfiguration @Disabled class DubboEndpointAnnotationAutoConfigurationTest { @Autowired private DubboQosEndpoints dubboQosEndpoints; @Autowired private DubboConfigsMetadataEndpoint dubboConfigsMetadataEndpoint; @Autowired private DubboPropertiesMetadataEndpoint dubboPropertiesEndpoint; @Autowired private DubboReferencesMetadataEndpoint dubboReferencesMetadataEndpoint; @Autowired private DubboServicesMetadataEndpoint dubboServicesMetadataEndpoint; @Autowired private DubboShutdownEndpoint dubboShutdownEndpoint; private RestTemplate restTemplate = new RestTemplate(); @Autowired private ObjectMapper objectMapper; @Value("http://127.0.0.1:${local.management.port}${management.endpoints.web.base-path:/actuator}") private String actuatorBaseURL; @BeforeEach void init() { DubboBootstrap.reset(); } @AfterEach void destroy() { DubboBootstrap.reset(); } @Test void testShutdown() throws Exception { Map<String, Object> value = dubboShutdownEndpoint.shutdown(); Map<String, Object> shutdownCounts = (Map<String, Object>) value.get("shutdown.count"); assertEquals(0, shutdownCounts.get("registries")); assertEquals(1, shutdownCounts.get("protocols")); assertEquals(1, shutdownCounts.get("services")); assertEquals(0, shutdownCounts.get("references")); } @Test void testConfigs() { Map<String, Map<String, Map<String, Object>>> configsMap = dubboConfigsMetadataEndpoint.configs(); Map<String, Map<String, Object>> beansMetadata = configsMap.get("ApplicationConfig"); assertEquals( "dubbo-demo-application", beansMetadata.get("my-application").get("name")); beansMetadata = configsMap.get("ConsumerConfig"); assertTrue(beansMetadata.isEmpty()); beansMetadata = configsMap.get("MethodConfig"); assertTrue(beansMetadata.isEmpty()); beansMetadata = configsMap.get("ModuleConfig"); assertEquals("dubbo-demo-module", beansMetadata.get("my-module").get("name")); beansMetadata = configsMap.get("MonitorConfig"); assertTrue(beansMetadata.isEmpty()); beansMetadata = configsMap.get("ProtocolConfig"); assertEquals("dubbo", beansMetadata.get("my-protocol").get("name")); beansMetadata = configsMap.get("ProviderConfig"); assertEquals("127.0.0.1", beansMetadata.get("my-provider").get("host")); beansMetadata = configsMap.get("ReferenceConfig"); assertTrue(beansMetadata.isEmpty()); beansMetadata = configsMap.get("RegistryConfig"); assertEquals("N/A", beansMetadata.get("my-registry").get("address")); beansMetadata = configsMap.get("ServiceConfig"); assertFalse(beansMetadata.isEmpty()); } @Test void testServices() { Map<String, Map<String, Object>> services = dubboServicesMetadataEndpoint.services(); assertEquals(1, services.size()); Map<String, Object> demoServiceMeta = services.get( "ServiceBean:org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointAnnotationAutoConfigurationTest$DemoService:1.0.0:"); assertEquals("1.0.0", demoServiceMeta.get("version")); } @Test void testReferences() { Map<String, Map<String, Object>> references = dubboReferencesMetadataEndpoint.references(); assertFalse(references.isEmpty()); String injectedField = "private " + DemoService.class.getName() + " " + ConsumerConfiguration.class.getName() + ".demoService"; Map<String, Object> referenceMap = references.get(injectedField); assertNotNull(referenceMap); assertEquals(DemoService.class, referenceMap.get("interfaceClass")); assertEquals( BaseServiceMetadata.buildServiceKey( DemoService.class.getName(), ConsumerConfiguration.DEMO_GROUP, ConsumerConfiguration.DEMO_VERSION), referenceMap.get("uniqueServiceName")); } @Test void testProperties() { SortedMap<String, Object> properties = dubboPropertiesEndpoint.properties(); assertEquals("my-application", properties.get("dubbo.application.id")); assertEquals("dubbo-demo-application", properties.get("dubbo.application.name")); assertEquals("my-module", properties.get("dubbo.module.id")); assertEquals("dubbo-demo-module", properties.get("dubbo.module.name")); assertEquals("my-registry", properties.get("dubbo.registry.id")); assertEquals("N/A", properties.get("dubbo.registry.address")); assertEquals("my-protocol", properties.get("dubbo.protocol.id")); assertEquals("dubbo", properties.get("dubbo.protocol.name")); assertEquals("20880", properties.get("dubbo.protocol.port")); assertEquals("my-provider", properties.get("dubbo.provider.id")); assertEquals("127.0.0.1", properties.get("dubbo.provider.host")); assertEquals("org.apache.dubbo.spring.boot.actuate.autoconfigure", properties.get("dubbo.scan.basePackages")); } @Test void testHttpEndpoints() throws JsonProcessingException { // testHttpEndpoint("/dubbo", dubboQosEndpoints::invoke); testHttpEndpoint("/dubbo/configs", dubboConfigsMetadataEndpoint::configs); testHttpEndpoint("/dubbo/services", dubboServicesMetadataEndpoint::services); testHttpEndpoint("/dubbo/references", dubboReferencesMetadataEndpoint::references); testHttpEndpoint("/dubbo/properties", dubboPropertiesEndpoint::properties); } private void testHttpEndpoint(String actuatorURI, Supplier<Map> resultsSupplier) throws JsonProcessingException { String actuatorURL = actuatorBaseURL + actuatorURI; String response = restTemplate.getForObject(actuatorURL, String.class); assertEquals(objectMapper.writeValueAsString(resultsSupplier.get()), response); } interface DemoService { String sayHello(String name); } @DubboService( version = "${dubbo.service.version}", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}") static class DefaultDemoService implements DemoService { public String sayHello(String name) { return "Hello, " + name + " (from Spring Boot)"; } } @Configuration static class ConsumerConfiguration { public static final String DEMO_GROUP = "demo"; public static final String DEMO_VERSION = "1.0.0"; @DubboReference(group = DEMO_GROUP, version = DEMO_VERSION) private DemoService demoService; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboMetricsAutoConfiguration.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboMetricsAutoConfiguration.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.spring.boot.actuate.autoconfigure; import org.apache.dubbo.spring.boot.actuate.mertics.DubboMetricsBinder; import io.micrometer.core.instrument.MeterRegistry; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) @Configuration(proxyBeanMethods = false) @ConditionalOnWebApplication @AutoConfigureAfter(CompositeMeterRegistryAutoConfiguration.class) public class DubboMetricsAutoConfiguration { @Bean @ConditionalOnBean({MeterRegistry.class}) @ConditionalOnMissingBean({DubboMetricsBinder.class}) public DubboMetricsBinder dubboMetricsBinder(MeterRegistry meterRegistry) { return new DubboMetricsBinder(meterRegistry); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.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.spring.boot.actuate.autoconfigure; import org.apache.dubbo.spring.boot.actuate.health.DubboHealthIndicator; import org.apache.dubbo.spring.boot.actuate.health.DubboHealthIndicatorProperties; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * Dubbo {@link DubboHealthIndicator} Auto Configuration * * @see HealthIndicator * @since 2.7.0 */ @Configuration @ConditionalOnClass(name = {"org.springframework.boot.actuate.health.Health"}) @ConditionalOnProperty( name = {"management.health.dubbo.enabled", "dubbo.enabled"}, matchIfMissing = true, havingValue = "true") @EnableConfigurationProperties(DubboHealthIndicatorProperties.class) public class DubboHealthIndicatorAutoConfiguration { @Bean @ConditionalOnMissingBean public DubboHealthIndicator dubboHealthIndicator() { return new DubboHealthIndicator(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfiguration.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointAnnotationAutoConfiguration.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.spring.boot.actuate.autoconfigure; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboConfigsMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboPropertiesMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboQosEndpoints; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboReferencesMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboServicesMetadataEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboShutdownEndpoint; import org.apache.dubbo.spring.boot.actuate.endpoint.condition.CompatibleConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; /** * Dubbo {@link Endpoint @Endpoint} Auto-{@link Configuration} for Spring Boot Actuator 2.0 * * @see Endpoint * @see Configuration * @since 2.7.0 */ @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) @Configuration @PropertySource( name = "Dubbo Endpoints Default Properties", value = "classpath:/META-INF/dubbo-endpoints-default.properties") public class DubboEndpointAnnotationAutoConfiguration { @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint @CompatibleConditionalOnEnabledEndpoint public DubboQosEndpoints dubboQosEndpoints() { return new DubboQosEndpoints(); } @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint @CompatibleConditionalOnEnabledEndpoint public DubboConfigsMetadataEndpoint dubboConfigsMetadataEndpoint() { return new DubboConfigsMetadataEndpoint(); } @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint @CompatibleConditionalOnEnabledEndpoint public DubboPropertiesMetadataEndpoint dubboPropertiesEndpoint() { return new DubboPropertiesMetadataEndpoint(); } @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint @CompatibleConditionalOnEnabledEndpoint public DubboReferencesMetadataEndpoint dubboReferencesMetadataEndpoint() { return new DubboReferencesMetadataEndpoint(); } @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint @CompatibleConditionalOnEnabledEndpoint public DubboServicesMetadataEndpoint dubboServicesMetadataEndpoint() { return new DubboServicesMetadataEndpoint(); } @Bean @ConditionalOnMissingBean @ConditionalOnAvailableEndpoint @CompatibleConditionalOnEnabledEndpoint public DubboShutdownEndpoint dubboShutdownEndpoint() { return new DubboShutdownEndpoint(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboExtensionEndpointAutoConfiguration.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboExtensionEndpointAutoConfiguration.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.spring.boot.actuate.autoconfigure; import org.apache.dubbo.spring.boot.actuate.endpoint.DubboActuatorProperties; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; /** * Dubbo Extension Endpoints Auto-{@link Configuration} */ @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) @ConditionalOnClass(name = {"org.springframework.boot.actuate.health.Health"}) @Configuration @AutoConfigureAfter( name = {"org.apache.dubbo.spring.boot.actuate.autoconfigure.DubboEndpointMetadataAutoConfiguration"}) @ComponentScan(basePackageClasses = DubboActuatorProperties.class) public class DubboExtensionEndpointAutoConfiguration {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointMetadataAutoConfiguration.java
dubbo-spring-boot-project/dubbo-spring-boot-actuator-autoconfigure/src/main/java/org/apache/dubbo/spring/boot/actuate/autoconfigure/DubboEndpointMetadataAutoConfiguration.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.spring.boot.actuate.autoconfigure; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import static org.apache.dubbo.spring.boot.util.DubboUtils.DUBBO_PREFIX; /** * Dubbo Endpoints Metadata Auto-{@link Configuration} */ @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true) @ConditionalOnClass( name = {"org.springframework.boot.actuate.health.Health" // If spring-boot-actuator is present }) @Configuration @AutoConfigureAfter( name = { "org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration", "org.apache.dubbo.spring.boot.autoconfigure.DubboRelaxedBindingAutoConfiguration" }) @ComponentScan(basePackageClasses = AbstractDubboMetadata.class) public class DubboEndpointMetadataAutoConfiguration {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryService.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryService.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.config.spring; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.RegistryService; import org.apache.dubbo.rpc.RpcContext; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; public class SimpleRegistryService extends AbstractRegistryService { private static final Logger logger = LoggerFactory.getLogger(SimpleRegistryService.class); private final ConcurrentMap<String, ConcurrentMap<String, URL>> remoteRegistered = new ConcurrentHashMap<String, ConcurrentMap<String, URL>>(); private final ConcurrentMap<String, ConcurrentMap<String, NotifyListener>> remoteListeners = new ConcurrentHashMap<String, ConcurrentMap<String, NotifyListener>>(); private List<String> registries; @Override public void register(String service, URL url) { super.register(service, url); String client = RpcContext.getServiceContext().getRemoteAddressString(); Map<String, URL> urls = ConcurrentHashMapUtils.computeIfAbsent(remoteRegistered, client, k -> new ConcurrentHashMap<>()); urls.put(service, url); notify(service, getRegistered().get(service)); } @Override public void unregister(String service, URL url) { super.unregister(service, url); String client = RpcContext.getServiceContext().getRemoteAddressString(); Map<String, URL> urls = remoteRegistered.get(client); if (urls != null && urls.size() > 0) { urls.remove(service); } notify(service, getRegistered().get(service)); } @Override public void subscribe(String service, URL url, NotifyListener listener) { String client = RpcContext.getServiceContext().getRemoteAddressString(); if (logger.isInfoEnabled()) { logger.info("[subscribe] service: " + service + ",client:" + client); } List<URL> urls = getRegistered().get(service); if ((RegistryService.class.getName() + ":0.0.0").equals(service) && CollectionUtils.isEmpty(urls)) { register( service, new ServiceConfigURL( "dubbo", NetUtils.getLocalHost(), RpcContext.getServiceContext().getLocalPort(), RegistryService.class.getName(), url.getParameters())); List<String> rs = registries; if (rs != null && rs.size() > 0) { for (String registry : rs) { register(service, UrlUtils.parseURL(registry, url.getParameters())); } } } super.subscribe(service, url, listener); Map<String, NotifyListener> listeners = ConcurrentHashMapUtils.computeIfAbsent(remoteListeners, client, k -> new ConcurrentHashMap<>()); listeners.put(service, listener); urls = getRegistered().get(service); if (urls != null && urls.size() > 0) { listener.notify(urls); } } @Override public void unsubscribe(String service, URL url, NotifyListener listener) { super.unsubscribe(service, url, listener); String client = RpcContext.getServiceContext().getRemoteAddressString(); Map<String, NotifyListener> listeners = remoteListeners.get(client); if (listeners != null && listeners.size() > 0) { listeners.remove(service); } List<URL> urls = getRegistered().get(service); if (urls != null && urls.size() > 0) { listener.notify(urls); } } public void disconnect() { String client = RpcContext.getServiceContext().getRemoteAddressString(); if (logger.isInfoEnabled()) { logger.info("Disconnected " + client); } ConcurrentMap<String, URL> urls = remoteRegistered.get(client); if (urls != null && urls.size() > 0) { for (Map.Entry<String, URL> entry : urls.entrySet()) { super.unregister(entry.getKey(), entry.getValue()); } } Map<String, NotifyListener> listeners = remoteListeners.get(client); if (listeners != null && listeners.size() > 0) { for (Map.Entry<String, NotifyListener> entry : listeners.entrySet()) { String service = entry.getKey(); super.unsubscribe( service, new ServiceConfigURL( "subscribe", RpcContext.getServiceContext().getRemoteHost(), RpcContext.getServiceContext().getRemotePort(), RegistryService.class.getName(), getSubscribed(service)), entry.getValue()); } } } public List<String> getRegistries() { return registries; } public void setRegistries(List<String> registries) { this.registries = registries; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ServiceBeanTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ServiceBeanTest.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.config.spring; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.nullValue; import static org.mockito.Mockito.mock; class ServiceBeanTest { @BeforeEach public void setUp() { DubboBootstrap.reset(); } @AfterEach public void tearDown() { DubboBootstrap.reset(); } @Test void testGetService() { TestService service = mock(TestService.class); ServiceBean serviceBean = new ServiceBean(null, service); Service beanService = serviceBean.getService(); MatcherAssert.assertThat(beanService, not(nullValue())); } abstract class TestService implements Service {} }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/JavaConfigBeanTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/JavaConfigBeanTest.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.config.spring; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConsumerConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.rpc.Constants; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import java.util.Collection; import java.util.Map; 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 org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; class JavaConfigBeanTest { private static final String MY_PROTOCOL_ID = "myProtocol"; private static final String MY_REGISTRY_ID = "my-registry"; @BeforeEach public void beforeEach() { DubboBootstrap.reset(); SysProps.clear(); SysProps.setProperty("dubbo.metrics.enabled", "false"); SysProps.setProperty("dubbo.metrics.protocol", "disabled"); } @AfterEach public void afterEach() { DubboBootstrap.reset(); SysProps.clear(); } @Test void testBean() { SysProps.setProperty("dubbo.application.owner", "Tom"); SysProps.setProperty("dubbo.application.qos-enable", "false"); SysProps.setProperty("dubbo.protocol.name", "dubbo"); SysProps.setProperty("dubbo.protocol.port", "2346"); String registryAddress = ZookeeperRegistryCenterConfig.getConnectionAddress(); SysProps.setProperty("dubbo.registry.address", registryAddress); SysProps.setProperty("dubbo.provider.group", "test"); AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext( TestConfiguration.class, ConsumerConfiguration.class, ProviderConfiguration.class); try { consumerContext.start(); ConfigManager configManager = ApplicationModel.defaultModel().getApplicationConfigManager(); ApplicationConfig application = configManager.getApplication().get(); Assertions.assertEquals(false, application.getQosEnable()); Assertions.assertEquals("Tom", application.getOwner()); RegistryConfig registry = configManager.getRegistry(MY_REGISTRY_ID).get(); Assertions.assertEquals(registryAddress, registry.getAddress()); Collection<ProtocolConfig> protocols = configManager.getProtocols(); Assertions.assertEquals(1, protocols.size()); ProtocolConfig protocolConfig = protocols.iterator().next(); Assertions.assertEquals("dubbo", protocolConfig.getName()); Assertions.assertEquals(2346, protocolConfig.getPort()); Assertions.assertEquals(MY_PROTOCOL_ID, protocolConfig.getId()); ApplicationModel applicationModel = consumerContext.getBean(ApplicationModel.class); ModuleConfigManager moduleConfigManager = applicationModel.getDefaultModule().getConfigManager(); ConsumerConfig consumerConfig = moduleConfigManager.getDefaultConsumer().get(); Assertions.assertEquals(1000, consumerConfig.getTimeout()); Assertions.assertEquals("demo", consumerConfig.getGroup()); Assertions.assertEquals(false, consumerConfig.isCheck()); Assertions.assertEquals(2, consumerConfig.getRetries()); Map<String, ReferenceBean> referenceBeanMap = consumerContext.getBeansOfType(ReferenceBean.class); Assertions.assertEquals(1, referenceBeanMap.size()); ReferenceBean referenceBean = referenceBeanMap.get("&demoService"); Assertions.assertNotNull(referenceBean); ReferenceConfig referenceConfig = referenceBean.getReferenceConfig(); // use consumer's attributes as default value Assertions.assertEquals(consumerConfig.getTimeout(), referenceConfig.getTimeout()); Assertions.assertEquals(consumerConfig.getGroup(), referenceConfig.getGroup()); // consumer cannot override reference's attribute Assertions.assertEquals(5, referenceConfig.getRetries()); DemoService referProxy = (DemoService) referenceConfig.get(); Assertions.assertTrue(referProxy instanceof DemoService); String result = referProxy.sayName("dubbo"); Assertions.assertEquals("say:dubbo", result); } finally { consumerContext.close(); } } @EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.annotation.consumer") @Configuration static class TestConfiguration { @Bean("dubbo-demo-application") public ApplicationConfig applicationConfig() { ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("dubbo-demo-application"); return applicationConfig; } @Bean(MY_PROTOCOL_ID) public ProtocolConfig protocolConfig() { ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setName("rest"); protocolConfig.setPort(1234); return protocolConfig; } @Bean(MY_REGISTRY_ID) public RegistryConfig registryConfig() { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("N/A"); return registryConfig; } @Bean public ConsumerConfig consumerConfig() { ConsumerConfig consumer = new ConsumerConfig(); consumer.setTimeout(1000); consumer.setGroup("demo"); consumer.setCheck(false); consumer.setRetries(2); return consumer; } } @Configuration static class ConsumerConfiguration { @Bean @DubboReference(scope = Constants.SCOPE_LOCAL, retries = 5) public ReferenceBean<DemoService> demoService() { return new ReferenceBean<>(); } } @Configuration static class ProviderConfiguration { @Bean @DubboService(group = "demo") public DemoService demoServiceImpl() { return new DemoServiceImpl(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.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.config.spring; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ArgumentConfig; import org.apache.dubbo.config.ConsumerConfig; import org.apache.dubbo.config.MethodConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ProviderConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.action.DemoActionByAnnotation; import org.apache.dubbo.config.spring.action.DemoActionBySetter; import org.apache.dubbo.config.spring.annotation.consumer.AnnotationAction; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; import org.apache.dubbo.config.spring.filter.MockFilter; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; import org.apache.dubbo.config.spring.impl.NotifyService; import org.apache.dubbo.config.spring.registry.MockRegistry; import org.apache.dubbo.config.spring.registry.MockRegistryFactory; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryService; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.service.GenericService; import java.util.Collection; import java.util.List; import java.util.Map; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_BEAN; import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_TCP_RESPONSE_TIMEOUT; import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; class ConfigTest { private static String resourcePath = ConfigTest.class.getPackage().getName().replace('.', '/'); @BeforeEach public void setUp() { SysProps.clear(); DubboBootstrap.reset(); SysProps.setProperty("dubbo.metrics.enabled", "false"); SysProps.setProperty("dubbo.metrics.protocol", "disabled"); } @AfterEach public void tearDown() { SysProps.clear(); DubboBootstrap.reset(); } @Test @Disabled("waiting-to-fix") public void testSpringExtensionInject() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/spring-extension-inject.xml"); try { ctx.start(); MockFilter filter = (MockFilter) ExtensionLoader.getExtensionLoader(Filter.class).getExtension("mymock"); assertNotNull(filter.getMockDao()); assertNotNull(filter.getProtocol()); assertNotNull(filter.getLoadBalance()); } finally { ctx.stop(); ctx.close(); } } @Test void testServiceClass() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/service-class.xml"); try { ctx.start(); DemoService demoService = refer("dubbo://127.0.0.1:20887"); String hello = demoService.sayName("hello"); assertEquals("welcome:hello", hello); } finally { ctx.stop(); ctx.close(); } } @Test @Disabled("waiting-to-fix") public void testServiceAnnotation() { DubboBootstrap consumerBootstrap = null; AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext(); try { providerContext.register(ProviderConfiguration.class); providerContext.refresh(); ReferenceConfig<HelloService> reference = new ReferenceConfig<HelloService>(); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(HelloService.class); reference.setUrl("dubbo://127.0.0.1:12345"); consumerBootstrap = DubboBootstrap.newInstance() .application(new ApplicationConfig("consumer")) .reference(reference) .start(); HelloService helloService = consumerBootstrap.getCache().get(reference); String hello = helloService.sayHello("hello"); assertEquals("Hello, hello", hello); } finally { providerContext.close(); if (consumerBootstrap != null) { consumerBootstrap.stop(); } } } @Test @SuppressWarnings("unchecked") public void testProviderNestedService() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/provider-nested-service.xml"); try { ctx.start(); ServiceConfig<DemoService> serviceConfig = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig"); assertNotNull(serviceConfig.getProvider()); assertEquals(2000, serviceConfig.getProvider().getTimeout().intValue()); ServiceConfig<DemoService> serviceConfig2 = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig2"); assertNotNull(serviceConfig2.getProvider()); assertEquals(1000, serviceConfig2.getProvider().getTimeout().intValue()); } finally { ctx.stop(); ctx.close(); } } private DemoService refer(String url) { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl(url); DubboBootstrap bootstrap = DubboBootstrap.newInstance() .application(new ApplicationConfig("consumer")) .reference(reference) .start(); return bootstrap.getCache().get(reference); } @Test @Disabled("waiting-to-fix") public void testToString() { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:20881"); String str = reference.toString(); assertTrue(str.startsWith("<dubbo:reference ")); assertTrue(str.contains(" url=\"dubbo://127.0.0.1:20881\" ")); assertTrue(str.contains(" interface=\"org.apache.dubbo.config.spring.api.DemoService\" ")); assertTrue(str.endsWith(" />")); } @Test @Disabled("waiting-to-fix") public void testForks() { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("consumer")); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:20881"); int forks = 10; reference.setForks(forks); String str = reference.toString(); assertTrue(str.contains("forks=\"" + forks + "\"")); } @Test void testMultiProtocol() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/multi-protocol.xml"); try { ctx.start(); DemoService demoService = refer("dubbo://127.0.0.1:20881"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } } @Test @Disabled("waiting-to-fix") public void testMultiProtocolDefault() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/multi-protocol-default.xml"); try { ctx.start(); DemoService demoService = refer("rmi://127.0.0.1:10991"); String hello = demoService.sayName("hello"); assertEquals("say:hello", hello); } finally { ctx.stop(); ctx.close(); } } @Test @Disabled("waiting-to-fix") public void testMultiProtocolError() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/multi-protocol-error.xml"); try { ctx.start(); ctx.stop(); ctx.close(); fail(); } catch (BeanCreationException e) { assertTrue(e.getMessage().contains("Found multi-protocols")); } finally { try { ctx.close(); } catch (Exception e) { } } } @Test @Disabled("waiting-to-fix") public void testMultiProtocolRegister() { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/multi-protocol-register.xml"); try { ctx.start(); List<URL> urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals( "dubbo://" + NetUtils.getLocalHost() + ":20824/org.apache.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } } @Test @Disabled("waiting-to-fix") public void testMultiRegistry() { SimpleRegistryService registryService1 = new SimpleRegistryService(); Exporter<RegistryService> exporter1 = SimpleRegistryExporter.export(4545, registryService1); SimpleRegistryService registryService2 = new SimpleRegistryService(); Exporter<RegistryService> exporter2 = SimpleRegistryExporter.export(4546, registryService2); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/multi-registry.xml"); try { ctx.start(); List<URL> urls1 = registryService1.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService"); assertNull(urls1); List<URL> urls2 = registryService2.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService"); assertNotNull(urls2); assertEquals(1, urls2.size()); assertEquals( "dubbo://" + NetUtils.getLocalHost() + ":20880/org.apache.dubbo.config.spring.api.DemoService", urls2.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter1.unexport(); exporter2.unexport(); } } @Test @Disabled("waiting-to-fix") public void testDelayFixedTime() throws Exception { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/delay-fixed-time.xml"); try { ctx.start(); List<URL> urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService"); assertNull(urls); int i = 0; while ((i++) < 60 && urls == null) { urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService"); Thread.sleep(10); } assertNotNull(urls); assertEquals(1, urls.size()); assertEquals( "dubbo://" + NetUtils.getLocalHost() + ":20888/org.apache.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } } @Test @Disabled("waiting-to-fix") public void testDelayOnInitialized() throws Exception { SimpleRegistryService registryService = new SimpleRegistryService(); Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/delay-on-initialized.xml"); try { // ctx.start(); List<URL> urls = registryService.getRegistered().get("org.apache.dubbo.config.spring.api.DemoService"); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals( "dubbo://" + NetUtils.getLocalHost() + ":20888/org.apache.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString()); } finally { ctx.stop(); ctx.close(); exporter.unexport(); } } @Test void testRmiTimeout() throws Exception { SystemPropertyConfigUtils.clearSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT); ConsumerConfig consumer = new ConsumerConfig(); consumer.setTimeout(1000); assertEquals("1000", SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT)); consumer.setTimeout(2000); assertEquals("1000", SystemPropertyConfigUtils.getSystemProperty(SYSTEM_TCP_RESPONSE_TIMEOUT)); } @Test @Disabled("waiting-to-fix") public void testAutowireAndAOP() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( resourcePath + "/demo-provider.xml", resourcePath + "/demo-provider-properties.xml"); try { providerContext.start(); ClassPathXmlApplicationContext byNameContext = new ClassPathXmlApplicationContext(resourcePath + "/aop-autowire-byname.xml"); try { byNameContext.start(); DemoActionBySetter demoActionBySetter = (DemoActionBySetter) byNameContext.getBean("demoActionBySetter"); assertNotNull(demoActionBySetter.getDemoService()); assertEquals( "aop:say:hello", demoActionBySetter.getDemoService().sayName("hello")); DemoActionByAnnotation demoActionByAnnotation = (DemoActionByAnnotation) byNameContext.getBean("demoActionByAnnotation"); assertNotNull(demoActionByAnnotation.getDemoService()); assertEquals( "aop:say:hello", demoActionByAnnotation.getDemoService().sayName("hello")); } finally { byNameContext.stop(); byNameContext.close(); } ClassPathXmlApplicationContext byTypeContext = new ClassPathXmlApplicationContext(resourcePath + "/aop-autowire-bytype.xml"); try { byTypeContext.start(); DemoActionBySetter demoActionBySetter = (DemoActionBySetter) byTypeContext.getBean("demoActionBySetter"); assertNotNull(demoActionBySetter.getDemoService()); assertEquals( "aop:say:hello", demoActionBySetter.getDemoService().sayName("hello")); DemoActionByAnnotation demoActionByAnnotation = (DemoActionByAnnotation) byTypeContext.getBean("demoActionByAnnotation"); assertNotNull(demoActionByAnnotation.getDemoService()); assertEquals( "aop:say:hello", demoActionByAnnotation.getDemoService().sayName("hello")); } finally { byTypeContext.stop(); byTypeContext.close(); } } finally { providerContext.stop(); providerContext.close(); } } @Test void testAppendFilter() throws Exception { ApplicationConfig application = new ApplicationConfig("provider"); ProviderConfig provider = new ProviderConfig(); provider.setFilter("classloader,monitor"); ConsumerConfig consumer = new ConsumerConfig(); consumer.setFilter("classloader,monitor"); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setFilter("accesslog,trace"); service.setProvider(provider); service.setProtocol(new ProtocolConfig("dubbo", 20880)); service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setFilter("accesslog,trace"); reference.setConsumer(consumer); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl( "dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false"); try { DubboBootstrap.getInstance() .application(application) .provider(provider) .service(service) .reference(reference) .start(); List<URL> urls = service.getExportedUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter")); urls = reference.getExportedUrls(); assertNotNull(urls); assertEquals(1, urls.size()); assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter")); } finally { DubboBootstrap.getInstance().stop(); } } @Test void testInitReference() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext( resourcePath + "/demo-provider.xml", resourcePath + "/demo-provider-properties.xml"); try { providerContext.start(); // consumer app ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext( resourcePath + "/init-reference.xml", resourcePath + "/init-reference-properties.xml"); try { consumerContext.start(); NotifyService notifyService = consumerContext.getBean(NotifyService.class); // check reference bean Map<String, ReferenceBean> referenceBeanMap = consumerContext.getBeansOfType(ReferenceBean.class); Assertions.assertEquals(2, referenceBeanMap.size()); ReferenceBean referenceBean = referenceBeanMap.get("&demoService"); Assertions.assertNotNull(referenceBean); ReferenceConfig referenceConfig = referenceBean.getReferenceConfig(); // reference parameters Assertions.assertNotNull(referenceConfig.getParameters().get("connec.timeout")); Assertions.assertEquals("demo_tag", referenceConfig.getTag()); // methods Assertions.assertEquals(1, referenceConfig.getMethods().size()); MethodConfig methodConfig = referenceConfig.getMethods().get(0); Assertions.assertEquals("sayName", methodConfig.getName()); Assertions.assertEquals(notifyService, methodConfig.getOninvoke()); Assertions.assertEquals(notifyService, methodConfig.getOnreturn()); Assertions.assertEquals(notifyService, methodConfig.getOnthrow()); Assertions.assertEquals("onInvoke", methodConfig.getOninvokeMethod()); Assertions.assertEquals("onReturn", methodConfig.getOnreturnMethod()); Assertions.assertEquals("onThrow", methodConfig.getOnthrowMethod()); // method arguments Assertions.assertEquals(1, methodConfig.getArguments().size()); ArgumentConfig argumentConfig = methodConfig.getArguments().get(0); Assertions.assertEquals(0, argumentConfig.getIndex()); Assertions.assertEquals(true, argumentConfig.isCallback()); // method parameters Assertions.assertEquals(1, methodConfig.getParameters().size()); Assertions.assertEquals("my-token", methodConfig.getParameters().get("access-token")); // do call DemoService demoService = (DemoService) consumerContext.getBean("demoService"); assertEquals("say:world", demoService.sayName("world")); GenericService demoService2 = (GenericService) consumerContext.getBean("demoService2"); assertEquals( "say:world", demoService2.$invoke("sayName", new String[] {"java.lang.String"}, new Object[] {"world"})); } finally { consumerContext.stop(); consumerContext.close(); } } finally { providerContext.stop(); providerContext.close(); } } // DUBBO-571 methods key in provider's URLONE doesn't contain the methods from inherited super interface @Test void test_noMethodInterface_methodsKeyHasValue() throws Exception { List<URL> urls = null; ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/demo-provider-no-methods-interface.xml"); try { ctx.start(); ServiceBean bean = (ServiceBean) ctx.getBean("service"); urls = bean.getExportedUrls(); assertEquals(1, urls.size()); URL url = urls.get(0); assertEquals("getBox,sayName", url.getParameter("methods")); } finally { ctx.stop(); ctx.close(); // Check if the port is closed if (urls != null) { for (URL url : urls) { Assertions.assertFalse(NetUtils.isPortInUsed(url.getPort())); } } } } // DUBBO-147 find all invoker instances which have been tried from RpcContext @Disabled("waiting-to-fix") @Test void test_RpcContext_getUrls() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(resourcePath + "/demo-provider-long-waiting.xml"); try { providerContext.start(); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/init-reference-getUrls.xml"); try { ctx.start(); DemoService demoService = (DemoService) ctx.getBean("demoService"); try { demoService.sayName("Haha"); fail(); } catch (RpcException expected) { assertThat(expected.getMessage(), containsString("Tried 3 times")); } assertEquals(3, RpcContext.getServiceContext().getUrls().size()); } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } } // BUG: DUBBO-846 in version 2.0.9, config retry="false" on provider's method doesn't work @Test @Disabled("waiting-to-fix") public void test_retrySettingFail() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(resourcePath + "/demo-provider-long-waiting.xml"); try { providerContext.start(); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(resourcePath + "/init-reference-retry-false.xml"); try { ctx.start(); DemoService demoService = (DemoService) ctx.getBean("demoService"); try { demoService.sayName("Haha"); fail(); } catch (RpcException expected) { assertThat(expected.getMessage(), containsString("Tried 1 times")); } assertEquals(1, RpcContext.getServiceContext().getUrls().size()); } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } } // BuG: DUBBO-146 Provider doesn't have exception output, and consumer has timeout error when serialization fails // for example, object transported on the wire doesn't implement Serializable @Test @Disabled("waiting-to-fix") public void test_returnSerializationFail() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(resourcePath + "/demo-provider-UnserializableBox.xml"); try { providerContext.start(); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( resourcePath + "/init-reference.xml", resourcePath + "/init-reference-properties.xml"); try { ctx.start(); DemoService demoService = (DemoService) ctx.getBean("demoService"); try { demoService.getBox(); fail(); } catch (RpcException expected) { assertThat(expected.getMessage(), containsString("must implement java.io.Serializable")); } } finally { ctx.stop(); ctx.close(); } } finally { providerContext.stop(); providerContext.close(); } } @Test @Disabled("waiting-to-fix") public void testXmlOverrideProperties() throws Exception { ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(resourcePath + "/xml-override-properties.xml"); try { providerContext.start(); ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application"); assertEquals("demo-provider", application.getName()); assertEquals("world", application.getOwner()); RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry"); assertEquals("N/A", registry.getAddress()); ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo"); assertEquals(20813, dubbo.getPort().intValue()); } finally { providerContext.stop(); providerContext.close(); } } @Test @Disabled("waiting-to-fix") public void testApiOverrideProperties() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("api-override-properties"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("N/A"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); protocol.setPort(13123); ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setInterface(DemoService.class); service.setRef(new DemoServiceImpl()); service.setRegistry(registry); service.setProtocol(protocol); ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:13123"); try { DubboBootstrap.getInstance() .application(application) .registry(registry) .protocol(protocol) .service(service) .reference(reference) .start(); URL url = service.getExportedUrls().get(0); assertEquals("api-override-properties", url.getParameter("application")); assertEquals("world", url.getParameter("owner")); assertEquals(13123, url.getPort()); url = reference.getExportedUrls().get(0); assertEquals("2000", url.getParameter("timeout")); } finally { DubboBootstrap.getInstance().stop(); } } @Test void testSystemPropertyOverrideProtocol() throws Exception { SysProps.setProperty("dubbo.protocols.tri.port", ""); // empty config should be ignored SysProps.setProperty("dubbo.protocols.dubbo.port", "20812"); // override success SysProps.setProperty("dubbo.protocol.port", "20899"); // override fail ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(resourcePath + "/override-protocol.xml"); try { providerContext.start(); ConfigManager configManager = ApplicationModel.defaultModel().getApplicationConfigManager(); ProtocolConfig protocol = configManager.getProtocol("dubbo").get(); assertEquals(20812, protocol.getPort()); } finally { providerContext.close(); } } @Test void testSystemPropertyOverrideMultiProtocol() throws Exception { SysProps.setProperty("dubbo.protocols.dubbo.port", "20814"); SysProps.setProperty("dubbo.protocols.tri.port", "10914"); ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(resourcePath + "/override-multi-protocol.xml"); try { providerContext.start(); ConfigManager configManager = ApplicationModel.defaultModel().getApplicationConfigManager(); ProtocolConfig dubboProtocol = configManager.getProtocol("dubbo").get();
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
true
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/AbstractRegistryService.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/AbstractRegistryService.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.config.spring; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.RegistryService; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_FAILED_NOTIFY_EVENT; public abstract class AbstractRegistryService implements RegistryService { // logger protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass()); // registered services // Map<serviceName, Map<url, queryString>> private final ConcurrentMap<String, List<URL>> registered = new ConcurrentHashMap<String, List<URL>>(); // subscribed services // Map<serviceName, queryString> private final ConcurrentMap<String, Map<String, String>> subscribed = new ConcurrentHashMap<String, Map<String, String>>(); // notified services // Map<serviceName, Map<url, queryString>> private final ConcurrentMap<String, List<URL>> notified = new ConcurrentHashMap<String, List<URL>>(); // notification listeners for the subscribed services // Map<serviceName, List<notificationListener>> private final ConcurrentMap<String, List<NotifyListener>> notifyListeners = new ConcurrentHashMap<String, List<NotifyListener>>(); @Override public void register(URL url) { if (logger.isInfoEnabled()) { logger.info("Register service: " + url.getServiceKey() + ",url:" + url); } register(url.getServiceKey(), url); } @Override public void unregister(URL url) { if (logger.isInfoEnabled()) { logger.info("Unregister service: " + url.getServiceKey() + ",url:" + url); } unregister(url.getServiceKey(), url); } @Override public void subscribe(URL url, NotifyListener listener) { if (logger.isInfoEnabled()) { logger.info("Subscribe service: " + url.getServiceKey() + ",url:" + url); } subscribe(url.getServiceKey(), url, listener); } @Override public void unsubscribe(URL url, NotifyListener listener) { if (logger.isInfoEnabled()) { logger.info("Unsubscribe service: " + url.getServiceKey() + ",url:" + url); } unsubscribe(url.getServiceKey(), url, listener); } @Override public List<URL> lookup(URL url) { return getRegistered(url.getServiceKey()); } public void register(String service, URL url) { if (service == null) { throw new IllegalArgumentException("service == null"); } if (url == null) { throw new IllegalArgumentException("url == null"); } List<URL> urls = ConcurrentHashMapUtils.computeIfAbsent(registered, service, k -> new CopyOnWriteArrayList<>()); if (!urls.contains(url)) { urls.add(url); } } public void unregister(String service, URL url) { if (service == null) { throw new IllegalArgumentException("service == null"); } if (url == null) { throw new IllegalArgumentException("url == null"); } List<URL> urls = registered.get(service); if (urls != null) { URL deleteURL = null; for (URL u : urls) { if (u.toIdentityString().equals(url.toIdentityString())) { deleteURL = u; break; } } if (deleteURL != null) { urls.remove(deleteURL); } } } public void subscribe(String service, URL url, NotifyListener listener) { if (service == null) { throw new IllegalArgumentException("service == null"); } if (url == null) { throw new IllegalArgumentException("parameters == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } subscribed.put(service, url.getParameters()); addListener(service, listener); } public void unsubscribe(String service, URL url, NotifyListener listener) { if (service == null) { throw new IllegalArgumentException("service == null"); } if (url == null) { throw new IllegalArgumentException("parameters == null"); } if (listener == null) { throw new IllegalArgumentException("listener == null"); } subscribed.remove(service); removeListener(service, listener); } private void addListener(final String service, final NotifyListener listener) { if (listener == null) { return; } List<NotifyListener> listeners = ConcurrentHashMapUtils.computeIfAbsent(notifyListeners, service, k -> new CopyOnWriteArrayList<>()); if (!listeners.contains(listener)) { listeners.add(listener); } } private void removeListener(final String service, final NotifyListener listener) { if (listener == null) { return; } List<NotifyListener> listeners = notifyListeners.get(service); if (listeners != null) { listeners.remove(listener); } } private void doNotify(String service, List<URL> urls) { notified.put(service, urls); List<NotifyListener> listeners = notifyListeners.get(service); if (listeners != null) { for (NotifyListener listener : listeners) { try { notify(service, urls, listener); } catch (Throwable t) { logger.error( CONFIG_FAILED_NOTIFY_EVENT, "", "", "Failed to notify registry event, service: " + service + ", urls: " + urls + ", cause: " + t.getMessage(), t); } } } } protected void notify(String service, List<URL> urls, NotifyListener listener) { listener.notify(urls); } protected final void forbid(String service) { doNotify(service, new ArrayList<URL>(0)); } protected final void notify(String service, List<URL> urls) { if (StringUtils.isEmpty(service) || CollectionUtils.isEmpty(urls)) { return; } doNotify(service, urls); } public Map<String, List<URL>> getRegistered() { return Collections.unmodifiableMap(registered); } public List<URL> getRegistered(String service) { return Collections.unmodifiableList(registered.get(service)); } public Map<String, Map<String, String>> getSubscribed() { return Collections.unmodifiableMap(subscribed); } public Map<String, String> getSubscribed(String service) { return subscribed.get(service); } public Map<String, List<URL>> getNotified() { return Collections.unmodifiableMap(notified); } public List<URL> getNotified(String service) { return Collections.unmodifiableList(notified.get(service)); } public Map<String, List<NotifyListener>> getListeners() { return Collections.unmodifiableMap(notifyListeners); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryExporter.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SimpleRegistryExporter.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.config.spring; import org.apache.dubbo.common.URLBuilder; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.registry.RegistryService; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; import static org.apache.dubbo.common.constants.CommonConstants.CALLBACK_INSTANCES_LIMIT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_STICKY_KEY; public class SimpleRegistryExporter { private static final Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension(); private static final ProxyFactory PROXY_FACTORY = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension(); public static synchronized Exporter<RegistryService> exportIfAbsent(int port) { try { ServerSocket serverSocket = new ServerSocket(); if (NetUtils.isReuseAddressSupported()) { // SO_REUSEADDR should be enabled before bind. serverSocket.setReuseAddress(true); } serverSocket.bind(new InetSocketAddress(port)); serverSocket.close(); return export(port); } catch (IOException e) { return null; } } public static Exporter<RegistryService> export(int port) { return export(port, new SimpleRegistryService()); } public static Exporter<RegistryService> export(int port, RegistryService registryService) { return protocol.export(PROXY_FACTORY.getInvoker( registryService, RegistryService.class, new URLBuilder(DUBBO_PROTOCOL, NetUtils.getLocalHost(), port, RegistryService.class.getName()) .setPath(RegistryService.class.getName()) .addParameter(INTERFACE_KEY, RegistryService.class.getName()) .addParameter(CLUSTER_STICKY_KEY, "true") .addParameter(CALLBACK_INSTANCES_LIMIT_KEY, "1000") .addParameter("ondisconnect", "disconnect") .addParameter("subscribe.1.callback", "true") .addParameter("unsubscribe.1.callback", "false") .build())); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/GenericDemoService.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/GenericDemoService.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.config.spring; import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService; public class GenericDemoService implements GenericService { public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ControllerServiceConfigTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ControllerServiceConfigTest.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.config.spring; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.spring.api.SpringControllerService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @Disabled public class ControllerServiceConfigTest { @Test void testServiceConfig() { ServiceConfig<SpringControllerService> serviceServiceConfig = new ServiceConfig<>(); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("dubbo"); serviceServiceConfig.setApplication(applicationConfig); serviceServiceConfig.setProtocol(new ProtocolConfig("dubbo", 8080)); serviceServiceConfig.setRef(new SpringControllerService()); serviceServiceConfig.setInterface(SpringControllerService.class.getName()); serviceServiceConfig.export(); serviceServiceConfig.unexport(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/EmbeddedZooKeeper.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/EmbeddedZooKeeper.java
/* * Copyright 2014 the original author or authors. * * Licensed 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.config.spring; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.utils.SystemPropertyConfigUtils; import org.apache.dubbo.test.common.utils.TestSocketUtils; import org.apache.zookeeper.server.ServerConfig; import org.apache.zookeeper.server.ZooKeeperServerMain; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; import org.springframework.context.SmartLifecycle; import org.springframework.util.ErrorHandler; import java.io.File; import java.lang.reflect.Method; import java.util.Properties; import java.util.UUID; import static org.apache.dubbo.common.constants.CommonConstants.SystemProperty.SYSTEM_JAVA_IO_TMPDIR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_INIT_ZOOKEEPER_SERVER_ERROR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER; /** * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java * <p> * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper. * <p> * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication} */ public class EmbeddedZooKeeper implements SmartLifecycle { /** * Logger. */ private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(EmbeddedZooKeeper.class); /** * ZooKeeper client port. This will be determined dynamically upon startup. */ private final int clientPort; /** * Whether to auto-start. Default is true. */ private boolean autoStartup = true; /** * Lifecycle phase. Default is 0. */ private int phase = 0; /** * Thread for running the ZooKeeper server. */ private volatile Thread zkServerThread; /** * ZooKeeper server. */ private volatile ZooKeeperServerMain zkServer; /** * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. */ private ErrorHandler errorHandler; private boolean daemon = true; /** * Construct an EmbeddedZooKeeper with a random port. */ public EmbeddedZooKeeper() { clientPort = TestSocketUtils.findAvailableTcpPort(); } /** * Construct an EmbeddedZooKeeper with the provided port. * * @param clientPort port for ZooKeeper server to bind to */ public EmbeddedZooKeeper(int clientPort, boolean daemon) { this.clientPort = clientPort; this.daemon = daemon; } /** * Returns the port that clients should use to connect to this embedded server. * * @return dynamically determined client port */ public int getClientPort() { return this.clientPort; } /** * Specify whether to start automatically. Default is true. * * @param autoStartup whether to start automatically */ public void setAutoStartup(boolean autoStartup) { this.autoStartup = autoStartup; } /** * {@inheritDoc} */ @Override public boolean isAutoStartup() { return this.autoStartup; } /** * Specify the lifecycle phase for the embedded server. * * @param phase the lifecycle phase */ public void setPhase(int phase) { this.phase = phase; } /** * {@inheritDoc} */ @Override public int getPhase() { return this.phase; } /** * {@inheritDoc} */ @Override public boolean isRunning() { return (zkServerThread != null); } /** * Start the ZooKeeper server in a background thread. * <p> * Register an error handler via {@link #setErrorHandler} in order to handle * any exceptions thrown during startup or execution. */ @Override public synchronized void start() { if (zkServerThread == null) { zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter"); zkServerThread.setDaemon(daemon); zkServerThread.start(); } } /** * Shutdown the ZooKeeper server. */ @Override public synchronized void stop() { if (zkServerThread != null) { // The shutdown method is protected...thus this hack to invoke it. // This will log an exception on shutdown; see // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details. try { Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown"); shutdown.setAccessible(true); shutdown.invoke(zkServer); } catch (Exception e) { throw new RuntimeException(e); } // It is expected that the thread will exit after // the server is shutdown; this will block until // the shutdown is complete. try { zkServerThread.join(5000); zkServerThread = null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.warn(TESTING_REGISTRY_FAILED_TO_STOP_ZOOKEEPER, "", "", "Interrupted while waiting for embedded ZooKeeper to exit"); // abandoning zk thread zkServerThread = null; } } } /** * Stop the server if running and invoke the callback when complete. */ @Override public void stop(Runnable callback) { stop(); callback.run(); } /** * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none * is provided, only error-level logging will occur. * * @param errorHandler the {@link ErrorHandler} to be invoked */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; } /** * Runnable implementation that starts the ZooKeeper server. */ private class ServerRunnable implements Runnable { @Override public void run() { try { Properties properties = new Properties(); File file = new File(SystemPropertyConfigUtils.getSystemProperty(SYSTEM_JAVA_IO_TMPDIR) + File.separator + UUID.randomUUID()); file.deleteOnExit(); properties.setProperty("dataDir", file.getAbsolutePath()); properties.setProperty("clientPort", String.valueOf(clientPort)); QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); quorumPeerConfig.parseProperties(properties); zkServer = new ZooKeeperServerMain(); ServerConfig configuration = new ServerConfig(); configuration.readFrom(quorumPeerConfig); zkServer.runFromConfig(configuration); } catch (Exception e) { if (errorHandler != null) { errorHandler.handleError(e); } else { logger.error(TESTING_INIT_ZOOKEEPER_SERVER_ERROR, "ZooKeeper server error", "", "Exception running embedded ZooKeeper.", e); } } } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/DubboStateListener.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/DubboStateListener.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.config.spring; import org.apache.dubbo.common.deploy.DeployState; import org.apache.dubbo.config.spring.context.event.DubboApplicationStateEvent; import org.springframework.context.ApplicationListener; public class DubboStateListener implements ApplicationListener<DubboApplicationStateEvent> { private DeployState state; @Override public void onApplicationEvent(DubboApplicationStateEvent event) { state = event.getState(); } public DeployState getState() { return state; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SysProps.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/SysProps.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.config.spring; import java.util.LinkedHashMap; import java.util.Map; /** * Use to set and clear System property */ public class SysProps { private static Map<String, String> map = new LinkedHashMap<String, String>(); public static void reset() { map.clear(); } public static void setProperty(String key, String value) { map.put(key, value); System.setProperty(key, value); } public static void clear() { for (String key : map.keySet()) { System.clearProperty(key); } reset(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/util/EnvironmentUtilsTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/util/EnvironmentUtilsTest.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.config.spring.util; import java.util.HashMap; import java.util.Map; import java.util.SortedMap; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.StandardEnvironment; import org.springframework.mock.env.MockEnvironment; import static org.apache.dubbo.config.spring.util.EnvironmentUtils.filterDubboProperties; /** * {@link EnvironmentUtils} Test * * @see EnvironmentUtils * @since 2.7.0 */ class EnvironmentUtilsTest { @Test void testExtraProperties() { String key = "test.name"; System.setProperty(key, "Tom"); try { StandardEnvironment environment = new StandardEnvironment(); Map<String, Object> map = new HashMap<>(); map.put(key, "Mercy"); MapPropertySource propertySource = new MapPropertySource("first", map); CompositePropertySource compositePropertySource = new CompositePropertySource("comp"); compositePropertySource.addFirstPropertySource(propertySource); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(compositePropertySource); Map<String, Object> properties = EnvironmentUtils.extractProperties(environment); Assertions.assertEquals("Mercy", properties.get(key)); } finally { System.clearProperty(key); } } @Test void testFilterDubboProperties() { MockEnvironment environment = new MockEnvironment(); environment.setProperty("message", "Hello,World"); environment.setProperty("dubbo.registry.address", "zookeeper://10.10.10.1:2181"); environment.setProperty("dubbo.consumer.check", "false"); SortedMap<String, String> dubboProperties = filterDubboProperties(environment); Assertions.assertEquals(2, dubboProperties.size()); Assertions.assertEquals("zookeeper://10.10.10.1:2181", dubboProperties.get("dubbo.registry.address")); Assertions.assertEquals("false", dubboProperties.get("dubbo.consumer.check")); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceCreatorTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceCreatorTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.ArgumentConfig; import org.apache.dubbo.config.ConsumerConfig; import org.apache.dubbo.config.MethodConfig; import org.apache.dubbo.config.ModuleConfig; import org.apache.dubbo.config.MonitorConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.annotation.Argument; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.impl.NotifyService; import org.apache.dubbo.config.spring.reference.ReferenceCreator; import org.apache.dubbo.config.spring.util.AnnotationUtils; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ModuleModel; import java.lang.reflect.Field; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.apache.dubbo.common.utils.CollectionUtils.ofSet; import static org.springframework.core.annotation.AnnotationUtils.findAnnotation; import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; import static org.springframework.util.ReflectionUtils.findField; /** * {@link ReferenceCreator} Test * * @see ReferenceCreator * @see DubboReference * @see Reference * @since 2.6.4 */ @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {ReferenceCreatorTest.class, ReferenceCreatorTest.ConsumerConfiguration.class}) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) class ReferenceCreatorTest { private static final String MODULE_CONFIG_ID = "mymodule"; private static final String CONSUMER_CONFIG_ID = "myconsumer"; private static final String MONITOR_CONFIG_ID = "mymonitor"; private static final String REGISTRY_CONFIG_ID = "myregistry"; @DubboReference( // interfaceClass = HelloService.class, version = "1.0.0", group = "TEST_GROUP", url = "dubbo://localhost:12345", client = "client", generic = false, injvm = false, check = false, init = false, lazy = true, stubevent = true, reconnect = "reconnect", sticky = true, proxy = "javassist", stub = "org.apache.dubbo.config.spring.api.HelloService", cluster = "failover", connections = 3, callbacks = 1, onconnect = "onconnect", ondisconnect = "ondisconnect", owner = "owner", layer = "layer", retries = 1, loadbalance = "random", async = true, actives = 3, sent = true, mock = "mock", validation = "validation", timeout = 3, cache = "cache", filter = {"echo", "generic", "accesslog"}, listener = {"deprecated"}, parameters = {"n1=v1 ", "n2 = v2 ", " n3 = v3 "}, application = "application", module = MODULE_CONFIG_ID, consumer = CONSUMER_CONFIG_ID, monitor = MONITOR_CONFIG_ID, registry = {REGISTRY_CONFIG_ID}, // @since 2.7.3 id = "reference", // @since 2.7.8 services = {"service1", "service2", "service3", "service2", "service1"}, providedBy = {"service1", "service2", "service3"}, methods = @Method( name = "sayHello", isReturn = false, loadbalance = "loadbalance", oninvoke = "notifyService.onInvoke", onreturn = "notifyService.onReturn", onthrow = "notifyService.onThrow", timeout = 1000, retries = 2, parameters = {"a", "1", "b", "2"}, arguments = @Argument(index = 0, callback = true))) private HelloService helloService; @Autowired private ApplicationContext context; @Autowired private NotifyService notifyService; @BeforeAll public static void setUp() { DubboBootstrap.reset(); } @Test void testBuild() throws Exception { Field helloServiceField = findField(getClass(), "helloService"); DubboReference reference = findAnnotation(helloServiceField, DubboReference.class); // filter default value AnnotationAttributes attributes = AnnotationUtils.getAnnotationAttributes(reference, true); ReferenceConfig referenceBean = ReferenceCreator.create(attributes, context) .defaultInterfaceClass(helloServiceField.getType()) .build(); Assertions.assertEquals(HelloService.class, referenceBean.getInterfaceClass()); Assertions.assertEquals("org.apache.dubbo.config.spring.api.HelloService", referenceBean.getInterface()); Assertions.assertEquals("1.0.0", referenceBean.getVersion()); Assertions.assertEquals("TEST_GROUP", referenceBean.getGroup()); Assertions.assertEquals("dubbo://localhost:12345", referenceBean.getUrl()); Assertions.assertEquals("client", referenceBean.getClient()); Assertions.assertEquals(null, referenceBean.isGeneric()); Assertions.assertEquals(false, referenceBean.isInjvm()); Assertions.assertEquals(false, referenceBean.isCheck()); Assertions.assertEquals(false, referenceBean.isInit()); Assertions.assertEquals(true, referenceBean.getLazy()); Assertions.assertEquals(true, referenceBean.getStubevent()); Assertions.assertEquals("reconnect", referenceBean.getReconnect()); Assertions.assertEquals(true, referenceBean.getSticky()); Assertions.assertEquals("javassist", referenceBean.getProxy()); Assertions.assertEquals("org.apache.dubbo.config.spring.api.HelloService", referenceBean.getStub()); Assertions.assertEquals("failover", referenceBean.getCluster()); Assertions.assertEquals(Integer.valueOf(3), referenceBean.getConnections()); Assertions.assertEquals(Integer.valueOf(1), referenceBean.getCallbacks()); Assertions.assertEquals("onconnect", referenceBean.getOnconnect()); Assertions.assertEquals("ondisconnect", referenceBean.getOndisconnect()); Assertions.assertEquals("owner", referenceBean.getOwner()); Assertions.assertEquals("layer", referenceBean.getLayer()); Assertions.assertEquals(Integer.valueOf(1), referenceBean.getRetries()); Assertions.assertEquals("random", referenceBean.getLoadbalance()); Assertions.assertEquals(true, referenceBean.isAsync()); Assertions.assertEquals(Integer.valueOf(3), referenceBean.getActives()); Assertions.assertEquals(true, referenceBean.getSent()); Assertions.assertEquals("mock", referenceBean.getMock()); Assertions.assertEquals("validation", referenceBean.getValidation()); Assertions.assertEquals(Integer.valueOf(3), referenceBean.getTimeout()); Assertions.assertEquals("cache", referenceBean.getCache()); Assertions.assertEquals("echo,generic,accesslog", referenceBean.getFilter()); Assertions.assertEquals("deprecated", referenceBean.getListener()); Assertions.assertEquals("reference", referenceBean.getId()); Assertions.assertEquals(ofSet("service1", "service2", "service3"), referenceBean.getSubscribedServices()); Assertions.assertEquals("service1,service2,service3", referenceBean.getProvidedBy()); Assertions.assertEquals(REGISTRY_CONFIG_ID, referenceBean.getRegistryIds()); // parameters Map<String, String> parameters = new HashMap<String, String>(); parameters.put("n1", "v1"); parameters.put("n2", "v2"); parameters.put("n3", "v3"); Assertions.assertEquals(parameters, referenceBean.getParameters()); // methods List<MethodConfig> methods = referenceBean.getMethods(); Assertions.assertNotNull(methods); Assertions.assertEquals(1, methods.size()); MethodConfig methodConfig = methods.get(0); Assertions.assertEquals("sayHello", methodConfig.getName()); Assertions.assertEquals(false, methodConfig.isReturn()); Assertions.assertEquals(1000, methodConfig.getTimeout()); Assertions.assertEquals(2, methodConfig.getRetries()); Assertions.assertEquals("loadbalance", methodConfig.getLoadbalance()); Assertions.assertEquals(notifyService, methodConfig.getOninvoke()); Assertions.assertEquals(notifyService, methodConfig.getOnreturn()); Assertions.assertEquals(notifyService, methodConfig.getOnthrow()); Assertions.assertEquals("onInvoke", methodConfig.getOninvokeMethod()); Assertions.assertEquals("onReturn", methodConfig.getOnreturnMethod()); Assertions.assertEquals("onThrow", methodConfig.getOnthrowMethod()); // method parameters Map<String, String> methodParameters = new HashMap<String, String>(); methodParameters.put("a", "1"); methodParameters.put("b", "2"); Assertions.assertEquals(methodParameters, methodConfig.getParameters()); // method arguments List<ArgumentConfig> arguments = methodConfig.getArguments(); Assertions.assertEquals(1, arguments.size()); ArgumentConfig argumentConfig = arguments.get(0); Assertions.assertEquals(0, argumentConfig.getIndex()); Assertions.assertEquals(true, argumentConfig.isCallback()); // Asserts Null fields Assertions.assertThrows(IllegalStateException.class, referenceBean::getApplication); Assertions.assertNotNull(referenceBean.getModule()); Assertions.assertNotNull(referenceBean.getConsumer()); Assertions.assertNotNull(referenceBean.getMonitor()); } @Configuration public static class ConsumerConfiguration { @Bean public NotifyService notifyService() { return new NotifyService(); } @Bean("org.apache.dubbo.rpc.model.ModuleModel") public ModuleModel moduleModel() { return ApplicationModel.defaultModel().getDefaultModule(); } @Bean(CONSUMER_CONFIG_ID) public ConsumerConfig consumerConfig() { return new ConsumerConfig(); } @Bean(MONITOR_CONFIG_ID) public MonitorConfig monitorConfig() { return new MonitorConfig(); } @Bean(MODULE_CONFIG_ID) public ModuleConfig moduleConfig() { return new ModuleConfig(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MergedAnnotationTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MergedAnnotationTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.annotation.merged.MergedReference; import org.apache.dubbo.config.spring.annotation.merged.MergedService; import org.apache.dubbo.config.spring.api.DemoService; import java.lang.reflect.Field; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.util.ReflectionUtils; class MergedAnnotationTest { @Test void testMergedReference() { Field field = ReflectionUtils.findField(TestBean1.class, "demoService"); Reference reference = AnnotatedElementUtils.getMergedAnnotation(field, Reference.class); Assertions.assertEquals("dubbo", reference.group()); Assertions.assertEquals("1.0.0", reference.version()); Field field2 = ReflectionUtils.findField(TestBean2.class, "demoService"); Reference reference2 = AnnotatedElementUtils.getMergedAnnotation(field2, Reference.class); Assertions.assertEquals("group", reference2.group()); Assertions.assertEquals("2.0", reference2.version()); } @Test void testMergedService() { Service service1 = AnnotatedElementUtils.getMergedAnnotation(DemoServiceImpl1.class, Service.class); Assertions.assertEquals("dubbo", service1.group()); Assertions.assertEquals("1.0.0", service1.version()); Service service2 = AnnotatedElementUtils.getMergedAnnotation(DemoServiceImpl2.class, Service.class); Assertions.assertEquals("group", service2.group()); Assertions.assertEquals("2.0", service2.version()); } @MergedService public static class DemoServiceImpl1 {} @MergedService(group = "group", version = "2.0") public static class DemoServiceImpl2 {} private static class TestBean1 { @MergedReference private DemoService demoService; } private static class TestBean2 { @MergedReference(group = "group", version = "2.0") private DemoService demoService; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ParameterConvertTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ParameterConvertTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.spring.util.DubboAnnotationUtils; import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; /** * {@link DubboAnnotationUtils#convertParameters} Test */ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) class ParameterConvertTest { @Test void test() { /** * (array->map) * ["a","b"] ==> {a=b} * [" a "," b "] ==> {a=b} * ["a=b"] ==>{a=b} * ["a:b"] ==>{a=b} * ["a=b","c","d"] ==>{a=b,c=d} * ["a=b","c:d"] ==>{a=b,c=d} * ["a","a:b"] ==>{a=a:b} */ Map<String, String> parametersMap = new HashMap<>(); parametersMap.put("a", "b"); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a", "b"})); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {" a ", " b "})); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a=b"})); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a:b"})); parametersMap.put("c", "d"); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a=b", "c", "d"})); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a:b", "c=d"})); parametersMap.clear(); parametersMap.put("a", "a:b"); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a", "a:b"})); parametersMap.clear(); parametersMap.put("a", "0,100"); Assertions.assertEquals(parametersMap, DubboAnnotationUtils.convertParameters(new String[] {"a", "0,100"})); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessorTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessorTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import java.util.Map; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; /** * {@link ServiceAnnotationPostProcessor} Test * * @since 2.7.7 */ @ExtendWith(SpringExtension.class) @ContextConfiguration( classes = { ServiceAnnotationTestConfiguration.class, ServiceAnnotationPostProcessorTest.class, ServiceAnnotationPostProcessorTest.DuplicatedScanConfig.class }) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @TestPropertySource( properties = { "provider.package = org.apache.dubbo.config.spring.context.annotation.provider", }) @EnableDubbo(scanBasePackages = "${provider.package}") class ServiceAnnotationPostProcessorTest { @BeforeAll public static void setUp() { DubboBootstrap.reset(); } @AfterEach public void tearDown() { DubboBootstrap.reset(); } @Autowired private ConfigurableListableBeanFactory beanFactory; @Test void test() { Map<String, HelloService> helloServicesMap = beanFactory.getBeansOfType(HelloService.class); Assertions.assertEquals(2, helloServicesMap.size()); Map<String, ServiceBean> serviceBeansMap = beanFactory.getBeansOfType(ServiceBean.class); Assertions.assertEquals(3, serviceBeansMap.size()); Map<String, ServiceAnnotationPostProcessor> beanPostProcessorsMap = beanFactory.getBeansOfType(ServiceAnnotationPostProcessor.class); Assertions.assertEquals(2, beanPostProcessorsMap.size()); } @Test void testMethodAnnotation() { Map<String, ServiceBean> serviceBeansMap = beanFactory.getBeansOfType(ServiceBean.class); Assertions.assertEquals(3, serviceBeansMap.size()); ServiceBean demoServiceBean = serviceBeansMap.get("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:2.5.7:"); Assertions.assertNotNull(demoServiceBean.getMethods()); } @DubboComponentScan({"org.apache.dubbo.config.spring.context.annotation", "${provider.package}"}) static class DuplicatedScanConfig {} }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/MethodConfigCallbackTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.api.MethodCallback; import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; import org.apache.dubbo.config.spring.impl.MethodCallbackImpl; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.awaitility.Awaitility.await; @ExtendWith(SpringExtension.class) @ContextConfiguration( classes = { ProviderConfiguration.class, MethodConfigCallbackTest.class, MethodConfigCallbackTest.MethodCallbackConfiguration.class }) @TestPropertySource(properties = {"dubbo.protocol.port=-1", "dubbo.registry.address=${zookeeper.connection.address}"}) @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) class MethodConfigCallbackTest { @BeforeAll public static void beforeAll() { DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); } @Autowired private ConfigurableApplicationContext context; @DubboReference( check = false, async = true, injvm = false, // Currently, local call is not supported method callback cause by Injvm protocol is not // supported ClusterFilter methods = { @Method( name = "sayHello", oninvoke = "methodCallback.oninvoke1", onreturn = "methodCallback.onreturn1", onthrow = "methodCallback.onthrow1") }) private HelloService helloServiceMethodCallBack; @DubboReference( check = false, async = true, injvm = false, // Currently, local call is not supported method callback cause by Injvm protocol is not // supported ClusterFilter methods = { @Method( name = "sayHello", oninvoke = "methodCallback.oninvoke2", onreturn = "methodCallback.onreturn2", onthrow = "methodCallback.onthrow2") }) private HelloService helloServiceMethodCallBack2; @Test void testMethodAnnotationCallBack() { int threadCnt = Math.min(4, Runtime.getRuntime().availableProcessors()); int callCnt = 2 * threadCnt; for (int i = 0; i < threadCnt; i++) { new Thread(() -> { for (int j = 0; j < callCnt; j++) { helloServiceMethodCallBack.sayHello("dubbo"); helloServiceMethodCallBack2.sayHello("dubbo(2)"); } }) .start(); } await().until(() -> MethodCallbackImpl.cnt.get() >= (2 * threadCnt * callCnt)); MethodCallback notify = (MethodCallback) context.getBean("methodCallback"); StringBuilder invoke1Builder = new StringBuilder(); StringBuilder invoke2Builder = new StringBuilder(); StringBuilder return1Builder = new StringBuilder(); StringBuilder return2Builder = new StringBuilder(); for (int i = 0; i < threadCnt * callCnt; i++) { invoke1Builder.append("dubbo invoke success!"); invoke2Builder.append("dubbo invoke success(2)!"); return1Builder.append("dubbo return success!"); return2Builder.append("dubbo return success(2)!"); } Assertions.assertEquals(invoke1Builder.toString(), notify.getOnInvoke1()); Assertions.assertEquals(return1Builder.toString(), notify.getOnReturn1()); Assertions.assertEquals(invoke2Builder.toString(), notify.getOnInvoke2()); Assertions.assertEquals(return2Builder.toString(), notify.getOnReturn2()); } @Configuration static class MethodCallbackConfiguration { @Bean("methodCallback") public MethodCallback methodCallback() { return new MethodCallbackImpl(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.annotation.Service; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.PropertySource; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; import org.springframework.transaction.TransactionStatus; /** * {@link Service} Bean * * @since 2.6.5 */ @PropertySource("classpath:/META-INF/default.properties") public class ServiceAnnotationTestConfiguration { /** * Current application configuration, to replace XML config: * <prev> * &lt;dubbo:application name="dubbo-demo-application"/&gt; * </prev> * * @return {@link ApplicationConfig} Bean */ @Bean("dubbo-demo-application") public ApplicationConfig applicationConfig() { ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("dubbo-demo-application"); return applicationConfig; } /** * Current registry center configuration, to replace XML config: * <prev> * &lt;dubbo:registry id="my-registry" address="N/A"/&gt; * </prev> * * @return {@link RegistryConfig} Bean */ @Bean("my-registry") public RegistryConfig registryConfig() { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("N/A"); return registryConfig; } /** * Current protocol configuration, to replace XML config: * <prev> * &lt;dubbo:protocol name="dubbo" port="12345"/&gt; * </prev> * * @return {@link ProtocolConfig} Bean */ @Bean // ("dubbo") public ProtocolConfig protocolConfig() { ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setName("dubbo"); protocolConfig.setPort(12345); return protocolConfig; } @Primary @Bean public PlatformTransactionManager platformTransactionManager() { return new PlatformTransactionManager() { @Override public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException { return null; } @Override public void commit(TransactionStatus status) throws TransactionException {} @Override public void rollback(TransactionStatus status) throws TransactionException {} }; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceBeanNameBuilderTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.annotation.Service; import org.apache.dubbo.config.spring.api.DemoService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.mock.env.MockEnvironment; import org.springframework.util.ReflectionUtils; import static org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilderTest.GROUP; import static org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilderTest.VERSION; /** * {@link ServiceBeanNameBuilder} Test * * @see ServiceBeanNameBuilder * @since 2.6.6 */ @Service( interfaceClass = DemoService.class, group = GROUP, version = VERSION, application = "application", module = "module", registry = {"1", "2", "3"}) class ServiceBeanNameBuilderTest { @Reference( interfaceClass = DemoService.class, group = "DUBBO", version = "${dubbo.version}", application = "application", module = "module", registry = {"1", "2", "3"}) static final Class<?> INTERFACE_CLASS = DemoService.class; static final String GROUP = "DUBBO"; static final String VERSION = "1.0.0"; private MockEnvironment environment; @BeforeEach public void prepare() { environment = new MockEnvironment(); environment.setProperty("dubbo.version", "1.0.0"); } @Test void testServiceAnnotation() { Service service = AnnotationUtils.getAnnotation(ServiceBeanNameBuilderTest.class, Service.class); ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(service, INTERFACE_CLASS, environment); Assertions.assertEquals( "ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:DUBBO", builder.build()); } @Test void testReferenceAnnotation() { Reference reference = AnnotationUtils.getAnnotation( ReflectionUtils.findField(ServiceBeanNameBuilderTest.class, "INTERFACE_CLASS"), Reference.class); ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(reference, INTERFACE_CLASS, environment); Assertions.assertEquals( "ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:DUBBO", builder.build()); } @Test void testServiceNameBuild() { ServiceBeanNameBuilder vBuilder = ServiceBeanNameBuilder.create(INTERFACE_CLASS, environment); String vBeanName = vBuilder.version("DUBBO").build(); ServiceBeanNameBuilder gBuilder = ServiceBeanNameBuilder.create(INTERFACE_CLASS, environment); String gBeanName = gBuilder.group("DUBBO").build(); Assertions.assertNotEquals(vBeanName, gBeanName); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigAliasPostProcessorTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigAliasPostProcessorTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; class DubboConfigAliasPostProcessorTest { private static final String APP_NAME = "APP_NAME"; private static final String APP_ID = "APP_ID"; @Test void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfigurationX.class); try { context.start(); Assertions.assertEquals(context.getAliases(APP_NAME)[0], APP_ID); Assertions.assertEquals(context.getAliases(APP_ID)[0], APP_NAME); Assertions.assertEquals(context.getBean(APP_NAME), context.getBean(APP_ID)); } finally { context.close(); } } @EnableDubbo(scanBasePackages = "") @Configuration static class TestConfigurationX { @Bean(APP_NAME) public ApplicationConfig applicationConfig() { ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName(APP_NAME); applicationConfig.setId(APP_ID); return applicationConfig; } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessorTest.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.config.spring.beans.factory.annotation; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.Method; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.reference.ReferenceBeanManager; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import org.apache.dubbo.rpc.RpcContext; import java.net.InetSocketAddress; import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.InjectionMetadata; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Component; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; /** * {@link ReferenceAnnotationBeanPostProcessor} Test * * @since 2.5.7 */ @EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.context.annotation.provider") @ExtendWith(SpringExtension.class) @ContextConfiguration( classes = { ServiceAnnotationTestConfiguration.class, ReferenceAnnotationBeanPostProcessorTest.class, ReferenceAnnotationBeanPostProcessorTest.MyConfiguration.class, ReferenceAnnotationBeanPostProcessorTest.TestAspect.class }) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @TestPropertySource( properties = { "consumer.version = ${demo.service.version}", "consumer.url = dubbo://127.0.0.1:12345?version=2.5.7", }) @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) class ReferenceAnnotationBeanPostProcessorTest { @BeforeAll public static void setUp() { DubboBootstrap.reset(); } @AfterEach public void tearDown() { DubboBootstrap.reset(); } private static final String AOP_SUFFIX = "(based on AOP)"; @Aspect @Component public static class TestAspect { @Around("execution(* org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl.*(..))") public Object aroundDemoService(ProceedingJoinPoint pjp) throws Throwable { return pjp.proceed() + AOP_SUFFIX + " from " + RpcContext.getContext().getLocalAddress(); } @Around("execution(* org.apache.dubbo.config.spring.context.annotation.provider.*HelloService*.*(..))") public Object aroundHelloService(ProceedingJoinPoint pjp) throws Throwable { return pjp.proceed() + AOP_SUFFIX + " from " + RpcContext.getContext().getLocalAddress(); } } @Autowired private ConfigurableApplicationContext context; @Autowired private HelloService defaultHelloService; @Autowired private HelloService helloServiceImpl; @Autowired private DemoService demoServiceImpl; // #5 ReferenceBean (Field Injection #3) @Reference(id = "helloService", methods = @Method(name = "sayHello", timeout = 100)) private HelloService helloService; // #6 ReferenceBean (Field Injection #4) @DubboReference(version = "2", url = "dubbo://127.0.0.1:12345?version=2", tag = "demo_tag") private HelloService helloService2; // #7 ReferenceBean (Field Injection #5) // The HelloService is the same as above service(#6 ReferenceBean (Field Injection #4)), helloService3 will be // registered as an alias of helloService2 @DubboReference(version = "2", url = "dubbo://127.0.0.1:12345?version=2", tag = "demo_tag") private HelloService helloService3; // #8 ReferenceBean (Method Injection #3) @DubboReference(version = "3", url = "dubbo://127.0.0.1:12345?version=2", tag = "demo_tag") public void setHelloService2(HelloService helloService2) { // The helloService2 beanName is the same as above(#6 ReferenceBean (Field Injection #4)), and this will rename // to helloService2#2 renamedHelloService2 = helloService2; } // #9 ReferenceBean (Method Injection #4) @DubboReference(version = "4", url = "dubbo://127.0.0.1:12345?version=2") public void setHelloService3(DemoService helloService3) { // The helloService3 beanName is the same as above(#7 ReferenceBean (Field Injection #5) is an alias), // The current beanName(helloService3) is not registered in the beanDefinitionMap, but it is already an alias. // so this will rename to helloService3#2 this.renamedHelloService3 = helloService3; } private HelloService renamedHelloService2; private DemoService renamedHelloService3; @Test void testAop() throws Exception { Assertions.assertTrue(context.containsBean("helloService")); TestBean testBean = context.getBean(TestBean.class); Map<String, DemoService> demoServicesMap = context.getBeansOfType(DemoService.class); Assertions.assertNotNull(testBean.getDemoServiceFromAncestor()); Assertions.assertNotNull(testBean.getDemoServiceFromParent()); Assertions.assertNotNull(testBean.getDemoService()); Assertions.assertNotNull(testBean.myDemoService); Assertions.assertEquals(3, demoServicesMap.size()); Assertions.assertNotNull(context.getBean("demoServiceImpl")); Assertions.assertNotNull(context.getBean("myDemoService")); Assertions.assertNotNull(context.getBean("demoService")); Assertions.assertNotNull(context.getBean("demoServiceFromParent")); String callSuffix = AOP_SUFFIX + " from " + InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 12345); String localCallSuffix = AOP_SUFFIX + " from " + InetSocketAddress.createUnresolved("127.0.0.1", 0); String directInvokeSuffix = AOP_SUFFIX + " from null"; String defaultHelloServiceResult = "Greeting, Mercy"; Assertions.assertEquals(defaultHelloServiceResult + directInvokeSuffix, defaultHelloService.sayHello("Mercy")); Assertions.assertEquals(defaultHelloServiceResult + localCallSuffix, helloService.sayHello("Mercy")); String helloServiceImplResult = "Hello, Mercy"; Assertions.assertEquals(helloServiceImplResult + directInvokeSuffix, helloServiceImpl.sayHello("Mercy")); Assertions.assertEquals(helloServiceImplResult + callSuffix, helloService2.sayHello("Mercy")); String demoServiceResult = "Hello,Mercy"; Assertions.assertEquals(demoServiceResult + directInvokeSuffix, demoServiceImpl.sayName("Mercy")); Assertions.assertEquals( demoServiceResult + callSuffix, testBean.getDemoServiceFromAncestor().sayName("Mercy")); Assertions.assertEquals(demoServiceResult + callSuffix, testBean.myDemoService.sayName("Mercy")); Assertions.assertEquals( demoServiceResult + callSuffix, testBean.getDemoService().sayName("Mercy")); Assertions.assertEquals( demoServiceResult + callSuffix, testBean.getDemoServiceFromParent().sayName("Mercy")); DemoService myDemoService = context.getBean("myDemoService", DemoService.class); Assertions.assertEquals(demoServiceResult + callSuffix, myDemoService.sayName("Mercy")); } @Test void testGetInjectedFieldReferenceBeanMap() { ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor(); Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap = beanPostProcessor.getInjectedFieldReferenceBeanMap(); Assertions.assertEquals(5, referenceBeanMap.size()); Map<String, Integer> checkingFieldNames = new HashMap<>(); checkingFieldNames.put( "private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest$MyConfiguration.helloService", 0); checkingFieldNames.put( "private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest.helloService", 0); checkingFieldNames.put( "private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest.helloService2", 0); checkingFieldNames.put( "private org.apache.dubbo.config.spring.api.HelloService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest.helloService3", 0); checkingFieldNames.put( "private org.apache.dubbo.config.spring.api.DemoService org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessorTest$ParentBean.demoServiceFromParent", 0); for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : referenceBeanMap.entrySet()) { InjectionMetadata.InjectedElement injectedElement = entry.getKey(); String member = injectedElement.getMember().toString(); Integer count = checkingFieldNames.get(member); Assertions.assertNotNull(count); checkingFieldNames.put(member, count + 1); } for (Map.Entry<String, Integer> entry : checkingFieldNames.entrySet()) { Assertions.assertEquals(1, entry.getValue().intValue(), "check field element failed: " + entry.getKey()); } } private ReferenceAnnotationBeanPostProcessor getReferenceAnnotationBeanPostProcessor() { return DubboBeanUtils.getReferenceAnnotationBeanPostProcessor(context); } @Test void testGetInjectedMethodReferenceBeanMap() { ReferenceAnnotationBeanPostProcessor beanPostProcessor = getReferenceAnnotationBeanPostProcessor(); Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap = beanPostProcessor.getInjectedMethodReferenceBeanMap(); Assertions.assertEquals(4, referenceBeanMap.size()); Map<String, Integer> checkingMethodNames = new HashMap<>(); checkingMethodNames.put("setDemoServiceFromAncestor", 0); checkingMethodNames.put("setDemoService", 0); checkingMethodNames.put("setHelloService2", 0); checkingMethodNames.put("setHelloService3", 0); for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : referenceBeanMap.entrySet()) { InjectionMetadata.InjectedElement injectedElement = entry.getKey(); java.lang.reflect.Method method = (java.lang.reflect.Method) injectedElement.getMember(); Integer count = checkingMethodNames.get(method.getName()); Assertions.assertNotNull(count); Assertions.assertEquals(0, count.intValue()); checkingMethodNames.put(method.getName(), count + 1); } for (Map.Entry<String, Integer> entry : checkingMethodNames.entrySet()) { Assertions.assertEquals(1, entry.getValue().intValue(), "check method element failed: " + entry.getKey()); } } @Test void testReferenceBeansMethodAnnotation() { ReferenceBeanManager referenceBeanManager = context.getBean(ReferenceBeanManager.BEAN_NAME, ReferenceBeanManager.class); Collection<ReferenceBean> referenceBeans = referenceBeanManager.getReferences(); Assertions.assertEquals(5, referenceBeans.size()); for (ReferenceBean referenceBean : referenceBeans) { ReferenceConfig referenceConfig = referenceBean.getReferenceConfig(); Assertions.assertNotNull(referenceConfig); Assertions.assertNotNull(referenceConfig.get()); } ReferenceBean helloServiceReferenceBean = referenceBeanManager.getById("helloService"); Assertions.assertEquals("helloService", helloServiceReferenceBean.getId()); ReferenceConfig referenceConfig = helloServiceReferenceBean.getReferenceConfig(); Assertions.assertEquals(1, referenceConfig.getMethods().size()); ReferenceBean demoServiceFromParentReferenceBean = referenceBeanManager.getById("demoServiceFromParent"); ReferenceBean demoServiceReferenceBean = referenceBeanManager.getById("demoService"); Assertions.assertEquals(demoServiceFromParentReferenceBean.getKey(), demoServiceReferenceBean.getKey()); Assertions.assertEquals( demoServiceFromParentReferenceBean.getReferenceConfig(), demoServiceReferenceBean.getReferenceConfig()); Assertions.assertSame(demoServiceFromParentReferenceBean, demoServiceReferenceBean); ReferenceBean helloService2Bean = referenceBeanManager.getById("helloService2"); Assertions.assertNotNull(helloService2Bean); Assertions.assertNotNull(helloService2Bean.getReferenceConfig()); Assertions.assertEquals( "demo_tag", helloService2Bean.getReferenceConfig().getTag()); Assertions.assertNotNull(referenceBeanManager.getById("myDemoService")); Assertions.assertNotNull(referenceBeanManager.getById("helloService2#2")); } private static class AncestorBean { private DemoService demoServiceFromAncestor; @Autowired private ApplicationContext applicationContext; public DemoService getDemoServiceFromAncestor() { return demoServiceFromAncestor; } // #4 ReferenceBean (Method Injection #2) @Reference(id = "myDemoService", version = "2.5.7", url = "dubbo://127.0.0.1:12345?version=2.5.7") public void setDemoServiceFromAncestor(DemoService demoServiceFromAncestor) { this.demoServiceFromAncestor = demoServiceFromAncestor; } public ApplicationContext getApplicationContext() { return applicationContext; } } private static class ParentBean extends AncestorBean { // #2 ReferenceBean (Field Injection #2) @Reference(version = "${consumer.version}", url = "${consumer.url}") private DemoService demoServiceFromParent; public DemoService getDemoServiceFromParent() { return demoServiceFromParent; } } static class TestBean extends ParentBean { private DemoService demoService; @Autowired private DemoService myDemoService; @Autowired private ApplicationContext applicationContext; public DemoService getDemoService() { return demoService; } // #3 ReferenceBean (Method Injection #1) @Reference(version = "2.5.7", url = "dubbo://127.0.0.1:12345?version=2.5.7") public void setDemoService(DemoService demoService) { this.demoService = demoService; } } @Configuration static class MyConfiguration { // #1 ReferenceBean (Field Injection #1) @Reference(methods = @Method(name = "sayHello", timeout = 100)) private HelloService helloService; @Bean public TestBean testBean() { return new TestBean(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigDefaultPropertyValueBeanPostProcessorTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigDefaultPropertyValueBeanPostProcessorTest.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.config.spring.beans.factory.config; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.spring.context.annotation.provider.ProviderConfiguration; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; class DubboConfigDefaultPropertyValueBeanPostProcessorTest { @Test void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class); try { context.start(); ApplicationConfig applicationConfig = context.getBean(ApplicationConfig.class); Assertions.assertEquals(applicationConfig.getName(), applicationConfig.getId()); ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class); Assertions.assertEquals(protocolConfig.getName(), protocolConfig.getId()); } finally { context.close(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactory.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactory.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.config.spring.beans.factory.config; import java.io.IOException; import java.util.AbstractMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import org.springframework.beans.factory.config.YamlProcessor; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.core.io.support.EncodedResource; import org.springframework.core.io.support.PropertySourceFactory; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.parser.ParserException; import org.yaml.snakeyaml.representer.Representer; import org.yaml.snakeyaml.resolver.Resolver; /** * YAML {@link PropertySourceFactory} implementation, some source code is copied Spring Boot * org.springframework.boot.env.YamlPropertySourceLoader , see {@link #createYaml()} and {@link #process()} * * @since 2.6.5 */ public class YamlPropertySourceFactory extends YamlProcessor implements PropertySourceFactory { @Override public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException { setResources(resource.getResource()); return new MapPropertySource(name, process()); } @Override protected Yaml createYaml() { return new Yaml( new Constructor(new LoaderOptions()) { @Override protected Map<Object, Object> constructMapping(MappingNode node) { try { return super.constructMapping(node); } catch (IllegalStateException ex) { throw new ParserException( "while parsing MappingNode", node.getStartMark(), ex.getMessage(), node.getEndMark()); } } @Override protected Map<Object, Object> createDefaultMap(int initSize) { final Map<Object, Object> delegate = super.createDefaultMap(initSize); return new AbstractMap<Object, Object>() { @Override public Object put(Object key, Object value) { if (delegate.containsKey(key)) { throw new IllegalStateException("Duplicate key: " + key); } return delegate.put(key, value); } @Override public Set<Entry<Object, Object>> entrySet() { return delegate.entrySet(); } }; } }, new Representer(new DumperOptions()), new DumperOptions(), new Resolver() { @Override public void addImplicitResolver(Tag tag, Pattern regexp, String first) { if (tag == Tag.TIMESTAMP) { return; } super.addImplicitResolver(tag, regexp, first); } }); } /** * {@link Resolver} that limits {@link Tag#TIMESTAMP} tags. */ private static class LimitedResolver extends Resolver { @Override public void addImplicitResolver(Tag tag, Pattern regexp, String first) { if (tag == Tag.TIMESTAMP) { return; } super.addImplicitResolver(tag, regexp, first); } } public Map<String, Object> process() { final Map<String, Object> result = new LinkedHashMap<String, Object>(); process((properties, map) -> result.putAll(getFlattenedMap(map))); return result; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactoryTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactoryTest.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.config.spring.beans.factory.config; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; /** * {@link YamlPropertySourceFactory} Test * * @since 2.6.5 */ @ExtendWith(SpringExtension.class) @PropertySource( name = "yaml-source", value = {"classpath:/META-INF/dubbo.yml"}, factory = YamlPropertySourceFactory.class) @Configuration @ContextConfiguration(classes = YamlPropertySourceFactoryTest.class) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) class YamlPropertySourceFactoryTest { @Autowired private Environment environment; @Value("${dubbo.consumer.default}") private Boolean isDefault; @Value("${dubbo.consumer.client}") private String client; @Value("${dubbo.consumer.threadpool}") private String threadPool; @Value("${dubbo.consumer.corethreads}") private Integer coreThreads; @Value("${dubbo.consumer.threads}") private Integer threads; @Value("${dubbo.consumer.queues}") private Integer queues; @Test void testProperty() { Assertions.assertEquals(isDefault, environment.getProperty("dubbo.consumer.default", Boolean.class)); Assertions.assertEquals(client, environment.getProperty("dubbo.consumer.client", String.class)); Assertions.assertEquals(threadPool, environment.getProperty("dubbo.consumer.threadpool", String.class)); Assertions.assertEquals(coreThreads, environment.getProperty("dubbo.consumer.corethreads", Integer.class)); Assertions.assertEquals(threads, environment.getProperty("dubbo.consumer.threads", Integer.class)); Assertions.assertEquals(queues, environment.getProperty("dubbo.consumer.queues", Integer.class)); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/MultipleServicesWithMethodConfigsTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/MultipleServicesWithMethodConfigsTest.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.config.spring.beans.factory.config; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.ServiceBean; import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ImportResource; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = MultipleServicesWithMethodConfigsTest.class) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @ImportResource(locations = "classpath:/META-INF/spring/multiple-services-with-methods.xml") class MultipleServicesWithMethodConfigsTest { @BeforeAll public static void setUp() { DubboBootstrap.reset(); } @Autowired private ApplicationContext applicationContext; @Test void test() { Map<String, ServiceBean> serviceBeanMap = applicationContext.getBeansOfType(ServiceBean.class); for (ServiceBean serviceBean : serviceBeanMap.values()) { Assertions.assertEquals(1, serviceBean.getMethods().size()); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/Issue6000Test.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/Issue6000Test.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.config.spring.issues.issue6000; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.issues.issue6000.adubbo.HelloDubbo; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; /** * The test-case for https://github.com/apache/dubbo/issues/6000 * Autowired a ReferenceBean failed in some situation in Spring environment */ @Configuration @EnableDubbo @ComponentScan @PropertySource("classpath:/META-INF/issues/issue6000/config.properties") class Issue6000Test { private static final Logger logger = LoggerFactory.getLogger(Issue6000Test.class); @BeforeAll public static void beforeAll() { DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); } @Test void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Issue6000Test.class); try { HelloDubbo helloDubbo = context.getBean(HelloDubbo.class); String result = helloDubbo.sayHello("dubbo"); logger.info(result); } catch (Exception e) { String s = e.toString(); Assertions.assertTrue(s.contains("No provider available"), s); Assertions.assertTrue(s.contains("org.apache.dubbo.config.spring.api.HelloService:1.0.0"), s); } finally { context.close(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/dubbo/MyReferenceConfig.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/dubbo/MyReferenceConfig.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.config.spring.issues.issue6000.dubbo; import org.apache.dubbo.config.annotation.Reference; import org.apache.dubbo.config.spring.api.HelloService; import org.springframework.context.annotation.Configuration; /** * This configuration class is considered to be initialized after HelloDubbo, * but the reference bean defined in it can be injected into HelloDubbo */ @Configuration public class MyReferenceConfig { @Reference(version = "1.0.0", check = false) HelloService helloService; }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/adubbo/HelloDubbo.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6000/adubbo/HelloDubbo.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.config.spring.issues.issue6000.adubbo; import org.apache.dubbo.config.spring.api.HelloService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class HelloDubbo { HelloService helloService; @Autowired public void setHelloService(HelloService helloService) { this.helloService = helloService; } public String sayHello(String name) { return helloService.sayHello(name); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6252/Issue6252Test.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue6252/Issue6252Test.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.config.spring.issues.issue6252; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; /** * The test-case for https://github.com/apache/dubbo/issues/6252 * * @since 2.7.8 */ @Configuration @EnableDubboConfig @PropertySource("classpath:/META-INF/issues/issue6252/config.properties") class Issue6252Test { @BeforeAll public static void beforeAll() { DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); } @DubboReference private DemoService demoService; @Test void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Issue6252Test.class); try { DemoService demoService = context.getBean(DemoService.class); } finally { context.close(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9207/ConfigCenterBeanTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9207/ConfigCenterBeanTest.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.config.spring.issues.issue9207; import org.apache.dubbo.config.ConfigCenterConfig; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.spring.ConfigCenterBean; import org.apache.dubbo.config.spring.SysProps; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.stream.Collectors; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; class ConfigCenterBeanTest { private static final String DUBBO_PROPERTIES_FILE = "/META-INF/issues/issue9207/dubbo-properties-in-configcenter.properties"; private static final String DUBBO_EXTERNAL_CONFIG_KEY = "my-dubbo.properties"; @Test void testConfigCenterBeanFromProps() throws IOException { SysProps.setProperty("dubbo.config-center.include-spring-env", "true"); SysProps.setProperty("dubbo.config-center.config-file", DUBBO_EXTERNAL_CONFIG_KEY); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProviderConfiguration.class); try { ConfigManager configManager = DubboBeanUtils.getApplicationModel(applicationContext).getApplicationConfigManager(); Collection<ConfigCenterConfig> configCenters = configManager.getConfigCenters(); Assertions.assertEquals(1, configCenters.size()); ConfigCenterConfig cc = configCenters.stream().findFirst().get(); Assertions.assertFalse(cc.getExternalConfiguration().isEmpty()); Assertions.assertTrue(cc instanceof ConfigCenterBean); // check loaded external config String content = readContent(DUBBO_PROPERTIES_FILE); content = applicationContext.getEnvironment().resolvePlaceholders(content); Properties properties = new Properties(); properties.load(new StringReader(content)); Assertions.assertEquals(properties, cc.getExternalConfiguration()); } finally { SysProps.clear(); if (applicationContext != null) { applicationContext.close(); } } } @EnableDubbo(scanBasePackages = "") @Configuration static class ProviderConfiguration { @Bean public BeanFactoryPostProcessor envPostProcessor(ConfigurableEnvironment environment) { return new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { // add custom external configs to spring environment early before processing normal bean. // e.g. we can do it in BeanFactoryPostProcessor or EnvironmentPostProcessor Map<String, Object> dubboProperties = new HashMap<>(); String content = readContent(DUBBO_PROPERTIES_FILE); dubboProperties.put(DUBBO_EXTERNAL_CONFIG_KEY, content); MapPropertySource dubboPropertySource = new MapPropertySource("dubbo external config", dubboProperties); environment.getPropertySources().addLast(dubboPropertySource); } }; } } private static String readContent(String file) { BufferedReader reader = new BufferedReader(new InputStreamReader(ConfigCenterBeanTest.class.getResourceAsStream(file))); String content = reader.lines().collect(Collectors.joining("\n")); return content; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue7003/Issue7003Test.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue7003/Issue7003Test.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.config.spring.issues.issue7003; import org.apache.dubbo.config.ReferenceConfigBase; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Collection; import java.util.Map; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; /** * * Multiple duplicate Dubbo Reference annotations with the same attribute generate only one instance. * The test-case for https://github.com/apache/dubbo/issues/7003 */ @Configuration @EnableDubbo @ComponentScan @PropertySource("classpath:/META-INF/issues/issue7003/config.properties") class Issue7003Test { @BeforeAll public static void beforeAll() { DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); } @Test void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Issue7003Test.class); try { Map<String, ReferenceBean> referenceBeanMap = context.getBeansOfType(ReferenceBean.class); Assertions.assertEquals(1, referenceBeanMap.size()); Collection<ReferenceConfigBase<?>> references = ApplicationModel.defaultModel() .getDefaultModule() .getConfigManager() .getReferences(); Assertions.assertEquals(1, references.size()); } finally { context.close(); } } @Component static class ClassA { @DubboReference(group = "demo", version = "1.2.3", check = false) private HelloService helloService; } @Component static class ClassB { @DubboReference(check = false, version = "1.2.3", group = "demo") private HelloService helloService; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9172/MultipleConsumerAndProviderTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/issues/issue9172/MultipleConsumerAndProviderTest.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.config.spring.issues.issue9172; import org.apache.dubbo.config.ReferenceConfigBase; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.context.ModuleConfigManager; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import org.apache.dubbo.rpc.model.ModuleModel; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; /** * Test for issue 9172 */ class MultipleConsumerAndProviderTest { @Test void test() { AnnotationConfigApplicationContext providerContext = null; AnnotationConfigApplicationContext consumerContext = null; try { providerContext = new AnnotationConfigApplicationContext(ProviderConfiguration.class); consumerContext = new AnnotationConfigApplicationContext(ConsumerConfiguration.class); ModuleModel consumerModuleModel = DubboBeanUtils.getModuleModel(consumerContext); ModuleConfigManager consumerConfigManager = consumerModuleModel.getConfigManager(); ReferenceConfigBase helloServiceOneConfig = consumerConfigManager.getReference("helloServiceOne"); ReferenceConfigBase demoServiceTwoConfig = consumerConfigManager.getReference("demoServiceTwo"); Assertions.assertEquals( consumerConfigManager.getConsumer("consumer-one").get(), helloServiceOneConfig.getConsumer()); Assertions.assertEquals( consumerConfigManager.getConsumer("consumer-two").get(), demoServiceTwoConfig.getConsumer()); Assertions.assertEquals( consumerConfigManager.getRegistry("registry-one").get(), helloServiceOneConfig.getRegistry()); Assertions.assertEquals( consumerConfigManager.getRegistry("registry-two").get(), demoServiceTwoConfig.getRegistry()); HelloService helloServiceOne = consumerContext.getBean("helloServiceOne", HelloService.class); DemoService demoServiceTwo = consumerContext.getBean("demoServiceTwo", DemoService.class); String sayHello = helloServiceOne.sayHello("dubbo"); String sayName = demoServiceTwo.sayName("dubbo"); Assertions.assertEquals("Hello, dubbo", sayHello); Assertions.assertEquals("say:dubbo", sayName); } finally { if (providerContext != null) { providerContext.close(); } if (consumerContext != null) { consumerContext.close(); } } } @EnableDubbo(scanBasePackages = "") @PropertySource("classpath:/META-INF/issues/issue9172/consumer.properties") static class ConsumerConfiguration { @DubboReference(consumer = "consumer-one") private HelloService helloServiceOne; @DubboReference(consumer = "consumer-two") private DemoService demoServiceTwo; } @EnableDubbo(scanBasePackages = "") @PropertySource("classpath:/META-INF/issues/issue9172/provider.properties") static class ProviderConfiguration { @Bean @DubboService(provider = "provider-one") public HelloService helloServiceOne() { return new HelloServiceImpl(); } @Bean @DubboService(provider = "provider-two") public DemoService demoServiceTwo() { return new DemoServiceImpl(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/extension/SpringExtensionInjectorTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/extension/SpringExtensionInjectorTest.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.config.spring.extension; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.SysProps; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; import org.apache.dubbo.config.spring.util.DubboBeanUtils; import org.apache.dubbo.rpc.Protocol; 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 org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @EnableDubbo(scanBasePackages = "") @Configuration class SpringExtensionInjectorTest { @BeforeEach public void init() { DubboBootstrap.reset(); SysProps.clear(); SysProps.setProperty("dubbo.metrics.enabled", "false"); SysProps.setProperty("dubbo.metrics.protocol", "disabled"); } @AfterEach public void destroy() { DubboBootstrap.reset(); SysProps.clear(); } @Test void testSpringInjector() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); try { context.setDisplayName("Context1"); context.register(getClass()); context.refresh(); SpringExtensionInjector springExtensionInjector = SpringExtensionInjector.get(DubboBeanUtils.getApplicationModel(context)); Assertions.assertEquals(springExtensionInjector.getContext(), context); Protocol protocol = springExtensionInjector.getInstance(Protocol.class, "protocol"); Assertions.assertNull(protocol); DemoService demoServiceBean1 = springExtensionInjector.getInstance(DemoService.class, "bean1"); Assertions.assertNotNull(demoServiceBean1); DemoService demoServiceBean2 = springExtensionInjector.getInstance(DemoService.class, "bean2"); Assertions.assertNotNull(demoServiceBean2); HelloService helloServiceBean = springExtensionInjector.getInstance(HelloService.class, "hello"); Assertions.assertNotNull(helloServiceBean); HelloService helloService = springExtensionInjector.getInstance(HelloService.class, null); Assertions.assertEquals(helloService, helloServiceBean); Assertions.assertThrows( IllegalStateException.class, () -> springExtensionInjector.getInstance(DemoService.class, null), "Expect single but found 2 beans in spring context: [bean1, bean2]"); } finally { context.close(); } } @Bean("bean1") public DemoService bean1() { return new DemoServiceImpl(); } @Bean("bean2") public DemoService bean2() { return new DemoServiceImpl(); } @Bean("hello") public HelloService helloService() { return new HelloServiceImpl(); } @Bean public ApplicationConfig applicationConfig() { return new ApplicationConfig("test-app"); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/extension/BeanForContext2.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/extension/BeanForContext2.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.config.spring.extension; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class BeanForContext2 { @Bean("bean1") public DemoService context2Bean() { return new DemoServiceImpl(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/filter/MockFilter.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/filter/MockFilter.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.config.spring.filter; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.LoadBalance; public class MockFilter implements Filter { private LoadBalance loadBalance; private Protocol protocol; private MockDao mockDao; public MockDao getMockDao() { return mockDao; } public void setMockDao(MockDao mockDao) { this.mockDao = mockDao; } public LoadBalance getLoadBalance() { return loadBalance; } public void setLoadBalance(LoadBalance loadBalance) { this.loadBalance = loadBalance; } public Protocol getProtocol() { return protocol; } public void setProtocol(Protocol protocol) { this.protocol = protocol; } public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { return invoker.invoke(invocation); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/filter/MockDaoImpl.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/filter/MockDaoImpl.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.config.spring.filter; public class MockDaoImpl implements MockDao {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/filter/MockDao.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/filter/MockDao.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.config.spring.filter; public interface MockDao {}
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/api/ApiIsolationTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/api/ApiIsolationTest.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.config.spring.isolation.api; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; import org.apache.dubbo.common.threadpool.manager.IsolationExecutorRepository; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.impl.DemoServiceImpl; import org.apache.dubbo.config.spring.impl.HelloServiceImpl; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_ISOLATION; public class ApiIsolationTest { private static RegistryConfig registryConfig; @BeforeAll public static void beforeAll() { FrameworkModel.destroyAll(); registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1()); } @AfterAll public static void afterAll() throws Exception { FrameworkModel.destroyAll(); } private String version1 = "1.0"; private String version2 = "2.0"; private String version3 = "3.0"; @Test @Disabled public void test() throws Exception { DubboBootstrap providerBootstrap = null; DubboBootstrap consumerBootstrap1 = null; DubboBootstrap consumerBootstrap2 = null; try { // provider app providerBootstrap = DubboBootstrap.newInstance(); ServiceConfig serviceConfig1 = new ServiceConfig(); serviceConfig1.setInterface(DemoService.class); serviceConfig1.setRef(new DemoServiceImpl()); serviceConfig1.setVersion(version1); // set executor1 for serviceConfig1, max threads is 10 NamedThreadFactory threadFactory1 = new NamedThreadFactory("DemoService-executor"); ExecutorService executor1 = Executors.newFixedThreadPool(10, threadFactory1); serviceConfig1.setExecutor(executor1); ServiceConfig serviceConfig2 = new ServiceConfig(); serviceConfig2.setInterface(HelloService.class); serviceConfig2.setRef(new HelloServiceImpl()); serviceConfig2.setVersion(version2); // set executor2 for serviceConfig2, max threads is 100 NamedThreadFactory threadFactory2 = new NamedThreadFactory("HelloService-executor"); ExecutorService executor2 = Executors.newFixedThreadPool(100, threadFactory2); serviceConfig2.setExecutor(executor2); ServiceConfig serviceConfig3 = new ServiceConfig(); serviceConfig3.setInterface(HelloService.class); serviceConfig3.setRef(new HelloServiceImpl()); serviceConfig3.setVersion(version3); // Because executor is not set for serviceConfig3, the default executor of serviceConfig3 is built using // the threadpool parameter of the protocolConfig ( FixedThreadpool , max threads is 200) serviceConfig3.setExecutor(null); // It takes effect only if [executor-management-mode=isolation] is configured ApplicationConfig applicationConfig = new ApplicationConfig("provider-app"); applicationConfig.setExecutorManagementMode(EXECUTOR_MANAGEMENT_MODE_ISOLATION); providerBootstrap .application(applicationConfig) .registry(registryConfig) // export with tri and dubbo protocol .protocol(new ProtocolConfig("tri", 20001)) .protocol(new ProtocolConfig("dubbo", 20002)) .service(serviceConfig1) .service(serviceConfig2) .service(serviceConfig3); providerBootstrap.start(); // Verify that the executor is the previously configured ApplicationModel applicationModel = providerBootstrap.getApplicationModel(); ExecutorRepository repository = ExecutorRepository.getInstance(applicationModel); Assertions.assertTrue(repository instanceof IsolationExecutorRepository); Assertions.assertEquals(executor1, repository.getExecutor(serviceConfig1.toUrl())); Assertions.assertEquals(executor2, repository.getExecutor(serviceConfig2.toUrl())); // the default executor of serviceConfig3 is built using the threadpool parameter of the protocol ThreadPoolExecutor executor3 = (ThreadPoolExecutor) repository.getExecutor(serviceConfig3.toUrl()); Assertions.assertTrue(executor3.getThreadFactory() instanceof NamedInternalThreadFactory); NamedInternalThreadFactory threadFactory3 = (NamedInternalThreadFactory) executor3.getThreadFactory(); // consumer app start with dubbo protocol and rpc call consumerBootstrap1 = configConsumerBootstrapWithProtocol("dubbo"); rpcInvoke(consumerBootstrap1); // consumer app start with tri protocol and rpc call consumerBootstrap2 = configConsumerBootstrapWithProtocol("tri"); rpcInvoke(consumerBootstrap2); // Verify that when the provider accepts different service requests, // whether to use the respective executor(threadFactory) of different services to create threads AtomicInteger threadNum1 = threadFactory1.getThreadNum(); AtomicInteger threadNum2 = threadFactory2.getThreadNum(); AtomicInteger threadNum3 = threadFactory3.getThreadNum(); Assertions.assertEquals(threadNum1.get(), 11); Assertions.assertEquals(threadNum2.get(), 101); Assertions.assertEquals(threadNum3.get(), 201); } finally { if (providerBootstrap != null) { providerBootstrap.destroy(); } if (consumerBootstrap1 != null) { consumerBootstrap1.destroy(); } if (consumerBootstrap2 != null) { consumerBootstrap2.destroy(); } } } private void rpcInvoke(DubboBootstrap consumerBootstrap) { DemoService demoServiceV1 = consumerBootstrap.getCache().get(DemoService.class.getName() + ":" + version1); HelloService helloServiceV2 = consumerBootstrap.getCache().get(HelloService.class.getName() + ":" + version2); HelloService helloServiceV3 = consumerBootstrap.getCache().get(HelloService.class.getName() + ":" + version3); for (int i = 0; i < 250; i++) { demoServiceV1.sayName("name, version = " + version1); } for (int i = 0; i < 250; i++) { helloServiceV2.sayHello("hello, version = " + version2); } for (int i = 0; i < 250; i++) { helloServiceV3.sayHello("hello, version = " + version3); } } private DubboBootstrap configConsumerBootstrapWithProtocol(String protocol) { DubboBootstrap consumerBootstrap; consumerBootstrap = DubboBootstrap.newInstance(); consumerBootstrap .application("consumer-app") .registry(registryConfig) .reference(builder -> builder.interfaceClass(DemoService.class) .version(version1) .protocol(protocol) .injvm(false)) .reference(builder -> builder.interfaceClass(HelloService.class) .version(version2) .protocol(protocol) .injvm(false)) .reference(builder -> builder.interfaceClass(HelloService.class) .version(version3) .protocol(protocol) .injvm(false)); consumerBootstrap.start(); return consumerBootstrap; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/BaseTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/BaseTest.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.config.spring.isolation.spring; import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory; import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; import org.apache.dubbo.common.threadpool.manager.IsolationExecutorRepository; import org.apache.dubbo.common.utils.NamedThreadFactory; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.apache.dubbo.config.spring.isolation.spring.support.DemoServiceExecutor; import org.apache.dubbo.config.spring.isolation.spring.support.HelloServiceExecutor; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.Map; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; public abstract class BaseTest { protected ServiceConfig serviceConfig1; protected ServiceConfig serviceConfig2; protected ServiceConfig serviceConfig3; @Test public void test() throws Exception { test(); } protected void assertExecutor(ApplicationContext providerContext, ApplicationContext consumerContext) { // find configured "executor-demo-service" executor Map<String, DemoServiceExecutor> beansOfType1 = providerContext.getBeansOfType(DemoServiceExecutor.class); ThreadPoolExecutor executor1 = beansOfType1.get("executor-demo-service"); NamedThreadFactory threadFactory1 = (NamedThreadFactory) executor1.getThreadFactory(); // find configured "executor-hello-service" executor Map<String, HelloServiceExecutor> beansOfType2 = providerContext.getBeansOfType(HelloServiceExecutor.class); ThreadPoolExecutor executor2 = beansOfType2.get("executor-hello-service"); NamedThreadFactory threadFactory2 = (NamedThreadFactory) executor2.getThreadFactory(); // Verify that the executor is the previously configured Map<String, ApplicationModel> applicationModelMap = providerContext.getBeansOfType(ApplicationModel.class); ApplicationModel applicationModel = applicationModelMap.get(ApplicationModel.class.getName()); ExecutorRepository repository = ExecutorRepository.getInstance(applicationModel); Assertions.assertTrue(repository instanceof IsolationExecutorRepository); Assertions.assertEquals(executor1, repository.getExecutor(serviceConfig1.toUrl())); Assertions.assertEquals(executor2, repository.getExecutor(serviceConfig2.toUrl())); // the default executor of serviceConfig3 is built using the threadpool parameter of the protocol ThreadPoolExecutor executor3 = (ThreadPoolExecutor) repository.getExecutor(serviceConfig3.toUrl()); Assertions.assertTrue(executor3.getThreadFactory() instanceof NamedInternalThreadFactory); NamedInternalThreadFactory threadFactory3 = (NamedInternalThreadFactory) executor3.getThreadFactory(); // rpc invoke with dubbo protocol DemoService demoServiceV1 = consumerContext.getBean("dubbo-demoServiceV1", DemoService.class); HelloService helloServiceV2 = consumerContext.getBean("dubbo-helloServiceV2", HelloService.class); HelloService helloServiceV3 = consumerContext.getBean("dubbo-helloServiceV3", HelloService.class); rpcInvoke(demoServiceV1, helloServiceV2, helloServiceV3); // rpc invoke with tri protocol demoServiceV1 = consumerContext.getBean("tri-demoServiceV1", DemoService.class); helloServiceV2 = consumerContext.getBean("tri-helloServiceV2", HelloService.class); helloServiceV3 = consumerContext.getBean("tri-helloServiceV3", HelloService.class); rpcInvoke(demoServiceV1, helloServiceV2, helloServiceV3); // Verify that when the provider accepts different service requests, // whether to use the respective executor(threadFactory) of different services to create threads AtomicInteger threadNum1 = threadFactory1.getThreadNum(); AtomicInteger threadNum2 = threadFactory2.getThreadNum(); AtomicInteger threadNum3 = threadFactory3.getThreadNum(); Assertions.assertEquals(threadNum1.get(), 11); Assertions.assertEquals(threadNum2.get(), 101); Assertions.assertEquals(threadNum3.get(), 201); } private void rpcInvoke(DemoService demoServiceV1, HelloService helloServiceV2, HelloService helloServiceV3) { for (int i = 0; i < 250; i++) { demoServiceV1.sayName("name"); } for (int i = 0; i < 250; i++) { helloServiceV2.sayHello("hello"); } for (int i = 0; i < 250; i++) { helloServiceV3.sayHello("hello"); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/support/DemoServiceExecutor.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/support/DemoServiceExecutor.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.config.spring.isolation.spring.support; import org.apache.dubbo.common.utils.NamedThreadFactory; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class DemoServiceExecutor extends ThreadPoolExecutor { public DemoServiceExecutor() { super(10, 10, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), new NamedThreadFactory("DemoServiceExecutor")); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/support/HelloServiceExecutor.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/support/HelloServiceExecutor.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.config.spring.isolation.spring.support; import org.apache.dubbo.common.utils.NamedThreadFactory; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class HelloServiceExecutor extends ThreadPoolExecutor { public HelloServiceExecutor() { super( 100, 100, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), new NamedThreadFactory("HelloServiceExecutor")); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/xml/XmlIsolationTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/xml/XmlIsolationTest.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.config.spring.isolation.spring.xml; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.spring.isolation.spring.BaseTest; import java.util.Map; import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class XmlIsolationTest extends BaseTest { @Test public void test() throws Exception { // start provider app ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext("META-INF/isolation/dubbo-provider.xml"); providerContext.start(); // start consumer app ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext("META-INF/isolation/dubbo-consumer.xml"); consumerContext.start(); // getAndSet serviceConfig setServiceConfig(providerContext); // assert isolation of executor assertExecutor(providerContext, consumerContext); // close context providerContext.close(); consumerContext.close(); } private void setServiceConfig(ClassPathXmlApplicationContext providerContext) { Map<String, ServiceConfig> serviceConfigMap = providerContext.getBeansOfType(ServiceConfig.class); serviceConfig1 = serviceConfigMap.get("org.apache.dubbo.config.spring.ServiceBean#0"); serviceConfig2 = serviceConfigMap.get("org.apache.dubbo.config.spring.ServiceBean#1"); serviceConfig3 = serviceConfigMap.get("org.apache.dubbo.config.spring.ServiceBean#2"); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/AnnotationIsolationTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/AnnotationIsolationTest.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.config.spring.isolation.spring.annotation; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; import org.apache.dubbo.config.spring.SysProps; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.isolation.spring.BaseTest; import org.apache.dubbo.config.spring.isolation.spring.support.DemoServiceExecutor; import org.apache.dubbo.config.spring.isolation.spring.support.HelloServiceExecutor; import java.util.Map; import java.util.concurrent.Executor; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_ISOLATION; public class AnnotationIsolationTest extends BaseTest { @Test public void test() throws Exception { SysProps.clear(); SysProps.setProperty("dubbo.metrics.enabled", "false"); SysProps.setProperty("dubbo.metrics.protocol", "disabled"); // start provider app AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext(ProviderConfiguration.class); providerContext.start(); // start consumer app AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext(ConsumerConfiguration.class); consumerContext.start(); // getAndSet serviceConfig setServiceConfig(providerContext); // assert isolation of executor assertExecutor(providerContext, consumerContext); // close context providerContext.close(); consumerContext.close(); } private void setServiceConfig(AnnotationConfigApplicationContext providerContext) { Map<String, ServiceConfig> serviceConfigMap = providerContext.getBeansOfType(ServiceConfig.class); serviceConfig1 = serviceConfigMap.get("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:Group1"); serviceConfig2 = serviceConfigMap.get("ServiceBean:org.apache.dubbo.config.spring.api.HelloService:2.0.0:Group2"); serviceConfig3 = serviceConfigMap.get("ServiceBean:org.apache.dubbo.config.spring.api.HelloService:3.0.0:Group3"); } // note scanBasePackages, refer three service with dubbo and tri protocol @Configuration @EnableDubbo(scanBasePackages = "org.apache.dubbo.demo.consumer.comp") @ComponentScan(value = {"org.apache.dubbo.config.spring.isolation.spring.annotation.consumer"}) static class ConsumerConfiguration { @Bean public RegistryConfig registryConfig() { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("zookeeper://127.0.0.1:2181"); return registryConfig; } @Bean public ApplicationConfig applicationConfig() { ApplicationConfig applicationConfig = new ApplicationConfig("consumer-app"); return applicationConfig; } } // note scanBasePackages, expose three service with dubbo and tri protocol @Configuration @EnableDubbo(scanBasePackages = "org.apache.dubbo.config.spring.isolation.spring.annotation.provider") static class ProviderConfiguration { @Bean public RegistryConfig registryConfig() { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("zookeeper://127.0.0.1:2181"); return registryConfig; } // NOTE: we need config executor-management-mode="isolation" @Bean public ApplicationConfig applicationConfig() { ApplicationConfig applicationConfig = new ApplicationConfig("provider-app"); applicationConfig.setExecutorManagementMode(EXECUTOR_MANAGEMENT_MODE_ISOLATION); return applicationConfig; } // expose services with dubbo protocol @Bean public ProtocolConfig dubbo() { ProtocolConfig protocolConfig = new ProtocolConfig("dubbo", NetUtils.getAvailablePort()); return protocolConfig; } // expose services with tri protocol @Bean public ProtocolConfig tri() { ProtocolConfig protocolConfig = new ProtocolConfig("tri", NetUtils.getAvailablePort()); return protocolConfig; } // customized thread pool @Bean("executor-demo-service") public Executor demoServiceExecutor() { return new DemoServiceExecutor(); } // customized thread pool @Bean("executor-hello-service") public Executor helloServiceExecutor() { return new HelloServiceExecutor(); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/provider/HelloServiceImplV3.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/provider/HelloServiceImplV3.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.config.spring.isolation.spring.annotation.provider; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.api.HelloService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @DubboService(executor = "executor-hello-service", version = "2.0.0", group = "Group2") public class HelloServiceImplV3 implements HelloService { private static final Logger logger = LoggerFactory.getLogger(HelloServiceImplV3.class); @Override public String sayHello(String name) { return "server hello"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/provider/DemoServiceImplV1.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/provider/DemoServiceImplV1.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.config.spring.isolation.spring.annotation.provider; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; @DubboService(executor = "executor-demo-service", version = "1.0.0", group = "Group1") public class DemoServiceImplV1 implements DemoService { @Override public String sayName(String name) { return "server name"; } @Override public Box getBox() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/provider/HelloServiceImplV2.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/provider/HelloServiceImplV2.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.config.spring.isolation.spring.annotation.provider; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.api.HelloService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @DubboService(version = "3.0.0", group = "Group3") public class HelloServiceImplV2 implements HelloService { private static final Logger logger = LoggerFactory.getLogger(HelloServiceImplV2.class); @Override public String sayHello(String name) { return "server hello"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/dubbo/HelloServiceV2.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/dubbo/HelloServiceV2.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.config.spring.isolation.spring.annotation.consumer.dubbo; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.HelloService; import org.springframework.stereotype.Component; @Component("dubbo-helloServiceV2") public class HelloServiceV2 implements HelloService { @DubboReference(version = "2.0.0", group = "Group2", scope = "remote", protocol = "dubbo") private HelloService helloService; @Override public String sayHello(String name) { return helloService.sayHello(name); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/dubbo/HelloServiceV3.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/dubbo/HelloServiceV3.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.config.spring.isolation.spring.annotation.consumer.dubbo; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.HelloService; import org.springframework.stereotype.Component; @Component("dubbo-helloServiceV3") public class HelloServiceV3 implements HelloService { @DubboReference(version = "3.0.0", group = "Group3", scope = "remote", protocol = "dubbo") private HelloService helloService; @Override public String sayHello(String name) { return helloService.sayHello(name); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/dubbo/DemoServiceV1.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/dubbo/DemoServiceV1.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.config.spring.isolation.spring.annotation.consumer.dubbo; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; import org.springframework.stereotype.Component; @Component("dubbo-demoServiceV1") public class DemoServiceV1 implements DemoService { @DubboReference(version = "1.0.0", group = "Group1", scope = "remote", protocol = "dubbo") private DemoService demoService; @Override public String sayName(String name) { return demoService.sayName(name); } @Override public Box getBox() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/tri/HelloServiceV2.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/tri/HelloServiceV2.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.config.spring.isolation.spring.annotation.consumer.tri; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.HelloService; import org.springframework.stereotype.Component; @Component("tri-helloServiceV2") public class HelloServiceV2 implements HelloService { @DubboReference(version = "2.0.0", group = "Group2", scope = "remote", protocol = "tri") private HelloService helloService; @Override public String sayHello(String name) { return helloService.sayHello(name); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/tri/HelloServiceV3.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/tri/HelloServiceV3.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.config.spring.isolation.spring.annotation.consumer.tri; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.HelloService; import org.springframework.stereotype.Component; @Component("tri-helloServiceV3") public class HelloServiceV3 implements HelloService { @DubboReference(version = "3.0.0", group = "Group3", scope = "remote", protocol = "tri") private HelloService helloService; @Override public String sayHello(String name) { return helloService.sayHello(name); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/tri/DemoServiceV1.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/isolation/spring/annotation/consumer/tri/DemoServiceV1.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.config.spring.isolation.spring.annotation.consumer.tri; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; import org.springframework.stereotype.Component; @Component("tri-demoServiceV1") public class DemoServiceV1 implements DemoService { @DubboReference(version = "1.0.0", group = "Group1", scope = "remote", protocol = "tri") private DemoService demoService; @Override public String sayName(String name) { return demoService.sayName(name); } @Override public Box getBox() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/action/DemoInterceptor.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/action/DemoInterceptor.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.config.spring.action; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; public class DemoInterceptor implements MethodInterceptor { public Object invoke(MethodInvocation invocation) throws Throwable { return "aop:" + invocation.proceed(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/action/DemoActionByAnnotation.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/action/DemoActionByAnnotation.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.config.spring.action; import org.apache.dubbo.config.spring.api.DemoService; import org.springframework.beans.factory.annotation.Autowired; /** * DemoAction */ public class DemoActionByAnnotation { @Autowired private DemoService demoService; public DemoService getDemoService() { return demoService; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/action/DemoActionBySetter.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/action/DemoActionBySetter.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.config.spring.action; import org.apache.dubbo.config.spring.api.DemoService; /** * DemoAction */ public class DemoActionBySetter { private DemoService demoService; public DemoService getDemoService() { return demoService; } public void setDemoService(DemoService demoService) { this.demoService = demoService; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/samples/ZookeeperDubboSpringConsumerXmlBootstrap.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/samples/ZookeeperDubboSpringConsumerXmlBootstrap.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.config.spring.samples; import org.apache.dubbo.config.spring.api.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Zookeeper Dubbo Spring Provider XML Bootstrap * * @since 2.7.8 */ public class ZookeeperDubboSpringConsumerXmlBootstrap { private static final Logger logger = LoggerFactory.getLogger(ZookeeperDubboSpringConsumerXmlBootstrap.class); public static void main(String[] args) throws Exception { String location = "classpath:/META-INF/service-introspection/zookeeper-dubbo-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(location); DemoService demoService = context.getBean("demoService", DemoService.class); for (int i = 0; i < 100; i++) { logger.info(demoService.sayName("Hello")); } context.close(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/samples/ZookeeperDubboSpringProviderBootstrap.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/samples/ZookeeperDubboSpringProviderBootstrap.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.config.spring.samples; import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.rpc.RpcContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; import static java.lang.String.format; /** * Zookeeper Dubbo Spring Provider Bootstrap * * @since 2.7.8 */ @EnableDubbo @PropertySource("classpath:/META-INF/service-introspection/zookeeper-dubbb-provider.properties") public class ZookeeperDubboSpringProviderBootstrap { public static void main(String[] args) throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ZookeeperDubboSpringProviderBootstrap.class); System.in.read(); context.close(); } } @DubboService class DefaultDemoService implements DemoService { @Override public String sayName(String name) { RpcContext rpcContext = RpcContext.getServiceContext(); return format("[%s:%s] Say - %s", rpcContext.getLocalHost(), rpcContext.getLocalPort(), name); } @Override public Box getBox() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/samples/ZookeeperDubboSpringConsumerBootstrap.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/samples/ZookeeperDubboSpringConsumerBootstrap.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.config.spring.samples; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; /** * Zookeeper Dubbo Spring Provider Bootstrap * * @since 2.7.8 */ @EnableDubboConfig @PropertySource("classpath:/META-INF/service-introspection/zookeeper-dubbb-consumer.properties") public class ZookeeperDubboSpringConsumerBootstrap { private static final Logger logger = LoggerFactory.getLogger(ZookeeperDubboSpringConsumerBootstrap.class); @DubboReference(services = "${dubbo.provider.name},${dubbo.provider.name1},${dubbo.provider.name2}") private DemoService demoService; public static void main(String[] args) throws Exception { Class<?> beanType = ZookeeperDubboSpringConsumerBootstrap.class; AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanType); ZookeeperDubboSpringConsumerBootstrap bootstrap = context.getBean(ZookeeperDubboSpringConsumerBootstrap.class); for (int i = 0; i < 100; i++) { logger.info(bootstrap.demoService.sayName("Hello")); Thread.sleep(1000L); } System.in.read(); context.close(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/metrics/SpringBootConfigMetricsTest.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/metrics/SpringBootConfigMetricsTest.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.config.spring.metrics; import org.apache.dubbo.config.MetricsConfig; import org.apache.dubbo.config.bootstrap.DubboBootstrap; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS; @SpringBootTest( properties = { "dubbo.application.NAME = dubbo-demo-application", "dubbo.module.name = dubbo-demo-module", "dubbo.registry.address = zookeeper://localhost:2181", "dubbo.protocol.name=dubbo", "dubbo.protocol.port=20880", "dubbo.metrics.protocol=prometheus", "dubbo.metrics.export-service-protocol=tri", "dubbo.metrics.export-service-port=9999", "dubbo.metrics.enable-jvm=true", "dubbo.metrics.prometheus.exporter.enabled=true", "dubbo.metrics.prometheus.exporter.enable-http-service-discovery=true", "dubbo.metrics.prometheus.exporter.http-service-discovery-url=localhost:8080", "dubbo.metrics.aggregation.enabled=true", "dubbo.metrics.aggregation.bucket-num=5", "dubbo.metrics.aggregation.time-window-seconds=120", "dubbo.metrics.histogram.enabled=true", "dubbo.metadata-report.address=${zookeeper.connection.address.2}" }, classes = {SpringBootConfigMetricsTest.class}) @Configuration @ComponentScan @EnableDubbo public class SpringBootConfigMetricsTest { @BeforeAll public static void beforeAll() { DubboBootstrap.reset(); } @AfterAll public static void afterAll() { DubboBootstrap.reset(); } @Autowired private ConfigManager configManager; @Test public void testMetrics() { MetricsConfig metricsConfig = configManager.getMetrics().get(); Assertions.assertEquals(PROTOCOL_PROMETHEUS, metricsConfig.getProtocol()); Assertions.assertTrue(metricsConfig.getEnableJvm()); Assertions.assertEquals("tri", metricsConfig.getExportServiceProtocol()); Assertions.assertEquals(9999, metricsConfig.getExportServicePort()); Assertions.assertTrue(metricsConfig.getPrometheus().getExporter().getEnabled()); Assertions.assertTrue(metricsConfig.getPrometheus().getExporter().getEnableHttpServiceDiscovery()); Assertions.assertEquals( "localhost:8080", metricsConfig.getPrometheus().getExporter().getHttpServiceDiscoveryUrl()); Assertions.assertEquals(5, metricsConfig.getAggregation().getBucketNum()); Assertions.assertEquals(120, metricsConfig.getAggregation().getTimeWindowSeconds()); Assertions.assertTrue(metricsConfig.getAggregation().getEnabled()); Assertions.assertTrue(metricsConfig.getHistogram().getEnabled()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/MethodCallbackImpl.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/MethodCallbackImpl.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.config.spring.impl; import org.apache.dubbo.config.spring.api.MethodCallback; import javax.annotation.PostConstruct; import java.util.concurrent.atomic.AtomicInteger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionSynchronizationManager; public class MethodCallbackImpl implements MethodCallback { private String onInvoke1 = ""; private final Object lock = new Object(); private String onReturn1 = ""; private String onThrow1 = ""; private String onInvoke2 = ""; private String onReturn2 = ""; private String onThrow2 = ""; @Autowired private Environment environment; @Autowired private ApplicationContext context; public static AtomicInteger cnt = new AtomicInteger(); @PostConstruct protected void init() { checkInjection(); } @Transactional(rollbackFor = Exception.class) @Override public void oninvoke1(String request) { try { checkInjection(); checkTranscation(); synchronized (lock) { this.onInvoke1 += "dubbo invoke success!"; } } catch (Exception e) { synchronized (lock) { this.onInvoke1 += e.toString(); } throw e; } } @Transactional(rollbackFor = Exception.class) @Override public void oninvoke2(String request) { try { checkInjection(); checkTranscation(); synchronized (lock) { this.onInvoke2 += "dubbo invoke success(2)!"; } } catch (Exception e) { synchronized (lock) { this.onInvoke2 += e.toString(); } throw e; } } @Override @Transactional(rollbackFor = Exception.class) public void onreturn1(String response, String request) { try { checkInjection(); checkTranscation(); synchronized (lock) { this.onReturn1 += "dubbo return success!"; } } catch (Exception e) { synchronized (lock) { this.onReturn1 += e.toString(); } throw e; } finally { cnt.incrementAndGet(); } } @Override @Transactional(rollbackFor = Exception.class) public void onreturn2(String response, String request) { try { checkInjection(); checkTranscation(); synchronized (lock) { this.onReturn2 += "dubbo return success(2)!"; } } catch (Exception e) { synchronized (lock) { this.onReturn2 += e.toString(); } throw e; } finally { cnt.incrementAndGet(); } } @Override @Transactional(rollbackFor = Exception.class) public void onthrow1(Throwable ex, String request) { try { checkInjection(); checkTranscation(); synchronized (lock) { this.onThrow1 += "dubbo throw exception!"; } } catch (Exception e) { synchronized (lock) { this.onThrow1 += e.toString(); } throw e; } } @Override @Transactional(rollbackFor = Exception.class) public void onthrow2(Throwable ex, String request) { try { checkInjection(); checkTranscation(); synchronized (lock) { this.onThrow2 += "dubbo throw exception(2)!"; } } catch (Exception e) { synchronized (lock) { this.onThrow2 += e.toString(); } throw e; } } public String getOnInvoke1() { return this.onInvoke1; } public String getOnReturn1() { return this.onReturn1; } public String getOnThrow1() { return this.onThrow1; } public String getOnInvoke2() { return this.onInvoke2; } public String getOnReturn2() { return this.onReturn2; } public String getOnThrow2() { return this.onThrow2; } private void checkInjection() { if (environment == null) { throw new IllegalStateException("environment is null"); } if (context == null) { throw new IllegalStateException("application context is null"); } } private void checkTranscation() { if (!TransactionSynchronizationManager.isActualTransactionActive()) { throw new IllegalStateException("No active transaction"); } } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceImpl.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/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.config.spring.impl; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; public class DemoServiceImpl implements DemoService { private String prefix = "say:"; public String sayName(String name) { return prefix + name; } public Box getBox() { return null; } public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/HelloServiceImpl.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.config.spring.impl; import org.apache.dubbo.config.spring.api.HelloService; public class HelloServiceImpl implements HelloService { 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-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceSonImpl.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceSonImpl.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.config.spring.impl; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoServiceSon; public class DemoServiceSonImpl implements DemoServiceSon { private String prefix = "say:"; public String sayName(String name) { return prefix + name; } public Box getBox() { return null; } public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceImpl_LongWaiting.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/DemoServiceImpl_LongWaiting.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.config.spring.impl; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; /** * DemoServiceImpl */ public class DemoServiceImpl_LongWaiting implements DemoService { public String sayName(String name) { try { Thread.sleep(100 * 1000); } catch (InterruptedException e) { } return "say:" + name; } public Box getBox() { return null; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/NotifyService.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/NotifyService.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.config.spring.impl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class NotifyService { private static final Logger logger = LoggerFactory.getLogger(NotifyService.class); public void onInvoke(Object[] params) { logger.info("invoke param-0: {}", params[0]); } public void onReturn(Object result, Object[] params) { logger.info("invoke param-0: {}, return: {}", params[0], result); } public void onThrow(Throwable t, Object[] params) { logger.info("invoke param-0: {}, throw: {}", params[0], t.getMessage()); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/UnserializableBox.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/UnserializableBox.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.config.spring.impl; import org.apache.dubbo.config.spring.api.Box; public class UnserializableBox implements Box { private static final long serialVersionUID = -4141012025649711421L; private int count = 3; private String name = "Jerry"; public int getCount() { return count; } public void setCount(int count) { this.count = count; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Box [count=" + count + ", name=" + name + "]"; } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false
apache/dubbo
https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/UnserializableBoxDemoServiceImpl.java
dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/impl/UnserializableBoxDemoServiceImpl.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.config.spring.impl; import org.apache.dubbo.config.spring.api.Box; import org.apache.dubbo.config.spring.api.DemoService; /** * DemoServiceImpl */ public class UnserializableBoxDemoServiceImpl implements DemoService { public String sayName(String name) { return "say:" + name; } public Box getBox() { return new UnserializableBox(); } }
java
Apache-2.0
ac1621f9a0470054c0308c47f84c7668f6bc2868
2026-01-04T14:45:57.057261Z
false