Skip to content

Commit 84cd529

Browse files
authored
fix #450 [master] release 0.2.2 (#451)
1 parent f064095 commit 84cd529

File tree

27 files changed

+393
-51
lines changed

27 files changed

+393
-51
lines changed

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Fescar
2+
3+
## Fescar Code Style
4+
Fescar code style Comply with Alibaba Java Coding Guidelines.
5+
6+
Fescar 的编码规范遵从于《阿里巴巴JAVA开发规约》。
7+
8+
9+
### Guidelines
10+
[Alibaba-Java-Coding-Guidelines](https://alibaba.github.io/Alibaba-Java-Coding-Guidelines/)
11+
12+
[阿里巴巴JAVA开发规约](https://github.com/alibaba/p3c/blob/master/%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4Java%E5%BC%80%E5%8F%91%E6%89%8B%E5%86%8C%EF%BC%88%E8%AF%A6%E5%B0%BD%E7%89%88%EF%BC%89.pdf)
13+
14+
15+
### IDE Plugin Install(not necessary)
16+
17+
*It is not necessary to install, if you want to find a problem when you are coding.*
18+
19+
*不是必须安装,如果你需要在开发的时候实时发现问题的话,你需要安装。*
20+
21+
#### idea IDE
22+
[p3c-idea-plugin-install](https://github.com/alibaba/p3c/blob/master/idea-plugin/README.md)
23+
24+
[p3c插件idea IDE上安装方法](https://github.com/alibaba/p3c/blob/master/idea-plugin/README_cn.md)
25+
26+
#### eclipse IDE
27+
[p3c-eclipse-plugin-install](https://github.com/alibaba/p3c/blob/master/eclipse-plugin/README.md)
28+
29+
[p3c插件eclipse IDE上安装方法](https://github.com/alibaba/p3c/blob/master/eclipse-plugin/README_cn.md)
30+
31+
#### Acknowledgement [Alibaba p3c](https://github.com/alibaba/p3c)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ For more details about principle and design, please go to [Fescar wiki page](htt
6565

6666
## Maven dependency
6767
```xml
68-
<fescar.version>0.2.0</fescar.version>
68+
<fescar.version>0.2.1</fescar.version>
6969

7070
<dependency>
7171
<groupId>com.alibaba.fescar</groupId>

common/pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<artifactId>fescar-all</artifactId>
2222
<groupId>com.alibaba.fescar</groupId>
23-
<version>0.2.1</version>
23+
<version>0.2.2</version>
2424
</parent>
2525
<modelVersion>4.0.0</modelVersion>
2626
<artifactId>fescar-common</artifactId>
@@ -47,5 +47,15 @@
4747
<groupId>com.alibaba</groupId>
4848
<artifactId>fastjson</artifactId>
4949
</dependency>
50+
<dependency>
51+
<groupId>junit</groupId>
52+
<artifactId>junit</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.testng</groupId>
57+
<artifactId>testng</artifactId>
58+
<scope>test</scope>
59+
</dependency>
5060
</dependencies>
5161
</project>

common/src/main/java/com/alibaba/fescar/common/loader/EnhancedServiceLoader.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@
3737
/**
3838
* The type Enhanced service loader.
3939
*
40-
* @Author: jimin.jm @alibaba-inc.com
41-
* @Project: fescar -all
42-
* @DateTime: 2018 /10/10 14:28
43-
* @FileName: EnhancedServiceLoader
44-
* @Description:
40+
* @author: jimin.jm @alibaba-inc.com
41+
* @date: 2018/10/10
4542
*/
4643
public class EnhancedServiceLoader {
4744
private static final Logger LOGGER = LoggerFactory.getLogger(EnhancedServiceLoader.class);
@@ -98,7 +95,8 @@ public static <S> S load(Class<S> service, String activateName) throws EnhancedS
9895
* @return s
9996
* @throws EnhancedServiceNotFoundException the enhanced service not found exception
10097
*/
101-
public static <S> S load(Class<S> service, String activateName, ClassLoader loader) throws EnhancedServiceNotFoundException {
98+
public static <S> S load(Class<S> service, String activateName, ClassLoader loader)
99+
throws EnhancedServiceNotFoundException {
102100
return loadFile(service, activateName, loader);
103101
}
104102

@@ -151,7 +149,7 @@ private static <S> S loadFile(Class<S> service, String activateName, ClassLoader
151149
for (int i = 0; i < extensions.size(); i++) {
152150
Class clz = extensions.get(i);
153151
@SuppressWarnings("unchecked")
154-
LoadLevel activate = (LoadLevel) clz.getAnnotation(LoadLevel.class);
152+
LoadLevel activate = (LoadLevel)clz.getAnnotation(LoadLevel.class);
155153
if (activate != null && activateName.equals(activate.name())) {
156154
activateExtensions.add(clz);
157155
}
@@ -161,21 +159,24 @@ private static <S> S loadFile(Class<S> service, String activateName, ClassLoader
161159
}
162160

163161
if (extensions.isEmpty()) {
164-
throw new EnhancedServiceNotFoundException("not found service provider for : " + service.getName() + "[" + activateName
165-
+ "] and classloader : " + ObjectUtils.toString(loader));
162+
throw new EnhancedServiceNotFoundException(
163+
"not found service provider for : " + service.getName() + "[" + activateName
164+
+ "] and classloader : " + ObjectUtils.toString(loader));
166165
}
167-
Class<?> extension = extensions.get(extensions.size() - 1);// 最大的一个
166+
Class<?> extension = extensions.get(extensions.size() - 1);
168167
S result = service.cast(extension.newInstance());
169168
if (!foundFromCache && LOGGER.isInfoEnabled()) {
170-
LOGGER.info("load " + service.getSimpleName() + "[" + activateName + "] extension by class[" + extension.getName() + "]");
169+
LOGGER.info("load " + service.getSimpleName() + "[" + activateName + "] extension by class[" + extension
170+
.getName() + "]");
171171
}
172172
return result;
173173
} catch (Throwable e) {
174174
if (e instanceof EnhancedServiceNotFoundException) {
175-
throw (EnhancedServiceNotFoundException) e;
175+
throw (EnhancedServiceNotFoundException)e;
176176
} else {
177177
throw new EnhancedServiceNotFoundException(
178-
"not found service provider for : " + service.getName() + " caused by " + ExceptionUtils.getFullStackTrace(e));
178+
"not found service provider for : " + service.getName() + " caused by " + ExceptionUtils
179+
.getFullStackTrace(e));
179180
}
180181
}
181182
}
@@ -193,17 +194,15 @@ private static <S> List<Class> findAllExtensionClass(Class<S> service, String ac
193194
if (extensions.isEmpty()) {
194195
return extensions;
195196
}
196-
197-
// 做一下排序
198197
Collections.sort(extensions, new Comparator<Class>() {
199198
@Override
200199
public int compare(Class c1, Class c2) {
201200
Integer o1 = 0;
202201
Integer o2 = 0;
203202
@SuppressWarnings("unchecked")
204-
LoadLevel a1 = (LoadLevel) c1.getAnnotation(LoadLevel.class);
203+
LoadLevel a1 = (LoadLevel)c1.getAnnotation(LoadLevel.class);
205204
@SuppressWarnings("unchecked")
206-
LoadLevel a2 = (LoadLevel) c2.getAnnotation(LoadLevel.class);
205+
LoadLevel a2 = (LoadLevel)c2.getAnnotation(LoadLevel.class);
207206

208207
if (a1 != null) {
209208
o1 = a1.order();
@@ -222,7 +221,8 @@ public int compare(Class c1, Class c2) {
222221
}
223222

224223
@SuppressWarnings("rawtypes")
225-
private static void loadFile(Class<?> service, String dir, ClassLoader classLoader, List<Class> extensions) throws IOException {
224+
private static void loadFile(Class<?> service, String dir, ClassLoader classLoader, List<Class> extensions)
225+
throws IOException {
226226
String fileName = dir + service.getName();
227227
Enumeration<URL> urls;
228228
if (classLoader != null) {
@@ -249,16 +249,14 @@ private static void loadFile(Class<?> service, String dir, ClassLoader classLoad
249249
}
250250
}
251251
} catch (ClassNotFoundException e) {
252-
// ignore
253252
} catch (Throwable e) {
254-
LOGGER.warn(e.getMessage()); // 记录一下失败日志
253+
LOGGER.warn(e.getMessage());
255254
} finally {
256255
try {
257256
if (reader != null) {
258257
reader.close();
259258
}
260259
} catch (IOException ioe) {
261-
// ignore
262260
}
263261
}
264262
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 1999-2018 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.fescar.common;
18+
19+
import com.alibaba.fescar.common.util.StringUtils;
20+
import java.io.FileNotFoundException;
21+
import java.io.IOException;
22+
import java.io.InputStream;
23+
import java.sql.SQLException;
24+
import javax.sql.rowset.serial.SerialBlob;
25+
import org.testng.Assert;
26+
import org.testng.annotations.Test;
27+
28+
/**
29+
* @author melon.zhao
30+
* @since 2019/2/20
31+
*/
32+
public class StringUtilsTest {
33+
34+
@Test
35+
public void testIsEmpty() {
36+
Assert.assertEquals(StringUtils.isEmpty(null), true);
37+
Assert.assertEquals(StringUtils.isEmpty("abc"), false);
38+
Assert.assertEquals(StringUtils.isEmpty(""), true);
39+
Assert.assertEquals(StringUtils.isEmpty(" "), false);
40+
}
41+
42+
@Test
43+
public void testString2blob() throws SQLException {
44+
Assert.assertEquals(StringUtils.string2blob(null), null);
45+
String[] strs = new String[]{"abc", "", " "};
46+
for (String str : strs) {
47+
Assert.assertEquals(StringUtils.string2blob(str), new SerialBlob(str.getBytes()));
48+
}
49+
}
50+
51+
@Test
52+
public void testBlob2string() throws SQLException {
53+
String[] strs = new String[]{"abc", " "};
54+
for (String str : strs) {
55+
Assert.assertEquals(StringUtils.blob2string(new SerialBlob(str.getBytes())), str);
56+
}
57+
}
58+
59+
@Test
60+
public void testInputStream2String() {
61+
try {
62+
InputStream inputStream = StringUtilsTest.class.getClassLoader().getResourceAsStream("test.txt");
63+
Assert.assertEquals(StringUtils.inputStream2String(inputStream), "abc\n"
64+
+ ":\"klsdf\n"
65+
+ "2ks,x:\".,-3sd˚ø≤ø¬≥");
66+
} catch (FileNotFoundException e) {
67+
e.printStackTrace();
68+
} catch (IOException e) {
69+
e.printStackTrace();
70+
}
71+
}
72+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 1999-2018 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.fescar.common;
18+
19+
import java.util.Random;
20+
import org.testng.Assert;
21+
import org.testng.annotations.Test;
22+
23+
/**
24+
* @author melon.zhao
25+
* @since 2019/2/22
26+
*/
27+
public class XIDTest {
28+
29+
@Test
30+
public void testSetIpAddress() {
31+
XID.setIpAddress("127.0.0.1");
32+
Assert.assertEquals(XID.getIpAddress(), "127.0.0.1");
33+
}
34+
35+
@Test
36+
void testSetPort() {
37+
XID.setPort(8080);
38+
Assert.assertEquals(XID.getPort(), 8080);
39+
}
40+
41+
42+
@Test
43+
void testGenerateXID() {
44+
long tranId = new Random().nextLong();
45+
XID.setPort(8080);
46+
XID.setIpAddress("127.0.0.1");
47+
Assert.assertEquals(XID.generateXID(tranId), XID.getIpAddress() + ":" + XID.getPort() + ":" + tranId);
48+
}
49+
50+
@Test
51+
void testGetServerAddress() {
52+
Assert.assertNull(XID.getServerAddress(null));
53+
Assert.assertEquals(XID.getServerAddress("127.0.0.1:8080:8577662204289747564"), "127.0.0.1:8080");
54+
}
55+
56+
@Test
57+
void testGetTransactionId() {
58+
Assert.assertEquals(XID.getTransactionId(null), -1);
59+
Assert.assertEquals(XID.getTransactionId("127.0.0.1:8080:8577662204289747564"), 8577662204289747564L);
60+
}
61+
}

common/src/test/resources/test.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
abc
2+
:"klsdf
3+
2ks,x:".,-3sd˚ø≤ø¬≥

0 commit comments

Comments
 (0)