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 Person self.session_initialized = True """ Test. From now on, the Functional Test itself. """ alias = "" # Test make_persistent object1 = Person(name='Nikola', age=86) worked = False try: object1.make_persistent(alias) except: worked = True finally: self.assertTrue(worked) 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 Person from dataclay import getRuntime from dataclay.commonruntime.Settings import settings self.session_initialized = True """ Test. From now on, the Functional Test itself. """ lm_client = getRuntime().ready_clients["@LM"] alias = "test_alias" # Test make_persistent person = Person(name='Nikola', age=86) person.make_persistent(alias) # Verify object_iD is not null object_id = person.get_object_id() self.assertTrue(object_id != None) # check you can get person by alias without exception Person.get_by_alias(alias=alias) # Verify that object is in DB/Cache/Metadata # TODO: Missing the check on DB metadata = lm_client.get_metadata_by_oid(settings.current_session_id, object_id) alias_cache = getRuntime().alias_cache self.assertIn(alias, metadata.aliases) self.assertIn(alias, alias_cache) # Test delete_alias Person.delete_alias(alias) self.assertRaises(Exception, Person.get_by_alias, alias=alias) # Verify that object is not in DB/Cache/Metadata metadata = lm_client.get_metadata_by_oid(settings.current_session_id, object_id) alias_cache = getRuntime().alias_cache self.assertNotIn(alias, metadata.aliases) self.assertNotIn(alias, alias_cache) 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 Person from dataclay.commonruntime.Runtime import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ p = Person('foo', 100) execution_environments = list(getRuntime().get_execution_environments_info().keys()) self.assertTrue(len(execution_environments) > 1) p.make_persistent(backend_id=execution_environments[0]) p.new_replica(backend_id=execution_environments[1]) self.assertEqual(p.run_remote(execution_environments[0], 'getMyMasterLocation', None), execution_environments[0]) self.assertEqual(p.run_remote(execution_environments[1], 'getMyMasterLocation', None), execution_environments[0]) 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 from dataclay import getRuntime 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 Person self.session_initialized = True """ Test. From now on, the Functional Test itself. """ p = Person() p.make_persistent() # IndexError when we try to access to an invalid index try: p.raise_exception() except IndexError: print("Expected built-in Exception IndexError") self.assertTrue(True) except: print("Unexpected Exception") self.assertTrue(False) 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 Person self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Test makePersistent person = Person(name='Nikola', age=86) person.make_persistent(alias="Tesla") self.assertTrue(person.is_persistent()) # Test NewVersion version_info, unloaded_version_info = person.new_version( list(person.get_all_locations().keys())[0]) logger.debug("Version info are:\n%s", version_info) versionOID = version_info.versionOID person_version = Person.get_object_by_id(versionOID) logger.debug("New version of person is:\n%s", person_version) # NewVersion name and age are the same of the original self.assertEqual(person.name, person_version.name) self.assertEqual(person.age, person_version.age) # NewVersion ID is different self.assertNotEqual(person.get_object_id(), person_version.get_object_id()) 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 Person self.session_initialized = True """ Test. From now on, the Functional Test itself. """ alias = "my_object" # Test make_persistent person = Person(name='Nikola', age=86) person.make_persistent(alias) # Verify object_iD is not null object_id = person.get_object_id() self.assertTrue(object_id != None) # Get new_person with alias new_person = Person.get_by_alias(alias) # Verify result self.assertTrue(object_id == new_person.get_object_id()) # Test delete_alias Person.delete_alias(alias) self.assertRaises(Exception, person.get_by_alias, alias=alias) 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 Person self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Test makePersistent person = Person(name='Nikola', age=86) person.make_persistent(alias="Tesla") self.assertTrue(person.is_persistent()) # Create newVersion and change name and age of it for k, v in person.get_all_locations().items(): version_info, unloaded_version_info = person.new_version(k) versionOID = version_info.versionOID person_version = Person.get_object_by_id(versionOID) person_version.name = "Thomas" person_version.age = 84 # Test ConsolidateVersion person.consolidate_version(unloaded_version_info) # Check that fields are consolidated self.assertEqual(person.name, "Thomas") self.assertEqual(person.age, 84) self.assertEqual(Person.get_by_alias("Tesla").name, "Thomas") self.assertEqual(Person.get_by_alias("Tesla").age, 84) logger.debug("After Consolidate, new name: %s and new age: %s", person.name, person.age) 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 Person from dataclay.DataClayObjProperties import DCLAY_GETTER_PREFIX from dataclay.commonruntime.Runtime import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ p = Person('foo', 100) execution_environments = list( getRuntime().get_execution_environments_info().keys()) self.assertTrue(len(execution_environments) > 1) p.make_persistent(backend_id=execution_environments[0]) p.new_replica(backend_id=execution_environments[1]) # Name is a replicated attribute so the after method should be called after the setter p.name = 'aaa' # Assert that the attribute 'name' was properly changed in both dataservices self.assertEqual( p.run_remote(execution_environments[0], DCLAY_GETTER_PREFIX + 'name', None), 'aaa') self.assertEqual( p.run_remote(execution_environments[1], DCLAY_GETTER_PREFIX + 'name', None), 'aaa') # Assert that the attribute 'years' was changed only in one dataservice p.years = 1000 years0 = p.run_remote(execution_environments[0], DCLAY_GETTER_PREFIX + 'years', None) years1 = p.run_remote(execution_environments[1], DCLAY_GETTER_PREFIX + 'years', None) self.assertEqual(abs(years0 - years1), 900) logger.debug("Test OK!")