示例#1
0
    def test_bitmap_index_options(self):
        config = IndexConfig()

        config.bitmap_index_options = {
            "unique_key": QueryConstants.THIS_ATTRIBUTE_NAME
        }
        self.assertEqual(QueryConstants.THIS_ATTRIBUTE_NAME,
                         config.bitmap_index_options.unique_key)
        self.assertEqual(UniqueKeyTransformation.OBJECT,
                         config.bitmap_index_options.unique_key_transformation)

        invalid_options = [
            ({
                "unique_key": None
            }, TypeError),
            ({
                "unique_key_transformation": None
            }, TypeError),
            ({
                "invalid_config": None
            }, InvalidConfigurationError),
            ([], TypeError),
        ]

        for o, e in invalid_options:
            with self.assertRaises(e):
                config.bitmap_index_options = o
    def test_adding_indexes(self):
        # single-attribute index
        single_index = IndexConfig(attributes=["name"])
        self.map.add_index(single_index)

        # nested-attribute index
        nested_index = IndexConfig(attributes=["limb.name"])
        self.map.add_index(nested_index)
示例#3
0
    def test_name(self):
        config = IndexConfig()

        config.name = "test"
        self.assertEqual("test", config.name)

        with self.assertRaises(TypeError):
            config.name = 123
示例#4
0
    def test_type(self):
        config = IndexConfig()

        config.type = IndexType.BITMAP
        self.assertEqual(IndexType.BITMAP, config.type)

        config.type = "HASH"
        self.assertEqual(IndexType.HASH, config.type)

        with self.assertRaises(TypeError):
            config.type = "HASHH"
示例#5
0
    def test_attributes(self):
        config = IndexConfig()

        config.attributes = ["a"]
        self.assertEqual(["a"], config.attributes)

        with self.assertRaises(TypeError):
            config.attributes = None

        with self.assertRaises(ValueError):
            config.attributes = ["a."]
示例#6
0
    def test_normalized_name(self):
        config = IndexConfig(None, IndexType.SORTED, ["attr"])
        normalized = IndexUtil.validate_and_normalize("map", config)
        self.assertEqual("map_sorted_attr", normalized.name)

        config = IndexConfig("test", IndexType.BITMAP, ["attr"])
        normalized = IndexUtil.validate_and_normalize("map", config)
        self.assertEqual("test", normalized.name)

        config = IndexConfig(None, IndexType.HASH, ["this.attr2.x"])
        normalized = IndexUtil.validate_and_normalize("map2", config)
        self.assertEqual("map2_hash_attr2.x", normalized.name)
 def test_defaults(self):
     config = IndexConfig()
     self.assertIsNone(config.name)
     self.assertEqual(IndexType.SORTED, config.type)
     self.assertEqual([], config.attributes)
     self.assertEqual("__key", config.bitmap_index_options.unique_key)
     self.assertEqual(UniqueKeyTransformation.OBJECT,
                      config.bitmap_index_options.unique_key_transformation)
 def test_with_bitmap_indexes(self):
     bio = {
         "unique_key": QueryConstants.THIS_ATTRIBUTE_NAME,
         "unique_key_transformation": UniqueKeyTransformation.RAW
     }
     config = IndexConfig(type=IndexType.BITMAP, attributes=["attr"], bitmap_index_options=bio)
     normalized = IndexUtil.validate_and_normalize("map", config)
     self.assertEqual(bio["unique_key"], normalized.bitmap_index_options.unique_key)
     self.assertEqual(bio["unique_key_transformation"], normalized.bitmap_index_options.unique_key_transformation)
示例#9
0
 def test_from_dict_defaults(self):
     config = IndexConfig.from_dict({})
     self.assertIsNone(config.name)
     self.assertEqual(IndexType.SORTED, config.type)
     self.assertEqual([], config.attributes)
     self.assertEqual(QueryConstants.KEY_ATTRIBUTE_NAME,
                      config.bitmap_index_options.unique_key)
     self.assertEqual(UniqueKeyTransformation.OBJECT,
                      config.bitmap_index_options.unique_key_transformation)
 def decode(msg):
     msg.next_frame()
     initial_frame = msg.next_frame()
     type = FixSizedTypesCodec.decode_int(initial_frame.buf,
                                          _TYPE_DECODE_OFFSET)
     name = CodecUtil.decode_nullable(msg, StringCodec.decode)
     attributes = ListMultiFrameCodec.decode(msg, StringCodec.decode)
     bitmap_index_options = CodecUtil.decode_nullable(
         msg, BitmapIndexOptionsCodec.decode)
     CodecUtil.fast_forward_to_end_frame(msg)
     return IndexConfig(name, type, attributes, bitmap_index_options)
    def test_add_attributes(self):
        config = IndexConfig()

        invalid_attributes = [(None, AssertionError), ("   ", ValueError),
                              ("x.", ValueError), ("  x.x.", ValueError)]

        for attr, error in invalid_attributes:
            with self.assertRaises(error):
                config.add_attribute(attr)

        config.add_attribute("x.y")
        config.add_attribute("x.y.z")
        self.assertEqual(["x.y", "x.y.z"], config.attributes)
示例#12
0
    def test_duplicate_attributes(self):
        invalid_attributes = [
            ["a", "b", "a"],
            ["a", "b", " a"],
            [" a", "b", "a"],
            ["this.a", "b", "a"],
            ["this.a ", "b", " a"],
            ["this.a", "b", "this.a"],
            ["this.a ", "b", " this.a"],
            [" this.a", "b", "a"],
        ]

        for attributes in invalid_attributes:
            with self.assertRaises(ValueError):
                config = IndexConfig(attributes=attributes)
                IndexUtil.validate_and_normalize("", config)
    def test_bitmap_index_options(self):
        invalid_options = [
            ({
                "unique_key": None
            }, TypeError),
            ({
                "unique_key_transformation": None
            }, TypeError),
            ({
                "invalid_config": None
            }, InvalidConfigurationError),
            ([], TypeError),
        ]

        for o, e in invalid_options:
            with self.assertRaises(e):
                IndexConfig(bitmap_index_options=o)
    def test_with_changes(self):
        name = "name"
        idx_type = IndexType.HASH
        attributes = ["attr", "attr.nested"]
        bio = {
            "unique_key": QueryConstants.THIS_ATTRIBUTE_NAME,
            "unique_key_transformation": UniqueKeyTransformation.RAW
        }
        config = IndexConfig(name, idx_type, attributes, bio)

        self.assertEqual(name, config.name)
        self.assertEqual(idx_type, config.type)
        self.assertEqual(attributes, attributes)
        self.assertEqual(bio["unique_key"],
                         config.bitmap_index_options.unique_key)
        self.assertEqual(bio["unique_key_transformation"],
                         config.bitmap_index_options.unique_key_transformation)
示例#15
0
 def test_canonicalize_attribute_name(self):
     config = IndexConfig(attributes=["this.x.y.z", "a.b.c"])
     normalized = IndexUtil.validate_and_normalize("", config)
     self.assertEqual("x.y.z", normalized.attributes[0])
     self.assertEqual("a.b.c", normalized.attributes[1])
示例#16
0
    def test_with_composite_bitmap_indexes(self):
        config = IndexConfig(attributes=["attr1", "attr2"],
                             type=IndexType.BITMAP)

        with self.assertRaises(ValueError):
            IndexUtil.validate_and_normalize("", config)
示例#17
0
    def test_with_too_many_attributes(self):
        attributes = ["attr_%s" % i for i in range(512)]
        config = IndexConfig(attributes=attributes)

        with self.assertRaises(ValueError):
            IndexUtil.validate_and_normalize("", config)
示例#18
0
    def test_with_no_attributes(self):
        config = IndexConfig()

        with self.assertRaises(ValueError):
            IndexUtil.validate_and_normalize("", config)
示例#19
0
 def test_from_dict(self):
     with self.assertRaises(InvalidConfigurationError):
         IndexConfig.from_dict({"unknown_key": 1})
 def test_add_index(self):
     ordered_index = IndexConfig("length", attributes=["this"])
     unordered_index = IndexConfig("length", INDEX_TYPE.HASH, ["this"])
     self.map.add_index(ordered_index)
     self.map.add_index(unordered_index)
 def test_add_index_duplicate_fields(self):
     config = IndexConfig("length", attributes=["this", "this"])
     with self.assertRaises(ValueError):
         self.map.add_index(config)
 def test_add_index_invalid_attribute(self):
     config = IndexConfig("length", attributes=["this.x."])
     with self.assertRaises(ValueError):
         self.map.add_index(config)