| 1 | |
|---|
| 2 | package tmcsim.client.cadclientgui.data; |
|---|
| 3 | |
|---|
| 4 | import java.util.ArrayList; |
|---|
| 5 | import java.util.Vector; |
|---|
| 6 | import java.util.logging.Level; |
|---|
| 7 | import java.util.logging.Logger; |
|---|
| 8 | import javax.swing.table.DefaultTableModel; |
|---|
| 9 | import junit.framework.TestCase; |
|---|
| 10 | import static junit.framework.TestCase.assertTrue; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * Test of CADData tableForUnitStatus() |
|---|
| 14 | * @author jdalbey |
|---|
| 15 | */ |
|---|
| 16 | public class CADDataConcurrencyTest extends TestCase { |
|---|
| 17 | private Vector<Unit> units; |
|---|
| 18 | private Unit alpha; |
|---|
| 19 | public CADDataConcurrencyTest(String testName) { |
|---|
| 20 | super(testName); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | @Override |
|---|
| 24 | protected void setUp() throws Exception { |
|---|
| 25 | super.setUp(); |
|---|
| 26 | units = new Vector<Unit>(); |
|---|
| 27 | alpha = new Unit("14-1"); |
|---|
| 28 | units.add(alpha); |
|---|
| 29 | units.add(new Unit("14-2")); |
|---|
| 30 | units.add(new Unit("14-3")); |
|---|
| 31 | units.add(new Unit("14-4")); |
|---|
| 32 | units.add(new Unit("14-5")); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | @Override |
|---|
| 36 | protected void tearDown() throws Exception { |
|---|
| 37 | super.tearDown(); |
|---|
| 38 | System.out.println("Tearing down"); |
|---|
| 39 | try |
|---|
| 40 | { |
|---|
| 41 | Thread.sleep(100); |
|---|
| 42 | } |
|---|
| 43 | catch(InterruptedException e) |
|---|
| 44 | { ; } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | public void testThreads() |
|---|
| 49 | { |
|---|
| 50 | System.out.println("Testing tableForUnitStatus()"); |
|---|
| 51 | CADData caddata = new CADData(); |
|---|
| 52 | caddata.setUnitsFromXML(units); // add 5 units |
|---|
| 53 | caddata.addIncident(new Incident(101,"Desc", 10L)); |
|---|
| 54 | String unitNum = "14-1"; |
|---|
| 55 | caddata.unitAssignedToIncident(unitNum, 101, true); |
|---|
| 56 | caddata.unitAvailable(unitNum); |
|---|
| 57 | Threadserve ts1=new Threadserve(caddata, "A"); |
|---|
| 58 | Threadserve ts2=new Threadserve(caddata, "B"); |
|---|
| 59 | Threadserve ts3=new Threadserve(caddata, "C"); |
|---|
| 60 | DefaultTableModel m = caddata.tableForUnitStatus(); |
|---|
| 61 | assertEquals("main Incorrect Row Count:",5,m.getRowCount()); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | class Threadserve implements Runnable |
|---|
| 65 | { |
|---|
| 66 | private CADData caddata; |
|---|
| 67 | private String id; |
|---|
| 68 | private Thread th; |
|---|
| 69 | Threadserve(CADData caddata, String id) |
|---|
| 70 | { |
|---|
| 71 | this.caddata = caddata; |
|---|
| 72 | this.id = id; |
|---|
| 73 | th=new Thread(this); |
|---|
| 74 | th.start(); |
|---|
| 75 | } |
|---|
| 76 | public void run() |
|---|
| 77 | { |
|---|
| 78 | //System.out.println("Start "+ id); |
|---|
| 79 | DefaultTableModel m = caddata.tableForUnitStatus(); |
|---|
| 80 | int loopLimit = m.getRowCount(); |
|---|
| 81 | assertEquals(id + " Incorrect Row Count:"+loopLimit,5,loopLimit); |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | } |
|---|