-
Notifications
You must be signed in to change notification settings - Fork 411
Expand file tree
/
Copy pathUnregisteredClassTest.java
More file actions
172 lines (156 loc) · 6.59 KB
/
Copy pathUnregisteredClassTest.java
File metadata and controls
172 lines (156 loc) · 6.59 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package com.esotericsoftware.kryonet;
import java.io.IOException;
import java.util.Arrays;
public class UnregisteredClassTest extends KryoNetTestCase {
public void testPingPong () throws IOException {
final Data dataTCP = new Data();
populateData(dataTCP, true);
final Data dataUDP = new Data();
populateData(dataUDP, false);
final Server server = new Server(16384, 8192);
server.getKryo().setRegistrationRequired(false);
startEndPoint(server);
server.bind(tcpPort, udpPort);
server.addListener(new Listener() {
public void connected (Connection connection) {
connection.sendTCP(dataTCP);
connection.sendUDP(dataUDP); // Note UDP ping pong stops if a UDP packet is lost.
}
public void received (Connection connection, Object object) {
if (object instanceof Data) {
Data data = (Data)object;
if (data.isTCP) {
if (!data.equals(dataTCP)) throw new RuntimeException("Fail!");
connection.sendTCP(data);
} else {
if (!data.equals(dataUDP)) throw new RuntimeException("Fail!");
connection.sendUDP(data);
}
}
}
});
// ----
final Client client = new Client(16384, 8192);
client.getKryo().setRegistrationRequired(false);
startEndPoint(client);
client.addListener(new Listener() {
public void received (Connection connection, Object object) {
if (object instanceof Data) {
Data data = (Data)object;
if (data.isTCP) {
if (!data.equals(dataTCP)) throw new RuntimeException("Fail!");
connection.sendTCP(data);
} else {
if (!data.equals(dataUDP)) throw new RuntimeException("Fail!");
connection.sendUDP(data);
}
}
}
});
client.connect(5000, host, tcpPort, udpPort);
waitForThreads(5000);
}
private void populateData (Data data, boolean isTCP) {
data.isTCP = isTCP;
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 3000; i++)
buffer.append('a');
data.string = buffer.toString();
data.strings = new String[] {"abcdefghijklmnopqrstuvwxyz0123456789", "", null, "!@#$", "�����"};
data.ints = new int[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE};
data.shorts = new short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE};
data.floats = new float[] {0, -0, 1, -1, 123456, -123456, 0.1f, 0.2f, -0.3f, (float)Math.PI, Float.MAX_VALUE,
Float.MIN_VALUE};
data.doubles = new double[] {0, -0, 1, -1, 123456, -123456, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE, Double.MIN_VALUE};
data.longs = new long[] {0, -0, 1, -1, 123456, -123456, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE};
data.bytes = new byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE};
data.chars = new char[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE};
data.booleans = new boolean[] {true, false};
data.Ints = new Integer[] {-1234567, 1234567, -1, 0, 1, Integer.MAX_VALUE, Integer.MIN_VALUE};
data.Shorts = new Short[] {-12345, 12345, -1, 0, 1, Short.MAX_VALUE, Short.MIN_VALUE};
data.Floats = new Float[] {0f, -0f, 1f, -1f, 123456f, -123456f, 0.1f, 0.2f, -0.3f, (float)Math.PI, Float.MAX_VALUE,
Float.MIN_VALUE};
data.Doubles = new Double[] {0d, -0d, 1d, -1d, 123456d, -123456d, 0.1d, 0.2d, -0.3d, Math.PI, Double.MAX_VALUE,
Double.MIN_VALUE};
data.Longs = new Long[] {0l, -0l, 1l, -1l, 123456l, -123456l, 99999999999l, -99999999999l, Long.MAX_VALUE, Long.MIN_VALUE};
data.Bytes = new Byte[] {-123, 123, -1, 0, 1, Byte.MAX_VALUE, Byte.MIN_VALUE};
data.Chars = new Character[] {32345, 12345, 0, 1, 63, Character.MAX_VALUE, Character.MIN_VALUE};
data.Booleans = new Boolean[] {true, false};
}
static public class Data {
public String string;
public String[] strings;
public int[] ints;
public short[] shorts;
public float[] floats;
public double[] doubles;
public long[] longs;
public byte[] bytes;
public char[] chars;
public boolean[] booleans;
public Integer[] Ints;
public Short[] Shorts;
public Float[] Floats;
public Double[] Doubles;
public Long[] Longs;
public Byte[] Bytes;
public Character[] Chars;
public Boolean[] Booleans;
public boolean isTCP;
public int hashCode () {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(Booleans);
result = prime * result + Arrays.hashCode(Bytes);
result = prime * result + Arrays.hashCode(Chars);
result = prime * result + Arrays.hashCode(Doubles);
result = prime * result + Arrays.hashCode(Floats);
result = prime * result + Arrays.hashCode(Ints);
result = prime * result + Arrays.hashCode(Longs);
result = prime * result + Arrays.hashCode(Shorts);
result = prime * result + Arrays.hashCode(booleans);
result = prime * result + Arrays.hashCode(bytes);
result = prime * result + Arrays.hashCode(chars);
result = prime * result + Arrays.hashCode(doubles);
result = prime * result + Arrays.hashCode(floats);
result = prime * result + Arrays.hashCode(ints);
result = prime * result + (isTCP ? 1231 : 1237);
result = prime * result + Arrays.hashCode(longs);
result = prime * result + Arrays.hashCode(shorts);
result = prime * result + ((string == null) ? 0 : string.hashCode());
result = prime * result + Arrays.hashCode(strings);
return result;
}
public boolean equals (Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
Data other = (Data)obj;
if (!Arrays.equals(Booleans, other.Booleans)) return false;
if (!Arrays.equals(Bytes, other.Bytes)) return false;
if (!Arrays.equals(Chars, other.Chars)) return false;
if (!Arrays.equals(Doubles, other.Doubles)) return false;
if (!Arrays.equals(Floats, other.Floats)) return false;
if (!Arrays.equals(Ints, other.Ints)) return false;
if (!Arrays.equals(Longs, other.Longs)) return false;
if (!Arrays.equals(Shorts, other.Shorts)) return false;
if (!Arrays.equals(booleans, other.booleans)) return false;
if (!Arrays.equals(bytes, other.bytes)) return false;
if (!Arrays.equals(chars, other.chars)) return false;
if (!Arrays.equals(doubles, other.doubles)) return false;
if (!Arrays.equals(floats, other.floats)) return false;
if (!Arrays.equals(ints, other.ints)) return false;
if (isTCP != other.isTCP) return false;
if (!Arrays.equals(longs, other.longs)) return false;
if (!Arrays.equals(shorts, other.shorts)) return false;
if (string == null) {
if (other.string != null) return false;
} else if (!string.equals(other.string)) return false;
if (!Arrays.equals(strings, other.strings)) return false;
return true;
}
public String toString () {
return "Data";
}
}
}