~ubuntu-branches/ubuntu/oneiric/tomcat7/oneiric-updates

« back to all changes in this revision

Viewing changes to test/org/apache/catalina/tribes/membership/TestMemberImplSerialization.java

  • Committer: Bazaar Package Importer
  • Author(s): tony mancill
  • Date: 2011-07-25 22:58:33 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110725225833-1t773ak3y3g9utm2
Tags: 7.0.19-1
* Team upload.
* New upstream release.
  - Includes fix for CVE-2011-2526 (Closes: #634992)
* Remove patch for CVE-2011-2204 (included upstream).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
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.
 
16
 */
 
17
package org.apache.catalina.tribes.membership;
 
18
 
 
19
import java.util.Arrays;
 
20
 
 
21
import junit.framework.TestCase;
 
22
 
 
23
/**
 
24
 * <p>Title: </p>
 
25
 *
 
26
 * <p>Description: </p>
 
27
 *
 
28
 * <p>Company: </p>
 
29
 *
 
30
 * @author not attributable
 
31
 * @version 1.0
 
32
 */
 
33
public class TestMemberImplSerialization extends TestCase {
 
34
    MemberImpl m1, m2, p1,p2;
 
35
    byte[] payload = null;
 
36
    int udpPort = 3445;
 
37
    @Override
 
38
    protected void setUp() throws Exception {
 
39
        super.setUp();
 
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());
 
54
    }
 
55
    
 
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));
 
64
    }
 
65
    
 
66
    public void testUdpPort() throws Exception {
 
67
        byte[] md1 = m1.getData();
 
68
        byte[] md2 = m2.getData();
 
69
 
 
70
        MemberImpl a1 = MemberImpl.getMember(md1);
 
71
        MemberImpl a2 = MemberImpl.getMember(md2);
 
72
        
 
73
        assertEquals(true, a1.getUdpPort()==a2.getUdpPort());
 
74
        assertEquals(true,a1.getUdpPort()==udpPort);
 
75
    }
 
76
    
 
77
    public void testSerializationOne() throws Exception {
 
78
        MemberImpl m = m1;
 
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));
 
90
        
 
91
        md1 = m.getData(true,true);
 
92
        Thread.sleep(50);
 
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));
 
98
        
 
99
        
 
100
    }
 
101
    
 
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();
 
108
        return result;
 
109
    }
 
110
}