Beispiel #1
0
    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!")
Beispiel #2
0
    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!")
Beispiel #3
0
    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. 
        """

        host = "bsc.es"
        web_site = WebSite(host)
        web_page = WebPage(host + "/page.html")
        web_page2 = WebPage(host + "/page2.html")

        # Verify object_iD is not null
        object_id = web_site.get_object_id()

        self.assertTrue(object_id != None)

        web_site.add_web_page(web_page)

        self.assertEqual(len(web_site.pages), 1)
        # Test make_persistent

        web_site.make_persistent(recursive=False)

        self.assertTrue(web_site.is_persistent())

        # TODO: Test better this
        # Add another page after persistence but web_site.uri.host is not persistent
        # (See add_we_page method in model/classes.py)
        self.assertRaises(Exception, web_site.add_web_page, web_page2)

        logger.debug("Test OK!")
Beispiel #4
0
    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_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())

        object_id = web_site.get_object_id()
        backend_id = web_site.get_location()

        # Assert that backend_id of volatile object is the hint
        self.assertIsNotNone(object_id)
        self.assertEqual(backend_id, web_site.get_hint())

        logger.debug("Test OK!")
Beispiel #5
0
    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
        from dataclay import getRuntime
        self.session_initialized = True
        """
        Test. From now on, the Functional Test itself. 
        """

        execs_info = getRuntime().get_execution_environments_info()

        exec_env_info_1 = execs_info[list(execs_info.keys())[0]]
        exec_env_info_2 = execs_info[list(execs_info.keys())[1]]

        host = "bsc.es"
        web_site = WebSite(host)
        web_site.make_persistent(alias=web_site.uri.host,
                                 backend_id=exec_env_info_1.dataClayID)

        web_page = WebPage(host + "/page.html")
        web_page.make_persistent(backend_id=exec_env_info_2.dataClayID)

        web_site.add_web_page(web_page)

        self.assertTrue(web_site.is_persistent())
        self.assertTrue(web_site.uri.is_persistent())
        self.assertTrue(web_page.is_persistent())  # volatile is persistent
        self.assertTrue(web_page.uri.is_persistent())  # volatile is persistent

        logger.debug("Test OK!")
Beispiel #6
0
    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. 
        """

        host = "bsc.es"
        web_site = WebSite(host)
        web_page = WebPage(host + "/page.html")

        # Add web_page to web_site and make it persistent
        web_site.add_web_page(web_page)
        self.assertIs(web_page, web_site.pages[0])
        web_site.make_persistent()

        self.assertTrue(web_site.is_persistent())
        self.assertEqual(len(web_site.get_all_locations()), 1)
        self.assertTrue(web_site.uri.is_persistent())
        self.assertEqual(len(web_site.uri.get_all_locations()), 1)

        # NewVersion for WebSite
        version_info, unloaded_version_info = web_site.new_version(
            list(web_site.get_all_locations().keys())[0])
        logger.debug(version_info)
        versionOID = version_info.versionOID
        web_site_version = WebSite.get_object_by_id(versionOID)

        self.assertNotEqual(web_site.get_object_id(),
                            web_site_version.get_object_id())
        self.assertTrue(web_site_version.is_persistent())
        self.assertEqual(len(web_site_version.get_all_locations()), 1)
        self.assertTrue(web_site_version.uri.is_persistent())
        self.assertEqual(len(web_site_version.uri.get_all_locations()), 1)

        web_page_version = web_site_version.pages[0]

        self.assertEqual(len(web_site_version.pages), 1)
        self.assertNotEqual(web_page.get_object_id(),
                            web_page_version.get_object_id())
        self.assertNotEqual(web_page, web_page_version)

        # Remove WebPage to version pages and consolidate
        web_site_version.remove_last_web_page()
        self.assertEqual(len(web_site_version.pages), 0)
        self.assertEqual(len(web_site.pages), 1)

        web_site.consolidate_version(unloaded_version_info)

        self.assertEqual(len(web_site.pages), 0)

        logger.debug("Test OK!")
Beispiel #7
0
    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. 
        """
        # Test recursive makePersistent without circular dependencies
        host = "bsc.es"
        web_site = WebSite(host)
        web_page = WebPage(host + "/page.html")

        web_site.add_web_page(web_page)

        environments_ids = list(
            getRuntime().get_execution_environments_info().keys())
        environment1_id = environments_ids[0]
        environment2_id = environments_ids[1]
        environment3_id = environments_ids[2]

        self.assertEqual(len(environments_ids), 3)

        web_site.make_persistent(alias=web_site.uri.host,
                                 backend_id=environment1_id)

        ws_locations = web_site.get_all_locations()
        ws_uri_locations = web_site.uri.get_all_locations()
        wp_locations = web_page.get_all_locations()
        wp_uri_locations = web_page.uri.get_all_locations()

        # Check Persistence
        self.assertTrue(web_site.is_persistent())
        self.assertEqual(len(ws_locations), 1)
        self.assertIn(environment1_id, ws_locations)

        self.assertTrue(web_site.uri.is_persistent())
        self.assertEqual(len(ws_uri_locations), 1)
        self.assertIn(environment1_id, ws_uri_locations)

        self.assertTrue(web_page.is_persistent())
        self.assertEqual(len(wp_locations), 1)
        self.assertIn(environment1_id, wp_locations)

        self.assertTrue(web_page.uri.is_persistent())
        self.assertEqual(len(wp_uri_locations), 1)
        self.assertIn(environment1_id, wp_uri_locations)

        # Move in the second location
        getRuntime().move_object(web_site, environment1_id, environment2_id,
                                 True)

        ws_locations = web_site.get_all_locations()
        ws_uri_locations = web_site.uri.get_all_locations()
        wp_locations = web_page.get_all_locations()
        wp_uri_locations = web_page.uri.get_all_locations()

        # Check that the object and associated ones are now in the second location
        self.assertEqual(len(ws_locations), 1)
        self.assertIn(environment2_id, ws_locations)

        self.assertEqual(len(ws_uri_locations), 1)
        self.assertIn(environment2_id, ws_uri_locations)

        self.assertEqual(len(wp_locations), 1)
        self.assertIn(environment2_id, wp_locations)

        self.assertEqual(len(wp_uri_locations), 1)
        self.assertIn(environment2_id, wp_uri_locations)

        # Move in the third location
        getRuntime().move_object(web_site, environment2_id, environment3_id,
                                 True)

        ws_locations = web_site.get_all_locations()
        ws_uri_locations = web_site.uri.get_all_locations()
        wp_locations = web_page.get_all_locations()
        wp_uri_locations = web_page.uri.get_all_locations()

        # Check that the object and associated ones are now in the third location
        self.assertEqual(len(ws_locations), 1)
        self.assertIn(environment3_id, ws_locations)

        self.assertEqual(len(ws_uri_locations), 1)
        self.assertIn(environment3_id, ws_uri_locations)

        self.assertEqual(len(wp_locations), 1)
        self.assertIn(environment3_id, wp_locations)

        self.assertEqual(len(wp_uri_locations), 1)
        self.assertIn(environment3_id, wp_uri_locations)
        logger.debug("Test OK!")
Beispiel #8
0
    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. 
        """

        host = "bsc.es"
        web_site = WebSite(host)
        web_page = WebPage(host + "/page.html")

        # Add web_page to web_site and make it persistent
        web_site.add_web_page(web_page)
        self.assertIs(web_page, web_site.pages[0])
        web_site.make_persistent()

        self.assertTrue(web_site.is_persistent())
        self.assertEqual(len(web_site.get_all_locations()), 1)
        self.assertTrue(web_site.uri.is_persistent())
        self.assertEqual(len(web_site.uri.get_all_locations()), 1)

        # Create new version for WebSite
        version_info, unloaded_version_info = web_site.new_version(
            list(web_site.get_all_locations().keys())[0])
        logger.debug(version_info)
        versionOID = version_info.versionOID
        web_site_version = WebSite.get_object_by_id(versionOID)

        self.assertNotEqual(web_site.get_object_id(),
                            web_site_version.get_object_id())
        self.assertTrue(web_site_version.is_persistent())
        self.assertEqual(len(web_site_version.get_all_locations()), 1)
        self.assertTrue(web_site_version.uri.is_persistent())
        self.assertEqual(len(web_site_version.uri.get_all_locations()), 1)

        web_page_version = web_site_version.pages[0]

        self.assertEqual(len(web_site_version.pages), 1)
        self.assertNotEqual(web_page.get_object_id(),
                            web_page_version.get_object_id())
        self.assertNotEqual(web_page, web_page_version)

        # Modifying uri and num of WebSite version's page and consolidate
        new_host = "bsc.cat"
        new_uri = URI(new_host + "/page.html")
        # FIXME: New URI is consolidated just if is maked Persistent before
        # FIXME: If I change the uri with modify_uri_str (passing a string) object is not consolidated (Object not registered)
        new_uri.make_persistent()
        web_page_version.modify_uri(new_uri)
        web_page_version.modify_num(2)

        self.assertNotEqual(web_site.pages[0].uri.host,
                            web_site_version.pages[0].uri.host)
        self.assertEqual(web_site.pages[0].uri.path,
                         web_site_version.pages[0].uri.path)
        self.assertEqual(web_site.pages[0].uri.host, host)
        self.assertIsNone(web_site.pages[0].num)

        self.assertTrue(web_page_version.uri.is_persistent())

        web_site.consolidate_version(unloaded_version_info)

        self.assertEqual(web_site.pages[0].uri.host, new_host)
        self.assertEqual(web_site.pages[0].num, 2)

        logger.debug("Test OK!")
Beispiel #9
0
    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. 
        """

        host = "bsc.es"
        host2 = "bsc.en"
        web_site = WebSite(host)
        web_page = WebPage(host + "/main.html")
        web_page2 = WebPage(host2 + "/who.html")
        uri1 = URI(host2 + "/where.html")
        uri2 = URI(host + "/why.html")

        # Verify object_iD is not null

        object_id = web_site.get_object_id()
        self.assertIsNotNone(object_id)

        # Execute method locally

        web_site.add_web_page(web_page)
        self.assertTrue(len(web_site.pages) > 0)

        # Execute setter and getter locally

        web_site.uri = uri1
        self.assertEqual(web_site.uri.host, host2)

        # Test make_persistent

        web_site.make_persistent()
        self.assertTrue(web_site.is_persistent())

        # Execute method remotely

        web_site.add_web_page(web_page2)
        self.assertEqual(len(web_site.pages), 2)

        # Execute setter and getter locally

        web_site.uri = uri2

        # Get of get on volatiles cause exception

        self.assertEqual(web_site.uri.host, host)

        logger.debug("Test OK!")
Beispiel #10
0
    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. 
        """

        host = "bsc.es"
        web_site = WebSite(host)
        web_page = WebPage(host + "/page.html")
        web_page2 = WebPage(host + "/page2.html")
        web_page3 = WebPage(host + "/page3.html")
        web_page4 = WebPage(host + "/page4.html")

        # Verify object_iD is not null
        object_id = web_site.get_object_id()

        self.assertTrue(object_id != None)

        web_site.add_web_page(web_page)

        # Test make_persistent

        web_site.make_persistent("BSCwebsite")

        # Not added (yet!) to the web_site
        web_page3.make_persistent("page3")
        web_page4.make_persistent("page4")
        
        self.assertTrue(web_site.is_persistent())

        # Add another page after persistence 
        web_site.add_web_page(web_page2)
        self.assertEqual(len(web_site.pages), 2)

        web_site_bis = WebSite.get_by_alias("BSCwebsite")
        self.assertEqual(len(web_site_bis.pages), 2)

        web_site_bis.add_web_page(WebPage.get_by_alias("page3"))
        web_site_bis.add_web_page(WebPage.get_by_alias("page4"))

        self.assertEqual(len(web_site.pages), 4)
        self.assertEqual(len(web_site_bis.pages), 4)

        # Test recursive make_persistent
        for page in web_site.pages:
            self.assertTrue(page.is_persistent())
            self.assertTrue(page.uri.is_persistent())

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

        logger.debug("Test OK!")