1# The include statement below is a temp one for tests that are yet to 2#be ported to run with InnoDB, 3#but needs to be kept for tests that would need MyISAM in future. 4--source include/force_myisam_default.inc 5 6################################################################ 7# Test access via unique index 8# 9# Write-access via unique index is subject to some restrictions: 10# 11# (1) Inserts are not allowed; they will fail with NOT_FOUND 12# (2) Updates that do not contain the PK column are allowed 13# (3) Updates that contain the PK column are allowed if the PK value 14# does not change, but attempts to change the PK fail with NOT_STORED. 15 16--source include/have_ndb.inc 17--source suite/ndb_memcache/include/have_memcache.inc 18--source suite/ndb_memcache/include/memcached_wait_for_ready.inc 19--source suite/ndb_memcache/include/misc_tables.inc 20 21--perl 22 23use strict; 24use Carp; 25use lib "lib"; 26use My::Memcache; 27 28my $port = $ENV{NDB_MEMCACHED_1_PORT} or die "Need NDB_MEMCACHED_1_PORT"; 29 30my $mc = My::Memcache->new(); 31my $r = $mc->connect("localhost",$port); 32 33# 1: SET on primary key 34$mc->set("tup:1","key1\tSuperbe!") || $mc->fail("Failed test 1.A"); 35$mc->set("tup:2","key2\tIncroyable!") || $mc->fail("Failed test 1.B"); 36$mc->set("tup:3","key3\tTres bien fait"); 37$mc->set("tup:4","key4\tPas mal"); 38 39# 2: GET on primary key 40($mc->get("tup:1") == "key1\tSuperbe!") || $mc->fail("Failed test 2.A"); 41($mc->get("tup:2") == "key2\tIncroyable!")|| $mc->fail("Failed test 2.B"); 42 43# 3: GET via unique key (two value columns) 44($mc->get("tur:key1") == "1\tSuperbe!") || $mc->fail("Failed test 3."); 45 46# 4: GET via unique key (one value column) 47($mc->get("tui:key2") == "Incroyable!") || $mc->fail("Failed test 4."); 48 49# 5. SET via unique key (one value column, not part of primary key) 50$mc->set("tui:key3", "Assez bien") || $mc->fail("Failed test 5.A"); 51$mc->set("tui:key4", "Pas trop mal...") || $mc->fail("Failed test 5.B"); 52 53# 6. REPLACE via unique key (one value column, not part of primary key) 54$mc->replace("tui:key2", "Passable") || $mc->fail("Failed test 6"); 55 56# 7. Inserts via unique key access fail with NOT_FOUND: 57# (A) SET 58($mc->set("tui:key5", "rien") == 0) || $mc->fail("Test 7.A SET should fail"); 59($mc->{error} =~ "NOT_FOUND") || $mc->fail("Test 7.A expected NOT_FOUND"); 60 61# (B) ADD 62($mc->add("tui:key6", "rien") == 0) || $mc->fail("Test 7.B ADD should fail"); 63($mc->{error} =~ "NOT_FOUND") || $mc->fail("Test 7.B expected NOT_FOUND"); 64 65# 8. Update via unique key succeeds if PK is equal to old PK 66$mc->set("tur:key1", "1\tQuotidien") || $mc->fail("Failed test 8.A"); 67($mc->get("tui:key1") == "Quotidien") || $mc->fail("Failed test 8.B"); 68 69# 9. Attempt to change PK fails with NOT_STORED 70($mc->set("tur:key3", "5\tJamais!") == 0) || $mc->fail("Test 9 SET should fail."); 71($mc->{error} =~ "NOT_STORED") || $mc->fail("Test 9 expected NOT_STORED"); 72 73# 10. This is the final test in the ndb_memcache suite; send a "stats errors" 74# request so that the server will flush its log file. 75$mc->stats("errors"); 76 77EOF 78 79# At the end of the test the values should be 80# 1 Quotidien 81# 2 Passable 82# 3 Assez bien 83# 4 Pas trop mal... 84 85 86--sorted_result 87SELECT * FROM ndbmemcache.test_unique_idx; 88DELETE FROM ndbmemcache.test_unique_idx; 89 90