diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc092e184..f66e33a4ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ --- - [feat: implement circuit breaker in enhance plugin, support listen config group, support refresh single config in refresh_context mode.](https://github.com/Tencent/spring-cloud-tencent/pull/1500) +- [feat:support polaris event.](https://github.com/Tencent/spring-cloud-tencent/pull/1523) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisAutoServiceRegistration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisAutoServiceRegistration.java index db0ebc2b9a..8e18a0a2be 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisAutoServiceRegistration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisAutoServiceRegistration.java @@ -17,8 +17,15 @@ package com.tencent.cloud.polaris.registry; +import java.time.LocalDateTime; + import com.tencent.cloud.polaris.PolarisDiscoveryProperties; +import com.tencent.polaris.api.plugin.compose.Extensions; +import com.tencent.polaris.api.plugin.event.FlowEvent; +import com.tencent.polaris.api.plugin.event.FlowEventConstants; +import com.tencent.polaris.api.pojo.ServiceEventKey; import com.tencent.polaris.assembly.api.AssemblyAPI; +import com.tencent.polaris.client.flow.BaseFlow; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,6 +91,25 @@ protected void registerManagement() { @Override protected void deregister() { + // report thread end event. + if (this.registration.getPolarisContext() != null + && this.registration.getPolarisContext().getExtensions() != null) { + Extensions extensions = this.registration.getPolarisContext().getExtensions(); + FlowEvent.Builder flowEventBuilder = new FlowEvent.Builder() + .withEventType(ServiceEventKey.EventType.INSTANCE) + .withEventName(FlowEventConstants.EventName.InstanceThreadEnd) + .withTimestamp(LocalDateTime.now()) + .withClientId(extensions.getValueContext().getClientId()) + .withClientIp(extensions.getValueContext().getHost()) + .withNamespace(polarisDiscoveryProperties.getNamespace()) + .withService(registration.getServiceId()) + .withHost(registration.getHost()) + .withPort(registration.getPort()); + + FlowEvent flowEvent = flowEventBuilder.build(); + BaseFlow.reportFlowEvent(extensions, flowEvent); + } + if (!this.registration.isRegisterEnabled()) { return; } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java index 9a0f999366..f8b93b9b1e 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisRegistration.java @@ -56,13 +56,12 @@ public class PolarisRegistration implements Registration { private final SDKContext polarisContext; private final StaticMetadataManager staticMetadataManager; - - private String serviceId; private final String host; private final boolean isSecure; private final ServletWebServerApplicationContext servletWebServerApplicationContext; private final ReactiveWebServerApplicationContext reactiveWebServerApplicationContext; private final List customizers; + private String serviceId; private boolean registerEnabled = false; private Map metadata; private Map> extendedMetadata; @@ -164,15 +163,15 @@ public void customize() { } } - public void setServiceId(String serviceId) { - this.serviceId = serviceId; - } - @Override public String getServiceId() { return serviceId; } + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + @Override public String getHost() { return host; @@ -238,6 +237,10 @@ public boolean isRegisterEnabled() { return registerEnabled; } + public SDKContext getPolarisContext() { + return polarisContext; + } + @Override public String toString() { return "PolarisRegistration{" + diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/OrderConstant.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/OrderConstant.java index 39a28ab899..14bf52f0ed 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/OrderConstant.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/constant/OrderConstant.java @@ -206,5 +206,10 @@ public static final class Modifier { * Order of trace configuration modifier. */ public static Integer TRACE_ORDER = 2; + + /** + * Order of push gateway event reporter modifier. + */ + public static Integer PUSH_GATEWAY_EVENT_ORDER = 2; } } diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 47505cf26d..9c1984ccb7 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -74,7 +74,7 @@ 2.0.1.0-2022.0.5-SNAPSHOT - 2.0.0.1 + 2.0.1.0-SNAPSHOT 32.0.1-jre diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java index bbf8ea6190..a3fff2fd52 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java @@ -23,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; -import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -56,9 +55,6 @@ public class CircuitBreakerController { @Autowired private CircuitBreakerFactory circuitBreakerFactory; - @Autowired - private ReactiveCircuitBreakerFactory reactiveCircuitBreakerFactory; - @Autowired private WebClient.Builder webClientBuilder; @@ -146,11 +142,6 @@ public Mono webclient() { .get() .uri("/quickstart/callee/circuitBreak") .retrieve() - .bodyToMono(String.class) - .transform(it -> - reactiveCircuitBreakerFactory - .create(MetadataContext.LOCAL_NAMESPACE + "QuickstartCalleeService#/quickstart/callee/circuitBreak#http#GET") - .run(it, throwable -> Mono.just("fallback: trigger the refuse for service callee")) - ); + .bodyToMono(String.class); } } diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-security-protection-plugin/src/main/resources/META-INF/spring.factories b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-security-protection-plugin/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 3e0f0ee081..0000000000 --- a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-security-protection-plugin/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Auto Configuration -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -com.tencent.cloud.plugin.protection.SecurityProtectionAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-security-protection-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-security-protection-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..778b1e84a7 --- /dev/null +++ b/spring-cloud-tencent-plugin-starters/spring-cloud-tencent-security-protection-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.tencent.cloud.plugin.protection.SecurityProtectionAutoConfiguration diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java index c9f3e991d7..a77abde5d5 100644 --- a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/config/PolarisContextAutoConfiguration.java @@ -29,6 +29,8 @@ import com.tencent.cloud.polaris.context.config.extend.consul.ConsulProperties; import com.tencent.cloud.polaris.context.config.extend.tsf.TsfCoreProperties; import com.tencent.cloud.polaris.context.config.extend.tsf.TsfInstanceMetadataProvider; +import com.tencent.cloud.polaris.context.event.PushGatewayEventReporterConfigModifier; +import com.tencent.cloud.polaris.context.event.PushGatewayEventReporterProperties; import com.tencent.cloud.polaris.context.listener.PolarisContextApplicationEventListener; import com.tencent.polaris.api.exception.PolarisException; import com.tencent.polaris.client.api.SDKContext; @@ -81,6 +83,18 @@ public PolarisAdminConfigModifier polarisAdminConfigModifier(PolarisAdminPropert return new PolarisAdminConfigModifier(polarisAdminProperties); } + @Bean + @ConditionalOnMissingBean + public PushGatewayEventReporterProperties pushGatewayEventReporterProperties() { + return new PushGatewayEventReporterProperties(); + } + + @Bean + @ConditionalOnMissingBean + public PushGatewayEventReporterConfigModifier pushGatewayEventReporterConfigModifier(PushGatewayEventReporterProperties pushGatewayEventReporterProperties) { + return new PushGatewayEventReporterConfigModifier(pushGatewayEventReporterProperties); + } + @Bean @ConditionalOnMissingBean public ConsulProperties consulProperties() { diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterConfigModifier.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterConfigModifier.java new file mode 100644 index 0000000000..175055afcc --- /dev/null +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterConfigModifier.java @@ -0,0 +1,65 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.context.event; + +import com.tencent.cloud.common.constant.OrderConstant; +import com.tencent.cloud.polaris.context.PolarisConfigModifier; +import com.tencent.polaris.api.config.plugin.DefaultPlugins; +import com.tencent.polaris.api.utils.StringUtils; +import com.tencent.polaris.factory.config.ConfigurationImpl; +import com.tencent.polaris.plugins.event.pushgateway.PushGatewayEventReporterConfig; + +/** + * Modifier for push gateway event reporter. + * + * @author Haotian Zhang + */ +public class PushGatewayEventReporterConfigModifier implements PolarisConfigModifier { + + private final PushGatewayEventReporterProperties properties; + + public PushGatewayEventReporterConfigModifier(PushGatewayEventReporterProperties properties) { + this.properties = properties; + } + + @Override + public void modify(ConfigurationImpl configuration) { + configuration.getGlobal().getEventReporter().getReporters() + .add(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE); + + PushGatewayEventReporterConfig pushGatewayEventReporterConfig = new PushGatewayEventReporterConfig(); + if (!properties.isEnabled() || StringUtils.isBlank(properties.getAddress())) { + pushGatewayEventReporterConfig.setEnable(false); + return; + } + else { + pushGatewayEventReporterConfig.setEnable(true); + } + pushGatewayEventReporterConfig.setAddress(properties.getAddress()); + pushGatewayEventReporterConfig.setEventQueueSize(properties.getEventQueueSize()); + pushGatewayEventReporterConfig.setMaxBatchSize(properties.getMaxBatchSize()); + + configuration.getGlobal().getEventReporter() + .setPluginConfig(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE, pushGatewayEventReporterConfig); + } + + @Override + public int getOrder() { + return OrderConstant.Modifier.PUSH_GATEWAY_EVENT_ORDER; + } +} diff --git a/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterProperties.java b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterProperties.java new file mode 100644 index 0000000000..4854693d80 --- /dev/null +++ b/spring-cloud-tencent-polaris-context/src/main/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterProperties.java @@ -0,0 +1,91 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.context.event; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Properties for Polaris push gateway event reporter. + * + * @author Haotian Zhang + */ +@ConfigurationProperties(prefix = "spring.cloud.polaris.event.pushgateway") +public class PushGatewayEventReporterProperties { + + /** + * If push gateway event enabled. + */ + private boolean enabled = false; + + /** + * Address of pushgateway. For example: 1.2.3.4:9091. + */ + private String address; + + /** + * Queue size for push gateway event queue. Default is 1000. + */ + private int eventQueueSize = 1000; + + /** + * Max batch size for push gateway event. Default is 100. + */ + private int maxBatchSize = 100; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public int getEventQueueSize() { + return eventQueueSize; + } + + public void setEventQueueSize(int eventQueueSize) { + this.eventQueueSize = eventQueueSize; + } + + public int getMaxBatchSize() { + return maxBatchSize; + } + + public void setMaxBatchSize(int maxBatchSize) { + this.maxBatchSize = maxBatchSize; + } + + @Override + public String toString() { + return "PushGatewayEventReporterProperties{" + + "enabled=" + enabled + + ", address='" + address + '\'' + + ", eventQueueSize=" + eventQueueSize + + ", maxBatchSize=" + maxBatchSize + + '}'; + } +} diff --git a/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json index f3244d1fdc..736469d7d3 100644 --- a/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-tencent-polaris-context/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -17,21 +17,21 @@ "name": "spring.cloud.polaris.namespace", "type": "java.lang.String", "description": "polaris namespace", - "default": "default", + "defaultValue": "default", "sourceType": "com.tencent.cloud.polaris.context.config.PolarisContextProperties" }, { "name": "spring.cloud.polaris.service", "type": "java.lang.String", "description": "polaris service name", - "default": "${spring.application.name}", + "defaultValue": "${spring.application.name}", "sourceType": "com.tencent.cloud.polaris.context.config.PolarisContextProperties" }, { "name": "spring.cloud.polaris.enabled", "type": "java.lang.Boolean", "description": "polaris enabled", - "default": "true", + "defaultValue": "true", "sourceType": "com.tencent.cloud.polaris.context.config.PolarisContextProperties" }, { @@ -51,6 +51,29 @@ "type": "java.lang.String", "defaultValue": "./polaris/logs", "description": "polaris log storage path." + }, + { + "name": "spring.cloud.polaris.event.pushgateway.enabled", + "type": "java.lang.Boolean", + "description": "If push gateway event reporter is enabled.", + "defaultValue": false + }, + { + "name": "spring.cloud.polaris.event.pushgateway.address", + "type": "java.lang.String", + "description": "Address of pushgateway. For example: 1.2.3.4:9091." + }, + { + "name": "spring.cloud.polaris.event.pushgateway.eventQueueSize", + "type": "java.lang.Integer", + "description": "Queue size for push gateway event queue. Default is 1000.", + "defaultValue": 1000 + }, + { + "name": "spring.cloud.polaris.event.pushgateway.maxBatchSize", + "type": "java.lang.Integer", + "description": "Max batch size for push gateway event. Default is 100.", + "defaultValue": 100 } ], "hints": [] diff --git a/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterConfigModifierTest.java b/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterConfigModifierTest.java new file mode 100644 index 0000000000..091bdf6a88 --- /dev/null +++ b/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterConfigModifierTest.java @@ -0,0 +1,64 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.context.event; + +import com.tencent.cloud.polaris.context.PolarisSDKContextManager; +import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; +import com.tencent.polaris.api.config.plugin.DefaultPlugins; +import com.tencent.polaris.plugins.event.pushgateway.PushGatewayEventReporterConfig; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for {@link PushGatewayEventReporterConfigModifier}. + * + * @author Haotian Zhang + */ +public class PushGatewayEventReporterConfigModifierTest { + + private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PolarisContextAutoConfiguration.class)) + .withPropertyValues("spring.cloud.polaris.event.pushgateway.enabled=true") + .withPropertyValues("spring.cloud.polaris.event.pushgateway.address=1.2.3.4:9091") + .withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123") + .withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456"); + + @BeforeEach + void setUp() { + PolarisSDKContextManager.innerDestroy(); + } + + @Test + public void testModify() { + this.applicationContextRunner.run(context -> { + PolarisSDKContextManager polarisSDKContextManager = context.getBean(PolarisSDKContextManager.class); + PushGatewayEventReporterConfig config = polarisSDKContextManager.getSDKContext(). + getConfig().getGlobal().getEventReporter() + .getPluginConfig(DefaultPlugins.PUSH_GATEWAY_EVENT_REPORTER_TYPE, PushGatewayEventReporterConfig.class); + assertThat(config.isEnable()).isTrue(); + assertThat(config.getAddress()).isEqualTo("1.2.3.4:9091"); + assertThat(config.getEventQueueSize()).isEqualTo(123); + assertThat(config.getMaxBatchSize()).isEqualTo(456); + }); + } +} diff --git a/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterPropertiesTest.java b/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterPropertiesTest.java new file mode 100644 index 0000000000..112db07228 --- /dev/null +++ b/spring-cloud-tencent-polaris-context/src/test/java/com/tencent/cloud/polaris/context/event/PushGatewayEventReporterPropertiesTest.java @@ -0,0 +1,59 @@ +/* + * Tencent is pleased to support the open source community by making spring-cloud-tencent available. + * + * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.context.event; + +import com.tencent.cloud.polaris.context.PolarisSDKContextManager; +import com.tencent.cloud.polaris.context.config.PolarisContextAutoConfiguration; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for {@link PushGatewayEventReporterProperties}. + * + * @author Haotian Zhang + */ +public class PushGatewayEventReporterPropertiesTest { + + private final ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(PolarisContextAutoConfiguration.class)) + .withPropertyValues("spring.cloud.polaris.event.pushgateway.enabled=true") + .withPropertyValues("spring.cloud.polaris.event.pushgateway.address=1.2.3.4:9091") + .withPropertyValues("spring.cloud.polaris.event.pushgateway.eventQueueSize=123") + .withPropertyValues("spring.cloud.polaris.event.pushgateway.maxBatchSize=456"); + + @BeforeEach + void setUp() { + PolarisSDKContextManager.innerDestroy(); + } + + @Test + public void testGetAndSet() { + this.applicationContextRunner.run(context -> { + PushGatewayEventReporterProperties properties = context.getBean(PushGatewayEventReporterProperties.class); + assertThat(properties.isEnabled()).isTrue(); + assertThat(properties.getAddress()).isEqualTo("1.2.3.4:9091"); + assertThat(properties.getEventQueueSize()).isEqualTo(123); + assertThat(properties.getMaxBatchSize()).isEqualTo(456); + }); + } +}