Exemple #1
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)
    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)
 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(), "")
    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)
 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(), "")
    def setUp(self):
        self.server = CouchServer(os.getenv("COUCHURL", 'http://*****:*****@localhost:5984'))
        # 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,
                                archivename = self.arcname, timing = self.timing)
Exemple #7
0
class RotatingDatabaseTest(unittest.TestCase):
    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)

    def tearDown(self):
        testname = self.id().split('.')[-1].lower()
        if sys.exc_info()[0] == None:
            # This test has passed, clean up after it
            to_go = [
                db for db in self.server.listDatabases()
                if db.startswith('rotdb_unittest_%s' % testname)
            ]
            for dbname in to_go:
                try:
                    self.server.deleteDatabase(dbname)
                except CouchNotFoundError:
                    # db has already gone
                    pass

    def testRotate(self):
        """
        Test that rotation works
        """
        start_name = self.db.name
        self.db._rotate()
        end_name = self.db.name
        databases = [
            db for db in self.server.listDatabases()
            if db.startswith('rotdb_unittest_')
        ]
        self.assertTrue(start_name in databases)
        self.assertTrue(end_name in databases)

    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)

    def testExpire(self):
        """
        Test that expiring databases works
        """
        # rotate out the original db
        self.db._rotate()
        archived = self.db.archived_dbs()
        self.assertEqual(1, len(archived),
                         'test not starting from clean state, bail!')
        # Make sure the db has expired
        sleep(2)
        self.db._expire()
        self.assertEqual(0, len(self.db.archived_dbs()))
        self.assertFalse(archived[0] in self.server.listDatabases())

    @attr("integration")
    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(), "")
class RotatingDatabaseTest(unittest.TestCase):
    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)

    def tearDown(self):
        testname = self.id().split('.')[-1].lower()
        if sys.exc_info()[0] == None:
            # This test has passed, clean up after it
            to_go = [db for db in self.server.listDatabases() if db.startswith('rotdb_unittest_%s' % testname)]
            for dbname in to_go:
                try:
                    self.server.deleteDatabase(dbname)
                except CouchNotFoundError:
                    # db has already gone
                    pass

    def testRotate(self):
        """
        Test that rotation works
        """
        start_name = self.db.name
        self.db._rotate()
        end_name = self.db.name
        databases = [db for db in self.server.listDatabases() if db.startswith('rotdb_unittest_')]
        self.assertTrue(start_name in databases)
        self.assertTrue(end_name in databases)

    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)

    def testExpire(self):
        """
        Test that expiring databases works
        """
        # rotate out the original db
        self.db._rotate()
        archived = self.db.archived_dbs()
        self.assertEqual(1, len(archived), 'test not starting from clean state, bail!')
        # Make sure the db has expired
        sleep(2)
        self.db._expire()
        self.assertEqual(0, len(self.db.archived_dbs()))
        self.assertFalse(archived[0] in self.server.listDatabases())

    @attr("integration")
    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(), "")