KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > typedesc > TestTypeDescSynch


1 package test.typedesc;
2
3 import junit.framework.TestCase;
4
5 import org.apache.axis.client.Call;
6 import org.apache.axis.client.Service;
7 import org.apache.axis.description.AttributeDesc;
8 import org.apache.axis.description.TypeDesc;
9
10 import org.apache.axis.encoding.ser.BeanSerializerFactory;
11 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
12
13 import javax.xml.namespace.QName JavaDoc;
14
15 /**
16  * Confirm TypeDesc bugs are indeed fixed.
17  *
18  * See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22819 for details
19  *
20  * @author gawor@mcs.anl.gov
21  */

22 public class TestTypeDescSynch extends TestCase {
23     
24     public TestTypeDescSynch(String JavaDoc name) {
25         super(name);
26     }
27     
28     public TestTypeDescSynch() {
29         super("Test TypeDesc Synch");
30     }
31     
32     // with won't fail
33
public void testFields() throws Exception JavaDoc {
34         TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean2.class);
35         for (int i=0; i < 10; i++) {
36             desc.getFields(true);
37             
38             // Check to make sure we keep to the constant 5 fields (this
39
// used to grow each time we called getFields(true)).
40
assertEquals(5, desc.getFields().length);
41         }
42     }
43     
44     // this should fail
45
public void testFields2() throws Exception JavaDoc {
46         Service service = new Service();
47         Call call = (Call)service.createCall();
48         
49         call.registerTypeMapping(ComplexBean3.class,
50                                  new QName JavaDoc("foo2", "bar2"),
51                                  BeanSerializerFactory.class,
52                                  BeanDeserializerFactory.class,
53                                  false);
54         
55         TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean3.class);
56         assertEquals(4, desc.getFields().length);
57     }
58     
59     // this might fail
60
public void testSynch() throws Exception JavaDoc {
61         
62         int threads = 30;
63         
64         ThreadTest[] thread = new ThreadTest[threads];
65         for (int i=0;i<threads;i++) {
66             thread[i] = new ThreadTest();
67             thread[i].start();
68         }
69         
70         Throwable JavaDoc ex = null;
71         
72         for (int i=0;i<threads;i++) {
73             thread[i].join();
74             if (ex == null && thread[i].getException() != null) {
75                 ex = thread[i].getException();
76             }
77         }
78         
79         // either assertion will fail or ArrayIndexOutOfBoundException will
80
// be raised (or it might be ok)
81

82         TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean.class);
83         
84         assertEquals(6, desc.getFields().length);
85         
86         if (ex != null) {
87             fail(ex.getMessage());
88         }
89     }
90     
91     class ThreadTest extends Thread JavaDoc {
92         
93         Throwable JavaDoc ex = null;
94         
95         public Throwable JavaDoc getException() {
96             return this.ex;
97         }
98         
99         public void run() {
100             
101             try {
102                 
103                 /*
104                 Service service = new Service();
105                 Call call = (Call)service.createCall();
106                 
107                 call.registerTypeMapping(ComplexBean.class,
108                 new QName("foo", "bar"),
109                 BeanSerializerFactory.class,
110                 BeanDeserializerFactory.class,
111                 false);
112                 */

113                 
114                 // this - demonstrates the same problem as above
115
// just can check the ArrayIndexOutOfBoundsException
116
BeanSerializerFactory f =
117                         new BeanSerializerFactory(ComplexBean.class,
118                                                   new QName JavaDoc("foo", "bar"));
119             } catch (Exception JavaDoc e) {
120                 ex = e;
121             }
122             
123             
124         }
125     }
126     
127     public static void main(String JavaDoc args[])
128     {
129         try {
130             TestTypeDescSynch tester = new TestTypeDescSynch("TypeDesc Test");
131             tester.testSynch();
132             tester.testFields();
133         } catch (Exception JavaDoc e) {
134             e.printStackTrace();
135         }
136     }
137 }
138
Popular Tags