Debian Codegraph @

test/typedesc/TestTypeDescSynch.java

raw
1 /*
2 * Copyright 2002-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package test.typedesc;
17
18 import junit.framework.TestCase;
19
20 import org.apache.axis.client.Call;
21 import org.apache.axis.client.Service;
22 import org.apache.axis.description.AttributeDesc;
23 import org.apache.axis.description.TypeDesc;
24
25 import org.apache.axis.encoding.ser.BeanSerializerFactory;
26 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
27
28 import javax.xml.namespace.QName;
29
30 /**
31 * Confirm TypeDesc bugs are indeed fixed.
32 *
33 * See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22819 for details
34 *
35 * @author [email protected]
36 */
37 public class TestTypeDescSynch extends TestCase {
38
39 public TestTypeDescSynch(String name) {
40 super(name);
41 }
42
43 public TestTypeDescSynch() {
44 super("Test TypeDesc Synch");
45 }
46
47 // with won't fail
48 public void testFields() throws Exception {
49 TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean2.class);
50 for (int i=0; i < 10; i++) {
51 desc.getFields(true);
52
53 // Check to make sure we keep to the constant 5 fields (this
54 // used to grow each time we called getFields(true)).
55 assertEquals(5, desc.getFields().length);
56 }
57 }
58
59 // this should fail
60 public void testFields2() throws Exception {
61 Service service = new Service();
62 Call call = (Call)service.createCall();
63
64 call.registerTypeMapping(ComplexBean3.class,
65 new QName("foo2", "bar2"),
66 BeanSerializerFactory.class,
67 BeanDeserializerFactory.class,
68 false);
69
70 TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean3.class);
71 assertEquals(4, desc.getFields().length);
72 }
73
74 // this might fail
75 public void testSynch() throws Exception {
76
77 int threads = 30;
78
79 ThreadTest[] thread = new ThreadTest[threads];
80 for (int i=0;i<threads;i++) {
81 thread[i] = new ThreadTest();
82 thread[i].start();
83 }
84
85 Throwable ex = null;
86
87 for (int i=0;i<threads;i++) {
88 thread[i].join();
89 if (ex == null && thread[i].getException() != null) {
90 ex = thread[i].getException();
91 }
92 }
93
94 // either assertion will fail or ArrayIndexOutOfBoundException will
95 // be raised (or it might be ok)
96
97 TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean.class);
98
99 assertEquals(6, desc.getFields().length);
100
101 if (ex != null) {
102 fail(ex.getMessage());
103 }
104 }
105
106 class ThreadTest extends Thread {
107
108 Throwable ex = null;
109
110 public Throwable getException() {
111 return this.ex;
112 }
113
114 public void run() {
115
116 try {
117
118 /*
119 Service service = new Service();
120 Call call = (Call)service.createCall();
121
122 call.registerTypeMapping(ComplexBean.class,
123 new QName("foo", "bar"),
124 BeanSerializerFactory.class,
125 BeanDeserializerFactory.class,
126 false);
127 */
128
129 // this - demonstrates the same problem as above
130 // just can check the ArrayIndexOutOfBoundsException
131 BeanSerializerFactory f =
132 new BeanSerializerFactory(ComplexBean.class,
133 new QName("foo", "bar"));
134 } catch (Exception e) {
135 ex = e;
136 }
137
138
139 }
140 }
141
142 public static void main(String args[])
143 {
144 try {
145 TestTypeDescSynch tester = new TestTypeDescSynch("TypeDesc Test");
146 tester.testSynch();
147 tester.testFields();
148 } catch (Exception e) {
149 e.printStackTrace();
150 }
151 }
152 }