コード例 #1
0
  def test_apply_txn_changes(self):
    app = 'guestbook'
    txn = 1
    entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:])

    db_batch = flexmock()
    db_batch.should_receive('get_transaction_metadata').and_return({
      'puts': {entity.key().Encode(): entity.Encode()},
      'deletes': [],
      'tasks': [],
      'reads': set(),
      'start': datetime.datetime.utcnow(),
      'is_xg': False,
    })
    db_batch.should_receive('valid_data_version').and_return(True)
    db_batch.should_receive('group_updates').and_return([])

    db_batch.should_receive('get_indices').and_return([])

    dd = DatastoreDistributed(db_batch, self.get_zookeeper())
    prefix = dd.get_table_prefix(entity)
    entity_key = get_entity_key(prefix, entity.key().path())
    db_batch.should_receive('batch_get_entity').and_return({entity_key: {}})
    db_batch.should_receive('batch_mutate')

    entity_lock = flexmock(EntityLock)
    entity_lock.should_receive('acquire')
    entity_lock.should_receive('release')

    dd.apply_txn_changes(app, txn)
コード例 #2
0
  def test_apply_txn_changes(self):
    app = 'guestbook'
    txn = 1
    entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:])

    db_batch = flexmock()
    db_batch.should_receive('get_transaction_metadata').and_return({
      'puts': {entity.key().Encode(): entity.Encode()},
      'deletes': [],
      'tasks': [],
      'reads': set(),
      'start': datetime.datetime.utcnow(),
      'is_xg': False,
    })
    db_batch.should_receive('valid_data_version').and_return(True)
    db_batch.should_receive('group_updates').and_return([])

    db_batch.should_receive('get_indices').and_return([])

    transaction_manager = flexmock()
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    prefix = dd.get_table_prefix(entity)
    entity_key = get_entity_key(prefix, entity.key().path())
    db_batch.should_receive('batch_get_entity').and_return({entity_key: {}})
    db_batch.should_receive('batch_mutate')

    entity_lock = flexmock(EntityLock)
    entity_lock.should_receive('acquire')
    entity_lock.should_receive('release')

    dd.apply_txn_changes(app, txn)
コード例 #3
0
  def test_apply_txn_changes(self):
    app = 'guestbook'
    txn = 1
    entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:])

    db_batch = flexmock()
    db_batch.should_receive('valid_data_version').and_return(True)
    db_batch.should_receive('range_query').and_return([{
      'txn_entity_1': {'operation': dbconstants.TxnActions.PUT,
                       'operand': entity.Encode()}
    }])

    db_batch.should_receive('get_indices').and_return([])

    dd = DatastoreDistributed(db_batch, None)
    prefix = dd.get_table_prefix(entity)
    entity_key = get_entity_key(prefix, entity.key().path())
    db_batch.should_receive('batch_get_entity').and_return({entity_key: {}})
    db_batch.should_receive('batch_mutate')

    dd.apply_txn_changes(app, txn)
コード例 #4
0
  def test_apply_txn_changes(self):
    app = 'guestbook'
    txn = 1
    entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:])

    async_metadata = gen.Future()
    async_metadata.set_result({
      'puts': {entity.key().Encode(): entity.Encode()},
      'deletes': [],
      'tasks': [],
      'reads': set(),
      'start': datetime.datetime.utcnow(),
      'is_xg': False,
    })

    db_batch = flexmock()
    db_batch.should_receive('get_transaction_metadata').\
      and_return(async_metadata)
    db_batch.should_receive('valid_data_version_sync').and_return(True)
    db_batch.should_receive('group_updates').and_return([])

    transaction_manager = flexmock(
      delete_transaction_id=lambda project_id, txid: None,
      set_groups=lambda project_id, txid, groups: None)
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    dd.index_manager = flexmock(
      projects={'guestbook': flexmock(indexes_pb=[])})
    prefix = dd.get_table_prefix(entity)
    entity_key = get_entity_key(prefix, entity.key().path())

    async_result = gen.Future()
    async_result.set_result({entity_key: {}})

    db_batch.should_receive('batch_get_entity').and_return(async_result)
    db_batch.should_receive('normal_batch').and_return(ASYNC_NONE)

    async_true = gen.Future()
    async_true.set_result(True)
    entity_lock = flexmock(EntityLock)
    entity_lock.should_receive('acquire').and_return(async_true)
    entity_lock.should_receive('release')

    yield dd.apply_txn_changes(app, txn)