def client_process2(self, q): try: from dataclay.api import init, finish logger.info('**Starting init 2**') 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 Mapa, Node self.session_initialized = True """ Test. From now on, the Functional Test itself. """ m = Mapa.get_by_alias("mapa") logger.info("Map obtained ") mapa = m.mapa logger.info("** Getter of mapa done with num elements: %s" % str(len(mapa))) for nid, node in mapa.items(): logger.info("** Found node %s" % str(nid)) finish() q.put("OK") except: q.put("FAIL")
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 WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Init source host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") web_site.add_web_page(web_page) web_site.make_persistent() # Init target host2 = "bsc2.es" web_site2 = WebSite(host2) web_site2.make_persistent() web_site2.copy_pages(web_site) self.assertTrue(len(web_site2.pages) == len(web_site.pages)) 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, finish 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. """ uri = URI("host/bsc") try: uri.make_persistent() except: traceback.print_exc() from dataclay import getRuntime getRuntime().close_session() # Check if object exists while self.mock.mock.mock_dataclay.objectExists(str(uri.get_object_id())): print("Waiting... ") time.sleep(5) 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 = "" # 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 client_process1(self, q): try: from dataclay.api import init, finish logger.debug('**Starting init 1**') 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 """ Test. From now on, the Functional Test itself. """ web_sites_ids_str = list() for i in range(0, 10): alias = "bsc%s" % str(i) web_site = WebSite(alias) try: web_site.make_persistent(alias=alias) except: traceback.print_exc() web_sites_ids_str.append(str(web_site.get_object_id())) finish() q.put(["OK", web_sites_ids_str]) except: q.put("FAIL")
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 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") # 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() # Clone the web_site web_site_copy = web_site.dc_clone() self.assertTrue(len(web_site_copy.pages) == len(web_site.pages)) # 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()) self.assertTrue(len(web_site_copy.pages) == len(web_site.pages)) # Persist cloned web_site_copy.make_persistent() web_page2 = WebPage(host + "/page3.html") web_site_copy.add_web_page(web_page2) self.assertFalse(len(web_site_copy.pages) == len(web_site.pages)) # Update original web_site again web_site.dc_update(web_site_copy) self.assertTrue(web_site_copy.is_persistent()) self.assertTrue(len(web_site_copy.pages) == len(web_site.pages)) 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 HasEqMethod self.session_initialized = True # Test. From now on, the Functional Test itself. o = HasEqMethod(1) p = HasEqMethod(1) q = HasEqMethod(1) r = HasEqMethod(2) self.assertEqual(o, p) self.assertEqual(o, q) self.assertNotEqual(o, r) o.make_persistent() # This is triggering something like p == o, which doesn't matter self.assertEqual(p, o) # This is triggering something like o == q, # which will remote call the __eq__ method on a persistent object (o object) # which will trigger q to become a volatile # which will as a matter of act make q persistent (not exactly, but close) self.assertEqual(o, q) p.make_persistent("alias_p") # q was persistent , so this silently fails, no alias associated q.make_persistent("alias_q") r.make_persistent("alias_r") self.assertEqual(o, p) self.assertEqual(o, q) self.assertNotEqual(o, r) p_bis = HasEqMethod.get_by_alias("alias_p") # this fails because q has not been assigned an alias q_bis = HasEqMethod.get_by_alias("alias_q") r_bis = HasEqMethod.get_by_alias("alias_r") self.assertEqual(o, p_bis) self.assertEqual(o, q_bis) self.assertNotEqual(o, r_bis) 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 FancyUUMethods self.session_initialized = True # Test. From now on, the Functional Test itself. o = FancyUUMethods(42, "Hello World") self.assertEqual("%s" % o, "Message[42]: Hello World") o.make_persistent() self.assertEqual("%s" % o, "Message[42]: Hello World") p = FancyUUMethods(42, "Not Hello World") q = FancyUUMethods(43, "Hello World") p.make_persistent("p_obj") q.make_persistent("q_obj") self.assertEqual(o, p) self.assertNotEqual(o, q) self.assertNotEqual(p, q) p_bis = FancyUUMethods.get_by_alias("p_obj") q_bis = FancyUUMethods.get_by_alias("q_obj") self.assertEqual(o, p_bis) self.assertNotEqual(o, q_bis) self.assertNotEqual(p_bis, q_bis) s = set() s.add(o) self.assertEqual(len(s), 1) s.add(p_bis) # this won't add an object because o == p self.assertEqual(len(s), 1) s.add(q_bis) self.assertEqual(len(s), 2) self.assertIn(o, s) self.assertIn(p, s) # this works because o == p self.assertIn(q, s) logger.debug("Test OK!")
def step_impl(context, user_name): """ Start a new session :param context: the current feature context :type context: context :param user_name: user name :type user_name: string """ test_user = get_or_create_user(user_name) os.environ["DATACLAYCLIENTCONFIG"] = test_user.client_properties_path os.environ["DATACLAYSESSIONCONFIG"] = test_user.session_properties_path from dataclay.api import init init()
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!")
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.replication_class import Person from dataclay import getRuntime from dataclay.exceptions.exceptions import DataClayException 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] self.assertEqual(len(environments_ids), 2) # When we create a Person object we call the locally set for non-persistent object.__setattr__ p = Person('foo', 100) r = Person('fat', 200) p.make_persistent(backend_id=environment1_id) r.make_persistent(backend_id=environment1_id) self.assertEqual(p.get_master_location(), environment1_id) # name is a replicated attribute so the before method should be called before the setter # When we change the name we call a inMaster setter execute_implementation_aux('__setUpdate__', ...) p.name = 'aaa' # When we change the age we call a remote __setUpdate__ on object r.age = 78 self.assertEqual(r.age, 78) # Assert that the attribute was properly changed self.assertEqual(p.name, 'aaa') # Check that before method was called self.assertEqual(p.years, 3) 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!")
def main(): import sys import time from dataclay.api import init, finish from dataclay.exceptions.exceptions import DataClayException mqtt_wait = False if len(sys.argv) == 2: mqtt_wait = (sys.argv[1] != "False") init() from CityNS.classes import DKB, ListOfObjects # Register MQTT client to subscribe to MQTT server in 192.168.7.42 if mqtt_wait: client = register_mqtt() client.loop_start() # initialize all computing units in all workers num_cus = 8 for i in range(num_cus): init_task() compss_barrier() # Publish to the MQTT broker that the execution has started if mqtt_wait: publish_mqtt(client) try: kb = DKB.get_by_alias("DKB") except DataClayException: kb = DKB() list_objects = ListOfObjects() list_objects.make_persistent() kb.list_objects = list_objects kb.make_persistent("DKB") start_time = time.time() # execute_trackers(["192.168.50.103"], kb) execute_trackers([("/tmp/pipe_yolo2COMPSs", "/tmp/pipe_COMPSs2yolo")], kb) # pipe_paths = [("/tmp/pipe_yolo2COMPSs", "/tmp/pipe_COMPSs2yolo"), ("/tmp/pipe_write", "/tmp/pipe_read")] # print("ExecTime: " + str(time.time() - start_time)) # print("ExecTime per Iteration: " + str((time.time() - start_time) / NUM_ITERS)) if mqtt_wait: while CD_PROC < NUM_ITERS: pass print("Exiting Application...") finish()
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) # Verify object_iD is not null object_id = web_site.get_object_id() self.assertTrue(object_id != None) # Test make_persistent web_site.make_persistent() self.assertTrue(web_site.is_persistent) web_site.make_persistent("testAlias") web_site2 = WebSite.get_by_alias("testAlias") self.assertEqual(web_site, web_site2) web_site.make_persistent("otherAlias") web_site3 = WebSite.get_by_alias("otherAlias") web_site4 = WebSite.get_by_alias("testAlias") self.assertEqual(web_site3, web_site4) self.assertEqual(web_site3, web_site) self.assertEqual(web_site3, web_site2) 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 dataclay import getRuntime from dataclay.communication.grpc.messages.common.common_messages_pb2 import LANG_PYTHON, LANG_JAVA from dataclay.commonruntime.Settings import settings self.session_initialized = True """ Test. From now on, the Functional Test itself. """ lm_client = getRuntime().ready_clients["@LM"] python_ees_info = lm_client.get_execution_environments_info( settings.current_session_id, LANG_PYTHON) java_ees_info = lm_client.get_execution_environments_info( settings.current_session_id, LANG_JAVA) #### WARNING!!!!! get_execution_environments_per_locations_for_ds DEPRECATED! python_ee_per_loc_for_ds = lm_client.get_execution_environments_per_locations_for_ds( LANG_PYTHON) java_ee_per_loc_for_ds = lm_client.get_execution_environments_per_locations_for_ds( LANG_JAVA) # Check that EEs are correctly initialized and assigned to the right SL for py_ee in python_ees_info: self.assertNotIn(py_ee, java_ees_info.values()) self.assertIn(py_ee, python_ee_per_loc_for_ds.values()) self.assertNotIn(py_ee, java_ee_per_loc_for_ds.values()) for java_ee in java_ees_info: self.assertNotIn(java_ee, python_ees_info.values()) self.assertIn(java_ee, java_ee_per_loc_for_ds.values()) self.assertNotIn(java_ee, python_ee_per_loc_for_ds.values()) logger.debug("Test OK!")
def persist_info(trackers, count, dummy): import uuid from dataclay.exceptions.exceptions import DataClayException init() from CityNS.classes import Event, Object, EventsSnapshot, DKB kb = DKB.get_by_alias("DKB") classes = ["person", "car", "truck", "bus", "motor", "bike", "rider", "traffic light", "traffic sign", "train"] snapshot_alias = "events_" + str(count) snapshot = EventsSnapshot(snapshot_alias) print(f"Persisting {snapshot_alias}") snapshot.make_persistent(alias=snapshot_alias) objects = [] # dataclay_cloud = register_dataclay("192.168.7.32", 11034) for index, tracker in enumerate(trackers): vel_pred = tracker.predList[-1].vel if len(tracker.predList) > 0 else -1.0 yaw_pred = tracker.predList[-1].yaw if len(tracker.predList) > 0 else -1.0 lat, lon = pixel2GPS(tracker.traj[-1].x, tracker.traj[-1].y) event = Event(uuid.uuid4().int, int(datetime.now().timestamp() * 1000), float(lon), float(lat)) print(f"Registering object alias {tracker.id}") object_alias = "obj_" + str(index) try: event_object = Object.get_by_alias(object_alias) except DataClayException as e: event_object = Object(tracker.id, classes[tracker.cl], vel_pred, yaw_pred) print(f"Persisting {object_alias}") event_object.make_persistent(alias=object_alias) event_object.add_event(event) # event_object.federate(dataclay_cloud) snapshot.add_object_refs(object_alias) objects.append(event_object) kb.add_events_snapshot(snapshot) # trigger_openwhisk(snapshot_alias) """ try: snapshot.federate(dataclay_cloud) except DataClayException as e: print(e) """ return dummy, objects, snapshot
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!")
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!")
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!")
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 main(): import sys import time from dataclay.api import init, register_dataclay, finish from dataclay.exceptions.exceptions import DataClayException init() from CityNS.classes import DKB # register_dataclay("192.168.7.32", 11034) try: DKB.get_by_alias("DKB") except DataClayException: DKB().make_persistent("DKB") start_time = time.time() execute_trackers() print("ExecTime: " + str(time.time() - start_time)) print("Exiting Application...") finish()
def client_process2(self, q, web_sites_ids_str): try: from dataclay.api import init, finish logger.debug('**Starting init 2 **') 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 for i in range(0, 10): web_site_2 = WebSite.get_by_alias("bsc%s" % str(i)) self.assertEqual(web_sites_ids_str[i], str(web_site_2.get_object_id())) finish() q.put("OK") except: q.put("FAIL")
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!")
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 MissingAttributeConstructor self.session_initialized = True """ Test. From now on, the Functional Test itself. """ o = MissingAttributeConstructor("String1") o.assign_missing("String2") # This should work o.make_persistent() # Those are basic and expected to work self.assertEqual(o.present, "String1") self.assertEqual(o.missing, "String2") # Now let's make persistent an object with a missing (but annotated) attribute o = MissingAttributeConstructor("String3") o.make_persistent() self.assertEqual(o.present, "String3") # this is a design decision of dataClay, not entirely Python compliant self.assertIsNone(o.missing) 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 self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host + "/foo/bsc.html") web_site.make_persistent(alias=web_site.uri.host) cur_host = "volatile_web" web_page = WebPage(cur_host) logger.debug("web page oid = %s", web_page.get_object_id()) logger.debug("uri oid = %s", web_page.uri.get_object_id()) web_site.add_web_page(web_page) """ Sleep enough time to allow GC action """ print("Waiting for GC action...") time.sleep(5) """ Modify web page """ web_page.uri.host = "new_volatile_web" """ Sleep enough time to allow GC action """ print("Waiting for GC action...") time.sleep(5) """ Get web page """ self.assertEquals(web_page.uri.host, "new_volatile_web") logger.debug("Test OK!")