Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

CBD-667 CBD-538: use generators in viewgen class

Change-Id: Ib64383c05908a9c1de1733f6d0b0664f7335abb2
Reviewed-on: http://review.couchbase.org/22760
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>
Tested-by: Pavel Paulau <pavel.paulau@gmail.com>
  • Loading branch information...
commit 6dd1d1f88d29e4fcb527484593970293373bd24b 1 parent 20a6532
@pavel-paulau pavel-paulau authored
Showing with 46 additions and 46 deletions.
  1. +9 −9 pytests/performance/eperf.py
  2. +37 −37 pytests/performance/viewgen.py
View
18 pytests/performance/eperf.py
@@ -1143,7 +1143,7 @@ def test_evperf_workload2(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
def test_evperf_workload3(self):
"""Like workload 2 but has queries on view with reduce step"""
@@ -1189,7 +1189,7 @@ def test_evperf_workload3(self):
queries=queries,
proto_prefix='couchbase',
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
def test_vperf1(self):
"""1 design document, 1 view"""
@@ -1243,7 +1243,7 @@ def test_vperf1(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
if self.parami("debug_phase", 0):
self.debug_phase(ddocs)
@@ -1296,7 +1296,7 @@ def test_vperf2(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
if self.parami("debug_phase", 0):
self.debug_phase(ddocs)
@@ -1345,7 +1345,7 @@ def test_vperf3(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
if self.parami("debug_phase", 0):
self.debug_phase(ddocs)
@@ -1395,7 +1395,7 @@ def test_vperf4(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
if self.parami("debug_phase", 0):
self.debug_phase(ddocs)
@@ -1442,7 +1442,7 @@ def test_vperf5(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
def test_vperf6(self):
"""Only queries on pseudo primary index"""
@@ -1489,7 +1489,7 @@ def test_vperf6(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
if self.parami("debug_phase", 0):
self.debug_phase(ddocs)
@@ -1545,7 +1545,7 @@ def test_evperf2(self):
queries=queries,
proto_prefix="couchbase",
host=host,
- ddoc=view_gen.DDOC_NAMES[0])
+ ddoc=view_gen.ddoc_names.next())
if self.parami("debug_phase", 0):
self.debug_phase(ddocs)
View
74 pytests/performance/viewgen.py
@@ -1,11 +1,31 @@
-class ViewGen:
+import string
- DDOC_NAMES = ["A", "B", "C", "D", "E", "F", "G", "H"]
- VIEW_NAMES = ['city1', 'city2', 'realm1', 'experts1', 'experts2', 'realm2',
- 'realm3', 'category']
+class RepeatableGenerator(object):
- MAP_FUNCTIONS = [
+ def __init__(self, iterable):
+ self.reset()
+ self.iterable = iterable
+
+ def next(self):
+ self.counter += 1
+ if self.counter == len(self.iterable):
+ self.counter = 0
+ return self.iterable[self.counter]
+
+ def reset(self):
+ self.counter = -1
+
+
+class ViewGen(object):
+
+ ddoc_names = RepeatableGenerator(tuple(string.ascii_uppercase))
+
+ view_names = RepeatableGenerator(('city1', 'city2', 'realm1', 'experts1',
+ 'experts2', 'realm2', 'realm3',
+ 'category'))
+
+ map_functions = RepeatableGenerator((
"""
function(doc, meta) {
if (doc.city != null) {
@@ -60,51 +80,31 @@ class ViewGen:
emit(doc.category, doc.coins);
}
}
- """]
+ """
+ ))
- REDUCE_FUNCTIONS = ["_count", "_sum", "_stats"]
+ reduce_functions = RepeatableGenerator(('_count', '_sum', '_stats'))
- def generate_ddocs(self, pattern=None, add_reduce=False):
+ def generate_ddocs(self, pattern=None):
"""Generate dictionary with design documents and views.
Pattern looks like:
[8, 8, 8] -- 8 ddocs (8 views, 8 views, 8 views)
[2, 2, 4] -- 3 ddocs (2 views, 2 views, 4 views)
[8] -- 1 ddoc (8 views)
[1, 1, 1, 1, 1, 1, 1, 1] -- 8 ddocs (1 view)
- If `add_reduce` argument is True, additional ddoc with single
+ TODO: If `add_reduce` argument is True, additional ddoc with single
map-reduce view is added
"""
-
ddocs = dict()
-
- index_of_map = 0
- index_of_ddoc = 0
-
for number_of_views in pattern:
- ddoc_name = self.DDOC_NAMES[index_of_ddoc]
+ ddoc_name = self.ddoc_names.next()
ddocs[ddoc_name] = {'views': {}}
- for index_of_view in range(number_of_views):
- try:
- view_name = self.VIEW_NAMES[index_of_map]
- except IndexError:
- index_of_map = 0
- view_name = self.VIEW_NAMES[index_of_map]
- ddocs[ddoc_name]['views'][view_name] = {}
- ddocs[ddoc_name]['views'][view_name]['map'] = \
- self.MAP_FUNCTIONS[index_of_map]
- index_of_map += 1
- index_of_ddoc += 1
-
- if add_reduce:
- ddocs['reduce'] = {
- 'views': {
- 'reduce': {
- 'map': self.MAP_FUNCTIONS[-1],
- 'reduce': self.REDUCE_FUNCTIONS[-1]
- }
- }
- }
-
+ for index_of_view in xrange(number_of_views):
+ view_name = self.view_names.next()
+ map = self.map_functions.next()
+ ddocs[ddoc_name]['views'][view_name] = {'map': map}
+ self.ddoc_names.reset()
+ self.map_functions.reset()
return ddocs
def generate_all_docs_view(self):
Please sign in to comment.
Something went wrong with that request. Please try again.