Skip to content

Commit

Permalink
Reform test case. (sofastack#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjboy committed Nov 30, 2018
1 parent 151f9ae commit cd0caf3
Show file tree
Hide file tree
Showing 66 changed files with 322 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public void doSelect() throws Exception {
int per = total / count;
Assert.assertTrue(cnt.get(22000) == 0);
for (int i = 1; i < localps; i++) {
//System.out.println(cnt.get(9000 + i));
Assert.assertTrue(per * i * 0.9 < cnt.get(22000 + i)
&& per * i * 1.1 > cnt.get(22000 + i)); // 随机偏差不会太大,应该不超过10%
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void doSelect() throws Exception {

int avg = total / size;
for (int i = 0; i < size; i++) {
//System.out.println(cnt.get(9000 + i));
Assert.assertTrue(avg * 0.9 < cnt.get(9000 + i)
&& avg * 1.1 > cnt.get(9000 + i)); // 随机偏差不会太大,应该不超过10%
}
Expand Down Expand Up @@ -86,7 +85,6 @@ public void doSelect() throws Exception {
}
int per = total / count;
for (int i = 1; i < size; i++) {
//System.out.println(cnt.get(9000 + i));
Assert.assertTrue(per * i * 0.85 < cnt.get(9000 + i)
&& per * i * 1.15 > cnt.get(9000 + i)); // 随机偏差不会太大,应该不超过15%
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static int gcd(int a, int b) {
temp = a % b;
a = b;
b = temp;
System.out.println("gcd(" + a + ", " + b + ")=");
LOGGER.info("gcd(" + a + ", " + b + ")=");
}
LOGGER.info(String.valueOf(a));
return a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void doSelect() throws Exception {

int avg = total / size;
for (int i = 0; i < size; i++) {
//System.out.println(cnt.get(9000 + i));
Assert.assertTrue(avg == cnt.get(9000 + i));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.alipay.sofa.rpc.proxy.javassist;

import com.alipay.sofa.rpc.core.request.SofaRequest;
import com.alipay.sofa.rpc.log.Logger;
import com.alipay.sofa.rpc.log.LoggerFactory;
import com.alipay.sofa.rpc.proxy.AbstractTestClass;
import com.alipay.sofa.rpc.proxy.TestInterface;
import com.alipay.sofa.rpc.proxy.TestInvoker;
Expand All @@ -32,14 +34,17 @@
* @author <a href="mailto:[email protected]">GengZhang</a>
*/
public class JavassistProxyTest {

private final static Logger LOGGER = LoggerFactory.getLogger(JavassistProxyTest.class);

@Test
public void getProxy() throws Exception {
JavassistProxy proxy = new JavassistProxy();
AbstractTestClass testClass = null;
try {
testClass = proxy.getProxy(AbstractTestClass.class, new TestInvoker());
} catch (Exception e) {
System.out.println(e.getMessage());
LOGGER.info(e.getMessage());
}
Assert.assertNull(testClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.alipay.sofa.rpc.proxy.jdk;

import com.alipay.sofa.rpc.core.request.SofaRequest;
import com.alipay.sofa.rpc.log.Logger;
import com.alipay.sofa.rpc.log.LoggerFactory;
import com.alipay.sofa.rpc.proxy.AbstractTestClass;
import com.alipay.sofa.rpc.proxy.TestInterface;
import com.alipay.sofa.rpc.proxy.TestInvoker;
Expand All @@ -32,14 +34,17 @@
* @author <a href="mailto:[email protected]">GengZhang</a>
*/
public class JDKProxyTest {

private final static Logger LOGGER = LoggerFactory.getLogger(JDKProxyTest.class);

@Test
public void getProxy() throws Exception {
JDKProxy proxy = new JDKProxy();
AbstractTestClass testClass = null;
try {
testClass = proxy.getProxy(AbstractTestClass.class, new TestInvoker());
} catch (Exception e) {
System.out.println(e.getMessage());
LOGGER.info(e.getMessage());
}
Assert.assertNull(testClass);

Expand Down
6 changes: 6 additions & 0 deletions core/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void serialize() {
error = false;
try {
Map map = (Map) BeanSerializer.serialize(bean, true);
//System.out.println(map);
Assert.assertEquals(map.get("Name"), "zzzgg");
Assert.assertEquals(map.get("Sex"), true);
Assert.assertEquals(map.get("age"), 111);
Expand All @@ -89,7 +88,6 @@ public void serialize() {
Assert.assertTrue(map.containsKey(JSON.CLASS_KEY));

map = (Map) BeanSerializer.serialize(bean);
//System.out.println(map);
Assert.assertEquals(map.get("Name"), "zzzgg");
Assert.assertEquals(map.get("Sex"), true);
Assert.assertEquals(map.get("age"), 111);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -31,6 +33,8 @@
*/
public class JSONSerializerTest {

private final Logger LOGGER = LoggerFactory.getLogger(JSONSerializerTest.class);

@Test
public void testSerialize() {
Assert.assertEquals(JSONSerializer.serialize(null), "null");
Expand Down Expand Up @@ -115,7 +119,7 @@ public void testDeserializeWithComment() {
" \"c\":1, /*2 // asdsad \n \r / das */\n" +
" \"d\":9999999999" +
"}";
System.out.println(s);
LOGGER.info(s);
Map json = (Map) JSONSerializer.deserialize(s);
Assert.assertNotNull(json);
Assert.assertEquals(json.get("a"), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand All @@ -31,6 +33,8 @@
*/
public class ClassUtilsTest {

private static final Logger LOGGER = LoggerFactory.getLogger(CodecUtilsTest.class);

@Test
public void forName1() throws Exception {
Class clazz = ClassUtils.forName("java.lang.String");
Expand Down Expand Up @@ -195,17 +199,17 @@ private static class TestMemberClass1 {

private static class TestMemberClass2 {
private TestMemberClass2() {
System.out.println("init TestMemberClass2 ");
LOGGER.info("init TestMemberClass2 ");
}
}

private static class TestMemberClass3 {
private TestMemberClass3(String s) {
System.out.println("init TestMemberClass3 ");
LOGGER.info("init TestMemberClass3 ");
}

private TestMemberClass3(String s, int i) {
System.out.println("init TestMemberClass3 with 2 arg");
LOGGER.info("init TestMemberClass3 with 2 arg");
}
}

Expand All @@ -215,17 +219,17 @@ private class TestMemberClass4 {

private class TestMemberClass5 {
private TestMemberClass5() {
System.out.println("init TestMemberClass5 ");
LOGGER.info("init TestMemberClass5 ");
}
}

private class TestMemberClass6 {
private TestMemberClass6(int s) {
System.out.println("init TestMemberClass6 ");
LOGGER.info("init TestMemberClass6 ");
}

private TestMemberClass6(String s, int i) {
System.out.println("init TestMemberClass6 with 2 arg");
LOGGER.info("init TestMemberClass6 with 2 arg");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -28,6 +30,9 @@
* @author <a href="mailto:[email protected]">GengZhang</a>
*/
public class CodecUtilsTest {

private final Logger LOGGER = LoggerFactory.getLogger(CodecUtilsTest.class);

@Test
public void intToBytes() {
int i = 1000;
Expand Down Expand Up @@ -236,9 +241,9 @@ public void flatCopyTo() {
Assert.assertTrue(header.size() == 15);

for (Map.Entry<String, String> entry : header.entrySet()) {
System.out.println(entry.getKey() + " : " + entry.getValue());
LOGGER.info(entry.getKey() + " : " + entry.getValue());
}
System.out.println("");
LOGGER.info("");

Map<String, Object> newRequestProps = new HashMap<String, Object>();

Expand All @@ -257,7 +262,7 @@ public void flatCopyTo() {
newRequestProps.put(rpcRespBaggage, newContext);

for (Map.Entry<String, Object> entry : newRequestProps.entrySet()) {
System.out.println(entry.getKey() + " : " + entry.getValue());
LOGGER.info(entry.getKey() + " : " + entry.getValue());
}

newRequestProps.putAll(header);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.math.BigDecimal;
Expand All @@ -32,6 +34,9 @@
import static com.alipay.sofa.rpc.common.utils.ReflectUtils.isPublicInstanceField;

public class ReflectUtilsTest {

private final Logger LOGGER = LoggerFactory.getLogger(ReflectUtilsTest.class);

@Test
public void isPrimitives() {
Assert.assertTrue(ReflectUtils.isPrimitives(int.class));
Expand All @@ -50,11 +55,11 @@ public void getCodeBase() {
Assert.assertNull(ReflectUtils.getCodeBase(null));

String codebase = ReflectUtils.getCodeBase(ReflectUtils.class);
System.out.println(codebase);
LOGGER.info(codebase);
Assert.assertNotNull(codebase);

String codebase2 = ReflectUtils.getCodeBase(ReflectUtilsTest.class);
System.out.println(codebase2);
LOGGER.info(codebase2);
Assert.assertNotNull(codebase2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
*/
package com.alipay.sofa.rpc.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
*
* @author <a href=mailto:[email protected]>GengZhang</a>
*/
public class TestClass2 {

private final Logger LOGGER = LoggerFactory.getLogger(CodecUtilsTest.class);

private TestClass2() {
System.out.println("init TestClass2 ");
LOGGER.info("init TestClass2 ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@
*/
package com.alipay.sofa.rpc.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
*
* @author <a href=mailto:[email protected]>GengZhang</a>
*/
public class TestClass3 {
private String name;
private int age;

private final Logger LOGGER = LoggerFactory.getLogger(TestClass3.class);

private String name;
private int age;

private TestClass3(String s, int n) {
System.out.println("init TestClass3 ");
LOGGER.info("init TestClass3 ");
this.name = s;
this.age = n;
}
Expand Down
16 changes: 16 additions & 0 deletions core/common/src/test/resources/log4j.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %t %5p [%c:%M:%L] - %m%n"/>
</layout>
</appender>

<root>
<level value="INFO"/>
<appender-ref ref="CONSOLE"/>
</root>

</log4j:configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.alipay.sofa.rpc.context.RpcInvokeContext;
import com.alipay.sofa.rpc.core.request.RequestBase;
import com.alipay.sofa.rpc.log.Logger;
import com.alipay.sofa.rpc.log.LoggerFactory;
import com.alipay.sofa.rpc.message.bolt.BoltSendableResponseCallback;

import java.util.Random;
Expand All @@ -29,9 +31,11 @@
*/
public class ServiceBImpl implements ServiceB {

private Random random = new Random();
private final static Logger LOGGER = LoggerFactory.getLogger(ServiceBImpl.class);

ServiceC serviceC;
private Random random = new Random();

ServiceC serviceC;

public ServiceBImpl(ServiceC serviceC) {
this.serviceC = serviceC;
Expand All @@ -43,7 +47,7 @@ public int getInt(int num) {
@Override
public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
// 此时C-异步返回->B
System.out.println("b get resp from c :" + appResponse);
LOGGER.info("b get resp from c :" + appResponse);

int respToA = random.nextInt(1000);
// 调这个方法B-异步返回->A
Expand Down
Loading

0 comments on commit cd0caf3

Please sign in to comment.