Repository: alibaba/fescar
Pull request #308 (2019-01-27 07:38:24)

Add unit test of GlobalTransactionScanner
<!-- Please make sure you have read and understood the contributing guidelines -->

### Ⅰ. Describe what this PR did


### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->


### Ⅲ. Why don't you add test cases (unit test/integration test)? 


### Ⅳ. Describe how to verify it


### Ⅴ. Special notes for reviews



codecov-io: # [Codecov](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=h1) Report
> Merging [#308](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=desc) into [develop](https://codecov.io/gh/alibaba/fescar/commit/35d2c5ab8a8abec770fd6d4e8c1ca22709f3bfa0?src=pr&el=desc) will **increase** coverage by `0.75%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/alibaba/fescar/pull/308/graphs/tree.svg?width=650&token=Hy9a6MCc4p&height=150&src=pr)](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           develop    #308      +/-   ##
==========================================
+ Coverage    20.45%   21.2%   +0.75%     
==========================================
  Files          184     184              
  Lines         6923    6923              
  Branches       951     951              
==========================================
+ Hits          1416    1468      +52     
+ Misses        5357    5291      -66     
- Partials       150     164      +14
```


| [Impacted Files](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...ibaba/fescar/tm/dubbo/impl/AccountServiceImpl.java](https://codecov.io/gh/alibaba/fescar/pull/308/diff?src=pr&el=tree#diff-ZXhhbXBsZXMvc3JjL21haW4vamF2YS9jb20vYWxpYmFiYS9mZXNjYXIvdG0vZHViYm8vaW1wbC9BY2NvdW50U2VydmljZUltcGwuamF2YQ==) | `0% <0%> (ø)` | :arrow_up: |
| [...ing/annotation/GlobalTransactionalInterceptor.java](https://codecov.io/gh/alibaba/fescar/pull/308/diff?src=pr&el=tree#diff-c3ByaW5nL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL3NwcmluZy9hbm5vdGF0aW9uL0dsb2JhbFRyYW5zYWN0aW9uYWxJbnRlcmNlcHRvci5qYXZh) | `13.33% <0%> (+13.33%)` | :arrow_up: |
| [...m/alibaba/fescar/spring/annotation/MethodDesc.java](https://codecov.io/gh/alibaba/fescar/pull/308/diff?src=pr&el=tree#diff-c3ByaW5nL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL3NwcmluZy9hbm5vdGF0aW9uL01ldGhvZERlc2MuamF2YQ==) | `40% <0%> (+40%)` | :arrow_up: |
| [...ar/spring/annotation/GlobalTransactionScanner.java](https://codecov.io/gh/alibaba/fescar/pull/308/diff?src=pr&el=tree#diff-c3ByaW5nL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL3NwcmluZy9hbm5vdGF0aW9uL0dsb2JhbFRyYW5zYWN0aW9uU2Nhbm5lci5qYXZh) | `48.83% <0%> (+48.83%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=footer). Last update [35d2c5a...6d825f8](https://codecov.io/gh/alibaba/fescar/pull/308?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

slievrly: @tswstarplanet please add copyright
slievrly: @tswstarplanet sample module has been deleted，and your shuold delete 【system.out】in UT
tswstarplanet: OK, I will do it tonight.

Patch:
diff --git a/README.md b/README.md
index 475aaf33e..63526d735 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,7 @@
 [![Build Status](https://travis-ci.org/alibaba/fescar.svg?branch=develop)](https://travis-ci.org/alibaba/fescar)
 [![codecov](https://codecov.io/gh/alibaba/fescar/branch/develop/graph/badge.svg)](https://codecov.io/gh/alibaba/fescar)
 ![license](https://img.shields.io/github/license/alibaba/fescar.svg)
+![maven](https://img.shields.io/maven-central/v/com.alibaba.fescar/fescar-all.svg)
 
 ## What is FESCAR?
 
@@ -60,7 +61,17 @@ For more details about principle and design, please go to [FESCAR wiki page](htt
 - **GTS**: Global Transaction Service. TXC as an Aliyun middleware product with new name GTS was published since 2016.
 - **FESCAR**: we start the open source project FESCAR based on TXC/GTS since 2019 to work closely with the community in the future.
 
+## Maven dependency
+```xml
+<fescar.version>0.1.3</fescar.version>
 
+<dependency>
+    <groupId>com.alibaba.fescar</groupId>
+    <artifactId>fescar-all</artifactId>
+    <version>${fescar.version}</version>
+</dependency>
+
+```
 ## Quick Start
 
 [Quick Start](https://github.com/alibaba/fescar/wiki/Quick-Start)
@@ -89,6 +100,15 @@ Contributors are welcomed to join the FEATS project. Please check [CONTRIBUTING]
 
 ![dingding.png](https://upload-images.jianshu.io/upload_images/4420767-4e95b186a1a1bfba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
 
+## Fescar ecosystem
+
+* [Fescar Ecosystem Entry](https://github.com/fescar-group) - A GitHub group `fescar-group` to gather all Fescar relevant projects not appropriate in [alibaba](https://github.com/alibaba) group yet
+* [Dubbo Samples](https://github.com/fescar-group/fescar-samples) - Samples for Fescar
+* [Dubbo Docker](https://github.com/fescar-group/fescar-docker) - Fescar integration with docker
+* [Dubbo K8s](https://github.com/fescar-group/fescar-k8s) - Fescar integration with k8s
+* [Awesome Fescar](https://github.com/fescar-group/awesome-fescar) - Description of Fescar related projects 
+* [Fescar Website](https://github.com/fescar-group/fescar.io) - Fescar official website （***In the process of design***）
+
 ## License
 
-FESCAR is under the Apache 2.0 license. See the [LICENSE](https://github.com/alibaba/fescar/blob/master/LICENSE) file for details.
+FESCAR is under the Apache 2.0 license. See the [LICENSE](https://github.com/alibaba/fescar/blob/master/LICENSE) file for details.
\ No newline at end of file
diff --git a/rm-datasource/src/main/java/com/alibaba/fescar/rm/datasource/exec/AbstractDMLBaseExecutor.java b/rm-datasource/src/main/java/com/alibaba/fescar/rm/datasource/exec/AbstractDMLBaseExecutor.java
index 48d6bf80e..21b201e8f 100644
--- a/rm-datasource/src/main/java/com/alibaba/fescar/rm/datasource/exec/AbstractDMLBaseExecutor.java
+++ b/rm-datasource/src/main/java/com/alibaba/fescar/rm/datasource/exec/AbstractDMLBaseExecutor.java
@@ -92,6 +92,7 @@ public abstract class AbstractDMLBaseExecutor<T, S extends Statement> extends Ba
                     connectionProxy.commit();
                     break;
                 } catch (LockConflictException lockConflict) {
+                    connectionProxy.getTargetConnection().rollback();
                     lockRetryController.sleep(lockConflict);
                 }
             }
diff --git a/server/src/main/java/com/alibaba/fescar/server/Server.java b/server/src/main/java/com/alibaba/fescar/server/Server.java
index 2316d1287..d79cd5fd0 100644
--- a/server/src/main/java/com/alibaba/fescar/server/Server.java
+++ b/server/src/main/java/com/alibaba/fescar/server/Server.java
@@ -71,7 +71,11 @@ public class Server {
 
         UUIDGenerator.init(1);
 
-        XID.setIpAddress(NetUtil.getLocalIp());
+        if (args.length > 2) {
+            XID.setIpAddress(args[2]);
+        } else {
+            XID.setIpAddress(NetUtil.getLocalIp());
+        }
         XID.setPort(rpcServer.getListenPort());
 
         rpcServer.init();
diff --git a/spring/pom.xml b/spring/pom.xml
index 84d63c9a1..56f763d37 100644
--- a/spring/pom.xml
+++ b/spring/pom.xml
@@ -48,7 +48,11 @@
             <groupId>cglib</groupId>
             <artifactId>cglib</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 


Test patch:
diff --git a/spring/src/test/java/com/alibaba/fescar/spring/annotation/Business.java b/spring/src/test/java/com/alibaba/fescar/spring/annotation/Business.java
new file mode 100644
index 000000000..f6d9e7197
--- /dev/null
+++ b/spring/src/test/java/com/alibaba/fescar/spring/annotation/Business.java
@@ -0,0 +1,21 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.spring.annotation;
+
+public interface Business {
+    String doBiz(String msg);
+}
diff --git a/spring/src/test/java/com/alibaba/fescar/spring/annotation/BusinessImpl.java b/spring/src/test/java/com/alibaba/fescar/spring/annotation/BusinessImpl.java
new file mode 100644
index 000000000..00d9978e4
--- /dev/null
+++ b/spring/src/test/java/com/alibaba/fescar/spring/annotation/BusinessImpl.java
@@ -0,0 +1,31 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.spring.annotation;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BusinessImpl implements Business {
+    Logger logger = LoggerFactory.getLogger(BusinessImpl.class);
+
+    @Override
+    @GlobalTransactional(timeoutMills = 300000, name = "busi-doBiz")
+    public String doBiz(String msg) {
+        logger.info("Business doBiz");
+        return "hello " + msg;
+    }
+}
diff --git a/spring/src/test/java/com/alibaba/fescar/spring/annotation/BusinessProxy.java b/spring/src/test/java/com/alibaba/fescar/spring/annotation/BusinessProxy.java
new file mode 100644
index 000000000..a847ee574
--- /dev/null
+++ b/spring/src/test/java/com/alibaba/fescar/spring/annotation/BusinessProxy.java
@@ -0,0 +1,41 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.spring.annotation;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public class BusinessProxy implements InvocationHandler {
+    private Object proxy;
+
+    public BusinessProxy(Object proxy) {
+        this.proxy = proxy;
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        System.out.println("before");
+        Object result = null;
+        try {
+            result = method.invoke(proxy, args);
+        } catch (Exception e) {
+
+        }
+        System.out.println("after");
+        return result;
+    }
+}
diff --git a/spring/src/test/java/com/alibaba/fescar/spring/annotation/GlobalTransactionScannerTest.java b/spring/src/test/java/com/alibaba/fescar/spring/annotation/GlobalTransactionScannerTest.java
new file mode 100644
index 000000000..6c7a43704
--- /dev/null
+++ b/spring/src/test/java/com/alibaba/fescar/spring/annotation/GlobalTransactionScannerTest.java
@@ -0,0 +1,47 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.spring.annotation;
+
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * GlobalTransactionScanner Unit Test
+ */
+public class GlobalTransactionScannerTest {
+    private GlobalTransactionScanner globalTransactionScanner = new GlobalTransactionScanner("global-trans-scanner-test");
+
+    @Test(dataProvider = "normalBeanProvider")
+    public void testWrapNormalBean(Object bean, String beanName, Object cacheKey) {
+        Object result = globalTransactionScanner.wrapIfNecessary(bean, beanName, cacheKey);
+        Assert.assertNotSame(result, bean);
+    }
+
+    @Test
+    public void testAfterPropertiesSet() {
+        globalTransactionScanner.afterPropertiesSet();
+    }
+
+    @DataProvider
+    public static Object[][] normalBeanProvider() {
+        Business business = new BusinessImpl();
+        String beanName = "business";
+        String cacheKey = "business-key";
+        return new Object[][]{{business, beanName, cacheKey}};
+    }
+}