def test_batch_merge(self):
        #Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_merge'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()
        self.tc.insert_entity(self.test_table, entity)

        entity = self.tc.get_entity(self.test_table, '001', 'batch_merge')
        self.assertEqual(3, entity.test3)
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_merge'
        entity.test2 = 'value1'
        self.tc.begin_batch()
        self.tc.merge_entity(self.test_table, '001', 'batch_merge', entity)
        self.tc.commit_batch()
        entity = self.tc.get_entity(self.test_table, '001', 'batch_merge')

        #Assert
        self.assertEqual('value1', entity.test2)
        self.assertEqual(1234567890, entity.test4)
    def test_batch_insert_replace(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_insert_replace'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()
        self.ts.begin_batch()
        self.ts.insert_or_replace_entity(
            self.table_name, entity.PartitionKey, entity.RowKey, entity)
        self.ts.commit_batch()

        entity = self.ts.get_entity(
            self.table_name, '001', 'batch_insert_replace')

        # Assert
        self.assertIsNotNone(entity)
        self.assertEqual('value', entity.test2)
        self.assertEqual(1234567890, entity.test4)
    def test_batch_merge(self):
        #Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_merge'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()
        self.tc.insert_entity(self.test_table, entity)

        entity = self.tc.get_entity(self.test_table, '001', 'batch_merge')
        self.assertEqual(3, entity.test3)
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_merge'
        entity.test2 = 'value1'
        self.tc.begin_batch()
        self.tc.merge_entity(self.test_table, '001', 'batch_merge', entity)
        self.tc.commit_batch()
        entity = self.tc.get_entity(self.test_table, '001', 'batch_merge')

        #Assert
        self.assertEqual('value1', entity.test2)
        self.assertEqual(1234567890, entity.test4)
    def test_query_entities_large(self):
        # Arrange
        self._create_table(self.table_name)
        total_entities_count = 1000
        entities_per_batch = 50

        for j in range(total_entities_count // entities_per_batch):
            self.ts.begin_batch()
            for i in range(entities_per_batch):
                entity = Entity()
                entity.PartitionKey = 'large'
                entity.RowKey = 'batch{0}-item{1}'.format(j, i)
                entity.test = EntityProperty('Edm.Boolean', 'true')
                entity.test2 = 'hello world;' * 100
                entity.test3 = 3
                entity.test4 = EntityProperty('Edm.Int64', '1234567890')
                entity.test5 = datetime.utcnow()
                self.ts.insert_entity(self.table_name, entity)
            self.ts.commit_batch()

        # Act
        start_time = datetime.now()
        resp = self.ts.query_entities(self.table_name)
        elapsed_time = datetime.now() - start_time

        # Assert
        print('query_entities took {0} secs.'.format(elapsed_time.total_seconds()))
        # azure allocates 5 seconds to execute a query
        # if it runs slowly, it will return fewer results and make the test fail
        self.assertEqual(len(resp), total_entities_count)
Ejemplo n.º 5
0
    def test_batch_inserts(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        entity = Entity()
        entity.PartitionKey = 'batch_inserts'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')

        self.tc.begin_batch()
        for i in range(100):
            entity.RowKey = str(i)
            self.tc.insert_entity(self.table_name, entity)
        self.tc.commit_batch()

        entities = self.tc.query_entities(self.table_name,
                                          "PartitionKey eq 'batch_inserts'",
                                          '')

        # Assert
        self.assertIsNotNone(entities)
        self.assertEqual(100, len(entities))
    def test_batch_negative(self):
        #Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_negative_1'
        entity.test = 1

        self.tc.insert_entity(self.test_table, entity)
        entity.test = 2
        entity.RowKey = 'batch_negative_2'
        self.tc.insert_entity(self.test_table, entity)
        entity.test = 3
        entity.RowKey = 'batch_negative_3'
        self.tc.insert_entity(self.test_table, entity)
        entity.test = -2
        self.tc.update_entity(self.test_table, entity.PartitionKey,
                              entity.RowKey, entity)

        try:
            self.tc.begin_batch()
            entity.RowKey = 'batch_negative_1'
            self.tc.update_entity(self.test_table, entity.PartitionKey,
                                  entity.RowKey, entity)
            self.tc.merge_entity(self.test_table, entity.PartitionKey,
                                 entity.RowKey, entity)
            self.fail('Should raise WindowsAzueError exception')
            self.tc.commit_batch()
        except:
            self.tc.cancel_batch()
            pass

        try:
            self.tc.begin_batch()
            entity.PartitionKey = '001'
            entity.RowKey = 'batch_negative_1'
            self.tc.update_entity(self.test_table, entity.PartitionKey,
                                  entity.RowKey, entity)
            entity.PartitionKey = '002'
            entity.RowKey = 'batch_negative_1'
            self.tc.insert_entity(self.test_table, entity)
            self.fail('Should raise WindowsAzueError exception')
            self.tc.commit_batch()
        except:
            self.tc.cancel_batch()
            pass
    def test_batch_negative(self):
        #Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_negative_1'
        entity.test = 1

        self.tc.insert_entity(self.test_table, entity)
        entity.test = 2
        entity.RowKey = 'batch_negative_2'
        self.tc.insert_entity(self.test_table, entity)
        entity.test = 3
        entity.RowKey = 'batch_negative_3'
        self.tc.insert_entity(self.test_table, entity)
        entity.test = -2
        self.tc.update_entity(self.test_table, entity.PartitionKey, entity.RowKey, entity)

        try:        
            self.tc.begin_batch()
            entity.RowKey = 'batch_negative_1'
            self.tc.update_entity(self.test_table, entity.PartitionKey, entity.RowKey, entity)
            self.tc.merge_entity(self.test_table, entity.PartitionKey, entity.RowKey, entity)
            self.fail('Should raise WindowsAzueError exception')
            self.tc.commit_batch()            
        except:
            self.tc.cancel_batch()
            pass
        

        try:        
            self.tc.begin_batch()
            entity.PartitionKey = '001'
            entity.RowKey = 'batch_negative_1'
            self.tc.update_entity(self.test_table, entity.PartitionKey, entity.RowKey, entity)
            entity.PartitionKey = '002'
            entity.RowKey = 'batch_negative_1'
            self.tc.insert_entity(self.test_table, entity) 
            self.fail('Should raise WindowsAzueError exception')
            self.tc.commit_batch()
        except:
            self.tc.cancel_batch()
            pass
    def test_batch_all_operations_together(self):
        # Arrange
        self._create_table(self.table_name)

         # Act
        entity = Entity()
        entity.PartitionKey = '003'
        entity.RowKey = 'batch_all_operations_together-1'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-2'
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-3'
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-4'
        self.ts.insert_entity(self.table_name, entity)

        self.ts.begin_batch()
        entity.RowKey = 'batch_all_operations_together'
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-1'
        self.ts.delete_entity(
            self.table_name, entity.PartitionKey, entity.RowKey)
        entity.RowKey = 'batch_all_operations_together-2'
        entity.test3 = 10
        self.ts.update_entity(
            self.table_name, entity.PartitionKey, entity.RowKey, entity)
        entity.RowKey = 'batch_all_operations_together-3'
        entity.test3 = 100
        self.ts.merge_entity(
            self.table_name, entity.PartitionKey, entity.RowKey, entity)
        entity.RowKey = 'batch_all_operations_together-4'
        entity.test3 = 10
        self.ts.insert_or_replace_entity(
            self.table_name, entity.PartitionKey, entity.RowKey, entity)
        entity.RowKey = 'batch_all_operations_together-5'
        self.ts.insert_or_merge_entity(
            self.table_name, entity.PartitionKey, entity.RowKey, entity)
        self.ts.commit_batch()

        # Assert
        entities = self.ts.query_entities(
            self.table_name, "PartitionKey eq '003'", '')
        self.assertEqual(5, len(entities))
    def test_batch_insert(self):
        #Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_insert'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()

        self.tc.begin_batch()
        self.tc.insert_entity(self.test_table, entity)
        self.tc.commit_batch()

        #Assert 
        result = self.tc.get_entity(self.test_table, '001', 'batch_insert')
        self.assertIsNotNone(result) 
    def test_batch_insert(self):
        #Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_insert'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()

        self.tc.begin_batch()
        self.tc.insert_entity(self.test_table, entity)
        self.tc.commit_batch()

        #Assert
        result = self.tc.get_entity(self.test_table, '001', 'batch_insert')
        self.assertIsNotNone(result)
    def test_batch_inserts(self):
        #Act
        entity = Entity()
        entity.PartitionKey = 'batch_inserts'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')

        self.tc.begin_batch()
        for i in range(100):
            entity.RowKey = str(i)
            self.tc.insert_entity(self.test_table, entity)
        self.tc.commit_batch()
        
        entities = self.tc.query_entities(self.test_table, "PartitionKey eq 'batch_inserts'", '')

        #Assert
        self.assertIsNotNone(entities);
        self.assertEqual(100, len(entities))
    def test_batch_delete(self):
        # Arrange
        self._create_table(self.table_name)

        # Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_delete'
        entity.test = EntityProperty('Edm.Boolean', 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty('Edm.Int64', '1234567890')
        entity.test5 = datetime.utcnow()
        self.ts.insert_entity(self.table_name, entity)

        entity = self.ts.get_entity(self.table_name, '001', 'batch_delete')
        #self.assertEqual(3, entity.test3)
        self.ts.begin_batch()
        self.ts.delete_entity(self.table_name, '001', 'batch_delete')
        self.ts.commit_batch()