/** * Atomic - 2 transaction, concurrent update, aborted transaction shouldn't save any data */ public function testTransactionWDeleteAllCommit_atomic1() { $obj = new TestModel2($this->adapter); $obj->field1 = 'foo'; $obj->save(); $id1 = $obj->id; $obj = new TestModel2($this->adapter); $obj->field1 = 'bar'; $obj->save(); $id2 = $obj->id; $txn1 = new Transaction(); usleep(100); //sleep 100ms to ensure txn2 is benind txn1 $txn2 = new Transaction(); $this->assertTrue($txn2->getTimestamp() > $txn1->getTimestamp(), 'Transaction 2 is not newer than transaction 1'); //transaction 1 $obj_txn1 = new TestModel2($this->adapter); $obj_txn2 = new TestModel2($this->adapter); $obj_txn1->joinTransaction($txn1); $obj_txn2->joinTransaction($txn2); $obj_txn1->getById($id1); $obj_txn1->field1 = 'foo1'; $obj_txn1->save(); $obj_txn2->getById($id1); $obj_txn2->field1 = 'foo2'; $obj_txn2->save(); $obj_txn1->getById($id2); $obj_txn2->getById($id2); $obj_txn2->field1 = 'bar2'; $obj_txn2->save(); $obj_txn1->field1 = 'bar2'; try { $obj_txn1->delete(); $this->fail('Late delete did not throw exception'); } catch (OptimisticLockException $ex) { } $txn2->commit(); $objTest = new TestModel2($this->adapter); $objTest->getById($id1); $this->assertEquals('foo2', $objTest->field1); $objTest->getById($id2); $this->assertEquals('bar2', $objTest->field1); }