Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase spring autoconfigure module unit test coverage #6750

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] add unit test for sql-parser-core
- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] improve the test case coverage of saga module to 70%
- [[#6695](https://github.com/apache/incubator-seata/pull/6695)] old version(< 0.7.1) client test case for multi-version protocol
- [[#6750](https://github.com/apache/incubator-seata/pull/6750)] increase spring autoconfigure module unit test converage

Thanks to these contributors for their code commits. Please report an unintended omission.

Expand All @@ -97,6 +98,7 @@ Thanks to these contributors for their code commits. Please report an unintended
- [caohdgege](https://github.com/caohdgege)
- [imashimaro](https://github.com/hmj776521114)
- [lyl2008dsg](https://github.com/lyl2008dsg)
- [l81893521](https://github.com/l81893521)


Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- [[#6608](https://github.com/apache/incubator-seata/pull/6608)] 添加sql-parser-core模块测试用例
- [[#6647](https://github.com/apache/incubator-seata/pull/6647)] 增加saga模块的测试用例覆盖率
- [[#6695](https://github.com/apache/incubator-seata/pull/6695)] 多版本协议的旧版本(< 0.7.1)客户端测试用例
- [[#6750](https://github.com/apache/incubator-seata/pull/6750)] 提升spring autoconfigure模块单测覆盖率



Expand Down Expand Up @@ -102,6 +103,7 @@
- [caohdgege](https://github.com/caohdgege)
- [imashimaro](https://github.com/hmj776521114)
- [lyl2008dsg](https://github.com/lyl2008dsg)
- [l81893521](https://github.com/l81893521)



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.seata.spring.boot.autoconfigure;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.Ordered;

public class SeataClientEnvironmentPostProcessorTest {

@Test
public void testSeataClientEnvironmentPostProcessor() {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext("io.seata.spring.boot.autoconfigure.properties");

SeataClientEnvironmentPostProcessor seataClientEnvironmentPostProcessor = new SeataClientEnvironmentPostProcessor();
seataClientEnvironmentPostProcessor.postProcessEnvironment(applicationContext.getEnvironment(), null);
Assertions.assertEquals(Ordered.HIGHEST_PRECEDENCE, seataClientEnvironmentPostProcessor.getOrder());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.seata.spring.boot.autoconfigure.properties;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SagaAsyncThreadPoolPropertiesTest {

@Test
public void testSagaAsyncThreadPoolProperties() {
SagaAsyncThreadPoolProperties sagaAsyncThreadPoolProperties = new SagaAsyncThreadPoolProperties();
sagaAsyncThreadPoolProperties.setCorePoolSize(1);
Assertions.assertEquals(1, sagaAsyncThreadPoolProperties.getCorePoolSize());

sagaAsyncThreadPoolProperties.setMaxPoolSize(1);
Assertions.assertEquals(1, sagaAsyncThreadPoolProperties.getMaxPoolSize());

sagaAsyncThreadPoolProperties.setKeepAliveTime(1);
Assertions.assertEquals(1, sagaAsyncThreadPoolProperties.getKeepAliveTime());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.seata.spring.boot.autoconfigure.properties;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SeataPropertiesTest {

@Test
public void testSeataProperties() {
SeataProperties seataProperties = new SeataProperties();
seataProperties.setEnabled(true);
Assertions.assertTrue(seataProperties.isEnabled());

seataProperties.setApplicationId("applicationId");
Assertions.assertEquals("applicationId", seataProperties.getApplicationId());

seataProperties.setTxServiceGroup("group");
Assertions.assertEquals("group", seataProperties.getTxServiceGroup());

seataProperties.setEnableAutoDataSourceProxy(true);
Assertions.assertTrue(seataProperties.isEnableAutoDataSourceProxy());

seataProperties.setDataSourceProxyMode("AT");
Assertions.assertEquals("AT", seataProperties.getDataSourceProxyMode());

seataProperties.setUseJdkProxy(true);
Assertions.assertTrue(seataProperties.isUseJdkProxy());

String[] excludesForAutoProxying = new String[]{"test"};
seataProperties.setExcludesForAutoProxying(excludesForAutoProxying);
Assertions.assertEquals(excludesForAutoProxying, seataProperties.getExcludesForAutoProxying());

String[] scanPackages = new String[]{"com"};
seataProperties.setScanPackages(scanPackages);
Assertions.assertEquals(scanPackages, seataProperties.getScanPackages());

String[] excludesForScanning = new String[]{"com"};
seataProperties.setExcludesForScanning(excludesForScanning);
Assertions.assertEquals(excludesForScanning, seataProperties.getExcludesForScanning());

seataProperties.setAccessKey("key");
Assertions.assertEquals("key", seataProperties.getAccessKey());

seataProperties.setSecretKey("secret");
Assertions.assertEquals("secret", seataProperties.getSecretKey());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.seata.spring.boot.autoconfigure.properties;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.PropertiesPropertySource;

import java.util.Properties;

public class SpringCloudAlibabaConfigurationTest {

@Test
public void testSpringCloudAlibabaConfiguration() {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext("org.apache.seata.spring.boot.autoconfigure.properties");
Properties properties = new Properties();
properties.setProperty("spring.application.name", "test");
applicationContext.getEnvironment().getPropertySources().addFirst(new PropertiesPropertySource("my_test", properties));

SpringCloudAlibabaConfiguration springCloudAlibabaConfiguration = (SpringCloudAlibabaConfiguration) applicationContext.getBean("springCloudAlibabaConfiguration");

// application id is null
Assertions.assertEquals("test", springCloudAlibabaConfiguration.getApplicationId());
// application is not null
Assertions.assertEquals("test", springCloudAlibabaConfiguration.getApplicationId());
Assertions.assertEquals("default_tx_group", springCloudAlibabaConfiguration.getTxServiceGroup());
springCloudAlibabaConfiguration.setTxServiceGroup("default_tx_group_1");
Assertions.assertEquals("default_tx_group_1", springCloudAlibabaConfiguration.getTxServiceGroup());
applicationContext.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.seata.config.FileConfiguration;
import org.apache.seata.config.springcloud.SpringApplicationContextProvider;
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;
Expand Down Expand Up @@ -61,6 +62,13 @@ public void testLoadBalanceProperties() {
assertEquals(30, currentConfiguration.getInt("client.loadBalance.virtualNodes"));
System.setProperty("seata.client.loadBalance.type", "test");
assertEquals("test", currentConfiguration.getConfig("client.loadBalance.type"));

LoadBalanceProperties loadBalanceProperties = new LoadBalanceProperties();
loadBalanceProperties.setType("type");
Assertions.assertEquals("type", loadBalanceProperties.getType());

loadBalanceProperties.setVirtualNodes(1);
Assertions.assertEquals(1, loadBalanceProperties.getVirtualNodes());
}

@AfterAll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.seata.spring.boot.autoconfigure.properties.client;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class LockPropertiesTest {

@Test
public void testLockProperties() {
LockProperties lockProperties = new LockProperties();
lockProperties.setRetryInterval(1);
Assertions.assertEquals(1, lockProperties.getRetryInterval());

lockProperties.setRetryTimes(1);
Assertions.assertEquals(1, lockProperties.getRetryTimes());

lockProperties.setRetryPolicyBranchRollbackOnConflict(true);
Assertions.assertEquals(true, lockProperties.isRetryPolicyBranchRollbackOnConflict());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.seata.spring.boot.autoconfigure.properties.client;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class RmPropertiesTest {

@Test
public void testRmProperties() {
RmProperties rmProperties = new RmProperties();
rmProperties.setAsyncCommitBufferLimit(1);
Assertions.assertEquals(1, rmProperties.getAsyncCommitBufferLimit());

rmProperties.setReportRetryCount(1);
Assertions.assertEquals(1, rmProperties.getReportRetryCount());

rmProperties.setTableMetaCheckEnable(true);
Assertions.assertTrue(rmProperties.isTableMetaCheckEnable());

rmProperties.setReportSuccessEnable(true);
Assertions.assertTrue(rmProperties.isReportSuccessEnable());

rmProperties.setSagaBranchRegisterEnable(true);
Assertions.assertTrue(rmProperties.isSagaBranchRegisterEnable());

rmProperties.setSagaJsonParser("json");
Assertions.assertEquals("json", rmProperties.getSagaJsonParser());

rmProperties.setTableMetaCheckerInterval(1);
Assertions.assertEquals(1, rmProperties.getTableMetaCheckerInterval());

rmProperties.setSagaRetryPersistModeUpdate(true);
Assertions.assertTrue(rmProperties.isSagaRetryPersistModeUpdate());

rmProperties.setSagaCompensatePersistModeUpdate(true);
Assertions.assertTrue(rmProperties.isSagaCompensatePersistModeUpdate());

rmProperties.setTccActionInterceptorOrder(1);
Assertions.assertEquals(1, rmProperties.getTccActionInterceptorOrder());

rmProperties.setSqlParserType("type");
Assertions.assertEquals("type", rmProperties.getSqlParserType());

rmProperties.setBranchExecutionTimeoutXA(1);
Assertions.assertEquals(1, rmProperties.getBranchExecutionTimeoutXA());

rmProperties.setConnectionTwoPhaseHoldTimeoutXA(1);
Assertions.assertEquals(1, rmProperties.getConnectionTwoPhaseHoldTimeoutXA());

rmProperties.setApplicationDataLimitCheck(true);
Assertions.assertTrue(rmProperties.getApplicationDataLimitCheck());

rmProperties.setApplicationDataLimit(1);
Assertions.assertEquals(1, rmProperties.getApplicationDataLimit());
}
}
Loading
Loading