From 201abebd9c23bac3991965445cea8384117a003d Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Sun, 1 Sep 2013 01:04:54 +0400 Subject: [PATCH] Add basic test coverage for create/drop/alter space. --- test/box/alter.result | 183 ++++++++++++++++++++++++++++++++++++++++ test/box/alter.test.lua | 69 +++++++++++++++ 2 files changed, 252 insertions(+) create mode 100644 test/box/alter.result create mode 100644 test/box/alter.test.lua diff --git a/test/box/alter.result b/test/box/alter.result new file mode 100644 index 0000000000..7d78da47fb --- /dev/null +++ b/test/box/alter.result @@ -0,0 +1,183 @@ +_space = box.space[box.schema.SPACE_ID] +--- +... +_index = box.space[box.schema.INDEX_ID] +--- +... +-- +-- Test insertion into a system space - verify that +-- mandatory fields are required. +-- +_space:insert(_space.n, 5, 'test') +--- +- error: Duplicate key exists in unique index 0 +... +-- +-- Bad space id +-- +_space:insert('hello', 'world', 'test') +--- +- error: 'Tuple field 0 type does not match one required by operation: expected NUM' +... +-- +-- Can't create a space which has wrong arity - arity must be NUM +-- +_space:insert(_space.n, 'world', 'test') +--- +- error: Duplicate key exists in unique index 0 +... +-- +-- There is already a tuple for the system space +-- +_space:insert(_space.n, 0, '_space') +--- +- error: Duplicate key exists in unique index 0 +... +_space:replace(_space.n, 0, '_space') +--- +- [280, 0, '_space'] +... +_space:insert(_index.n, 0, '_index') +--- +- error: Duplicate key exists in unique index 0 +... +_space:replace(_index.n, 0, '_index') +--- +- [288, 0, '_index'] +... +-- +-- Can't change properties of a space +-- +_space:replace(_space.n, 0, '_space') +--- +- [280, 0, '_space'] +... +-- +-- # Can't drop a system space +-- +_space:delete(_space.n) +--- +- error: 'Can''t drop space 280: the space has indexes' +... +_space:delete(_index.n) +--- +- error: 'Can''t drop space 288: the space has indexes' +... +-- +-- Can't change properties of a space +-- +_space:update(_space.n, '+p', 0, 1) +--- +- error: 'Can''t modify space 280: space id is immutable' +... +_space:update(_space.n, '+p', 0, 2) +--- +- error: 'Can''t modify space 280: space id is immutable' +... +-- +-- Create a space +-- +t = box.auto_increment(_space.n, 0, 'hello') +--- +... +-- # Check that a space exists +space = box.space[box.unpack('i', t[0])] +--- +... +space.n +--- +- 289 +... +space.arity +--- +- 0 +... +space.index[0] +--- +{} +... +-- +-- check dml - the space has no indexes yet, but must not crash on DML +-- +space:select(0, 0) +--- +- error: 'No index #0 is defined in space 289' +... +space:insert(0, 0) +--- +- error: 'No index #0 is defined in space 289' +... +space:replace(0, 0) +--- +- error: 'No index #0 is defined in space 289' +... +space:update(0, '+p', 0, 1) +--- +- error: 'No index #0 is defined in space 289' +... +space:delete(0) +--- +- error: 'No index #0 is defined in space 289' +... +t = _space:delete(space.n) +--- +... +space_deleted = box.space[box.unpack('i', t[0])] +--- +... +space_deleted +--- +{} +... +space:replace(0) +--- +- error: Space 289 does not exist +... +_index:insert(_space.n, 0, 'primary', 'tree', 1, 1, 0, 'num') +--- +- error: Duplicate key exists in unique index 0 +... +_index:replace(_space.n, 0, 'primary', 'tree', 1, 1, 0, 'num') +--- +- [280, 0, 'primary', 1701147252, 1, 1, 0, 'num'] +... +_index:insert(_index.n, 0, 'primary', 'tree', 1, 2, 0, 'num', 1, 'num') +--- +- error: Duplicate key exists in unique index 0 +... +_index:replace(_index.n, 0, 'primary', 'tree', 1, 2, 0, 'num', 1, 'num') +--- +- [288, 0, 'primary', 1701147252, 1, 2, 0, 'num', 1, 'num'] +... +_index:select(0) +--- +- [272, 0, 'primary', 1701147252, 1, 1, 0, 'str'] +- [280, 0, 'primary', 1701147252, 1, 1, 0, 'num'] +- [280, 1, 1701667182, 1701147252, 1, 1, 2, 'str'] +- [288, 0, 'primary', 1701147252, 1, 2, 0, 'num', 1, 'num'] +- [288, 1, 1701667182, 1701147252, 1, 2, 0, 'num', 2, 'str'] +... +-- # modify indexes of a system space +_index:delete(_index.n, 0) +--- +- error: Can't drop the primary key in a system space, space id 288 +... +_space:insert(1000, 0, 'hello') +--- +- [1000, 0, 'hello'] +... +_index:insert(1000, 0, 'primary', 'tree', 1, 1, 0, 'num') +--- +- [1000, 0, 'primary', 1701147252, 1, 1, 0, 'num'] +... +box.space[1000]:insert(0, 'hello, world') +--- +- [0, 'hello, world'] +... +box.space[1000]:drop() +--- +... +box.space[1000] +--- +{} +... diff --git a/test/box/alter.test.lua b/test/box/alter.test.lua new file mode 100644 index 0000000000..861e164fc1 --- /dev/null +++ b/test/box/alter.test.lua @@ -0,0 +1,69 @@ +_space = box.space[box.schema.SPACE_ID] +_index = box.space[box.schema.INDEX_ID] +-- +-- Test insertion into a system space - verify that +-- mandatory fields are required. +-- +_space:insert(_space.n, 5, 'test') +-- +-- Bad space id +-- +_space:insert('hello', 'world', 'test') +-- +-- Can't create a space which has wrong arity - arity must be NUM +-- +_space:insert(_space.n, 'world', 'test') +-- +-- There is already a tuple for the system space +-- +_space:insert(_space.n, 0, '_space') +_space:replace(_space.n, 0, '_space') +_space:insert(_index.n, 0, '_index') +_space:replace(_index.n, 0, '_index') +-- +-- Can't change properties of a space +-- +_space:replace(_space.n, 0, '_space') +-- +-- # Can't drop a system space +-- +_space:delete(_space.n) +_space:delete(_index.n) +-- +-- Can't change properties of a space +-- +_space:update(_space.n, '+p', 0, 1) +_space:update(_space.n, '+p', 0, 2) +-- +-- Create a space +-- +t = box.auto_increment(_space.n, 0, 'hello') +-- # Check that a space exists +space = box.space[box.unpack('i', t[0])] +space.n +space.arity +space.index[0] +-- +-- check dml - the space has no indexes yet, but must not crash on DML +-- +space:select(0, 0) +space:insert(0, 0) +space:replace(0, 0) +space:update(0, '+p', 0, 1) +space:delete(0) +t = _space:delete(space.n) +space_deleted = box.space[box.unpack('i', t[0])] +space_deleted +space:replace(0) +_index:insert(_space.n, 0, 'primary', 'tree', 1, 1, 0, 'num') +_index:replace(_space.n, 0, 'primary', 'tree', 1, 1, 0, 'num') +_index:insert(_index.n, 0, 'primary', 'tree', 1, 2, 0, 'num', 1, 'num') +_index:replace(_index.n, 0, 'primary', 'tree', 1, 2, 0, 'num', 1, 'num') +_index:select(0) +-- # modify indexes of a system space +_index:delete(_index.n, 0) +_space:insert(1000, 0, 'hello') +_index:insert(1000, 0, 'primary', 'tree', 1, 1, 0, 'num') +box.space[1000]:insert(0, 'hello, world') +box.space[1000]:drop() +box.space[1000] -- GitLab