Exemplo n.º 1
0
    def test_update_status_on_describe_for_deleting_table_negative(
            self, mock_repo_get, mock_repo_update):

        context = mock.Mock(tenant='fake_tenant')
        table_name = 'fake_table'
        storage_manager = simple_impl.SimpleStorageManager(
            None, table_info_repo.TableInfoRepository())

        table_info = table_info_repo.TableInfo(
            table_name, None, None, models.TableMeta.TABLE_STATUS_DELETING)
        table_info.last_update_date_time = timeutils.utcnow()

        mock_repo_get.return_value = table_info

        table_meta = storage_manager.describe_table(context, table_name)

        self.assertEqual(table_meta.status,
                         models.TableMeta.TABLE_STATUS_DELETING)
Exemplo n.º 2
0
    def test_execute_write_batch_put_delete_same_item(
            self, mock_repo_get, mock_validate_table_is_active,
            mock_validate_table_schema):

        table_info = mock.Mock()
        table_info.schema.key_attributes = ['id', 'range']
        mock_repo_get.return_value = table_info

        context = mock.Mock(tenant='fake_tenant')

        table_name = 'fake_table'

        request_map = {
            table_name: [
                models.WriteItemRequest.put({
                    'id':
                    models.AttributeValue('N', 1),
                    'range':
                    models.AttributeValue('S', '1'),
                    'str':
                    models.AttributeValue('S', 'str1'),
                }),
                models.WriteItemRequest.delete({
                    'id':
                    models.AttributeValue('N', 1),
                    'range':
                    models.AttributeValue('S', '1')
                })
            ]
        }

        storage_manager = simple_impl.SimpleStorageManager(
            storage_driver.StorageDriver(),
            table_info_repo.TableInfoRepository())

        with self.assertRaises(exception.ValidationError) as raises_cm:
            storage_manager.execute_write_batch(context, request_map)

        exc = raises_cm.exception
        self.assertIn("More than one", exc._error_string)
Exemplo n.º 3
0
    def test_execute_get_batch(self, mock_get_item, mock_repo_get,
                               mock_validate_table_is_active,
                               mock_validate_table_schema):
        future = futures.Future()
        future.set_result(True)
        mock_get_item.return_value = future

        context = mock.Mock(tenant='fake_tenant')

        table_name = 'fake_table'

        request_list = [
            models.GetItemRequest(
                table_name, {
                    'id': models.AttributeValue('N', 1),
                    'str': models.AttributeValue('S', 'str1'),
                }, None, True),
            models.GetItemRequest(
                table_name, {
                    'id': models.AttributeValue('N', 1),
                    'str': models.AttributeValue('S', 'str2'),
                }, None, True)
        ]

        expected_get = [
            mock.call(context, req.table_name, req.key_attribute_map,
                      req.attributes_to_get, req.consistent)
            for req in request_list
        ]

        storage_manager = simple_impl.SimpleStorageManager(
            None, table_info_repo.TableInfoRepository())

        result, unprocessed_items = storage_manager.execute_get_batch(
            context, request_list)
        mock_get_item.has_calls(expected_get)
        self.assertEqual(unprocessed_items, [])
Exemplo n.º 4
0
    def test_execute_write_batch(self, mock_put_item, mock_delete_item,
                                 mock_repo_get, mock_validate_table_is_active,
                                 mock_validate_table_schema, mock_batch_write):
        future = futures.Future()
        future.set_result(True)
        mock_put_item.return_value = future
        mock_delete_item.return_value = future
        mock_batch_write.side_effect = NotImplementedError()

        table_info = mock.Mock()
        table_info.schema.key_attributes = ['id', 'range']
        mock_repo_get.return_value = table_info

        context = mock.Mock(tenant='fake_tenant')

        table_name = 'fake_table'

        request_map = {
            table_name: [
                models.WriteItemRequest.put({
                    'id':
                    models.AttributeValue('N', 1),
                    'range':
                    models.AttributeValue('S', '1'),
                    'str':
                    models.AttributeValue('S', 'str1'),
                }),
                models.WriteItemRequest.put({
                    'id':
                    models.AttributeValue('N', 2),
                    'range':
                    models.AttributeValue('S', '1'),
                    'str':
                    models.AttributeValue('S', 'str1')
                }),
                models.WriteItemRequest.delete({
                    'id':
                    models.AttributeValue('N', 3),
                    'range':
                    models.AttributeValue('S', '3')
                })
            ]
        }

        expected_put = [
            mock.call(
                context, table_info, {
                    'id': models.AttributeValue('N', 1),
                    'range': models.AttributeValue('S', '1'),
                    'str': models.AttributeValue('S', 'str1')
                }),
            mock.call(
                context, table_info, {
                    'id': models.AttributeValue('N', 2),
                    'range': models.AttributeValue('S', '1'),
                    'str': models.AttributeValue('S', 'str1')
                }),
        ]
        expected_delete = [
            mock.call(
                context, table_info, {
                    'id': models.AttributeValue('N', 3),
                    'range': models.AttributeValue('S', '3')
                })
        ]

        storage_manager = simple_impl.SimpleStorageManager(
            storage_driver.StorageDriver(),
            table_info_repo.TableInfoRepository())

        unprocessed_items = storage_manager.execute_write_batch(
            context, request_map)

        self.assertEqual(expected_put, mock_put_item.call_args_list)
        self.assertEqual(expected_delete, mock_delete_item.call_args_list)

        self.assertEqual(unprocessed_items, {})