예제 #1
0
class TestIsolated(TestCase):

    def setUp(self):
        self.cluster = Cluster()
        self.cluster.start()

    def tearDown(self):
        self.cluster.terminate()

    def _make_one(self):
        from pyelastictest.isolated import Isolated
        return Isolated()

    def test_index_deletion(self):
        iso = self._make_one()
        iso.setup_es(self.cluster)
        iso.es_client.index('documents', 'doc', {'foo': 1})
        iso.es_client.refresh()
        self.assertEqual(len(iso.es_client.status()['indices']), 1)
        # clean up
        iso.teardown_es()
        self.assertEqual(len(self.cluster.client.status()['indices']), 0)
예제 #2
0
class TestIsolatedTestCase(IsolatedTestCase):

    def setUp(self):
        self.cluster = Cluster(size=3)
        self.cluster.start()

    def tearDown(self):
        self.cluster.terminate()

    def test_start_stop(self):
        es = ElasticSearch(reversed(self.cluster.urls))

        def es_health():
            for i in range(10):
                try:
                    return es.health(wait_for_nodes='>1')
                except ConnectionError:
                    pass
            return {}

        self.cluster[0].stop()
        self.assertEqual(es_health()['number_of_nodes'], 2)
예제 #3
0
class TestIsolatedContextManager(TestCase):

    def setUp(self):
        self.cluster = Cluster()
        self.cluster.start()

    def tearDown(self):
        self.cluster.terminate()

    def _get_target(self):
        from pyelastictest.isolated import isolated
        return isolated

    def test_with(self):
        with self._get_target()(cluster=self.cluster) as iso:
            self.assertTrue(iso.es_cluster[0].running)
            iso.es_client.index('documents', 'doc', {'foo': 1})
            iso.es_client.refresh()
            self.assertEqual(len(iso.es_client.status()['indices']), 1)
        self.assertEqual(len(self.cluster.client.status()['indices']), 0)

    def test_template_deletion(self):
        self.cluster.client.create_template('before', {
            "template": "index_*",
            "settings": {"number_of_replicas": "13"},
        })
        with self._get_target()(cluster=self.cluster) as iso:
            self.assertEqual(
                iso.es_client.list_templates().keys(), ['before'])
            iso.es_client.create_template('inside', {
                "template": "index_*",
                "settings": {"number_of_replicas": "7"},
            })
            self.assertEqual(set(iso.es_client.list_templates().keys()),
                             set(['before', 'inside']))
        self.assertEqual(
            self.cluster.client.list_templates().keys(), ['before'])
예제 #4
0
 def setUp(self):
     self.cluster = Cluster()
     self.cluster.start()
예제 #5
0
 def setUp(self):
     self.cluster = Cluster(size=3)
     self.cluster.start()