Makes get fail a transaction if the key doesn't exist.

pull/2028/head
James Phillips 9 years ago
parent 4882a9fe43
commit 04d99cd702

@ -484,11 +484,12 @@ func TestClient_Txn(t *testing.T) {
t.Fatalf("transaction should have failed") t.Fatalf("transaction should have failed")
} }
if ret == nil || len(ret.Errors) != 1 || len(ret.Results) != 0 { if ret == nil || len(ret.Errors) != 2 || len(ret.Results) != 0 {
t.Fatalf("bad: %v", ret) t.Fatalf("bad: %v", ret)
} }
if ret.Errors[0].OpIndex != 0 || if ret.Errors[0].OpIndex != 0 ||
!strings.Contains(ret.Errors[0].What, "missing session") { !strings.Contains(ret.Errors[0].What, "missing session") ||
!strings.Contains(ret.Errors[1].What, "doesn't exist") {
t.Fatalf("bad: %v", ret.Errors[0]) t.Fatalf("bad: %v", ret.Errors[0])
} }

@ -55,6 +55,9 @@ func (s *StateStore) txnKVS(tx *memdb.Txn, idx uint64, op *structs.TxnKVOp) (str
case structs.KVSGet: case structs.KVSGet:
_, entry, err = s.kvsGetTxn(tx, op.DirEnt.Key) _, entry, err = s.kvsGetTxn(tx, op.DirEnt.Key)
if entry == nil && err == nil {
err = fmt.Errorf("key %q doesn't exist", op.DirEnt.Key)
}
case structs.KVSCheckSession: case structs.KVSCheckSession:
entry, err = s.kvsCheckSessionTxn(tx, op.DirEnt.Key, op.DirEnt.Session) entry, err = s.kvsCheckSessionTxn(tx, op.DirEnt.Key, op.DirEnt.Session)

@ -102,14 +102,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
}, },
}, },
}, },
&structs.TxnOp{
KV: &structs.TxnKVOp{
Verb: structs.KVSGet,
DirEnt: structs.DirEntry{
Key: "not/there",
},
},
},
&structs.TxnOp{ &structs.TxnOp{
KV: &structs.TxnKVOp{ KV: &structs.TxnKVOp{
Verb: structs.KVSCheckIndex, Verb: structs.KVSCheckIndex,
@ -121,14 +113,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
}, },
}, },
}, },
&structs.TxnOp{
KV: &structs.TxnKVOp{
Verb: structs.KVSGet,
DirEnt: structs.DirEntry{
Key: "foo/lock",
},
},
},
&structs.TxnOp{ &structs.TxnOp{
KV: &structs.TxnKVOp{ KV: &structs.TxnKVOp{
Verb: structs.KVSLock, Verb: structs.KVSLock,
@ -227,7 +211,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
}, },
}, },
}, },
&structs.TxnResult{}, // get on not/there
&structs.TxnResult{ &structs.TxnResult{
KV: &structs.DirEntry{ KV: &structs.DirEntry{
Key: "foo/update", Key: "foo/update",
@ -237,7 +220,6 @@ func TestStateStore_Txn_KVS(t *testing.T) {
}, },
}, },
}, },
&structs.TxnResult{}, // get on foo/lock before it's created
&structs.TxnResult{ &structs.TxnResult{
KV: &structs.DirEntry{ KV: &structs.DirEntry{
Key: "foo/lock", Key: "foo/lock",
@ -449,6 +431,14 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) {
}, },
}, },
}, },
&structs.TxnOp{
KV: &structs.TxnKVOp{
Verb: structs.KVSGet,
DirEnt: structs.DirEntry{
Key: "nope",
},
},
},
&structs.TxnOp{ &structs.TxnOp{
KV: &structs.TxnKVOp{ KV: &structs.TxnKVOp{
Verb: structs.KVSCheckSession, Verb: structs.KVSCheckSession,
@ -505,6 +495,7 @@ func TestStateStore_Txn_KVS_Rollback(t *testing.T) {
"lock isn't held, or is held by another session", "lock isn't held, or is held by another session",
"current session", "current session",
`key "nope" doesn't exist`, `key "nope" doesn't exist`,
`key "nope" doesn't exist`,
"current modify index", "current modify index",
`key "nope" doesn't exist`, `key "nope" doesn't exist`,
"unknown KV verb", "unknown KV verb",

Loading…
Cancel
Save