Exemplo n.º 1
0
    def test_MPEngine6(self):
        try:
            print "Starting test"
            mpe = MPEngineProdCons(6, WkrTestProd, WkrTestCons)

            task_list = [i for i in xrange(1, 10)]
            mpe.addTaskList(task_list)

            mpe.addConsumer()
            time.sleep(5)
            mpe.addProducer()

            while mpe.working():
                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                mpe.rebalance()

            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")
Exemplo n.º 2
0
    def test_MPEngine_end2end(self):
        try:
            print "Starting test"
            num_tasks = 5
            mpe = MPEngineProdCons(4, WkrTestProd, WkrTestCons)
            # Add tasks
            task_list = [i for i in xrange(1, num_tasks + 1)]
            mpe.addTaskList(task_list)

            mpe.addProducer()
            mpe.addConsumer()

            while mpe.working():
                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                mpe.rebalance()

            results = mpe.grabResults()
            self.assertEquals(len(results), num_tasks, "test_MPEngine_end2end")
            self.assertEquals(results[-1], num_tasks, "test_MPEngine_end2end")

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine_end2end")
Exemplo n.º 3
0
    def test_MPEngine_brute_both(self):
        try:
            print "Starting test"
            mpe = MPEngineProdCons(99, WkrTestProd, WkrTestCons)
            max_procs = 5
            # Add tasks
            task_list = [i for i in xrange(1, 5)]
            mpe.addTaskList(task_list)

            for i in xrange(0, max_procs):
                mpe.addProducer()
            for i in xrange(0, max_procs):
                mpe.removeProducer()
            for i in xrange(0, max_procs):
                mpe.addConsumer()
            for i in xrange(0, max_procs):
                mpe.removeConsumer()

            for i in xrange(0, max_procs):
                mpe.addProducer()
            for i in xrange(0, max_procs):
                mpe.addConsumer()
            for i in xrange(0, max_procs):
                mpe.removeProducer()
            for i in xrange(0, max_procs):
                mpe.removeConsumer()

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")
Exemplo n.º 4
0
    def test_MPEngine_ConsumerSimple(self):
        try:
            # Get temp db name for the test
            tempdb = tempfile.NamedTemporaryFile(suffix='.db',
                                                 prefix='testCase',
                                                 dir=tempfile.gettempdir())
            tempdb.close()
            dbfilenameFullPath = tempdb.name
            with appDB.DBClass(dbfilenameFullPath, settings.__version__) as DB:
                DB.appInitDB()

            print "Starting test"
            mpe = MPEngineProdCons(6, WkrTestProd, WkrTestConsDB)
            # Add tasks
            task_list = [i for i in xrange(1, 5)]
            mpe.addTaskList(task_list)

            mpe.addConsumer([dbfilenameFullPath])
            time.sleep(1)
            mpe.removeConsumer()

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")
Exemplo n.º 5
0
    def test_MPEngine_DatabaseLocked(self):
        try:
            logger.info("Starting test_MPEngine_end2end_BalanceSimulation")
            # Get temp db name for the test
            tempdb = tempfile.NamedTemporaryFile(suffix='.db',
                                                 prefix='testCase',
                                                 dir=tempfile.gettempdir())
            tempdb.close()
            dbfilenameFullPath = tempdb.name
            with appDB.DBClass(dbfilenameFullPath, settings.__version__) as DB:
                DB.appInitDB()

            num_tasks = 50
            mpe = MPEngineProdCons(4, WkrTestProdFast, WkrTestConsDB)
            # Add tasks
            task_list = [i for i in xrange(1, num_tasks + 1)]
            mpe.addTaskList(task_list)

            mpe.addConsumer([dbfilenameFullPath])
            mpe.addProducer()

            loop_test_num = num_tasks
            while mpe.working():
                (num_prod, num_cons, task1, task2, task3) = mpe.getProgress()
                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                if task3 >= 20 and task3 <= 30:
                    logger.info("Simulating rebalance (task3: %d task1/2: %d" %
                                (task3, task1 / 2))
                    mpe.restartConsumers()
                    mpe.restartProducers()
                loop_test_num -= 1

            results = mpe.grabResults()
            self.assertEquals(len(results), num_tasks, "test_MPEngine_end2end")
            self.assertEquals(results[-1], num_tasks, "test_MPEngine_end2end")

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine_end2end")
Exemplo n.º 6
0
    def test_MPEngine_regressionBug(self):
        try:
            print "Starting test"
            maxCores = 4

            mpe = MPEngineProdCons(maxCores, WkrTestProd, WkrTestCons)
            # Add tasks
            task_list = [i for i in xrange(1, 8)]
            mpe.addTaskList(task_list)

            mpe.startProducers(3)
            time.sleep(2)
            mpe.startConsumers(1)
            time.sleep(2)
            mpe.endProducers()
            mpe.endConsumers()
            time.sleep(2)
            mpe.addConsumer()
            mpe.addProducer()
            time.sleep(2)
            mpe.addProducer()
            time.sleep(2)
            logger.debug("restartConsumers")
            mpe.restartConsumers()
            logger.debug("restartProducers")
            mpe.restartProducers()
            time.sleep(2)

            while mpe.working():
                print("Prod: %d / Cons: %d | %s -> %s -> %s" %
                      mpe.getProgress())
                time.sleep(1)
                # mpe.rebalance()

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")
Exemplo n.º 7
0
    def test_MPEngine_brute_both_badmix_single(self):
        try:
            print "Starting test"
            mpe = MPEngineProdCons(99, WkrTestProd, WkrTestCons)
            max_procs = 10
            # Add tasks
            task_list = [i for i in xrange(1, 5)]
            mpe.addTaskList(task_list)

            mpe.addProducer()
            mpe.removeProducer()
            mpe.addConsumer()
            mpe.removeConsumer()
            mpe.addProducer()
            mpe.addConsumer()
            mpe.removeProducer()
            mpe.removeConsumer()
            mpe.addProducer()
            mpe.addConsumer()
            mpe.removeConsumer()
            mpe.removeProducer()

            if (mpe.check_mpEngineStatus()): print("++Status looks ok!")
            else: print("++Status looks wrong!")

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")
Exemplo n.º 8
0
    def test_MPEngine_brute_consumers(self):
        try:
            print "Starting test"
            mpe = MPEngineProdCons(99, WkrTestProd, WkrTestCons)
            # Add tasks
            task_list = [i for i in xrange(1, 5)]
            mpe.addTaskList(task_list)

            for i in xrange(0, 25):
                print("Adding consumer %d" % i)
                mpe.addConsumer()
            for i in xrange(0, 25):
                print("Removing consumer %d" % i)
                mpe.removeConsumer()

            del mpe
            print "Test ended"
        except Exception:
            traceback.print_exc(file=sys.stdout)
            self.fail("Exception triggered")

        # Pass
        self.assertEquals(1, 1, "test_MPEngine")