Exemplo n.º 1
0
class TestConnection(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection(version=os.getenv('SOLR_VERSION', '6.1.0'))
        self.collparams = {}
        confname = os.getenv('SOLR_CONFNAME', '')
        if confname != '':
            self.collparams['collection_config_name'] = confname

    def test_list(self):
        self.conn['foo'].create(**self.collparams)
        colls = self.conn.list()
        self.assertTrue(len(colls) >= 1)
        self.conn['foo'].drop()

    def test_live_nodes(self):
        nodes = self.conn.live_nodes
        # to support easy use of solrcloud gettingstarted
        self.assertTrue(len(nodes) >= 1)

    def test_cluster_leader(self):
        leader = self.conn.cluster_leader
        self.assertTrue(leader is not None)

    def test_create_collection(self):
        coll = self.conn.create_collection('test2', **self.collparams)
        self.assertTrue(isinstance(coll, SolrCollection))
        self.conn.test2.drop()
Exemplo n.º 2
0
class TestConnection(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection(version=os.getenv("SOLR_VERSION", "6.1.0"))
        self.collparams = {}
        confname = os.getenv("SOLR_CONFNAME", "")
        if confname != "":
            self.collparams["collection_config_name"] = confname

    def test_list(self):
        self.conn["foo"].create(**self.collparams)
        colls = self.conn.list()
        self.assertTrue(len(colls) >= 1)
        self.conn["foo"].drop()

    def test_live_nodes(self):
        nodes = self.conn.live_nodes
        # to support easy use of solrcloud gettingstarted
        self.assertTrue(len(nodes) >= 1)

    def test_cluster_leader(self):
        leader = self.conn.cluster_leader
        self.assertTrue(leader is not None)

    def test_create_collection(self):
        coll = self.conn.create_collection("test2", **self.collparams)
        self.assertTrue(isinstance(coll, SolrCollection))
        self.conn.test2.drop()

    def test_create_collection_https(self):
        test_conn = SolrConnection(server="localhost", use_https=True)
        self.assertTrue(test_conn.url_template.startswith("https:"))
        test_conn = SolrConnection(server="localhost", use_https=False)
        self.assertTrue(test_conn.url_template.startswith("http:"))
        test_conn = SolrConnection(server="localhost")
        self.assertTrue(test_conn.url_template.startswith("http:"))
Exemplo n.º 3
0
class TestConnection(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection()

    def test_list(self):
        colls = self.conn.list()
        self.assertTrue(len(colls) >= 1)

    def test_live_nodes(self):
        nodes = self.conn.live_nodes
        self.assertTrue(len(nodes) == 1)

    def test_cluster_leader(self):
        leader = self.conn.cluster_leader
        self.assertTrue(leader is not None)

    def test_create_collection(self):
        coll = self.conn.create_collection('test2')
        self.assertTrue(isinstance(coll, SolrCollection))
        self.conn.test2.drop()
Exemplo n.º 4
0
class TestConnection(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection()

    def test_list(self):
        colls = self.conn.list()
        self.assertTrue(len(colls)>=1)

    def test_live_nodes(self):
        nodes = self.conn.live_nodes
        self.assertTrue(len(nodes)==1)

    def test_cluster_leader(self):
        leader = self.conn.cluster_leader
        self.assertTrue(leader is not None)

    def test_create_collection(self):
        coll = self.conn.create_collection('test2')
        self.assertTrue(isinstance(coll,SolrCollection))
        self.conn.test2.drop()
Exemplo n.º 5
0
from solrcloudpy import SolrConnection
import os

connection = SolrConnection(["localhost:8983", "localhost:7574"], version=os.getenv("SOLR_VERSION", "5.3.2"))
for collection_name in connection.list():
    print "Dropping %s" % collection_name
    connection[collection_name].drop()
Exemplo n.º 6
0
class TestCollectionAdmin(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection(version=os.getenv('SOLR_VERSION', '6.1.0'))
        self.collparams = {}
        confname = os.getenv('SOLR_CONFNAME', '')
        if confname != '':
            self.collparams['collection_config_name'] = confname

    def test_create_collection(self):
        original_count = len(self.conn.list())
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        self.assertEqual(len(self.conn.list()), original_count+1)
        self.conn.list()
        time.sleep(3)
        coll3 = self.conn.create_collection('coll3', **self.collparams)
        self.assertEqual(len(self.conn.list()), original_count+2)
        # todo calling state here means the integration works, but what should we assert?
        coll2.state
        coll2.drop()
        self.assertEqual(len(self.conn.list()), original_count+1)
        time.sleep(3)
        coll3.drop()
        self.assertEqual(len(self.conn.list()), original_count)

    def test_reload(self):
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        time.sleep(3)
        res = coll2.reload()
        self.assertTrue(getattr(res, 'success') is not None)
        coll2.drop()

    def test_split_shard(self):
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        time.sleep(3)
        res = coll2.split_shard('shard1', ranges="80000000-90000000,90000001-7fffffff")
        time.sleep(3)
        self.assertTrue(getattr(res, 'success') is not None)
        coll2.drop()

    def test_create_shard(self):
        coll2 = self.conn.create_collection('coll2',
                                            router_name='implicit',
                                            shards='myshard1', max_shards_per_node=3,
                                            **self.collparams)
        time.sleep(3)
        res = coll2.create_shard('shard_my')
        time.sleep(3)
        self.assertTrue(getattr(res, 'success') is not None)
        coll2.drop()

    def test_create_delete_alias(self):
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        coll2.create_alias('alias2')
        time.sleep(3)
        self.assertTrue(self.conn.alias2.is_alias())
        coll2.delete_alias('alias2')
        coll2.drop()

    def test_delete_replica(self):
        try:
            coll2 = self.conn.create_collection('test_delete_replica',
                                                router_name='implicit',
                                                shards='myshard1',
                                                max_shards_per_node=6,
                                                replication_factor=2,
                                                **self.collparams)
        except ReadTimeout:
            print("Encountered read timeout while testing delete replicate")
            print("This generally doesn't mean the collection wasn't created with the settings passed.")
            coll2 = self.conn['test_delete_replica']
        time.sleep(3)
        firstReplica = list(coll2.shards['shards']['myshard1']['replicas'].dict.keys())[0]
        result = coll2.delete_replica(firstReplica, 'myshard1')
        self.assertTrue(result.success)
        coll2.drop()
Exemplo n.º 7
0
class TestCollectionAdmin(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection(version=os.getenv('SOLR_VERSION', '6.1.0'))
        self.collparams = {}
        confname = os.getenv('SOLR_CONFNAME', '')
        if confname != '':
            self.collparams['collection_config_name'] = confname

    def test_create_collection(self):
        original_count = len(self.conn.list())
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        self.assertEqual(len(self.conn.list()), original_count + 1)
        self.conn.list()
        time.sleep(3)
        coll3 = self.conn.create_collection('coll3', **self.collparams)
        self.assertEqual(len(self.conn.list()), original_count + 2)
        # todo calling state here means the integration works, but what should we assert?
        coll2.state
        coll2.drop()
        self.assertEqual(len(self.conn.list()), original_count + 1)
        time.sleep(3)
        coll3.drop()
        self.assertEqual(len(self.conn.list()), original_count)

    def test_reload(self):
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        time.sleep(3)
        res = coll2.reload()
        self.assertTrue(getattr(res, 'success') is not None)
        coll2.drop()

    def test_split_shard(self):
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        time.sleep(3)
        res = coll2.split_shard('shard1',
                                ranges="80000000-90000000,90000001-7fffffff")
        time.sleep(3)
        self.assertTrue(getattr(res, 'success') is not None)
        coll2.drop()

    def test_create_shard(self):
        coll2 = self.conn.create_collection('coll2',
                                            router_name='implicit',
                                            shards='myshard1',
                                            max_shards_per_node=3,
                                            **self.collparams)
        time.sleep(3)
        res = coll2.create_shard('shard_my')
        time.sleep(3)
        self.assertTrue(getattr(res, 'success') is not None)
        coll2.drop()

    def test_create_delete_alias(self):
        coll2 = self.conn.create_collection('coll2', **self.collparams)
        coll2.create_alias('alias2')
        time.sleep(3)
        self.assertTrue(self.conn.alias2.is_alias())
        coll2.delete_alias('alias2')
        coll2.drop()

    def test_delete_replica(self):
        try:
            coll2 = self.conn.create_collection('test_delete_replica',
                                                router_name='implicit',
                                                shards='myshard1',
                                                max_shards_per_node=6,
                                                replication_factor=2,
                                                **self.collparams)
        except ReadTimeout:
            print "Encountered read timeout while testing delete replicate"
            print "This generally doesn't mean the collection wasn't created with the settings passed."
            coll2 = self.conn['test_delete_replica']
        time.sleep(3)
        coll2.delete_replica('core_node2', 'myshard1')
        coll2.drop()
Exemplo n.º 8
0
class QueueSolr(object):
    """
    SolrDB 连接模块
    """
    def __init__(self, table, server=None, **kwargs):
        """
        :param server: list or str
        :param table: collection
        :param kwargs:  detect_live_nodes=False,
                         user=None,
                         password=None,
                         timeout=10,
                         webappdir='solr'
        :return:
        """
        if 'host' in kwargs:
            del kwargs['host']
        if 'port' in kwargs:
            del kwargs['port']
        self.conn = SolrConnection(server=server, **kwargs)
        self.table = table
        self.collection = self.conn[table]

    @QueueBase.catch
    def collections(self):
        """
        获取所以集合列表
        :return:
        """
        return self.conn.list()

    @QueueBase.catch
    def find(self, *args, **kwargs):
        """
        查找某个集合下的field
        查找的字段必须键索引
        否则会报400 error
        :param args:
        :param kwargs:
        :return:
        """
        for dict_ in args:
            if isinstance(dict_, dict):
                kwargs.update(dict_)
        valuess = ' AND '.join([
            '%s:%s' % (k, v) for k, v in kwargs.items()
        ]) if len(kwargs) > 1 else ':'.join(kwargs.keys() + kwargs.values())
        q_item = {'q': valuess}
        #q_item=SearchOptions().commonparams.q(valuess)
        return self.collection.search(q_item).result['response']

    @QueueBase.catch
    def update(self, *args, **kwargs):
        """
        更新数据
        更新的数据字段
        原表必须存在,*_temp都可以
        :param args:
        :param kwargs:
        :return:
        """
        for dict_ in args:
            if isinstance(dict_, dict):
                kwargs.update(dict_)
        self.collection.add([kwargs])
        log.info(u"%s Storage success!" % json.dumps(kwargs))

    @QueueBase.catch
    def delete(self, *args, **kwargs):
        """
        删除数据
        删除的字段原表也必须存在
        否则400 Client Error: Bad Request
        :param args:
        :param kwargs:
        :return:
        """
        for dict_ in args:
            if isinstance(dict_, dict):
                kwargs.update(dict_)
        valuess = ' AND '.join([
            '%s:%s' % (k, v) for k, v in kwargs.items()
        ]) if len(kwargs) > 1 else ':'.join(kwargs.keys() + kwargs.values())
        q_item = {'q': valuess}
        self.collection.delete(q_item, commit=False)
        log.info(u"%s deleted!" % json.dumps(kwargs))
Exemplo n.º 9
0
class TestCollectionAdmin(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection(version=os.getenv("SOLR_VERSION", "6.1.0"))
        self.collparams = {}
        confname = os.getenv("SOLR_CONFNAME", "")
        if confname != "":
            self.collparams["collection_config_name"] = confname

    def test_create_collection(self):
        original_count = len(self.conn.list())
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        time.sleep(3)
        self.assertEqual(len(self.conn.list()), original_count + 1)
        self.conn.list()
        time.sleep(3)
        coll3 = self.conn.create_collection("coll3", **self.collparams)
        time.sleep(3)
        self.assertEqual(len(self.conn.list()), original_count + 2)
        # todo calling state here means the integration works, but what should we assert?
        coll2.state
        coll2.drop()
        time.sleep(3)
        self.assertEqual(len(self.conn.list()), original_count + 1)
        time.sleep(3)
        coll3.drop()
        time.sleep(3)
        self.assertEqual(len(self.conn.list()), original_count)

    def test_reload(self):
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        time.sleep(3)
        res = coll2.reload()
        self.assertTrue(getattr(res, "success") is not None)
        coll2.drop()

    def test_split_shard(self):
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        time.sleep(3)
        res = coll2.split_shard("shard1",
                                ranges="80000000-90000000,90000001-7fffffff")
        time.sleep(3)
        self.assertTrue(getattr(res, "success") is not None)
        coll2.drop()

    def test_create_shard(self):
        coll2 = self.conn.create_collection("coll2",
                                            router_name="implicit",
                                            shards="myshard1",
                                            max_shards_per_node=3,
                                            **self.collparams)
        time.sleep(3)
        res = coll2.create_shard("shard_my")
        time.sleep(3)
        self.assertTrue(getattr(res, "success") is not None)
        coll2.drop()

    def test_create_delete_alias(self):
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        coll2.create_alias("alias2")
        time.sleep(3)
        self.assertTrue(self.conn.alias2.is_alias())
        coll2.delete_alias("alias2")
        coll2.drop()

    def test_delete_replica(self):
        try:
            coll2 = self.conn.create_collection("test_delete_replica",
                                                router_name="implicit",
                                                shards="myshard1",
                                                max_shards_per_node=6,
                                                replication_factor=2,
                                                **self.collparams)
        except ReadTimeout:
            print("Encountered read timeout while testing delete replicate")
            print(
                "This generally doesn't mean the collection wasn't created with the settings passed."
            )
            coll2 = self.conn["test_delete_replica"]
        time.sleep(3)
        firstReplica = list(
            coll2.shards["shards"]["myshard1"]["replicas"].dict.keys())[0]
        result = coll2.delete_replica(firstReplica, "myshard1")
        self.assertTrue(result.success)
        coll2.drop()
Exemplo n.º 10
0
from solrcloudpy import SolrConnection
import os

connection = SolrConnection(['localhost:8983', 'localhost:7574'],
                            version=os.getenv('SOLR_VERSION', '5.3.2'))
for collection_name in connection.list():
    print "Dropping %s" % collection_name
    connection[collection_name].drop()
Exemplo n.º 11
0
class TestCollectionAdmin(unittest.TestCase):
    def setUp(self):
        self.conn = SolrConnection(version=os.getenv("SOLR_VERSION", "6.1.0"))
        self.collparams = {}
        confname = os.getenv("SOLR_CONFNAME", "")
        if confname != "":
            self.collparams["collection_config_name"] = confname

    def test_create_collection(self):
        original_count = len(self.conn.list())
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        self.assertEqual(len(self.conn.list()), original_count + 1)
        self.conn.list()
        time.sleep(3)
        coll3 = self.conn.create_collection("coll3", **self.collparams)
        self.assertEqual(len(self.conn.list()), original_count + 2)
        # todo calling state here means the integration works, but what should we assert?
        coll2.state
        coll2.drop()
        self.assertEqual(len(self.conn.list()), original_count + 1)
        time.sleep(3)
        coll3.drop()
        self.assertEqual(len(self.conn.list()), original_count)

    def test_reload(self):
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        time.sleep(3)
        res = coll2.reload()
        self.assertTrue(getattr(res, "success") is not None)
        coll2.drop()

    def test_split_shard(self):
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        time.sleep(3)
        res = coll2.split_shard("shard1", ranges="80000000-90000000,90000001-7fffffff")
        time.sleep(3)
        self.assertTrue(getattr(res, "success") is not None)
        coll2.drop()

    def test_create_shard(self):
        coll2 = self.conn.create_collection(
            "coll2", router_name="implicit", shards="myshard1", max_shards_per_node=3, **self.collparams
        )
        time.sleep(3)
        res = coll2.create_shard("shard_my")
        time.sleep(3)
        self.assertTrue(getattr(res, "success") is not None)
        coll2.drop()

    def test_create_delete_alias(self):
        coll2 = self.conn.create_collection("coll2", **self.collparams)
        coll2.create_alias("alias2")
        time.sleep(3)
        self.assertTrue(self.conn.alias2.is_alias())
        coll2.delete_alias("alias2")
        coll2.drop()

    def test_delete_replica(self):
        try:
            coll2 = self.conn.create_collection(
                "test_delete_replica",
                router_name="implicit",
                shards="myshard1",
                max_shards_per_node=6,
                replication_factor=2,
                **self.collparams
            )
        except ReadTimeout:
            print "Encountered read timeout while testing delete replicate"
            print "This generally doesn't mean the collection wasn't created with the settings passed."
            coll2 = self.conn["test_delete_replica"]
        time.sleep(3)
        coll2.delete_replica("core_node2", "myshard1")
        coll2.drop()