// Get, Set, Del, Incr, ZGet, ZSet, ZDel, ZIncr func (c *Context) goOneOp(zop bool, cmd, tableId uint8, rowKey, colKey, value []byte, score int64, cas uint32, done chan *Call) (*Call, error) { call := c.cli.newCall(cmd, done) if call.err != nil { return call, call.err } var p proto.PkgOneOp p.Seq = call.seq p.DbId = c.dbId p.Cmd = call.cmd p.TableId = tableId p.RowKey = rowKey p.ColKey = colKey p.SetCas(cas) p.SetScore(score) p.SetValue(value) // ZGet, ZSet, ZDel, ZIncr if zop { p.PkgFlag |= proto.FlagZop } var pkgLen = p.Length() if pkgLen > proto.MaxPkgLen { c.cli.errCall(call, ErrInvPkgLen) return call, call.err } call.pkg = make([]byte, pkgLen) _, err := p.Encode(call.pkg) if err != nil { c.cli.errCall(call, err) return call, err } // put request pkg to sending channel c.cli.sending <- call return call, nil }
func TestTableGetCas(t *testing.T) { var in proto.PkgOneOp in.Cmd = proto.CmdGet in.DbId = 1 in.Seq = 10 in.KeyValue = getTestKV(2, []byte("row1"), []byte("col1"), []byte("v1"), 0, 2) out := myGet(in, testAuth, getTestWA(), t) if bytes.Compare(out.Value, []byte("v1")) != 0 { t.Fatalf("Value mismatch: %q", out.Value) } if out.Score != 30 { t.Fatalf("Score mismatch") } if out.Cas == 0 { t.Fatalf("Should return new cas") } // Set in.Cmd = proto.CmdSet in.SetValue(append(out.Value, []byte("-cas")...)) in.SetScore(32) in.SetCas(out.Cas) mySet(in, testAuth, getTestWA(), true, t) // Set again should fail mySet(in, testAuth, getTestWA(), false, t) // Get in.Cmd = proto.CmdGet in.Cas = 0 in.CtrlFlag &^= 0xFF out = myGet(in, testAuth, getTestWA(), t) if bytes.Compare(out.Value, []byte("v1-cas")) != 0 { t.Fatalf("Value mismatch: %q", out.Value) } if out.Score != 32 { t.Fatalf("Score mismatch") } }