コード例 #1
0
  def test_dynamic_put(self):
    PREFIX = "x\x01"
    db_batch = flexmock(session=flexmock())
    db_batch.should_receive('valid_data_version').and_return(True)

    entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name",
                                              "prop1val", ns="blah")
    entity_key1 = 'test\x00blah\x00test_kind:bob\x01'
    entity_proto2 = self.get_new_entity_proto("test", "test_kind", "nancy", "prop1name",
                                              "prop2val", ns="blah")
    entity_key2 = 'test\x00blah\x00test_kind:nancy\x01'

    db_batch.should_receive('batch_get_entity').and_return(
      {entity_key1: {}, entity_key2: {}})
    db_batch.should_receive('batch_mutate')
    dd = DatastoreDistributed(db_batch, self.get_zookeeper())
    putreq_pb = datastore_pb.PutRequest()
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(0).MergeFrom(entity_proto1)
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(1).MergeFrom(entity_proto2)
    
    putresp_pb = datastore_pb.PutResponse()

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

    flexmock(ScatteredAllocator).should_receive('next').\
      and_return(random.randint(1, 500))

    dd.dynamic_put('test', putreq_pb, putresp_pb)
    self.assertEquals(len(putresp_pb.key_list()), 2)
コード例 #2
0
  def test_dynamic_put(self):
    PREFIX = "x\x01"
    db_batch = flexmock()
    db_batch.should_receive('valid_data_version').and_return(True)

    zookeeper = flexmock()
    zookeeper.should_receive("acquire_lock").and_return(True)
    zookeeper.should_receive("release_lock").and_return(True)
    zookeeper.should_receive("get_transaction_id").and_return(1)

    entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name",
                                              "prop1val", ns="blah")
    entity_key1 = 'test\x00blah\x00test_kind:bob\x01'
    entity_proto2 = self.get_new_entity_proto("test", "test_kind", "nancy", "prop1name",
                                              "prop2val", ns="blah")
    entity_key2 = 'test\x00blah\x00test_kind:nancy\x01'

    db_batch.should_receive('batch_get_entity').and_return(
      {entity_key1: {}, entity_key2: {}})
    db_batch.should_receive('batch_mutate')
    dd = DatastoreDistributed(db_batch, zookeeper)
    putreq_pb = datastore_pb.PutRequest()
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(0).MergeFrom(entity_proto1)
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(1).MergeFrom(entity_proto2)
    
    putresp_pb = datastore_pb.PutResponse()
    dd.dynamic_put('test', putreq_pb, putresp_pb)
    self.assertEquals(len(putresp_pb.key_list()), 2)
コード例 #3
0
  def test_dynamic_put(self):
    PREFIX = "x\x01"
    db_batch = flexmock(session=flexmock())
    db_batch.should_receive('valid_data_version').and_return(True)

    entity_proto1 = self.get_new_entity_proto("test", "test_kind", "bob", "prop1name",
                                              "prop1val", ns="blah")
    entity_key1 = 'test\x00blah\x00test_kind:bob\x01'
    entity_proto2 = self.get_new_entity_proto("test", "test_kind", "nancy", "prop1name",
                                              "prop2val", ns="blah")
    entity_key2 = 'test\x00blah\x00test_kind:nancy\x01'

    db_batch.should_receive('batch_get_entity').and_return(
      {entity_key1: {}, entity_key2: {}})
    db_batch.should_receive('batch_mutate')
    transaction_manager = flexmock(
      create_transaction_id=lambda project, xg: 1,
      delete_transaction_id=lambda project, txid: None)
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    putreq_pb = datastore_pb.PutRequest()
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(0).MergeFrom(entity_proto1)
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(1).MergeFrom(entity_proto2)
    
    putresp_pb = datastore_pb.PutResponse()

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

    flexmock(ScatteredAllocator).should_receive('next').\
      and_return(random.randint(1, 500))

    dd.dynamic_put('test', putreq_pb, putresp_pb)
    self.assertEquals(len(putresp_pb.key_list()), 2)
コード例 #4
0
  def test_dynamic_put(self):
    db_batch = flexmock(session=flexmock())
    db_batch.should_receive('valid_data_version_sync').and_return(True)

    entity_proto1 = self.get_new_entity_proto(
      "test", "test_kind", "bob", "prop1name", "prop1val", ns="blah")
    entity_key1 = 'test\x00blah\x00test_kind:bob\x01'
    entity_proto2 = self.get_new_entity_proto(
      "test", "test_kind", "nancy", "prop1name", "prop2val", ns="blah")
    entity_key2 = 'test\x00blah\x00test_kind:nancy\x01'
    async_result = gen.Future()
    async_result.set_result({entity_key1: {}, entity_key2: {}})

    db_batch.should_receive('batch_get_entity').and_return(async_result)
    db_batch.should_receive('normal_batch').and_return(ASYNC_NONE)
    transaction_manager = flexmock(
      create_transaction_id=lambda project, xg: 1,
      delete_transaction_id=lambda project, txid: None,
      set_groups=lambda project, txid, groups: None)
    dd = DatastoreDistributed(db_batch, transaction_manager,
                              self.get_zookeeper())
    dd.index_manager = flexmock(
      projects={'test': flexmock(indexes_pb=[])})
    putreq_pb = datastore_pb.PutRequest()
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(0).MergeFrom(entity_proto1)
    putreq_pb.add_entity()
    putreq_pb.mutable_entity(1).MergeFrom(entity_proto2)

    putresp_pb = datastore_pb.PutResponse()

    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')

    flexmock(ScatteredAllocator).should_receive('next').\
      and_return(random.randint(1, 500))

    yield dd.dynamic_put('test', putreq_pb, putresp_pb)
    self.assertEquals(len(putresp_pb.key_list()), 2)