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 ; 14 15 22 public class TestTypeDescSynch extends TestCase { 23 24 public TestTypeDescSynch(String name) { 25 super(name); 26 } 27 28 public TestTypeDescSynch() { 29 super("Test TypeDesc Synch"); 30 } 31 32 public void testFields() throws Exception { 34 TypeDesc desc= TypeDesc.getTypeDescForClass(ComplexBean2.class); 35 for (int i=0; i < 10; i++) { 36 desc.getFields(true); 37 38 assertEquals(5, desc.getFields().length); 41 } 42 } 43 44 public void testFields2() throws Exception { 46 Service service = new Service(); 47 Call call = (Call)service.createCall(); 48 49 call.registerTypeMapping(ComplexBean3.class, 50 new QName ("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 public void testSynch() throws Exception { 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 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 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 { 92 93 Throwable ex = null; 94 95 public Throwable getException() { 96 return this.ex; 97 } 98 99 public void run() { 100 101 try { 102 103 113 114 BeanSerializerFactory f = 117 new BeanSerializerFactory(ComplexBean.class, 118 new QName ("foo", "bar")); 119 } catch (Exception e) { 120 ex = e; 121 } 122 123 124 } 125 } 126 127 public static void main(String args[]) 128 { 129 try { 130 TestTypeDescSynch tester = new TestTypeDescSynch("TypeDesc Test"); 131 tester.testSynch(); 132 tester.testFields(); 133 } catch (Exception e) { 134 e.printStackTrace(); 135 } 136 } 137 } 138 | Popular Tags |