polardbxengine/mysql-test/suite/ndb_memcache/t/unique_idx.test

84 lines
2.9 KiB
Plaintext

################################################################
# Test access via unique index
#
# Write-access via unique index is subject to some restrictions:
#
# (1) Inserts are not allowed; they will fail with NOT_FOUND
# (2) Updates that do not contain the PK column are allowed
# (3) Updates that contain the PK column are allowed if the PK value
# does not change, but attempts to change the PK fail with NOT_STORED.
--source include/have_ndb.inc
--source suite/ndb_memcache/include/have_memcache.inc
--source suite/ndb_memcache/include/misc_tables.inc
--perl
use strict;
use Carp;
use lib "lib";
use My::Memcache;
my $port = $ENV{NDB_MEMCACHED_1_PORT} or die "Need NDB_MEMCACHED_1_PORT";
my $mc = My::Memcache->new();
my $r = $mc->connect("localhost",$port);
# 1: SET on primary key
$mc->set("tup:1","key1\tSuperbe!") || $mc->fail("Failed test 1.A");
$mc->set("tup:2","key2\tIncroyable!") || $mc->fail("Failed test 1.B");
$mc->set("tup:3","key3\tTres bien fait");
$mc->set("tup:4","key4\tPas mal");
# 2: GET on primary key
($mc->get("tup:1") == "key1\tSuperbe!") || $mc->fail("Failed test 2.A");
($mc->get("tup:2") == "key2\tIncroyable!")|| $mc->fail("Failed test 2.B");
# 3: GET via unique key (two value columns)
($mc->get("tur:key1") == "1\tSuperbe!") || $mc->fail("Failed test 3.");
# 4: GET via unique key (one value column)
($mc->get("tui:key2") == "Incroyable!") || $mc->fail("Failed test 4.");
# 5. SET via unique key (one value column, not part of primary key)
$mc->set("tui:key3", "Assez bien") || $mc->fail("Failed test 5.A");
$mc->set("tui:key4", "Pas trop mal...") || $mc->fail("Failed test 5.B");
# 6. REPLACE via unique key (one value column, not part of primary key)
$mc->replace("tui:key2", "Passable") || $mc->fail("Failed test 6");
# 7. Inserts via unique key access fail with NOT_FOUND:
# (A) SET
($mc->set("tui:key5", "rien") == 0) || $mc->fail("Test 7.A SET should fail");
($mc->{error} =~ "NOT_FOUND") || $mc->fail("Test 7.A expected NOT_FOUND");
# (B) ADD
($mc->add("tui:key6", "rien") == 0) || $mc->fail("Test 7.B ADD should fail");
($mc->{error} =~ "NOT_FOUND") || $mc->fail("Test 7.B expected NOT_FOUND");
# 8. Update via unique key succeeds if PK is equal to old PK
$mc->set("tur:key1", "1\tQuotidien") || $mc->fail("Failed test 8.A");
($mc->get("tui:key1") == "Quotidien") || $mc->fail("Failed test 8.B");
# 9. Attempt to change PK fails with NOT_STORED
($mc->set("tur:key3", "5\tJamais!") == 0) || $mc->fail("Test 9 SET should fail.");
($mc->{error} =~ "NOT_STORED") || $mc->fail("Test 9 expected NOT_STORED");
# 10. This is the final test in the ndb_memcache suite; send a "stats errors"
# request so that the server will flush its log file.
$mc->stats("errors");
EOF
# At the end of the test the values should be
# 1 Quotidien
# 2 Passable
# 3 Assez bien
# 4 Pas trop mal...
--sorted_result
SELECT * FROM ndbmemcache.test_unique_idx;
DELETE FROM ndbmemcache.test_unique_idx;