Changeset: 07960f5a1306 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=07960f5a1306 Added Files: tools/embeddedpy/Tests/pylite05.py tools/embeddedpy/Tests/pylite05.stable.err tools/embeddedpy/Tests/pylite05.stable.out tools/embeddedpy/Tests/pylite06.py tools/embeddedpy/Tests/pylite06.stable.err tools/embeddedpy/Tests/pylite06.stable.out Modified Files: tools/embeddedpy/Tests/All tools/embeddedpy/Tests/pylite01.py tools/embeddedpy/Tests/pylite02.py tools/embeddedpy/Tests/pylite03.py Branch: pyapi Log Message:
Added monetdblite.connect() testcases and changed other testcases to work with slight change in interface. diffs (200 lines): diff --git a/tools/embeddedpy/Tests/All b/tools/embeddedpy/Tests/All --- a/tools/embeddedpy/Tests/All +++ b/tools/embeddedpy/Tests/All @@ -4,3 +4,5 @@ HAVE_LIBPY?pylite01 HAVE_LIBPY?pylite02 HAVE_LIBPY?pylite03 HAVE_LIBPY?pylite04 +HAVE_LIBPY?pylite05 +HAVE_LIBPY?pylite06 diff --git a/tools/embeddedpy/Tests/pylite01.py b/tools/embeddedpy/Tests/pylite01.py --- a/tools/embeddedpy/Tests/pylite01.py +++ b/tools/embeddedpy/Tests/pylite01.py @@ -6,7 +6,7 @@ if os.path.isdir(dbfarm): shutil.rmtree( monetdblite.init(dbfarm) import numpy -monetdblite.create('pylite01', ['i'], numpy.arange(100000)) +monetdblite.create('pylite01', colnames=['i'], values=numpy.arange(100000)) res = monetdblite.sql('select * from pylite01') print res print 'Count', len(res['i']) diff --git a/tools/embeddedpy/Tests/pylite02.py b/tools/embeddedpy/Tests/pylite02.py --- a/tools/embeddedpy/Tests/pylite02.py +++ b/tools/embeddedpy/Tests/pylite02.py @@ -6,7 +6,7 @@ if os.path.isdir(dbfarm): shutil.rmtree( monetdblite.init(dbfarm) import numpy -monetdblite.create('pylite02', ['i'], numpy.arange(100000)) +monetdblite.create('pylite02', colnames=['i'], values=numpy.arange(100000)) monetdblite.insert('pylite02', numpy.arange(100000)) res = monetdblite.sql('select * from pylite02') print res diff --git a/tools/embeddedpy/Tests/pylite03.py b/tools/embeddedpy/Tests/pylite03.py --- a/tools/embeddedpy/Tests/pylite03.py +++ b/tools/embeddedpy/Tests/pylite03.py @@ -6,7 +6,7 @@ if os.path.isdir(dbfarm): shutil.rmtree( monetdblite.init(dbfarm) import numpy -monetdblite.create('pylite03', ['i', 'j', 'k', 'l', 'm'], numpy.arange(100000).reshape((5,20000))) +monetdblite.create('pylite03', colnames=['i', 'j', 'k', 'l', 'm'], values=numpy.arange(100000).reshape((5,20000))) res = monetdblite.sql('select * from pylite03') print res print 'Count', len(res['i']) diff --git a/tools/embeddedpy/Tests/pylite05.py b/tools/embeddedpy/Tests/pylite05.py new file mode 100644 --- /dev/null +++ b/tools/embeddedpy/Tests/pylite05.py @@ -0,0 +1,17 @@ +# Test connections in monetdblite + +import monetdblite, shutil, os +dbfarm = '/tmp/pylite_dbfarm' +if os.path.isdir(dbfarm): shutil.rmtree(dbfarm) +monetdblite.init(dbfarm) + +import numpy + +conn = monetdblite.connect() # create the client +monetdblite.create('pylite05', colnames=['i'], values=numpy.arange(100000), conn=conn) +print len(monetdblite.sql('select * from pylite05', conn=conn)['i']) +monetdblite.insert('pylite05', values=numpy.arange(100000), conn=conn) +print len(monetdblite.sql('select * from pylite05', conn=conn)['i']) +del conn # client is automatically disconnected when connection object is deleted + + diff --git a/tools/embeddedpy/Tests/pylite05.stable.err b/tools/embeddedpy/Tests/pylite05.stable.err new file mode 100644 --- /dev/null +++ b/tools/embeddedpy/Tests/pylite05.stable.err @@ -0,0 +1,12 @@ +stderr of test 'pylite05` in directory 'tools/embeddedpy` itself: + + +# 17:47:58 > +# 17:47:58 > "/usr/bin/python2" "pylite05.py" "pylite05" +# 17:47:58 > + + +# 17:47:59 > +# 17:47:59 > "Done." +# 17:47:59 > + diff --git a/tools/embeddedpy/Tests/pylite05.stable.out b/tools/embeddedpy/Tests/pylite05.stable.out new file mode 100644 --- /dev/null +++ b/tools/embeddedpy/Tests/pylite05.stable.out @@ -0,0 +1,15 @@ +stdout of test 'pylite05` in directory 'tools/embeddedpy` itself: + + +# 17:47:58 > +# 17:47:58 > "/usr/bin/python2" "pylite05.py" "pylite05" +# 17:47:58 > + +Making directory /tmp/pylite_dbfarm +100000 +200000 + +# 17:47:59 > +# 17:47:59 > "Done." +# 17:47:59 > + diff --git a/tools/embeddedpy/Tests/pylite06.py b/tools/embeddedpy/Tests/pylite06.py new file mode 100644 --- /dev/null +++ b/tools/embeddedpy/Tests/pylite06.py @@ -0,0 +1,55 @@ +# Test multithreading in MonetDBLite + +import monetdblite, shutil, os +dbfarm = '/tmp/pylite_dbfarm' +if os.path.isdir(dbfarm): shutil.rmtree(dbfarm) +monetdblite.init(dbfarm) + +import numpy, threading, time + +monetdblite.create('pylite06a', colnames=['i', 'j'], values=[numpy.arange(1000000), numpy.arange(1000000)]) +monetdblite.create('pylite06b', colnames=['i', 'k'], values=[numpy.arange(1000000), numpy.arange(1000000)]) +# commit the transaction, otherwise different clients do not see the table +# every connection has its own transaction state +monetdblite.sql('commit') + +default_conn = monetdblite.connect() + +def query(conn): + # do a query that takes a reasonable amount of time in the database, as time in the database is the only thing that is parallelized + monetdblite.sql('select j,k from pylite06a inner join pylite06b on pylite06a.i=pylite06b.i', conn) + +# test threading with every thread using the same client (only one SQL transaction per client, so the threads don't do much) +start = time.time() +threads = [] +for n in range(10): + thread = threading.Thread(target=query, args=[default_conn]) + thread.start() + threads.append(thread) + +for thread in threads: + thread.join() +end = time.time() + +same_client_time = end - start + +del default_conn + +start = time.time() +# test threading with different clients (every client can have its own SQL transaction) +threads = [] +for n in range(10): + thread = threading.Thread(target=query, args=[monetdblite.connect()]) + thread.start() + threads.append(thread) + +for thread in threads: + thread.join() +end = time.time() + +different_client_time = end - start + +if different_client_time > same_client_time: + print "Same client is faster" +else: print "Different client is faster" + diff --git a/tools/embeddedpy/Tests/pylite06.stable.err b/tools/embeddedpy/Tests/pylite06.stable.err new file mode 100644 --- /dev/null +++ b/tools/embeddedpy/Tests/pylite06.stable.err @@ -0,0 +1,12 @@ +stderr of test 'pylite06` in directory 'tools/embeddedpy` itself: + + +# 17:47:59 > +# 17:47:59 > "/usr/bin/python2" "pylite06.py" "pylite06" +# 17:47:59 > + + +# 17:48:01 > +# 17:48:01 > "Done." +# 17:48:01 > + diff --git a/tools/embeddedpy/Tests/pylite06.stable.out b/tools/embeddedpy/Tests/pylite06.stable.out new file mode 100644 --- /dev/null +++ b/tools/embeddedpy/Tests/pylite06.stable.out @@ -0,0 +1,14 @@ +stdout of test 'pylite06` in directory 'tools/embeddedpy` itself: + + +# 17:47:59 > +# 17:47:59 > "/usr/bin/python2" "pylite06.py" "pylite06" +# 17:47:59 > + +Making directory /tmp/pylite_dbfarm +Different client is faster + +# 17:48:01 > +# 17:48:01 > "Done." +# 17:48:01 > + _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list