1 4 package com.tc.test.transactions; 5 6 import com.tc.test.TCTestCase; 7 import com.tc.util.TCAssertionError; 8 9 12 public class StandardTransactionalObjectTest extends TCTestCase { 13 14 private TransactionalObject trans; 15 16 public void setUp() throws Exception { 17 this.trans = new StandardTransactionalObject("test-object", "foo"); 18 } 19 20 24 public void testMixedSpecifiedAndUnspecifiedTimes() throws Exception { 25 TransactionalObject.Context write6615 = this.trans.startWrite("6615"); 26 this.trans.endWrite(write6615); 27 28 Thread.sleep(100); 29 30 TransactionalObject.Context write6616 = this.trans.startWrite("6616"); 31 32 Thread.sleep(100); 33 34 long readTime = System.currentTimeMillis(); 35 36 Thread.sleep(100); 37 38 this.trans.endWrite(write6616); 39 40 Thread.sleep(100); 41 42 TransactionalObject.Context read = this.trans.startRead(); 43 this.trans.endRead(read, "6616"); 44 45 read = this.trans.startRead(readTime); 46 this.trans.endRead(read, "6615"); 47 } 48 49 public void xtestSimpleWrites() throws Exception { 50 checkValues(new String [] { "foo" }, new String [] { "bar", "baz", "quux" }); 51 52 StandardTransactionalObject.Context context1 = this.trans.startWrite("bar"); 53 checkValues(new String [] { "foo", "bar" }, new String [] { "baz", "quux" }); 54 55 this.trans.endWrite(context1); 56 checkValues(new String [] { "bar" }, new String [] { "foo", "baz", "quux" }); 57 58 context1 = this.trans.startWrite("foo"); 59 StandardTransactionalObject.Context context2 = this.trans.startWrite("baz"); 60 61 checkValues(new String [] { "foo", "bar", "baz" }, new String [] { "quux" }); 62 this.trans.endWrite(context1); 63 checkValues(new String [] { "foo", "baz" }, new String [] { "bar", "quux" }); 64 this.trans.endWrite(context2); 65 checkValues(new String [] { "foo", "baz" }, new String [] { "bar", "quux" }); 66 } 67 68 public void xtestInterlacedReads() { 69 this.trans = new StandardTransactionalObject("test-object", 0, "foo", 1000); 70 71 StandardTransactionalObject.Context readContext1 = this.trans.startRead(1020); 72 StandardTransactionalObject.Context readContext1b = this.trans.startRead(1020); 73 StandardTransactionalObject.Context readContext1c = this.trans.startRead(1020); 74 StandardTransactionalObject.Context writeContext1 = this.trans.startWrite("bar", 1040); 75 StandardTransactionalObject.Context readContext2 = this.trans.startRead(1060); 76 StandardTransactionalObject.Context readContext2b = this.trans.startRead(1060); 77 StandardTransactionalObject.Context readContext2c = this.trans.startRead(1060); 78 StandardTransactionalObject.Context writeContext2 = this.trans.startWrite("baz", 1080); 79 StandardTransactionalObject.Context readContext3 = this.trans.startRead(1100); 80 StandardTransactionalObject.Context readContext3b = this.trans.startRead(1100); 81 StandardTransactionalObject.Context readContext3c = this.trans.startRead(1100); 82 83 checkValues(readContext1, 1020, new String [] { "foo" }, new String [] { "bar", "baz" }); 84 checkValues(readContext1, 1030, new String [] { "foo" }, new String [] { "bar", "baz" }); 85 checkValues(readContext1, 1039, new String [] { "foo" }, new String [] { "bar", "baz" }); 86 checkValues(readContext1, 1040, new String [] { "foo", "bar" }, new String [] { "baz" }); 87 checkValues(readContext1, 1079, new String [] { "foo", "bar" }, new String [] { "baz" }); 88 checkValues(readContext1, 1080, new String [] { "foo", "bar", "baz" }, new String [] {}); 89 checkValues(readContext1, 1120, new String [] { "foo", "bar", "baz" }, new String [] {}); 90 91 checkValues(readContext2, 1060, new String [] { "foo", "bar" }, new String [] { "baz" }); 92 checkValues(readContext2, 1079, new String [] { "foo", "bar" }, new String [] { "baz" }); 93 checkValues(readContext2, 1080, new String [] { "foo", "bar", "baz" }, new String [] {}); 94 checkValues(readContext2, 1120, new String [] { "foo", "bar", "baz" }, new String [] {}); 95 96 checkValues(readContext3, 1100, new String [] { "foo", "bar", "baz" }, new String [] {}); 97 98 this.trans.endWrite(writeContext1, 1140); 99 100 checkValues(readContext1b, 1160, new String [] { "foo", "bar", "baz" }, new String [] {}); 101 checkValues(readContext2b, 1160, new String [] { "foo", "bar", "baz" }, new String [] {}); 102 checkValues(readContext3b, 1160, new String [] { "foo", "bar", "baz" }, new String [] {}); 103 104 this.trans.endWrite(writeContext2, 1180); 105 106 checkValues(readContext1c, 1200, new String [] { "foo", "bar", "baz" }, new String [] {}); 107 checkValues(readContext2c, 1200, new String [] { "foo", "bar", "baz" }, new String [] {}); 108 checkValues(readContext3c, 1200, new String [] { "foo", "bar", "baz" }, new String [] {}); 109 110 StandardTransactionalObject.Context readContext4 = this.trans.startRead(1180); 111 112 checkValues(readContext4, 1180, new String [] { "bar", "baz" }, new String [] { "foo" }); 113 } 114 115 public void xtestSlop() throws Exception { 116 this.trans = new StandardTransactionalObject("test-object", 100, "foo", 1000); 117 118 StandardTransactionalObject.Context context1 = this.trans.startWrite("bar", 1050); 119 checkValues(1050, new String [] { "foo", "bar" }, new String [] { "baz", "quux" }); 120 this.trans.endWrite(context1, 1070); 121 122 checkValues(1070, new String [] { "foo", "bar" }, new String [] { "baz", "quux" }); 123 checkValues(1100, new String [] { "foo", "bar" }, new String [] { "baz", "quux" }); 124 checkValues(1169, new String [] { "foo", "bar" }, new String [] { "baz", "quux" }); 125 checkValues(1170, new String [] { "foo", "bar" }, new String [] { "baz", "quux" }); 126 checkValues(1171, new String [] { "bar" }, new String [] { "foo", "baz", "quux" }); 127 checkValues(1500, new String [] { "bar" }, new String [] { "foo", "baz", "quux" }); 128 129 context1 = this.trans.startWrite("baz", 2000); 130 checkValues(2000, new String [] { "bar", "baz" }, new String [] { "foo", "quux" }); 131 checkValues(2050, new String [] { "bar", "baz" }, new String [] { "foo", "quux" }); 132 checkValues(2150, new String [] { "bar", "baz" }, new String [] { "foo", "quux" }); 133 StandardTransactionalObject.Context context2 = this.trans.startWrite("quux", 2200); 134 135 checkValues(2200, new String [] { "bar", "baz", "quux" }, new String [] { "foo" }); 136 checkValues(2300, new String [] { "bar", "baz", "quux" }, new String [] { "foo" }); 137 checkValues(2400, new String [] { "bar", "baz", "quux" }, new String [] { "foo" }); 138 139 this.trans.endWrite(context2, 2500); 140 checkValues(2500, new String [] { "bar", "baz", "quux" }, new String [] { "foo" }); 141 checkValues(2599, new String [] { "bar", "baz", "quux" }, new String [] { "foo" }); 142 checkValues(2600, new String [] { "bar", "baz", "quux" }, new String [] { "foo" }); 143 checkValues(2601, new String [] { "baz", "quux" }, new String [] { "foo", "bar" }); 144 145 this.trans.endWrite(context1, 2800); 146 checkValues(2800, new String [] { "baz", "quux" }, new String [] { "foo", "bar" }); 147 checkValues(2801, new String [] { "baz", "quux" }, new String [] { "foo", "bar" }); 148 checkValues(2900, new String [] { "baz", "quux" }, new String [] { "foo", "bar" }); 149 150 checkValues(2901, new String [] { "baz", "quux" }, new String [] { "foo", "bar" }); 153 checkValues(5000, new String [] { "baz", "quux" }, new String [] { "foo", "bar" }); 154 } 155 156 private void checkValues(String [] accepted, String [] notAccepted) { 157 checkValues(System.currentTimeMillis(), accepted, notAccepted); 158 } 159 160 private void checkValues(long when, String [] accepted, String [] notAccepted) { 161 checkValues(this.trans.startRead(when), when, accepted, notAccepted); 162 } 163 164 private void checkValues(StandardTransactionalObject.Context context, long when, String [] accepted, 165 String [] notAccepted) { 166 for (int i = 0; i < accepted.length; ++i) { 167 this.trans.endRead(context, accepted[i], when); 168 } 169 170 for (int i = 0; i < notAccepted.length; ++i) { 171 try { 172 this.trans.endRead(context, notAccepted[i], when); 173 fail("Didn't get TCAE on endRead with bad value"); 174 } catch (TCAssertionError tcae) { 175 } 177 } 178 179 } 180 181 } 182 | Popular Tags |