Ejemplo n.º 1
0
    def testArchive(self):
        """
        Test that archiving views works
        """
        dummy_view = {'_id':'_design/foo', 'language': 'javascript','views':{
                        'bar':{'map':"function(doc) {if (doc.foo) {emit(doc.int, 1);}}", 'reduce':'_sum'}
                        }
                    }
        archive_view = {'_id':'_design/foo', 'language': 'javascript','views':{
                        'bar':{'map':"function(doc) {emit(doc.key, doc.value);}", 'reduce':'_sum'}
                        }
                    }

        seed_db = self.server.connectDatabase(self.seedname)
        seed_db.commit(dummy_view)
        # Need to have the timing long enough so the data isn't archived by accident
        self.timing = {'archive':timedelta(seconds=1000), 'expire':timedelta(seconds=2000)}
        self.db = RotatingDatabase(dbname = self.dbname, url = self.couchURL, views=['foo/bar'],
                                archivename = self.arcname, timing = self.timing)
        self.db.archive_db.commitOne(archive_view)
        runs = 5
        docs = 5
        for run in range(runs):
            for i in range(docs):
                self.db.queue({'foo':'bar', 'int': i, 'run': run})
            self.db.commit()
            self.db._rotate()
        self.db._archive()
        view_result = self.db.archive_db.loadView('foo','bar')
        arch_sum = view_result['rows'][0]['value']
        self.assertEqual(arch_sum, runs * docs)
Ejemplo n.º 2
0
    def setUp(self):
        self.couchURL = os.getenv("COUCHURL")
        self.server = CouchServer(self.couchURL)
        # Kill off any databases left over from previous runs
        for db in [
                db for db in self.server.listDatabases()
                if db.startswith('rotdb_unittest_')
        ]:
            try:
                self.server.deleteDatabase(db)
            except:
                pass
        # Create a database, drop an existing one first
        testname = self.id().split('.')[-1].lower()
        self.dbname = 'rotdb_unittest_%s' % testname
        self.arcname = 'rotdb_unittest_%s_archive' % testname
        self.seedname = 'rotdb_unittest_%s_seedcfg' % testname
        # set a long value for times, tests do operations explicitly
        self.timing = {
            'archive': timedelta(seconds=1),
            'expire': timedelta(seconds=2)
        }

        self.db = RotatingDatabase(dbname=self.dbname,
                                   url=self.couchURL,
                                   archivename=self.arcname,
                                   timing=self.timing)
Ejemplo n.º 3
0
 def testCycle(self):
     """
     Test that committing data to different databases happens
     This is a bit of a dodgy test - if timings go funny it will fail
     """
     self.timing = {'archive':timedelta(seconds=0.5), 'expire':timedelta(seconds=1)}
     self.db = RotatingDatabase(dbname = self.dbname, url = self.couchURL,
                                archivename = self.arcname, timing = self.timing)
     my_name = self.db.name
     self.db.commit({'foo':'bar'})
     sleep(5)
     self.db.commit({'foo':'bar'})
     # the initial db should have expired by now
     self.db.commit({'foo':'bar'})
     self.assertFalse(my_name in self.server.listDatabases(), "")