From 007894cf34216511c8d1641e914fce0ebc99a292 Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Sat, 31 Aug 2013 01:38:40 +0400
Subject: [PATCH] Convert fiber.test.ua and stat.test.py to new data dictionary
 and lua console.

---
 test/box/fiber.result   | 154 +++++++++++++++++++++-------------------
 test/box/fiber.test.lua |  40 ++++++-----
 test/box/stat.result    |  85 ++++++++++++----------
 test/box/stat.test.py   |   9 +--
 4 files changed, 157 insertions(+), 131 deletions(-)

diff --git a/test/box/fiber.result b/test/box/fiber.result
index dee1c8af47..ff6dd688e9 100644
--- a/test/box/fiber.result
+++ b/test/box/fiber.result
@@ -1,3 +1,14 @@
+box.insert(box.schema.SPACE_ID, 0, 0, 'tweedledum')
+---
+- [0, 0, 'tweedledum']
+...
+box.insert(box.schema.INDEX_ID, 0, 0, 'primary', 'hash', 1, 1, 0, 'num')
+---
+- [0, 0, 'primary', 1752392040, 1, 1, 0, 'num']
+...
+space = box.space[0]
+---
+...
 -- A test case for a race condition between ev_schedule
 -- and wal_schedule fiber schedulers.
 -- The same fiber should not be scheduled by ev_schedule (e.g.
@@ -7,23 +18,23 @@
 -- pause
 box.cfg.rows_per_wal
 ---
- - 50
+- 50
 ...
-box.space[0]:insert(1, 'testing', 'lua rocks')
+space:insert(1, 'testing', 'lua rocks')
 ---
- - 1: {'testing', 'lua rocks'}
+- [1, 'testing', 'lua rocks']
 ...
-box.space[0]:delete(1)
+space:delete(1)
 ---
- - 1: {'testing', 'lua rocks'}
+- [1, 'testing', 'lua rocks']
 ...
-box.space[0]:insert(1, 'testing', 'lua rocks')
+space:insert(1, 'testing', 'lua rocks')
 ---
- - 1: {'testing', 'lua rocks'}
+- [1, 'testing', 'lua rocks']
 ...
-box.space[0]:delete(1)
+space:delete(1)
 ---
- - 1: {'testing', 'lua rocks'}
+- [1, 'testing', 'lua rocks']
 ...
 -- check delete
 box.process(17, box.pack('iiiiiip', 0, 0, 0, 2^31, 1, 1, 1))
@@ -31,195 +42,194 @@ box.process(17, box.pack('iiiiiip', 0, 0, 0, 2^31, 1, 1, 1))
 ...
 box.process(22, box.pack('iii', 0, 0, 0))
 ---
-error: 'box.process(CALL, ...) is not allowed'
+- error: box.process(CALL, ...) is not allowed
 ...
-box.space[0]:insert(1, 'test box delete')
+space:insert(1, 'test box delete')
 ---
- - 1: {'test box delete'}
+- [1, 'test box delete']
 ...
 box.delete('0', '\1\0\0\0')
 ---
- - 1: {'test box delete'}
+- [1, 'test box delete']
 ...
-box.space[0]:insert(1, 'test box delete')
+space:insert(1, 'test box delete')
 ---
- - 1: {'test box delete'}
+- [1, 'test box delete']
 ...
 box.delete(0, 1)
 ---
- - 1: {'test box delete'}
+- [1, 'test box delete']
 ...
-box.space[0]:insert('abcd', 'test box delete')
+space:insert('abcd', 'test box delete')
 ---
- - 1684234849: {'test box delete'}
+- [1684234849, 'test box delete']
 ...
 box.delete('0', 'abcd')
 ---
- - 1684234849: {'test box delete'}
+- [1684234849, 'test box delete']
 ...
-box.space[0]:insert('abcd', 'test box delete')
+space:insert('abcd', 'test box delete')
 ---
- - 1684234849: {'test box delete'}
+- [1684234849, 'test box delete']
 ...
 box.delete(0, 'abcd')
 ---
- - 1684234849: {'test box delete'}
+- [1684234849, 'test box delete']
 ...
-box.space[0]:insert('abcd', 'test box.select()')
+space:insert('abcd', 'test box.select()')
 ---
- - 1684234849: {'test box.select()'}
+- [1684234849, 'test box.select()']
 ...
 box.replace('0', 'abcd', 'hello', 'world')
 ---
- - 1684234849: {'hello', 'world'}
+- [1684234849, 'hello', 'world']
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'defc', 'goodbye', 'universe')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.replace('0', 'abcd')
 ---
- - 1684234849: {}
+- [1684234849]
 ...
 box.delete('0', 'abcd')
 ---
- - 1684234849: {}
+- [1684234849]
 ...
 box.delete('0', 'defc')
 ---
- - 1667655012: {'goodbye', 7310312400256331381}
+- [1667655012, 'goodbye', 7310312400256331381]
 ...
 box.insert('0', 'test', 'old', 'abcd')
 ---
- - 1953719668: {'old', 1684234849}
+- [1953719668, 'old', 1684234849]
 ...
 -- test that insert produces a duplicate key error
 box.insert('0', 'test', 'old', 'abcd')
 ---
-error: 'Duplicate key exists in unique index 0'
+- error: Duplicate key exists in unique index 0
 ...
 box.update('0', 'test', '=p=p', 0, 'pass', 1, 'new')
 ---
- - 1936941424: {'new', 1684234849}
+- [1936941424, 'new', 1684234849]
 ...
 box.update('0', 'miss', '+p', 2, '\1\0\0\0')
 ---
 ...
 box.update('0', 'pass', '+p', 2, '\1\0\0\0')
 ---
- - 1936941424: {'new', 1684234850}
+- [1936941424, 'new', 1684234850]
 ...
 box.update('0', 'pass', '-p', 2, '\1\0\0\0')
 ---
- - 1936941424: {'new', 1684234849}
+- [1936941424, 'new', 1684234849]
 ...
 box.update('0', 'pass', '-p', 2, '\1\0\0\0')
 ---
- - 1936941424: {'new', 1684234848}
+- [1936941424, 'new', 1684234848]
 ...
 box.update(0, 'pass', '+p', 2, 1)
 ---
- - 1936941424: {'new', 1684234849}
+- [1936941424, 'new', 1684234849]
 ...
 box.delete('0', 'pass')
 ---
- - 1936941424: {'new', 1684234849}
+- [1936941424, 'new', 1684234849]
 ...
 reload configuration
 ---
-ok
+- error: '[string "reload configuration"]:1: ''='' expected near ''configuration'''
 ...
 -- must be read-only
 box.insert(0, 'test')
 ---
- - 1953719668: {}
+- [1953719668]
 ...
 box.insert(0, 'abcd')
 ---
- - 1684234849: {}
+- [1684234849]
 ...
 box.delete(0, 'test')
 ---
- - 1953719668: {}
+- [1953719668]
 ...
 box.delete(0, 'abcd')
 ---
- - 1684234849: {}
+- [1684234849]
 ...
-box.space[0]:insert('test', 'hello world')
+space:insert('test', 'hello world')
 ---
- - 1953719668: {'hello world'}
+- [1953719668, 'hello world']
 ...
-box.space[0]:update('test', '=p', 1, 'bye, world')
+space:update('test', '=p', 1, 'bye, world')
 ---
- - 1953719668: {'bye, world'}
+- [1953719668, 'bye, world']
 ...
-box.space[0]:delete('test')
+space:delete('test')
 ---
- - 1953719668: {'bye, world'}
+- [1953719668, 'bye, world']
 ...
 -- test tuple iterators
-t = box.space[0]:insert('test')
+t = space:insert('test')
 ---
 ...
-t = box.space[0]:replace('test', 'another field')
+t = space:replace('test', 'another field')
 ---
 ...
-t = box.space[0]:replace('test', 'another field', 'one more')
+t = space:replace('test', 'another field', 'one more')
 ---
 ...
-box.space[0]:truncate()
+space:truncate()
 ---
 ...
 -- test passing arguments in and out created fiber
 -- setopt delimiter ';'
 function y()
-    print('started')
-    box.fiber.detach()
+    box.fiber.detach('started')
     while true do
         box.replace(0, 'test', os.time())
         box.fiber.sleep(0.001)
@@ -232,7 +242,7 @@ f = box.fiber.create(y);
 ...
 box.fiber.resume(f);
 ---
-started
+- started
 ...
 box.fiber.sleep(0.002);
 ---
@@ -242,7 +252,7 @@ box.fiber.cancel(f);
 ...
 box.fiber.resume(f);
 ---
-error: 'fiber.resume(): the fiber is dead'
+- error: 'fiber.resume(): the fiber is dead'
 ...
 for k = 1, 1000, 1 do
     box.fiber.create(
@@ -256,22 +266,22 @@ end;
 -- setopt delimiter ''
 collectgarbage('collect')
 ---
- - 0
+- 0
 ...
 -- check that these newly created fibers are garbage collected
 box.fiber.find(900)
 ---
- - nil
+{}
 ...
 box.fiber.find(910)
 ---
- - nil
+{}
 ...
 box.fiber.find(920)
 ---
- - nil
+{}
 ...
-box.space[0]:truncate()
+space:drop()
 ---
 ...
 -- vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 syntax=lua
diff --git a/test/box/fiber.test.lua b/test/box/fiber.test.lua
index 193f8b8f39..b3cbf3de01 100644
--- a/test/box/fiber.test.lua
+++ b/test/box/fiber.test.lua
@@ -1,3 +1,6 @@
+box.insert(box.schema.SPACE_ID, 0, 0, 'tweedledum')
+box.insert(box.schema.INDEX_ID, 0, 0, 'primary', 'hash', 1, 1, 0, 'num')
+space = box.space[0]
 -- A test case for a race condition between ev_schedule
 -- and wal_schedule fiber schedulers.
 -- The same fiber should not be scheduled by ev_schedule (e.g.
@@ -6,23 +9,23 @@
 -- we reopen the .xlog file and thus wal_scheduler takes a long
 -- pause
 box.cfg.rows_per_wal
-box.space[0]:insert(1, 'testing', 'lua rocks')
-box.space[0]:delete(1)
-box.space[0]:insert(1, 'testing', 'lua rocks')
-box.space[0]:delete(1)
+space:insert(1, 'testing', 'lua rocks')
+space:delete(1)
+space:insert(1, 'testing', 'lua rocks')
+space:delete(1)
 -- check delete
 box.process(17, box.pack('iiiiiip', 0, 0, 0, 2^31, 1, 1, 1))
 box.process(22, box.pack('iii', 0, 0, 0))
 
-box.space[0]:insert(1, 'test box delete')
+space:insert(1, 'test box delete')
 box.delete('0', '\1\0\0\0')
-box.space[0]:insert(1, 'test box delete')
+space:insert(1, 'test box delete')
 box.delete(0, 1)
-box.space[0]:insert('abcd', 'test box delete')
+space:insert('abcd', 'test box delete')
 box.delete('0', 'abcd')
-box.space[0]:insert('abcd', 'test box delete')
+space:insert('abcd', 'test box delete')
 box.delete(0, 'abcd')
-box.space[0]:insert('abcd', 'test box.select()')
+space:insert('abcd', 'test box.select()')
 box.replace('0', 'abcd', 'hello', 'world')
 box.replace('0', 'defc', 'goodbye', 'universe')
 box.replace('0', 'defc', 'goodbye', 'universe')
@@ -56,20 +59,19 @@ box.insert(0, 'test')
 box.insert(0, 'abcd')
 box.delete(0, 'test')
 box.delete(0, 'abcd')
-box.space[0]:insert('test', 'hello world')
-box.space[0]:update('test', '=p', 1, 'bye, world')
-box.space[0]:delete('test')
+space:insert('test', 'hello world')
+space:update('test', '=p', 1, 'bye, world')
+space:delete('test')
 -- test tuple iterators
-t = box.space[0]:insert('test')
-t = box.space[0]:replace('test', 'another field')
-t = box.space[0]:replace('test', 'another field', 'one more')
-box.space[0]:truncate()
+t = space:insert('test')
+t = space:replace('test', 'another field')
+t = space:replace('test', 'another field', 'one more')
+space:truncate()
 -- test passing arguments in and out created fiber
 
 -- setopt delimiter ';'
 function y()
-    print('started')
-    box.fiber.detach()
+    box.fiber.detach('started')
     while true do
         box.replace(0, 'test', os.time())
         box.fiber.sleep(0.001)
@@ -94,5 +96,5 @@ collectgarbage('collect')
 box.fiber.find(900)
 box.fiber.find(910)
 box.fiber.find(920)
-box.space[0]:truncate()
+space:drop()
 -- vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 syntax=lua
diff --git a/test/box/stat.result b/test/box/stat.result
index b87df665a4..2d98198907 100644
--- a/test/box/stat.result
+++ b/test/box/stat.result
@@ -1,3 +1,11 @@
+box.insert(box.schema.SPACE_ID, 0, 0, 'tweedledum')
+---
+- [0, 0, 'tweedledum']
+...
+box.insert(box.schema.INDEX_ID, 0, 0, 'primary', 'hash', 1, 1, 0, 'num')
+---
+- [0, 0, 'primary', 1752392040, 1, 1, 0, 'num']
+...
 #
 # check stat_cleanup
 #  add several tuples
@@ -23,15 +31,26 @@ insert into t0 values (8, 'tuple')
 Insert OK, 1 row affected
 insert into t0 values (9, 'tuple')
 Insert OK, 1 row affected
-show stat
+box.stat()
 ---
-statistics:
-  REPLACE:    { rps:  2    , total:  10          }
-  SELECT:     { rps:  0    , total:  0           }
-  UPDATE:     { rps:  0    , total:  0           }
-  DELETE_1_3: { rps:  0    , total:  0           }
-  DELETE:     { rps:  0    , total:  0           }
-  CALL:       { rps:  0    , total:  0           }
+- DELETE:
+    total: 0
+    rps: 0
+  SELECT:
+    total: 0
+    rps: 0
+  REPLACE:
+    total: 12
+    rps: 2
+  CALL:
+    total: 0
+    rps: 0
+  UPDATE:
+    total: 0
+    rps: 0
+  DELETE_1_3:
+    total: 0
+    rps: 0
 ...
 #
 # restart server
@@ -41,33 +60,27 @@ statistics:
 # statistics must be zero
 #
 
-show stat
+box.stat()
+---
+- DELETE:
+    total: 0
+    rps: 0
+  SELECT:
+    total: 0
+    rps: 0
+  REPLACE:
+    total: 0
+    rps: 0
+  CALL:
+    total: 0
+    rps: 0
+  UPDATE:
+    total: 0
+    rps: 0
+  DELETE_1_3:
+    total: 0
+    rps: 0
+...
+box.space[0]:drop()
 ---
-statistics:
-  REPLACE:    { rps:  0    , total:  0           }
-  SELECT:     { rps:  0    , total:  0           }
-  UPDATE:     { rps:  0    , total:  0           }
-  DELETE_1_3: { rps:  0    , total:  0           }
-  DELETE:     { rps:  0    , total:  0           }
-  CALL:       { rps:  0    , total:  0           }
 ...
-delete from t0 where k0 = 0
-Delete OK, 1 row affected
-delete from t0 where k0 = 1
-Delete OK, 1 row affected
-delete from t0 where k0 = 2
-Delete OK, 1 row affected
-delete from t0 where k0 = 3
-Delete OK, 1 row affected
-delete from t0 where k0 = 4
-Delete OK, 1 row affected
-delete from t0 where k0 = 5
-Delete OK, 1 row affected
-delete from t0 where k0 = 6
-Delete OK, 1 row affected
-delete from t0 where k0 = 7
-Delete OK, 1 row affected
-delete from t0 where k0 = 8
-Delete OK, 1 row affected
-delete from t0 where k0 = 9
-Delete OK, 1 row affected
diff --git a/test/box/stat.test.py b/test/box/stat.test.py
index 0184a4ce18..26fdb3a44c 100644
--- a/test/box/stat.test.py
+++ b/test/box/stat.test.py
@@ -2,6 +2,8 @@
 #
 # clear statistics
 server.restart()
+admin("box.insert(box.schema.SPACE_ID, 0, 0, 'tweedledum')")
+admin("box.insert(box.schema.INDEX_ID, 0, 0, 'primary', 'hash', 1, 1, 0, 'num')")
 
 print """#
 # check stat_cleanup
@@ -10,7 +12,7 @@ print """#
 """
 for i in range(10):
   sql("insert into t0 values ({0}, 'tuple')".format(i))
-admin("show stat")
+admin("box.stat()")
 print """#
 # restart server
 #
@@ -20,10 +22,9 @@ print """#
 # statistics must be zero
 #
 """
-admin("show stat")
+admin("box.stat()")
 
 # cleanup
-for i in range(10):
-  sql("delete from t0 where k0 = {0}".format(i))
+admin("box.space[0]:drop()")
 
 # vim: syntax=python
-- 
GitLab