Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
l81893521 committed Aug 13, 2024
1 parent af46fb4 commit eff39cb
Show file tree
Hide file tree
Showing 53 changed files with 1,743 additions and 426 deletions.
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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 @@ -88,6 +89,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 @@ -64,6 +64,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 @@ -93,6 +94,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,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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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;

import java.util.HashMap;
import java.util.Map;

public class ServicePropertiesTest {

@Test
public void testServiceProperties() {
ServiceProperties serviceProperties = new ServiceProperties();

Map<String, String> vGroupMapping = new HashMap<>();
vGroupMapping.put("default_tx_group", "default");
serviceProperties.setVgroupMapping(vGroupMapping);
Assertions.assertEquals("default", serviceProperties.getVgroupMapping().get("default_tx_group"));

Map<String, String> groupList = new HashMap<>();
groupList.put("default", "127.0.0.1:8091");
serviceProperties.setGrouplist(groupList);
Assertions.assertEquals("127.0.0.1:8091", serviceProperties.getGrouplist().get("default"));

serviceProperties.setDisableGlobalTransaction(true);
Assertions.assertTrue(serviceProperties.isDisableGlobalTransaction());
}

@Test
public void testAfterPropertiesSet() throws Exception {
ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.afterPropertiesSet();
Assertions.assertEquals("default", serviceProperties.getVgroupMapping().get("default_tx_group"));
Assertions.assertEquals("default", serviceProperties.getVgroupMapping().get("my_test_tx_group"));
Assertions.assertEquals("127.0.0.1:8091", serviceProperties.getGrouplist().get("default"));

serviceProperties = new ServiceProperties();

Map<String, String> vGroupMapping = new HashMap<>();
vGroupMapping.put("default_tx_group", "default");
serviceProperties.setVgroupMapping(vGroupMapping);

Map<String, String> groupList = new HashMap<>();
groupList.put("default", "127.0.0.1:8091");
serviceProperties.setGrouplist(groupList);

serviceProperties.afterPropertiesSet();
Assertions.assertEquals("default", serviceProperties.getVgroupMapping().get("default_tx_group"));
Assertions.assertEquals("127.0.0.1:8091", serviceProperties.getGrouplist().get("default"));
}
}
Loading

0 comments on commit eff39cb

Please sign in to comment.