示例#1
0
  def test_txn(self):
    oid = self.createObject(RaleighDeque.TYPE)
    deque = RaleighDeque(self.client, oid)

    txn_1 = RaleighTransaction(self.client)
    txn_1.begin()

    txn_2 = RaleighTransaction(self.client)
    txn_2.begin()

    deque.push_front('A', txn_1.txn_id)
    self.assertRaises(RaleighException, deque.push_front, 'B', txn_2.txn_id)
    self.assertRaises(RaleighException, deque.push_front, 'B')
    self.assertRaises(RaleighException, deque.pop_front, txn_2.txn_id)
    self.assertRaises(RaleighException, deque.pop_front)

    data = deque.pop_front(txn_1.txn_id)
    self.assertEquals(data['data'], 'A')
    deque.push_front('C', txn_1.txn_id)
    txn_1.commit()

    deque.push_back('D', txn_2.txn_id)
    self.assertRaises(RaleighException, deque.push_back, 'E')
    self.assertRaises(RaleighException, deque.pop_back)
    data = deque.pop_back(txn_2.txn_id)
    self.assertEquals(data['data'], 'D')
    deque.push_back('F', txn_2.txn_id)
    txn_2.rollback()

    data = deque.pop_front()
    self.assertEquals(data['data'], 'C')
示例#2
0
  def test_txn_multi_obj(self):
      def _sset_get(sset, key, txn_id, expected):
        try:
          data = sset.get(key, txn_id)
          print sset, data
          assert data['value'] == expected, (data['value'] == expected)
        except Exception as e:
          print sset, e
          assert expected == None, expected

      oid_1 = self.createObject(RaleighSSet.TYPE)
      sset_1 = RaleighSSet(self.client, oid_1)

      oid_2 = self.createObject(RaleighSSet.TYPE)
      sset_2 = RaleighSSet(self.client, oid_2)

      key = 'key-01'
      value = 'value-01'

      # Test Rollback
      txn = RaleighTransaction(self.client)
      txn.begin()
      sset_1.insert(key, value, txn.txn_id)
      sset_2.insert(key, value, txn.txn_id)

      self.assertRaises(RaleighException, sset_1.get, key)
      self.assertRaises(RaleighException, sset_2.get, key)
      data = sset_1.get(key, txn.txn_id)
      self.assertEquals(data['value'], value)
      data = sset_2.get(key, txn.txn_id)
      self.assertEquals(data['value'], value)

      txn.rollback()

      self.assertRaises(RaleighException, sset_1.get, key)
      self.assertRaises(RaleighException, sset_2.get, key)

      # Test Commit
      txn = RaleighTransaction(self.client)
      txn.begin()
      sset_1.insert(key, value, txn.txn_id)
      sset_2.insert(key, value, txn.txn_id)
      self.assertRaises(RaleighException, sset_1.get, key)
      self.assertRaises(RaleighException, sset_2.get, key)
      data = sset_1.get(key, txn.txn_id)
      self.assertEquals(data['value'], value)
      data = sset_2.get(key, txn.txn_id)
      self.assertEquals(data['value'], value)
      txn.commit()

      data = sset_1.get(key)
      self.assertEquals(data['value'], value)
      data = sset_2.get(key)
      self.assertEquals(data['value'], value)
示例#3
0
  def test_txn_key_locked(self):
    oid = self.createObject(RaleighSSet.TYPE)
    sset = RaleighSSet(self.client, oid)

    txn_1 = RaleighTransaction(self.client)
    txn_1.begin()

    txn_2 = RaleighTransaction(self.client)
    txn_2.begin()

    sset.insert('key-01', 'value-01', txn_1.txn_id)
    self.assertRaises(RaleighException, sset.insert, 'key-01', 'value-02', txn_2.txn_id)

    txn_2.rollback()
    txn_1.commit()

    data = sset.get('key-01')
    self.assertEquals(data['value'], 'value-01')
示例#4
0
  def test_txn(self):
    oid = self.createObject(RaleighNumber.TYPE)
    number = RaleighNumber(self.client, oid)

    txn_1 = RaleighTransaction(self.client)
    txn_1.begin()

    txn_2 = RaleighTransaction(self.client)
    txn_2.begin()

    data = number.inc(txn_1.txn_id)
    self.assertEquals(data['value'], 1)
    self.assertRaises(RaleighException, number.set, 10, txn_2.txn_id)
    self.assertRaises(RaleighException, number.cas, 10, 20, txn_2.txn_id)
    self.assertRaises(RaleighException, number.add, 10, txn_2.txn_id)
    self.assertRaises(RaleighException, number.mul, 10, txn_2.txn_id)
    data = number.get()
    self.assertEquals(data['value'], 0)
    data = number.get(txn_1.txn_id)
    self.assertEquals(data['value'], 1)

    txn_1.commit()

    number.inc(txn_2.txn_id)
    self.assertRaises(RaleighException, number.set, 10)
    self.assertRaises(RaleighException, number.cas, 10, 20)
    self.assertRaises(RaleighException, number.add, 10)
    self.assertRaises(RaleighException, number.mul, 10)
    data = number.get()
    self.assertEquals(data['value'], 1)
    data = number.get(txn_2.txn_id)
    self.assertEquals(data['value'], 2)

    txn_2.rollback()

    data = number.inc()
    self.assertEquals(data['value'], 2)