Kaydet (Commit) b3b4dbef authored tarafından Gregory P. Smith's avatar Gregory P. Smith

Cleanup test_thread. CDB (Concurrent Database) support in BerkeleyDB is only

intended to have one writer and multiple readers so only run one.
üst 89d996e5
...@@ -81,6 +81,9 @@ class BaseThreadedTestCase(unittest.TestCase): ...@@ -81,6 +81,9 @@ class BaseThreadedTestCase(unittest.TestCase):
except db.DBLockDeadlockError: except db.DBLockDeadlockError:
if verbose: if verbose:
print(currentThread().getName(), 'died from', e) print(currentThread().getName(), 'died from', e)
else:
if verbose:
print(currentThread().getName(), "finished.")
def readerThread(self, *args, **kwargs): def readerThread(self, *args, **kwargs):
try: try:
...@@ -88,7 +91,9 @@ class BaseThreadedTestCase(unittest.TestCase): ...@@ -88,7 +91,9 @@ class BaseThreadedTestCase(unittest.TestCase):
except db.DBLockDeadlockError as e: except db.DBLockDeadlockError as e:
if verbose: if verbose:
print(currentThread().getName(), 'died from', e) print(currentThread().getName(), 'died from', e)
else:
if verbose:
print(currentThread().getName(), "finished.")
...@@ -107,14 +112,14 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -107,14 +112,14 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
print('\n', '-=' * 30) print('\n', '-=' * 30)
print("Running %s.test01_1WriterMultiReaders..." % \ print("Running %s.test01_1WriterMultiReaders..." % \
self.__class__.__name__) self.__class__.__name__)
print('Using:', self.homeDir, self.filename)
threads = [] threads = []
for x in range(self.writers): wt = Thread(target = self.writerThread,
wt = Thread(target = self.writerThread, args = (self.d, self.records),
args = (self.d, self.records, x), name = 'the writer',
name = 'writer %d' % x, )#verbose = verbose)
)#verbose = verbose) threads.append(wt)
threads.append(wt)
for x in range(self.readers): for x in range(self.readers):
rt = Thread(target = self.readerThread, rt = Thread(target = self.readerThread,
...@@ -128,20 +133,18 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -128,20 +133,18 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
for t in threads: for t in threads:
t.join() t.join()
def _writerThread(self, d, howMany, writerNum): def _writerThread(self, d, howMany):
#time.sleep(0.01 * writerNum + 0.01)
name = currentThread().getName() name = currentThread().getName()
start = howMany * writerNum start = 0
stop = howMany * (writerNum + 1) - 1 stop = howMany
if verbose: if verbose:
print("%s: creating records %d - %d" % (name, start, stop)) print(name+": creating records", start, "-", stop)
for x in range(start, stop): for x in range(start, stop):
key = ('%04d' % x).encode("ascii") key = ('%04d' % x).encode("ascii")
dbutils.DeadlockWrap(d.put, key, self.makeData(key), d.put(key, self.makeData(key))
max_retries=20) if verbose and x > start and x % 50 == 0:
if verbose and x % 100 == 0: print(name+": records", start, "-", x, "finished")
print("%s: records %d - %d finished" % (name, start, x))
if verbose: if verbose:
print("%s: finished creating records" % name) print("%s: finished creating records" % name)
...@@ -157,8 +160,6 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -157,8 +160,6 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
## c.delete() ## c.delete()
## c.close() ## c.close()
if verbose:
print("%s: thread finished" % name)
def _readerThread(self, d, readerNum): def _readerThread(self, d, readerNum):
time.sleep(0.01 * readerNum) time.sleep(0.01 * readerNum)
...@@ -174,25 +175,22 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase): ...@@ -174,25 +175,22 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
self.assertEqual(self.makeData(key), data) self.assertEqual(self.makeData(key), data)
rec = c.next() rec = c.next()
if verbose: if verbose:
print("%s: found %d records" % (name, count)) print(name+": found", count, "records")
c.close() c.close()
time.sleep(0.05) time.sleep(0.05)
if verbose:
print("%s: thread finished" % name)
class BTreeConcurrentDataStore(ConcurrentDataStoreBase): class BTreeConcurrentDataStore(ConcurrentDataStoreBase):
dbtype = db.DB_BTREE dbtype = db.DB_BTREE
writers = 2 writers = 1
readers = 10 readers = 10
records = 1000 records = 1000
class HashConcurrentDataStore(ConcurrentDataStoreBase): class HashConcurrentDataStore(ConcurrentDataStoreBase):
dbtype = db.DB_HASH dbtype = db.DB_HASH
writers = 2 writers = 1
readers = 10 readers = 0
records = 1000 records = 1000
...@@ -373,7 +371,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -373,7 +371,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
finished = True finished = True
except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val: except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val:
if verbose: if verbose:
print("%s: Aborting transaction (%s)" % (name, val[1])) print("%s: Aborting transaction (%s)" % (name, val))
txn.abort() txn.abort()
time.sleep(0.05) time.sleep(0.05)
...@@ -411,7 +409,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -411,7 +409,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
print("%s: deleted records %s" % (name, recs)) print("%s: deleted records %s" % (name, recs))
except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val: except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val:
if verbose: if verbose:
print("%s: Aborting transaction (%s)" % (name, val[1])) print("%s: Aborting transaction (%s)" % (name, val))
txn.abort() txn.abort()
time.sleep(0.05) time.sleep(0.05)
...@@ -441,7 +439,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase): ...@@ -441,7 +439,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
finished = True finished = True
except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val: except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val:
if verbose: if verbose:
print("%s: Aborting transaction (%s)" % (name, val[1])) print("%s: Aborting transaction (%s)" % (name, val))
c.close() c.close()
txn.abort() txn.abort()
time.sleep(0.05) time.sleep(0.05)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment