1 19 20 package org.netbeans.modules.xml.axi.sync; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.IOException ; 25 import junit.framework.*; 26 import org.netbeans.modules.xml.axi.AXIComponent; 27 import org.netbeans.modules.xml.axi.AXIDocument; 28 import org.netbeans.modules.xml.schema.model.Schema; 29 import org.netbeans.modules.xml.schema.model.SchemaModel; 30 31 37 public class SyncDeadlockTest extends AbstractSyncTestCase { 38 39 public static final String TEST_XSD = "resources/po.xsd"; 40 public static final String GLOBAL_ELEMENT = "purchaseOrder"; 41 private boolean done = false; 42 43 46 public SyncDeadlockTest(String testName) { 47 super(testName, TEST_XSD, GLOBAL_ELEMENT); 48 } 49 50 public static Test suite() { 51 TestSuite suite = new TestSuite(SyncDeadlockTest.class); 52 return suite; 53 } 54 55 public void testDeadlock() throws Exception { 56 final AXIDocument doc = getAXIModel().getRoot(); 57 doc.addPropertyChangeListener(new AXIDocumentListener(doc)); 58 SchemaModel sm = getAXIModel().getSchemaModel(); 59 Thread t = new Thread (new Runnable () { 65 public void run() { 66 try { 67 doc.getModel().sync(); 68 } catch (IOException ioe) { 69 fail(); 70 } 71 } 72 }); 73 sm.addPropertyChangeListener(new SchemaModelListener(t)); 74 sm.startTransaction(); 75 Schema schema = sm.getSchema(); 76 schema.setTargetNamespace("http://xml.netbeans.org/schema/po"); 77 sm.endTransaction(); 78 t.join(); 79 assertTrue("axi model event not fired", done); 80 } 81 82 private class SchemaModelListener implements PropertyChangeListener { 83 private Thread t; 84 85 public SchemaModelListener(Thread t) { 86 this.t = t; 87 } 88 89 public void propertyChange(PropertyChangeEvent evt) { 90 if(evt.getSource() instanceof Schema && 91 evt.getPropertyName().equals(Schema.TARGET_NAMESPACE_PROPERTY)) { 92 t.start(); 94 while (!t.getState().equals(Thread.State.BLOCKED)) { 95 try { 96 Thread.currentThread().sleep(50); 97 } catch (InterruptedException ex) { 98 99 } 100 } 101 getAXIModel().isIntransaction(); 102 } 103 } 104 } 105 106 private class AXIDocumentListener implements PropertyChangeListener { 107 private AXIComponent source; 108 109 public AXIDocumentListener(AXIComponent source) { 110 this.source = source; 111 } 112 113 public void propertyChange(PropertyChangeEvent evt) { 114 if(evt.getSource() == source && evt.getPropertyName().equals(AXIDocument.PROP_TARGET_NAMESPACE)) { 115 String name = (String )evt.getNewValue(); 116 assertEquals("http://xml.netbeans.org/schema/po",name); 117 done = true; 118 } 119 } 120 } 121 } 122 | Popular Tags |