Esempio n. 1
0
class WordCountTestCase(unittest.TestCase):
    """
    DataClayMock object for simulation. 
    """
    mock = None
    """ 
    Number of nodes in this test
    """
    num_nodes = 1

    def setUp(self):
        """
        PyUnit function called before every test case.
        Starts DataClay simulation in one Python interpreter and one Java VM. This allows us to Debug in a local machine without 
        dockers and without a full start of DataClay (jars, configurations, ...) 
        """
        try:
            self.session_initialized = False
            self.mock = MockDataClay(self.num_nodes)
            self.mock.startSimulation(__file__)
            self.mock.newAccount("bsc", "password")
            self.mock.newDataContract("bsc", "password", "dstest", "bsc")
            self.mock.newNamespace("bsc", "password", "model", "python")

            class_path = os.path.dirname(os.path.abspath(__file__)) + "/model"
            stubs_path = os.path.dirname(os.path.abspath(__file__)) + "/stubs"

            contractid = self.mock.newModel("bsc", "password", "model",
                                            class_path)
            self.mock.getStubs("bsc", "password", contractid, stubs_path)

            dataclay_client_config = os.environ["DATACLAYCLIENTCONFIG"]
            self.mock.prepareSessionFiles("bsc", "password", stubs_path,
                                          "dstest", "dstest",
                                          dataclay_client_config, "DS1")
        except:
            traceback.print_exc()

    def tearDown(self):
        """ 
        Finish all services started for simulation. 
        """
        self.mock.finishSimulation()

    @unittest.skip("skipping wordcount compss test")
    def testWordCountWithCompss(self):
        """
        We execute test using COMPSs. COMPSs is going to run wordcount_compss_main.py directly. 
        """
        compss_main = os.path.dirname(
            os.path.abspath(__file__)) + "/compss/wordcount_compss_main.py"
        self.mock.runScriptUsingPyCOMPSs(compss_main)

        logger.debug("Test OK!")
Esempio n. 2
0
class SimpleMock(object):
    """
    DataClayMock object for simulation. 
    """
    mock = None
    """ 
    Number of nodes in this test
    """
    num_nodes = 0

    def setUp(self, test_file_path, nodes=1, ees_per_sl=1):

        from mock.mockdataclay import MockDataClay
        """
        PyUnit function called before every test case.
        Starts DataClay simulation in one Python interpreter and one Java VM. This allows us to Debug in a local machine without 
        dockers and without a full start of DataClay (jars, configurations, ...) 
        """
        self.num_nodes = nodes
        try:
            self.mock = MockDataClay(self.num_nodes, ees_per_sl=ees_per_sl)
            self.mock.startSimulation(test_file_path)
            self.mock.newAccount("bsc", "password")
            self.mock.newDataContract("bsc", "password", "dstest", "bsc")
            self.mock.newNamespace("bsc", "password", "model", "python")

            class_path = os.path.dirname(
                os.path.abspath(test_file_path)) + "/model"
            stubs_path = os.path.dirname(
                os.path.abspath(test_file_path)) + "/stubs"

            contractid = self.mock.newModel("bsc", "password", "model",
                                            class_path)
            self.mock.getStubs("bsc", "password", contractid, stubs_path)
            dataclay_client_config = os.path.dirname(
                os.path.abspath(__file__)) + "/client.properties"
            self.mock.prepareSessionFiles("bsc", "password", stubs_path,
                                          "dstest", "dstest",
                                          dataclay_client_config, "DS1")
        except Exception:
            traceback.print_exc()
            assert False

    def tearDown(self):
        """ 
        Finish all services started for simulation. 
        """
        self.mock.finishSimulation()

    def importStubModule(self, name):
        return self.mock.importStubModule(name)
Esempio n. 3
0
class VolatilesTestCase(unittest.TestCase):
    """
    DataClayMock object for simulation. 
    """
    mock = None
    """
    Indicates session is initialized.
    """
    session_initialized = False
    """ 
    Number of nodes in this test
    """
    num_nodes = 2

    def setUp(self):
        """
        PyUnit function called before every test case.
        Starts DataClay simulation in one Python interpreter and one Java VM. This allows us to Debug in a local machine without 
        dockers and without a full start of DataClay (jars, configurations, ...) 
        """
        try:
            self.session_initialized = False
            self.mock = MockDataClay(self.num_nodes)
            self.mock.startSimulation(__file__)
            self.mock.newAccount("bsc", "password")
            self.mock.newDataContract("bsc", "password", "dstest", "bsc")
            self.mock.newNamespace("bsc", "password", "model", "python")

            class_path = os.path.dirname(os.path.abspath(__file__)) + "/model"
            stubs_path = os.path.dirname(os.path.abspath(__file__)) + "/stubs"

            contractid = self.mock.newModel("bsc", "password", "model",
                                            class_path)
            self.mock.getStubs("bsc", "password", contractid, stubs_path)

            dataclay_client_config = os.environ["DATACLAYCLIENTCONFIG"]
            self.mock.prepareSessionFiles("bsc", "password", stubs_path,
                                          "dstest", "dstest",
                                          dataclay_client_config, "DS1")
        except:
            traceback.print_exc()

    def tearDown(self):
        """ 
        Finish all services started for simulation. 
        """
        if self.session_initialized:
            from dataclay.api import finish
            finish()
        self.mock.finishSimulation()
        logger.debug("Finished tear down of test")

    @pytest.mark.timeout(300, method='thread')
    def test(self):
        """Test. note that all test method names must begin with 'test.'"""
        """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. 
        Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """

        from dataclay.api import init

        logger.debug('**Starting init**')
        init()
        """ 
        Imports. Imports must be located here in order to simulate "import" order in a real scenario. 
        VERY IMPORTANT: Imports must be located AFTER init
        """
        from model.classes import WebSite, WebPage, URI

        self.session_initialized = True
        """
        Test. From now on, the Functional Test itself. 
        """

        # Test recursive makePersistent without circular dependencies
        host = "bsc1.es"
        web_site = WebSite(host)
        web_site.make_persistent(alias=web_site.uri.host)

        uri = URI(host + "/volatilepage.html")  # Volatile
        web_site.uri = uri  # param of setter is volatile

        self.assertTrue(uri.is_persistent())
        self.assertTrue(web_site.is_persistent())
        self.assertTrue(web_site.uri.is_persistent())

        # Test recursive with one circular dependency

        host = "bsc2.es"
        web_page = WebPage(host + "/foo/bsc.html")
        web_page.make_persistent(alias=web_page.uri.host)

        host = "fsf.org"
        web_site = WebSite(host)
        web_site.add_web_page(
            web_page)  # added persistent object to a volatile

        web_page.add_link(web_site)  # send volatile

        self.assertTrue(web_site.is_persistent())
        self.assertTrue(web_site.uri.is_persistent())
        self.assertTrue(web_page.is_persistent())
        self.assertTrue(web_page.uri.is_persistent())

        logger.debug("Test OK!")
Esempio n. 4
0
class MultipleEEsTest(unittest.TestCase):

    """ Python mock dataclay """
    mock = None
    """ Mock dataclay Java instance."""
    java_mock_dataclay = None 
    """ Mock consumer."""
    consumer = None 
    """ Number of nodes."""
    num_nodes = 1
    """ Number of EEs per node. """
    num_ees_per_sl = 4

    def setUp(self):
        """
        PyUnit function called before every test case.
        Starts DataClay simulation in one Python interpreter and one Java VM. This allows us to Debug in a local machine without 
        dockers and without a full start of DataClay (jars, configurations, ...) 
        """ 
        try:
            self.session_initialized = False
            self.mock = MockDataClay(self.num_nodes, ees_per_sl=self.num_ees_per_sl) 
            self.mock.startSimulation(__file__)            
            self.mock.newAccount("bsc", "password")
            self.mock.newDataContract("bsc", "password", "dstest", "bsc")
            self.mock.newNamespace("bsc", "password", "model", "python")
            
            class_path = os.path.dirname(os.path.abspath(__file__)) + "/model"
            stubs_path = os.path.dirname(os.path.abspath(__file__)) + "/stubs"
    
            contractid = self.mock.newModel("bsc", "password", "model", class_path)
            self.mock.getStubs("bsc", "password", contractid, stubs_path)
            
            dataclay_client_config = os.environ["DATACLAYCLIENTCONFIG"]
            self.mock.prepareSessionFiles("bsc", "password", stubs_path, "dstest", "dstest", dataclay_client_config, "DS1")
        except:
            traceback.print_exc()

    def tearDown(self):
        """ 
        Finish all services started for simulation. 
        """ 
        if self.session_initialized:
            from dataclay.api import finish
            finish()
        self.mock.finishSimulation()
        logger.debug("Finished tear down of test")

    @pytest.mark.timeout(300, method='thread')
    def test(self):
        """Test. note that all test method names must begin with 'test.'"""
        """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. 
        Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """
        from dataclay.api import init

        logger.debug('**Starting init**')
        init()
        
        """ 
        Imports. Imports must be located here in order to simulate "import" order in a real scenario. 
        VERY IMPORTANT: Imports must be located AFTER init
        """
        from model.classes import WebSite, WebPage, URI
        from dataclay import getRuntime        
        self.session_initialized = True
    
        """
        Test. From now on, the Functional Test itself. 
        """

        host = "bsc.es"
        web_site = WebSite(host)

        environments_ids = list(getRuntime().get_execution_environments_info().keys())
        self.assertEqual(len(environments_ids), 4)
        
        environment1_id = environments_ids[0]

        # MakePersistent in location1        
        web_site.make_persistent(backend_id=environment1_id)
        object_id = web_site.get_object_id()
        backend_id = web_site.get_location()

        # Assert that backend_id of persistent object is environment1
        self.assertTrue(web_site.is_persistent())
        self.assertIsNotNone(object_id)
        self.assertEqual(backend_id, environment1_id)
        
        # Create replicas in all EEs
        web_site.new_replica(backend_id=environments_ids[1])
        web_site.new_replica(backend_id=environments_ids[2])
        web_site.new_replica(backend_id=environments_ids[3])
        
        logger.debug("Test OK!")