Ejemplo n.º 1
0
 def create_default_views(self, is_one_ddoc=False):
     views = [View(self.testcase.default_view_name + "0",
                   'function (doc) {emit(doc.geometry, doc.age);}',
                   dev_view=self.testcase.use_dev_views, is_spatial=True),
             View(self.testcase.default_view_name + "1",
                   'function (doc) {emit(doc.geometry, null);}',
                   dev_view=self.testcase.use_dev_views, is_spatial=True),
             View(self.testcase.default_view_name + "2",
                   'function (doc) {emit(doc.geometry, doc.name);}',
                   dev_view=self.testcase.use_dev_views, is_spatial=True),
             View(self.testcase.default_view_name + "3",
                   'function (doc) {emit(doc.geometry, [doc.name, doc.age]);}',
                   dev_view=self.testcase.use_dev_views, is_spatial=True),
             View(self.testcase.default_view_name + "4",
                   'function (doc) {emit(doc.geometry, {result : {age:doc.age}});}',
                   dev_view=self.testcase.use_dev_views, is_spatial=True)]
     ddocs = []
     if is_one_ddoc:
         ddocs.append(DesignDocument(self.testcase.default_ddoc_name, [],
                                     spatial_views=views))
     else:
         for i in xrange(5):
             ddocs.append(DesignDocument(self.testcase.default_ddoc_name + str(i), [],
                                     spatial_views=[views[i]]))
     for ddoc in ddocs:
         for view in ddoc.spatial_views:
             self.testcase.cluster.create_view(self.testcase.master, ddoc.name, view,
                                               bucket=self.testcase.bucket_name)
     return ddocs
Ejemplo n.º 2
0
    def test_add_single_spatial_view(self):
        name_lenght = self.input.param('name_lenght', None)
        view_name = self.input.param('view_name', self.default_view_name)
        if name_lenght:
            view_name = ''.join(
                random.choice(string.ascii_lowercase)
                for x in range(name_lenght))
        not_compilable = self.input.param('not_compilable', False)
        error = self.input.param('error', None)
        map_fn = (
            self.default_map,
            'function (doc) {emit(doc.geometry, doc.age);')[not_compilable]

        ddoc = DesignDocument(self.default_ddoc_name, [],
                              spatial_views=[
                                  View(view_name,
                                       map_fn,
                                       dev_view=self.use_dev_views,
                                       is_spatial=True)
                              ])
        try:
            self.create_ddocs([ddoc])
        except Exception as ex:
            if error and str(ex).find(error) != -1:
                self.log.info("Error caught as expected %s" % error)
                return
            else:
                self.fail("Unexpected error appeared during run %s" % ex)
        if error:
            self.fail("Expected error '%s' didn't appear" % error)
Ejemplo n.º 3
0
    def test_views_during_ddoc_compaction(self):
        fragmentation_value = self.input.param("fragmentation_value", 80)
        ddoc_to_compact = DesignDocument(
            "ddoc_to_compact", [],
            spatial_views=[
                View(self.default_view_name,
                     'function (doc) { emit(doc.age, doc.name);}',
                     dev_view=self.use_dev_views)
            ])
        ddocs = self.make_ddocs(self.num_ddoc, self.views_per_ddoc, 0)
        self.disable_compaction()
        self.create_ddocs([
            ddoc_to_compact,
        ])
        fragmentation_monitor = self.cluster.async_monitor_view_fragmentation(
            self.master, ddoc_to_compact.name, fragmentation_value,
            self.default_bucket_name)
        end_time = time.time() + self.wait_timeout * 30
        while fragmentation_monitor.state != "FINISHED" and end_time > time.time(
        ):
            self.helper.insert_docs(self.num_items, 'spatial-doc')

        if end_time < time.time(
        ) and fragmentation_monitor.state != "FINISHED":
            self.fail("impossible to reach compaction value after %s sec" %
                      (self.wait_timeout * 20))
        fragmentation_monitor.result()
        compaction_task = self.cluster.async_compact_view(
            self.master, ddoc_to_compact.name, self.default_bucket_name)
        self.perform_ddoc_ops(ddocs)
        result = compaction_task.result(self.wait_timeout * 10)
        self.assertTrue(
            result, "Compaction didn't finished correctly. Please check diags")
Ejemplo n.º 4
0
 def test_add_spatial_views_threads(self):
     same_names = self.input.param('same-name', False)
     num_views_per_ddoc = 10
     create_threads = []
     ddocs = []
     for i in range(num_views_per_ddoc):
         ddoc = DesignDocument(self.default_ddoc_name + str(i), [],
                               spatial_views=[
                                   View(self.default_view_name +
                                        (str(i), "")[same_names],
                                        self.default_map,
                                        dev_view=self.use_dev_views,
                                        is_spatial=True)
                               ])
         ddocs.append(ddoc)
     if self.ddoc_op == 'update' or self.ddoc_op == 'delete':
         self.create_ddocs(ddocs)
     i = 0
     for ddoc in ddocs:
         create_thread = Thread(target=self.perform_ddoc_ops,
                                name="ops_thread" + str(i),
                                args=([
                                    ddoc,
                                ], ))
         i += 1
         create_threads.append(create_thread)
         create_thread.start()
     for create_thread in create_threads:
         create_thread.join()
     if self.thread_crashed.is_set():
         self.fail("Error occured during run")
Ejemplo n.º 5
0
 def test_add_views_to_1_ddoc(self):
     same_names = self.input.param('same-name', False)
     error = self.input.param('error', None)
     num_views_per_ddoc = 10
     create_threads = []
     try:
         for i in range(num_views_per_ddoc):
             ddoc = DesignDocument(self.default_ddoc_name, [],
                                   spatial_views=[
                                       View(self.default_view_name +
                                            (str(i), "")[same_names],
                                            self.default_map,
                                            dev_view=self.use_dev_views,
                                            is_spatial=True)
                                   ])
             create_thread = Thread(target=self.create_ddocs,
                                    name="create_thread" + str(i),
                                    args=([
                                        ddoc,
                                    ], ))
             create_threads.append(create_thread)
             create_thread.start()
         for create_thread in create_threads:
             create_thread.join()
     except Exception as ex:
         if error and str(ex).find(error) != -1:
             self.log.info("Error caught as expected %s" % error)
             return
         else:
             self.fail("Unexpected error appeared during run %s" % ex)
     if error:
         self.fail("Expected error '%s' didn't appear" % error)
Ejemplo n.º 6
0
    def _verify_ddoc_ops_all_buckets(self):
        """
        Verify number of Design Docs/Views on all buckets
        comparing with the internal dictionary of the create/update/delete ops
        :return:
        """
        self.log.info("DDoc Validation Started")
        rest = RestConnection(self.cluster.master)
        #Iterate over all the DDocs/Views stored in the internal dictionary
        for bucket, self.ddoc_view_map in self.bucket_ddoc_map.items():
            for ddoc_name, view_list in self.ddoc_view_map.items():
                try:
                    #fetch the DDoc information from the database
                    ddoc_json, header = rest.get_ddoc(bucket, ddoc_name)
                    self.log.info('Database Document {0} details : {1}'.format(
                        ddoc_name, json.dumps(ddoc_json)))
                    ddoc = DesignDocument._init_from_json(ddoc_name, ddoc_json)
                    for view in view_list:
                        if view.name not in [v.name for v in ddoc.views]:
                            self.fail(
                                "Validation Error: View - {0} in Design Doc - {1} and Bucket - {2} is missing from database"
                                .format(view.name, ddoc_name, bucket))

                except ReadDocumentException:
                    self.fail(
                        "Validation Error: Design Document - {0} is missing from Bucket - {1}"
                        .format(ddoc_name, bucket))

        self.log.info("DDoc Validation Successful")
Ejemplo n.º 7
0
 def test_add_spatial_views_case_sensative(self):
     ddoc = DesignDocument(self.default_ddoc_name, [], spatial_views=[
                               View(self.default_view_name, self.default_map,
                                    dev_view=self.use_dev_views, is_spatial=True),
                               View(self.default_view_name.upper(), self.default_map,
                                    dev_view=self.use_dev_views, is_spatial=True)])
     self.create_ddocs([ddoc])
Ejemplo n.º 8
0
 def make_ddocs(self, ddocs_num, views_per_ddoc):
     ddoc_name = "compaction_ddoc"
     view_name = "compaction_view"
     for i in xrange(ddocs_num):
         views = self.make_default_views(view_name,
                                         views_per_ddoc,
                                         different_map=True)
         self.ddocs.append(DesignDocument(ddoc_name + str(i), views))
Ejemplo n.º 9
0
 def make_ddocs(self, ddocs_num, views_per_ddoc, non_spatial_views_per_ddoc):
     ddocs = []
     for i in xrange(ddocs_num):
         views = []
         for k in xrange(views_per_ddoc):
             views.append(View(self.default_view_name + str(k), self.default_map,
                               dev_view=self.use_dev_views, is_spatial=True))
         non_spatial_views = []
         if non_spatial_views_per_ddoc:
             for k in xrange(non_spatial_views_per_ddoc):
                 non_spatial_views.append(View(self.default_view_name + str(k), 'function (doc) { emit(null, doc);}',
                                   dev_view=self.use_dev_views))
         ddocs.append(DesignDocument(self.default_ddoc_name + str(i), non_spatial_views, spatial_views=views))
     return ddocs
Ejemplo n.º 10
0
 def create_ddocs_and_views(self):
     self.default_view = View(self.default_view_name, None, None)
     for bucket in self.buckets:
         for i in xrange(int(self.ddocs_num)):
             views = self.make_default_views(self.default_view_name,
                                             self.view_num,
                                             self.is_dev_ddoc,
                                             different_map=True)
             ddoc = DesignDocument(self.default_view_name + str(i), views)
             self.ddocs.append(ddoc)
             for view in views:
                 self.cluster.create_view(self.master,
                                          ddoc.name,
                                          view,
                                          bucket=bucket)
Ejemplo n.º 11
0
 def _create_views(self, ddocs_num, buckets, views_num, server):
     ddocs = []
     if ddocs_num:
         self.default_view = View(self.default_view_name, None, None)
         for bucket in buckets:
             for i in xrange(ddocs_num):
                 views = self.make_default_views(self.default_view_name, views_num,
                                                 self.is_dev_ddoc, different_map=True)
                 ddoc = DesignDocument(self.default_view_name + str(i), views)
                 bucket_server = self._get_bucket(bucket, server)
                 tasks = self.async_create_views(server, ddoc.name, views, bucket=bucket_server)
                 for task in tasks:
                     task.result(timeout=90)
                 ddocs.append(ddoc)
     return ddocs
Ejemplo n.º 12
0
    def create_user_test_ddoc_check(self):
        rest = RestConnection(self.master)
        ddoc = DesignDocument("ddoc_ro_0", [
            View("ro_view",
                 "function (doc) {\n  emit(doc._id, doc);\n}",
                 dev_view=False)
        ])
        rest.create_design_document(self.buckets[0], ddoc)

        rest.create_ro_user(username=self.username, password=self.password)
        self.master.rest_username = self.username
        self.master.rest_password = self.password
        rest = RestConnection(self.master)

        self.log.info("Try to delete ddoc")
        try:
            rest.delete_view(self.buckets[0], ddoc.views[0])
        except Exception as ex:
            self.log.info("Unable to delete ddoc. Expected")
        else:
            self.fail("Able to delete ddoc")