Skip to content

Commit

Permalink
add test for serialization api & fastjson & fst module (apache#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
htynkn authored and beiwei30 committed May 3, 2018
1 parent 8079b08 commit 2a52a91
Show file tree
Hide file tree
Showing 59 changed files with 715 additions and 5,428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.model;
package com.alibaba.dubbo.common.serialize.support;

public class BizExceptionNoDefaultConstructor extends RuntimeException {
import org.junit.Test;

private static final long serialVersionUID = 1L;
import java.util.Set;

public BizExceptionNoDefaultConstructor(String message) {
super(message);
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;

public class SerializableClassRegistryTest {
@Test
public void testAddClasses() {
SerializableClassRegistry.registerClass(A.class);
SerializableClassRegistry.registerClass(B.class);

Set<Class> registeredClasses = SerializableClassRegistry.getRegisteredClasses();
assertThat(registeredClasses, hasSize(2));
}

private class A {
}

private class B {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import java.io.Reader;
import java.lang.reflect.Type;

/**
* JsonObjectInput
*/
public class FastJsonObjectInput implements ObjectInput {

private final BufferedReader reader;
Expand All @@ -45,74 +42,42 @@ public FastJsonObjectInput(Reader reader) {

@Override
public boolean readBool() throws IOException {
try {
return readObject(boolean.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(boolean.class);
}

@Override
public byte readByte() throws IOException {
try {
return readObject(byte.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(byte.class);
}

@Override
public short readShort() throws IOException {
try {
return readObject(short.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(short.class);
}

@Override
public int readInt() throws IOException {
try {
return readObject(int.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(int.class);
}

@Override
public long readLong() throws IOException {
try {
return readObject(long.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(long.class);
}

@Override
public float readFloat() throws IOException {
try {
return readObject(float.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(float.class);
}

@Override
public double readDouble() throws IOException {
try {
return readObject(double.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(double.class);
}

@Override
public String readUTF() throws IOException {
try {
return readObject(String.class);
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
}
return read(String.class);
}

@Override
Expand All @@ -128,8 +93,7 @@ public Object readObject() throws IOException, ClassNotFoundException {

@Override
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
String json = readLine();
return JSON.parseObject(json, cls);
return read(cls);
}

@Override
Expand All @@ -145,4 +109,8 @@ private String readLine() throws IOException, EOFException {
return line;
}

private <T> T read(Class<T> cls) throws IOException {
String json = readLine();
return JSON.parseObject(json, cls);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import java.io.PrintWriter;
import java.io.Writer;

/**
* JsonObjectOutput
*/
public class FastJsonObjectOutput implements ObjectOutput {

private final PrintWriter writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* FastJsonSerialization
*/
public class FastJsonSerialization implements Serialization {

@Override
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2a52a91

Please sign in to comment.