Exemplo n.º 1
0
 def test_configure_namespace(self):
   db_batch = flexmock()
   db_batch.should_receive("batch_put_entity").and_return(None)
   dd = DatastoreDistributed(db_batch)
   item = Item(key_name="Bob", name="Bob", _app="hello")
   key = db.model_to_protobuf(item)
   assert dd.get_table_prefix(key) == "hello/"
Exemplo n.º 2
0
  def test_delete_entities_txn(self):
    app = 'guestbook'
    txn_hash = {'root_key': 1}
    txn_str = '1'.zfill(ID_KEY_LENGTH)
    entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:])

    db_batch = flexmock()
    db_batch.should_receive('valid_data_version').and_return(True)
    dd = DatastoreDistributed(db_batch, None)

    keys = [entity.key()]
    prefix = dd.get_table_prefix(entity.key())
    entity_key = dd.get_entity_key(prefix, entity.key().path())
    encoded_path = str(
      dd.encode_index_pb(entity.key().path()))
    txn_keys = [dd._SEPARATOR.join([app, txn_str, '', encoded_path])]
    txn_values = {
      txn_keys[0]: {
        dbconstants.TRANSACTIONS_SCHEMA[0]: dbconstants.TxnActions.DELETE,
        dbconstants.TRANSACTIONS_SCHEMA[1]: entity_key,
        dbconstants.TRANSACTIONS_SCHEMA[2]: ''
      }
    }

    flexmock(dd).should_receive('get_root_key').and_return('root_key')

    db_batch.should_receive('batch_put_entity').with_args(
      dbconstants.TRANSACTIONS_TABLE,
      txn_keys,
      dbconstants.TRANSACTIONS_SCHEMA,
      txn_values,
      ttl=TX_TIMEOUT * 2
    )
    dd.delete_entities_txn(app, keys, txn_hash)
Exemplo n.º 3
0
 def test_configure_namespace(self):
     db_batch = flexmock()
     db_batch.should_receive("batch_put_entity").and_return(None)
     dd = DatastoreDistributed(db_batch)
     item = Item(key_name="Bob", name="Bob", _app="hello")
     key = db.model_to_protobuf(item)
     assert dd.get_table_prefix(key) == "hello/"
Exemplo n.º 4
0
  def test_delete_entities_txn(self):
    app = 'guestbook'
    txn_hash = {'root_key': 1}
    txn_str = '1'.zfill(ID_KEY_LENGTH)
    entity = self.get_new_entity_proto(app, *self.BASIC_ENTITY[1:])

    db_batch = flexmock()
    db_batch.should_receive('valid_data_version').and_return(True)
    dd = DatastoreDistributed(db_batch, None)

    keys = [entity.key()]
    prefix = dd.get_table_prefix(entity.key())
    entity_key = dd.get_entity_key(prefix, entity.key().path())
    encoded_path = str(
      dd._DatastoreDistributed__encode_index_pb(entity.key().path()))
    txn_keys = [dd._SEPARATOR.join([app, txn_str, '', encoded_path])]
    txn_values = {
      txn_keys[0]: {
        dbconstants.TRANSACTIONS_SCHEMA[0]: dbconstants.TxnActions.DELETE,
        dbconstants.TRANSACTIONS_SCHEMA[1]: entity_key,
        dbconstants.TRANSACTIONS_SCHEMA[2]: ''
      }
    }

    flexmock(dd).should_receive('get_root_key').and_return('root_key')

    db_batch.should_receive('batch_put_entity').with_args(
      dbconstants.TRANSACTIONS_TABLE,
      txn_keys,
      dbconstants.TRANSACTIONS_SCHEMA,
      txn_values,
      ttl=dd.MAX_TXN_DURATION * 2
    )
    dd.delete_entities_txn(app, keys, txn_hash)
Exemplo n.º 5
0
 def test_get_table_prefix(self):
     db_batch = flexmock()
     db_batch.should_receive("batch_put_entity").and_return(None)
     zookeeper = flexmock()
     zookeeper.should_receive("acquire_lock").and_return(True)
     zookeeper.should_receive("release_lock").and_return(True)
     dd = DatastoreDistributed(db_batch, zookeeper)
     item = Item(key_name="Bob", name="Bob", _app="hello")
     key = db.model_to_protobuf(item)
     self.assertEquals(dd.get_table_prefix(key), "hello/")
 def test_get_table_prefix(self):
   db_batch = flexmock()
   db_batch.should_receive("batch_put_entity").and_return(None)
   zookeeper = flexmock()
   zookeeper.should_receive("acquire_lock").and_return(True)
   zookeeper.should_receive("release_lock").and_return(True)
   dd = DatastoreDistributed(db_batch, zookeeper)
   item = Item(key_name="Bob", name="Bob", _app="hello")
   key = db.model_to_protobuf(item)
   self.assertEquals(dd.get_table_prefix(key), "hello\x00")
Exemplo n.º 7
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 = dd.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)
Exemplo n.º 8
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()}
    }])

    flexmock(DatastoreDistributed).should_receive('get_indices').and_return([])

    dd = DatastoreDistributed(db_batch, None)
    prefix = dd.get_table_prefix(entity)
    entity_key = dd.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)