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), 2)
        environment1_id = environments_ids[0]
        environment2_id = environments_ids[1]

        # MakePersistent in location1        
        web_site.make_persistent(backend_id=environment1_id)
        web_site.new_replica(backend_id=environment2_id, recursive=True)

        object_id = web_site.get_object_id()
        all_locations_ids = web_site.get_all_locations().keys()

        self.assertTrue(web_site.is_persistent())
        self.assertIsNotNone(object_id)
        
        # All_locations contains environment1_id and environment2_id
        self.assertIn(environment1_id, all_locations_ids)
        self.assertIn(environment2_id, all_locations_ids)
        self.assertEqual(len(all_locations_ids), 2)
        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_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()
        backends_ids = web_site.get_all_locations()

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

        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")

        # 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 #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. 
        """
        # 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 #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, 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!")
    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. 
        """

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

        host = "bsc.es"
        web_site = WebSite(host)
        web_page = WebPage(host + "/page.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)
        web_site.make_persistent(backend_id=environment1_id)
        web_site.new_replica(backend_id=environment2_id)
        ws_locations = web_site.get_all_locations()
        self.assertEqual(len(ws_locations), 2)

        # Clone the web_site
        web_site_copy = web_site.dc_clone()
        self.assertEqual(len(web_site_copy.pages), len(web_site.pages))
        nondefaultvalue = "notfoo"
        web_site_copy.replyme = nondefaultvalue

        # Add a web page to cloned web_site
        web_page2 = WebPage(host + "/page2.html")
        web_site_copy.add_web_page(web_page2)

        # Update original web_site
        web_site.dc_update(web_site_copy)
        self.assertFalse(web_site_copy.is_persistent())

        # Check updates
        self.assertEqual(len(web_site_copy.pages), len(web_site.pages))
        wrong = False
        from dataclay.DataClayObjProperties import DCLAY_GETTER_PREFIX
        for ws_location in ws_locations:
            value = web_site.run_remote(ws_location,
                                        DCLAY_GETTER_PREFIX + "replyme", None)
            if value != nondefaultvalue:
                wrong = True

        self.assertFalse(wrong)

        logger.debug("Test OK!")