2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.catalina.tribes.membership;
19
import java.util.Arrays;
21
import junit.framework.TestCase;
26
* <p>Description: </p>
30
* @author not attributable
33
public class TestMemberImplSerialization extends TestCase {
34
MemberImpl m1, m2, p1,p2;
35
byte[] payload = null;
38
protected void setUp() throws Exception {
40
payload = new byte[333];
41
Arrays.fill(payload,(byte)1);
42
m1 = new MemberImpl("localhost",3333,1,payload);
43
m2 = new MemberImpl("localhost",3333,1);
44
payload = new byte[333];
45
Arrays.fill(payload,(byte)2);
46
p1 = new MemberImpl("127.0.0.1",3333,1,payload);
47
p2 = new MemberImpl("localhost",3331,1,payload);
48
m1.setDomain(new byte[] {1,2,3,4,5,6,7,8,9});
49
m2.setDomain(new byte[] {1,2,3,4,5,6,7,8,9});
50
m1.setCommand(new byte[] {1,2,4,5,6,7,8,9});
51
m2.setCommand(new byte[] {1,2,4,5,6,7,8,9});
52
m1.setUdpPort(udpPort);
53
m2.setUdpPort(m1.getUdpPort());
56
public void testCompare() throws Exception {
57
assertTrue(m1.equals(m2));
58
assertTrue(m2.equals(m1));
59
assertTrue(p1.equals(m2));
60
assertFalse(m1.equals(p2));
61
assertFalse(m1.equals(p2));
62
assertFalse(m2.equals(p2));
63
assertFalse(p1.equals(p2));
66
public void testUdpPort() throws Exception {
67
byte[] md1 = m1.getData();
68
byte[] md2 = m2.getData();
70
MemberImpl a1 = MemberImpl.getMember(md1);
71
MemberImpl a2 = MemberImpl.getMember(md2);
73
assertEquals(true, a1.getUdpPort()==a2.getUdpPort());
74
assertEquals(true,a1.getUdpPort()==udpPort);
77
public void testSerializationOne() throws Exception {
79
byte[] md1 = m.getData(false,true);
80
byte[] mda1 = m.getData(false,false);
81
assertTrue(Arrays.equals(md1,mda1));
82
assertTrue(md1==mda1);
83
mda1 = m.getData(true,true);
84
MemberImpl ma1 = MemberImpl.getMember(mda1);
85
assertTrue(compareMembers(m,ma1));
86
mda1 = p1.getData(false);
87
assertFalse(Arrays.equals(md1,mda1));
88
ma1 = MemberImpl.getMember(mda1);
89
assertTrue(compareMembers(p1,ma1));
91
md1 = m.getData(true,true);
93
mda1 = m.getData(true,true);
94
MemberImpl a1 = MemberImpl.getMember(md1);
95
MemberImpl a2 = MemberImpl.getMember(mda1);
96
assertTrue(a1.equals(a2));
97
assertFalse(Arrays.equals(md1,mda1));
102
public boolean compareMembers(MemberImpl impl1, MemberImpl impl2) {
103
boolean result = true;
104
result = result && Arrays.equals(impl1.getHost(),impl2.getHost());
105
result = result && Arrays.equals(impl1.getPayload(),impl2.getPayload());
106
result = result && Arrays.equals(impl1.getUniqueId(),impl2.getUniqueId());
107
result = result && impl1.getPort() == impl2.getPort();