-
Notifications
You must be signed in to change notification settings - Fork 870
Expand file tree
/
Copy pathFurySerializerTest.java
More file actions
100 lines (86 loc) · 3.25 KB
/
FurySerializerTest.java
File metadata and controls
100 lines (86 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* 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 com.alipay.remoting.serialization.fury;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import com.alipay.remoting.serialization.HessianSerializerTest;
import com.alipay.remoting.exception.CodecException;
import org.apache.fury.exception.InsecureException;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author jianbin@apache.org
*/
public class FurySerializerTest {
public static FurySerializer serializer;
static {
FurySerializer.registry(HessianSerializerTest.class);
serializer = new FurySerializer();
}
@Test
public void concurrentSerializeTest() throws InterruptedException {
int concurrentNum = 10;
CountDownLatch countDownLatch = new CountDownLatch(concurrentNum);
for (int i = 0; i < concurrentNum; ++i) {
FurySerializerTest.MyThread thread = new FurySerializerTest.MyThread(countDownLatch);
new Thread(thread).start();
}
countDownLatch.await(2, TimeUnit.SECONDS);
}
@Test
public void testSerializeError() {
FurySerializerTest furySerializerTest = new FurySerializerTest();
try {
serializer.serialize(furySerializerTest);
} catch (CodecException e) {
Assert.assertEquals(e.getCause().getClass(), InsecureException.class);
}
}
@Test
public void testSerialize() {
HessianSerializerTest furySerializerTest = new HessianSerializerTest();
try {
Assert.assertNotNull(serializer.serialize(furySerializerTest));
} catch (CodecException e) {
fail();
}
}
static class MyThread implements Runnable {
CountDownLatch countDownLatch;
public MyThread(CountDownLatch countDownLatch) {
this.countDownLatch = countDownLatch;
}
@Override
public void run() {
try {
for (int i = 0; i < 100; i++) {
String randomStr = UUID.randomUUID().toString();
byte[] bytes = serializer.serialize(randomStr);
String o = serializer.deserialize(bytes, String.class.getName());
assertEquals(o, randomStr);
}
} catch (Exception e) {
fail();
} finally {
countDownLatch.countDown();
}
}
}
}