def test_create_with_unknown_action_meta_data(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "action-and-meta-data": "guess", }) self.assertEqual("Unknown 'action-and-meta-data' setting [guess]", ctx.exception.args[0])
def test_create_with_unknown_id_conflicts(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={"conflicts": "crazy"}) self.assertEqual("Unknown 'conflicts' setting [crazy]", ctx.exception.args[0])
def test_create_with_negative_bulk_size(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "bulk-size": -5 }) self.assertEqual("'bulk-size' must be positive but was -5", ctx.exception.args[0])
def test_create_with_non_numeric_bulk_size(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "bulk-size": "Three" }) self.assertEqual("'bulk-size' must be numeric", ctx.exception.args[0])
def test_create_valid_param_source(self): self.assertIsNotNone(params.BulkIndexParamSource(indices=[], params={ "action-and-meta-data": "generate", "conflicts": "random", "bulk-size": 5000, "batch-size": 20000, "pipeline": "test-pipeline" }))
def test_create_with_no_metadata_but_conflicts(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "action-and-meta-data": "none", "conflicts": "random" }) self.assertEqual("Cannot generate id conflicts [random] when 'action-and-meta-data' is [none].", ctx.exception.args[0])
def test_create_with_fraction_larger_batch_size(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "bulk-size": 5, "batch-size": 8 }) self.assertEqual("'batch-size' must be a multiple of 'bulk-size'", ctx.exception.args[0])
def test_create_with_fraction_smaller_batch_size(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "bulk-size": 5, "batch-size": 3 }) self.assertEqual("'batch-size' must be greater than or equal to 'bulk-size'", ctx.exception.args[0])
def test_create_with_unsupported_action_meta_data(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={ "action-and-meta-data": "generate", }) self.assertEqual( "The parameter \"action-and-meta-data\" is not supported anymore. Please specify instead the boolean " "flag \"includes-action-and-meta-data\" on each type definition.", ctx.exception.args[0])
def test_passes_all_indices_by_default(self): index1 = track.Index(name="index1", auto_managed=True, types=[]) index2 = track.Index(name="index2", auto_managed=True, types=[]) source = params.BulkIndexParamSource(indices=[index1, index2], params={ "conflicts": "random", "bulk-size": 5000, "batch-size": 20000, "pipeline": "test-pipeline" }) partition = source.partition(0, 1) self.assertEqual(partition.indices, [index1, index2])
def test_create_with_metadata_in_source_file_but_conflicts(self): type1 = track.Type("type1", mapping={}, number_of_documents=10, includes_action_and_meta_data=True) index1 = track.Index(name="index1", auto_managed=True, types=[type1]) with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[index1], params={"conflicts": "random"}) self.assertEqual( "Cannot generate id conflicts [random] as type [index1] in index [type1] already contains " "an action and meta-data line.", ctx.exception.args[0])
def test_raises_exception_if_no_index_matches(self): index1 = track.Index(name="index1", auto_managed=True, types=[]) source = params.BulkIndexParamSource(indices=[index1], params={ "index": "does_not_exist", "conflicts": "random", "bulk-size": 5000, "batch-size": 20000, "pipeline": "test-pipeline" }) with self.assertRaises(exceptions.RallyAssertionError) as ctx: source.partition(0, 1) self.assertEqual( "The provided index [does_not_exist] does not match any of the indices [index1].", ctx.exception.args[0])
def test_filters_indices(self): index1 = track.Index(name="index1", auto_managed=True, types=[]) index2 = track.Index(name="index2", auto_managed=True, types=[]) source = params.BulkIndexParamSource( indices=[index1, index2], params={ "index": "index2", "action-and-meta-data": "generate", "conflicts": "random", "bulk-size": 5000, "batch-size": 20000, "pipeline": "test-pipeline" }) partition = source.partition(0, 1) self.assertEqual(partition.indices, [index2])
def test_create_without_params(self): with self.assertRaises(exceptions.InvalidSyntax) as ctx: params.BulkIndexParamSource(indices=[], params={}) self.assertEqual("Mandatory parameter 'bulk-size' is missing", ctx.exception.args[0])