From 07780318d7810962fb6494b4528f37cc0a8259bf Mon Sep 17 00:00:00 2001 From: Luis Remis Date: Wed, 24 Oct 2018 09:33:58 -0700 Subject: [PATCH] Add testing for concurrency --- tests/python/TestEntities.py | 22 +- tests/python/TestRetail.py | 244 +++++++++++++ tests/python/longquery.py | 684 +++++++++++++++++++++++++++++++++++ 3 files changed, 945 insertions(+), 5 deletions(-) create mode 100644 tests/python/TestRetail.py create mode 100644 tests/python/longquery.py diff --git a/tests/python/TestEntities.py b/tests/python/TestEntities.py index 431640d8..a960bb76 100644 --- a/tests/python/TestEntities.py +++ b/tests/python/TestEntities.py @@ -95,17 +95,29 @@ def findEntity(self, thID): self.assertEqual(response[0]["FindEntity"]["entities"][0] ["threadid"], thID) - def ztest_runMultipleAdds(self): + def test_runMultipleAdds(self): - simultaneous = 1000; + # Test concurrent AddEntities + concurrency = 64; thread_arr = [] - for i in range(1,simultaneous): + for i in range(0,concurrency): thread_add = Thread(target=self.addEntity,args=(i,) ) thread_add.start() thread_arr.append(thread_add) - time.sleep(0.002) - for i in range(1,simultaneous): + for th in thread_arr: + th.join(); + + thread_arr = [] + + # Tests concurrent AddEntities and FindEntities (that should exists) + + for i in range(0,concurrency): + addidx = concurrency + i + thread_add = Thread(target=self.addEntity,args=(addidx,) ) + thread_add.start() + thread_arr.append(thread_add) + thread_find = Thread(target=self.findEntity,args=(i,) ) thread_find.start() thread_arr.append(thread_find) diff --git a/tests/python/TestRetail.py b/tests/python/TestRetail.py new file mode 100644 index 00000000..a0098c59 --- /dev/null +++ b/tests/python/TestRetail.py @@ -0,0 +1,244 @@ +# +# The MIT License +# +# @copyright Copyright (c) 2017 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, +# merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +from threading import Thread +import sys +import os +import urllib +import time +import json +import unittest +import numpy as np +import vdms + +import longquery + +hostname = "localhost" +port = 55557 + +n_cameras = 15 +dim = 1000 +name = "features_vectors_store1" + +class TestEntities(unittest.TestCase): + + def add_descriptor_set(self, name, dim): + + db = vdms.vdms() + db.connect(hostname, port) + + all_queries = [] + + descriptor_set = {} + descriptor_set["name"] = name + descriptor_set["dimensions"] = dim + + query = {} + query["AddDescriptorSet"] = descriptor_set + + all_queries.append(query) + + response, img_array = db.query(all_queries) + + # Check success + self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) + + def build_store(self): + + db = vdms.vdms() + db.connect(hostname, port) + + all_queries = [] + + store_ref = 999 + + query = { + "AddEntity" : + { + "_ref" : store_ref, + "class" : "Store", + "constraints" : { "Name" : [ "==", "Walmart" ] }, + "properties" : { + "Address" : "1428 alex way, Hillsboro 97124", + "Name" : "Walmart", + "Type" : "grocerys" + } + } + } + + all_queries.append(query) + + areas_tag = ["ChildrenClothes", + "WomenClothes", + "MenClothes", + "Computers", + "Sport", + "Food", + "ChildrenClothes", + "WomenClothes", + "MenClothes", + "Computers", + "Sport", + "Food", + "ChildrenClothes", + "ChildrenClothes", + "WomenClothes", + "MenClothes", + "Computers", + "Sport", + "Food", + "ChildrenClothes" + ] + + for i in range(1,n_cameras+1): + + addCamera = { + "AddEntity" : + { + "_ref": i, + "class" : "Camera", + "constraints" : { "Name" : [ "==", "cam" + str(i) ] }, + "properties" : { + "Name" : "cam" + str(i) + } + } + } + + all_queries.append(addCamera) + + addArea = { + "AddEntity" : + { + "_ref" : n_cameras * 10 + i, + "class" : "Area", + "constraints" : { "Name" : [ "==", "Area" + str(i) ] }, + "properties" : { + "Name" : "Area" + str(i), + "Tag" : areas_tag[i] + } + } + } + + if i == 1: + addArea["AddEntity"]["properties"]["Tag"] = "Entrance" + + if i == n_cameras: + addArea["AddEntity"]["properties"]["Tag"] = "Exit" + + all_queries.append(addArea) + + addConnection = { + "AddConnection" : + { + "class" : "Covers", + "ref1" : i, + "ref2" : n_cameras * 10 + i + } + } + + all_queries.append(addConnection) + + addConnection = { + "AddConnection" : + { + "class" : "Consists_Of", + "ref1" : store_ref, + "ref2" : n_cameras * 10 + i + } + } + + all_queries.append(addConnection) + + response, res_arr = db.query(all_queries) + # print (db.get_last_response_str()) + + self.assertEqual(response[0]["AddEntity"]["status"], 0) + + for i in range(1,n_cameras+1): + self.assertEqual(response[(i-1)*4+1]["AddEntity"]["status"], 0) + self.assertEqual(response[(i-1)*4+2]["AddEntity"]["status"], 0) + self.assertEqual(response[(i-1)*4+3]["AddConnection"]["status"], 0) + self.assertEqual(response[(i-1)*4+4]["AddConnection"]["status"], 0) + + def single(self, thrId, db): + + # id = "19149ec8-fa0d-4ed0-9cfb-3e0811b75391" + id = "19149ec8-fa0d-4ed0-9cfb-3e0811b" + str(thrId) + + all_queries = longquery.queryPerson(id) + + # send one random fv + descriptor_blob = [] + x = np.ones(dim) + x[2] = 2.34 + np.random.random_sample() + x = x.astype('float32') + descriptor_blob.append(x.tobytes()) + + response, res_arr = db.query(all_queries, [descriptor_blob]) + + for i in range(0, len(response)): + cmd = list(response[i].items())[0][0] + self.assertEqual(response[i][cmd]["status"], 0) + + # print (db.get_last_response_str()) + + all_queries = longquery.queryVisit(id) + + response, res_arr = db.query(all_queries) + + for i in range(0, len(response)): + cmd = list(response[i].items())[0][0] + self.assertEqual(response[i][cmd]["status"], 0) + + # print (db.get_last_response_str()) + + def test_concurrent(self): + + self.build_store() + self.add_descriptor_set(name, dim) + + retries = 3 + simultaneous = 64 + + db_list = [] + + for i in range(0, simultaneous): + db = vdms.vdms() + db.connect(hostname, port) + db_list.append(db) + + for ret in range(0,retries): + + thread_arr = [] + for i in range(0,simultaneous): + idx = simultaneous * ret + i + thread_add = Thread( + target=self.single,args=(idx, db_list[i]) ) + thread_add.start() + thread_arr.append(thread_add) + + for th in thread_arr: + th.join(); diff --git a/tests/python/longquery.py b/tests/python/longquery.py new file mode 100644 index 00000000..e2305b26 --- /dev/null +++ b/tests/python/longquery.py @@ -0,0 +1,684 @@ + +import os + +def queryPerson(id): + + query = [ { + "AddEntity" : + { + "_ref" : 1, + "class" : "Person", + "properties" : + { + "Id" : id, + "imaginary_node" : 1 + } + } + }, + { + "AddEntity" : + { + "_ref" : 2, + "class" : "BoundingBox", + "properties" : + { + "Height" : "267", + "Id" : id, + "Width" : "117", + "X" : "296", + "Y" : "496" + } + } + }, + { + "AddDescriptor" : + { + "_ref" : 3, + "label" : "Person", + "properties" : + { + "id" : id, + "tag" : "person", + "time_stamp" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "set" : "features_vectors_store1" + } + }, + { + "AddConnection" : + { + "class" : "Has", + "ref1" : 1, + "ref2" : 3 + } + }, + { + "AddConnection" : + { + "class" : "Represents", + "ref1" : 1, + "ref2" : 2 + } + }, + { + "AddConnection" : + { + "class" : "AppearsIn", + "ref1" : 3, + "ref2" : 2 + } + } + ] + + return query + +def queryVisit(id): + + query = [ + { + "AddEntity" : + { + "_ref" : 4, + "class" : "Visit", + "constraints" : + { + "Id" : + [ + "==", + id + ] + }, + "properties" : + { + "Id" : id, + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "starting_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + } + } + }, + { + "FindEntity" : + { + "_ref" : 5, + "class" : "Person", + "constraints" : + { + "Id" : + [ + "==", + id + ] + } + } + }, + { + "AddConnection" : + { + "class" : "visited", + "ref1" : 4, + "ref2" : 5 + } + }, + { + "FindEntity" : + { + "_ref" : 6, + "class" : "Store", + "constraints" : + { + "Name" : + [ + "==", + "Walmart" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "Store_Visit", + "ref1" : 4, + "ref2" : 6 + } + }, + { + "FindEntity" : + { + "_ref" : 7, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area15" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area15", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 7 + } + }, + { + "FindEntity" : + { + "_ref" : 8, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area14" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area14", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 8 + } + }, + { + "FindEntity" : + { + "_ref" : 9, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area13" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area13", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 9 + } + }, + { + "FindEntity" : + { + "_ref" : 10, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area12" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area12", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 10 + } + }, + { + "FindEntity" : + { + "_ref" : 11, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area11" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area11", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 11 + } + }, + { + "FindEntity" : + { + "_ref" : 12, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area10" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area10", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 12 + } + }, + { + "FindEntity" : + { + "_ref" : 13, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area9" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area9", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 13 + } + }, + { + "FindEntity" : + { + "_ref" : 14, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area8" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area8", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 14 + } + }, + { + "FindEntity" : + { + "_ref" : 15, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area7" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area7", + "ending_time" : + { + + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + + "passing_time" : + { + + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 15 + } + }, + { + "FindEntity" : + { + "_ref" : 16, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area6" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area6", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 16 + } + }, + { + "FindEntity" : + { + "_ref" : 17, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area5" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area5", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 17 + } + }, + { + "FindEntity" : + { + "_ref" : 18, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area4" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area4", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 18 + } + }, + { + "FindEntity" : + { + "_ref" : 19, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area3" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area3", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 19 + } + }, + { + "FindEntity" : + { + "_ref" : 20, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area2" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area2", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 20 + } + }, + { + "FindEntity" : + { + "_ref" : 21, + "class" : "Area", + "constraints" : + { + "Name" : + [ + "==", + "Area1" + ] + } + } + }, + { + "AddConnection" : + { + "class" : "PassBy", + "properties" : + { + "Area" : "Area1", + "ending_time" : + { + "_date" : "Sat Jan 06 23:03:00 PDT 2018" + }, + "passing_time" : + { + "_date" : "Sat Jan 06 23:00:00 PST 83186920" + } + }, + "ref1" : 4, + "ref2" : 21 + } + } + ] + + return query