zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #01056
[Merge] lp:~seif/zeitgeist/tests-fix into lp:zeitgeist
Seif Lotfy has proposed merging lp:~seif/zeitgeist/tests-fix into lp:zeitgeist.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
fixing some benchmark tests :)
--
https://code.launchpad.net/~seif/zeitgeist/tests-fix/+merge/26236
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~seif/zeitgeist/tests-fix into lp:zeitgeist.
=== modified file '_zeitgeist/engine/main.py'
--- _zeitgeist/engine/main.py 2010-05-14 17:16:49 +0000
+++ _zeitgeist/engine/main.py 2010-05-27 19:48:36 +0000
@@ -393,7 +393,6 @@
Only URIs for subjects matching the indicated `result_event_templates`
and `result_storage_state` are returned.
"""
-
if result_type == 0 or result_type == 1:
t1 = time.time()
@@ -411,6 +410,7 @@
result_storage_state, 0, 4)
landmarks = set([unicode(event[0]) for event in landmarks])
+
latest_uris = dict(uris)
events = [unicode(u[0]) for u in uris]
@@ -467,7 +467,6 @@
sets.sort(reverse = True)
sets = map(lambda result: result[1], sets[:num_results])
-
return sets
else:
raise NotImplementedError, "Unsupported ResultType."
=== modified file 'test/benchmarks.py'
--- test/benchmarks.py 2010-01-04 20:50:13 +0000
+++ test/benchmarks.py 2010-05-27 19:48:36 +0000
@@ -29,12 +29,10 @@
# range (0, randonmess)!
#
-CONTENTS = [Interpretation.DOCUMENT, Interpretation.TAG, Interpretation.BOOKMARK, Interpretation.MUSIC,
- Interpretation.EMAIL, Interpretation.IMAGE]
-SOURCES = [Manifestation.FILE, Manifestation.WEB_HISTORY, Manifestation.SYSTEM_RESOURCE,
- Manifestation.USER_ACTIVITY]
+INTERPRETATIONS = list(Interpretation.get_all_children())
+MANIFESTATIONS = list(Manifestation.get_all_children())
-USES = [Manifestation.USER_ACTIVITY, Manifestation.USER_NOTIFICATION]
+USES = list(Manifestation.get_all_children())
APPS = ["foo.desktop", "bar.desktop", "bleh.desktop"]
@@ -43,22 +41,22 @@
MIMES = ["application/pdf", "application/xml", "text/plain",
"image/png", "image/jpeg"]
-TAGS = ["puppies", "", "kittens", "", "ponies", "", "", ""]
-def new_dummy_item(uri, randomness=0, timestamp=0):
- return {
- "uri" : uri,
- "content" : CONTENTS[randint(0, randomness) % len(CONTENTS)],
- "source" : SOURCES[randint(0, randomness) % len(SOURCES)],
- "app" : APPS[randint(0, randomness) % len(APPS)],
- "timestamp" : timestamp,
- "text" : "Text",
- "mimetype" : MIMES[randint(0, randomness) % len(MIMES)],
- "use" : USES[randint(0, randomness) % len(USES)],
- "origin" : ORIGINS[randint(0, randomness) % len(ORIGINS)],
- "bookmark" : 0 if randomness == 0 else randint(0,1),
- "tags" : TAGS[randint(0, randomness) % len(TAGS)]
- }
+def new_dummy_item(uri, randomness=0, timestamp=0):
+ event = Event()
+ subject = Subject()
+ subject.uri = uri
+ subject.interpretation = INTERPRETATIONS[randint(0, randomness) % len(INTERPRETATIONS)]
+ subject.manifestation = MANIFESTATIONS[randint(0, randomness) % len(MANIFESTATIONS)]
+ event.actor = APPS[randint(0, randomness) % len(APPS)],
+ event.timestamp = timestamp
+ subject.text = "Text",
+ subject.mimetype = MIMES[randint(0, randomness) % len(MIMES)],
+ subject.origin = ORIGINS[randint(0, randomness) % len(ORIGINS)],
+ event.interpretation = INTERPRETATIONS[randint(0, randomness) % len(INTERPRETATIONS)]
+ event.manifestation = MANIFESTATIONS[randint(0, randomness) % len(MANIFESTATIONS)]
+ event.set_subjects([subject])
+ return event
class EngineBenchmark (unittest.TestCase):
"""
@@ -83,12 +81,14 @@
def do5ChunksOf200(self, randomness):
batch = []
full_start = time()
+ #batch_time = time()
for i in range(1,1001):
batch.append(new_dummy_item("test://item%s" % i, randomness=randomness, timestamp=i))
- if len(batch) % 200 == 0:
+ if len(batch) % 200 == 0:
+ #log.info("Finished batch of 200 in: %ss" % (time() - batch_time))
+ #batch_time = time()
start = time()
self.engine.insert_events(batch)
- log.info("Inserted 200 items in: %ss" % (time()-start))
batch = []
log.info("Total insertion time for 1000 items: %ss" % (time()-full_start))
@@ -115,9 +115,12 @@
inserted_items = []
batch = []
full_start = time()
+ #batch_time = time()
for i in range(1,num+1):
batch.append(new_dummy_item("test://item%s" % i, randomness=randomness, timestamp=i))
if len(batch) % 400 == 0:
+ #log.info("Finished batch of 400 in: %ss" % (time() - batch_time))
+ #batch_time = time()
self.engine.insert_events(batch)
inserted_items.extend(batch)
batch = []
@@ -128,7 +131,7 @@
log.info("Total insertion time for %s items: %ss" % (num, time()-full_start))
return inserted_items
- def do_find(self, expected_items, page_size, **kwargs):
+ def do_find(self, expected_items, page_size, filters = [], **kwargs):
"""
Helper method to find a set of items with page size of 'page_size'
passin 'kwargs' directly to the engine.find_events() method.
@@ -138,12 +141,14 @@
next_timestamp = 0
page_time = time()
full_time = page_time
- page = self.engine.find_events(min=next_timestamp,
- limit=page_size,
+ page = self.engine.find_events([next_timestamp,page_time], filters,
+ StorageState.Any,
+ page_size, 0,
**kwargs)
log.info("Found %s items in %ss" % (page_size, time()- page_time))
while page:
- dummy = page[len(page) - 1]["timestamp"]
+ print "***", len(page)
+ dummy = int(page[len(page) - 1].timestamp)
if dummy == next_timestamp:
self.fail("Too many items found")
if len(results) > total:
@@ -153,9 +158,10 @@
next_timestamp = dummy + 1
results += page
page_time = time()
- page = self.engine.find_events(min=next_timestamp,
- limit=page_size,
- **kwargs)
+ page = self.engine.find_events([next_timestamp,page_time], [],
+ StorageState.Any,
+ page_size, 0,
+ **kwargs)
log.info("Found %s items in %ss" % (len(page), time()- page_time))
log.info("Full retrieval of %s items in %ss" % (total, time()- full_time))
@@ -178,9 +184,13 @@
def testFindDocuments(self):
log.info("*** TEST: Find Documents In Chunks Of 20")
items = self.prepare_items(1000, 5)
- doc_items = filter(lambda i : i["content"] == Interpretation.DOCUMENT.uri, items)
+ doc_items = filter(lambda i : i.subjects[0].interpretation == Interpretation.DOCUMENT.uri, items)
+ event = Event()
+ subject = Subject()
+ subject.interpretation = Interpretation.DOCUMENT.uri
+ event.set_subjects([subject])
self.do_find(doc_items, 20,
- filters=[{"content" : [Interpretation.DOCUMENT.uri]}])
+ filters=[event])
if __name__ == '__main__':
unittest.main()