Exemplo n.º 1
0
def get_schema():
    # build a couple of keyspaces
    keyspaces = []
    for k in range(2):
        keyspace = get_keyspace("my_ks_%s" % k, True, "SimpleStrategy",
                                {"replication_factor": 1})
        keyspaces.append(keyspace)

    schema = Metadata()
    schema.keyspaces = keyspaces
    return schema
Exemplo n.º 2
0
    def test_build_index_as_cql(self):
        column_meta = Mock()
        column_meta.name = 'column_name_here'
        column_meta.table.name = 'table_name_here'
        column_meta.table.keyspace.name = 'keyspace_name_here'
        meta_model = Metadata(Mock())

        row = {'index_name': 'index_name_here', 'index_type': 'index_type_here'}
        index_meta = meta_model._build_index_metadata(column_meta, row)
        self.assertEqual(index_meta.as_cql_query(),
                'CREATE INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here)')

        row['index_options'] = '{ "class_name": "class_name_here" }'
        row['index_type'] = 'CUSTOM'
        index_meta = meta_model._build_index_metadata(column_meta, row)
        self.assertEqual(index_meta.as_cql_query(),
                "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'")
Exemplo n.º 3
0
    def test_build_index_as_cql(self):
        column_meta = Mock()
        column_meta.name = 'column_name_here'
        column_meta.table.name = 'table_name_here'
        column_meta.table.keyspace.name = 'keyspace_name_here'
        meta_model = Metadata(Mock())

        row = {'index_name': 'index_name_here', 'index_type': 'index_type_here'}
        index_meta = meta_model._build_index_metadata(column_meta, row)
        self.assertEqual(index_meta.as_cql_query(),
                'CREATE INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here)')

        row['index_options'] = '{ "class_name": "class_name_here" }'
        row['index_type'] = 'CUSTOM'
        index_meta = meta_model._build_index_metadata(column_meta, row)
        self.assertEqual(index_meta.as_cql_query(),
                "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'")
Exemplo n.º 4
0
    def test_iterate_all_hosts_and_modify(self):
        """
        PYTHON-572
        """
        metadata = Metadata()
        metadata.add_or_return_host(Host('dc1.1', SimpleConvictionPolicy))
        metadata.add_or_return_host(Host('dc1.2', SimpleConvictionPolicy))

        self.assertEqual(len(metadata.all_hosts()), 2)

        for host in metadata.all_hosts():  # this would previously raise in Py3
            metadata.remove_host(host)

        self.assertEqual(len(metadata.all_hosts()), 0)
Exemplo n.º 5
0
    def test_build_index_as_cql(self):
        column_meta = Mock()
        column_meta.name = "column_name_here"
        column_meta.table.name = "table_name_here"
        column_meta.table.keyspace.name = "keyspace_name_here"
        meta_model = Metadata(Mock())

        row = {"index_name": "index_name_here", "index_type": "index_type_here"}
        index_meta = meta_model._build_index_metadata(column_meta, row)
        self.assertEqual(
            index_meta.as_cql_query(),
            "CREATE INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here)",
        )

        row["index_options"] = '{ "class_name": "class_name_here" }'
        row["index_type"] = "CUSTOM"
        index_meta = meta_model._build_index_metadata(column_meta, row)
        self.assertEqual(
            index_meta.as_cql_query(),
            "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'",
        )
Exemplo n.º 6
0
    def test_iterate_all_hosts_and_modify(self):
        """
        PYTHON-572
        """
        metadata = Metadata()
        metadata.add_or_return_host(Host('dc1.1', SimpleConvictionPolicy))
        metadata.add_or_return_host(Host('dc1.2', SimpleConvictionPolicy))

        self.assertEqual(len(metadata.all_hosts()), 2)

        for host in metadata.all_hosts():  # this would previously raise in Py3
            metadata.remove_host(host)

        self.assertEqual(len(metadata.all_hosts()), 0)
Exemplo n.º 7
0
class MockCluster(object):

    metadata = Metadata()
    database = {}

    def __init__(self,
                 contact_points=["127.0.0.1"],
                 port=9042,
                 auth_provider=None):
        assert isinstance(contact_points, list)
        self.contact_points = contact_points
        self.port = port
        self.sessions = []

    def connect(self, keyspace=None):
        result = MockSession(self, keyspace)
        self.sessions.append(result)
        return result

    def shutdown(self):
        self.sessions = []
Exemplo n.º 8
0
 def __init__(self):
     from cassandra.metadata import Metadata
     self.metadata = Metadata()
     self.metadata.rebuild_token_map("Murmur3Partitioner", {})