Example #1
0
def store():
    store = RedisTileStore(url,
                           name="test",
                           stop_if_empty=True,
                           timeout=0.1,
                           pending_timeout=0.5,
                           max_retries=2,
                           max_errors_age=1)
    store.delete_all()
    yield store
    def test_redis(self) -> None:
        RedisTileStore(sentinels=[["redis_sentinel", 26379]]).delete_all()
        self.assert_cmd_equals(
            cmd=
            ".build/venv/bin/generate_tiles -c tilegeneration/test-redis.yaml --role master -l point",
            main_func=generate.main,
            regex=False,
            expected=
            """The tile generation of layer 'point (DATE=2012)' is finish
Nb of generated jobs: 10

""",
        )

        self.assert_cmd_equals(
            cmd=
            ".build/venv/bin/generate_controller -c tilegeneration/test-redis.yaml --status",
            main_func=controller.main,
            regex=False,
            expected="""Approximate number of tiles to generate: 10
Approximate number of generating tiles: 0
Tiles in error:
""",
        )

        self.assert_cmd_equals(
            cmd=
            ".build/venv/bin/generate_tiles -c tilegeneration/test-redis.yaml --role slave",
            main_func=generate.main,
            regex=True,
            expected=r"""The tile generation is finish
Nb generated metatiles: 10
Nb metatiles dropped: 0
Nb generated tiles: 640
Nb tiles dropped: 0
Nb tiles stored: 640
Nb tiles in error: 0
Total time: 0:\d\d:\d\d
Total size: \d+ Kio
Time per tile: \d+ ms
Size per tile: \d+ o

""",
        )

        self.assert_cmd_equals(
            cmd=
            ".build/venv/bin/generate_controller -c tilegeneration/test-redis.yaml --status",
            main_func=controller.main,
            regex=False,
            expected="""Approximate number of tiles to generate: 0
Approximate number of generating tiles: 0
Tiles in error:
""",
        )
Example #3
0
    def test_redis(self):
        RedisTileStore('redis://localhost:6379').delete_all()
        self.assert_cmd_equals(
            cmd=
            '.build/venv/bin/generate_tiles -c tilegeneration/test-redis.yaml --role master -l point',
            main_func=generate.main,
            regex=False,
            expected=
            """The tile generation of layer 'point (DATE=2012)' is finish
Nb of generated jobs: 10

""")

        self.assert_cmd_equals(
            cmd=
            '.build/venv/bin/generate_controller -c tilegeneration/test-redis.yaml --status',
            main_func=controller.main,
            regex=False,
            expected="""Approximate number of tiles to generate: 10
""")

        self.assert_cmd_equals(
            cmd=
            '.build/venv/bin/generate_tiles -c tilegeneration/test-redis.yaml --role slave',
            main_func=generate.main,
            regex=True,
            expected="""The tile generation is finish
Nb generated metatiles: 10
Nb metatiles dropped: 0
Nb generated tiles: 640
Nb tiles dropped: 0
Nb tiles stored: 640
Nb tiles in error: 0
Total time: 0:\d\d:\d\d
Total size: \d+ Kio
Time per tile: \d+ ms
Size per tile: \d+ o

""",
        )

        self.assert_cmd_equals(
            cmd=
            '.build/venv/bin/generate_controller -c tilegeneration/test-redis.yaml --status',
            main_func=controller.main,
            regex=False,
            expected="""Approximate number of tiles to generate: 0
""")
Example #4
0
    def load(name):  # pragma: no cover
        """
        Construct a :class:`TileStore` from a name.

        :param name: Name
        :type name: string

        :rtype: :class:`TileStore`

        The following shortcuts are available:

        bounds://<bounding-pyramid>

        file://<template>

        http://<template> and https://<template>

        memcached://<server>:<port>/<template>

        s3://<bucket>/<template>

        sqs://<region>/<queue>

        <filename>.bsddb

        <filename>.mbtiles

        <filename>.zip

        <module>

        """
        if name == "null://":
            from tilecloud.store.null import NullTileStore

            return NullTileStore()
        if name.startswith("bounds://"):
            from tilecloud.store.boundingpyramid import BoundingPyramidTileStore

            return BoundingPyramidTileStore(
                BoundingPyramid.from_string(name[9:]))
        if name.startswith("file://"):
            from tilecloud.layout.template import TemplateTileLayout
            from tilecloud.store.filesystem import FilesystemTileStore

            return FilesystemTileStore(TemplateTileLayout(name[7:]), )
        if name.startswith("http://") or name.startswith("https://"):
            from tilecloud.layout.template import TemplateTileLayout
            from tilecloud.store.url import URLTileStore

            return URLTileStore((TemplateTileLayout(name), ))
        if name.startswith("memcached://"):
            from tilecloud.layout.template import TemplateTileLayout
            from tilecloud.store.memcached import MemcachedTileStore
            from tilecloud.lib.memcached import MemcachedClient

            server, template = name[12:].split("/", 1)
            host, port = server.split(":", 1)
            client = MemcachedClient(host, int(port))
            return MemcachedTileStore(client, TemplateTileLayout(template))
        if name.startswith("s3://"):
            from tilecloud.layout.template import TemplateTileLayout
            from tilecloud.store.s3 import S3TileStore

            bucket, template = name[5:].split("/", 1)
            return S3TileStore(bucket, TemplateTileLayout(template))
        if name.startswith("sqs://"):
            from tilecloud.store.sqs import SQSTileStore
            import boto.sqs  # pylint: disable=import-error
            from boto.sqs.jsonmessage import JSONMessage  # pylint: disable=import-error

            region_name, queue_name = name[6:].split("/", 1)
            connection = boto.sqs.connect_to_region(region_name)
            queue = connection.create_queue(queue_name)
            queue.set_message_class(JSONMessage)
            return SQSTileStore(queue)
        if name.startswith("redis://"):
            from tilecloud.store.redis import RedisTileStore

            return RedisTileStore(name)
        _, ext = os.path.splitext(name)
        if ext == ".bsddb":
            import bsddb  # pylint: disable=import-error
            from tilecloud.store.bsddb import BSDDBTileStore

            return BSDDBTileStore(bsddb.hashopen(name))
        if ext == ".mbtiles":
            import sqlite3
            from tilecloud.store.mbtiles import MBTilesTileStore

            return MBTilesTileStore(sqlite3.connect(name))
        if ext == ".zip":
            import zipfile
            from tilecloud.store.zip import ZipTileStore

            return ZipTileStore(zipfile.ZipFile(name, "a"))
        module = __import__(name)
        components = name.split(".")
        module = reduce(getattr, components[1:], module)
        return getattr(module, "tilestore")
Example #5
0
def store():
    store = RedisTileStore(url, name="test", stop_if_empty=True, timeout=1)
    store.delete_all()
    yield store
Example #6
0
def store():
    store = RedisTileStore(url, name="test", stop_if_empty=True, timeout=0.1, pending_timeout=0.5, max_retries=2,
                           max_errors_age=1)
    store.delete_all()
    yield store