Esempio n. 1
0
func TestTableDel(t *testing.T) {
	var in proto.PkgOneOp
	in.Cmd = proto.CmdSet
	in.DbId = 1
	in.Seq = 10
	in.KeyValue = getTestKV(2, []byte("row1"), []byte("col1"), nil, 0, 0)

	myDel(in, testAuth, getTestWA(), true, t)
}
Esempio n. 2
0
func TestTableSetCas(t *testing.T) {
	var in proto.PkgOneOp
	in.Cmd = proto.CmdSet
	in.DbId = 1
	in.Seq = 10
	in.KeyValue = getTestKV(2, []byte("row1"), []byte("col1"), []byte("v1"), 30, 600)

	out := mySet(in, testAuth, getTestWA(), false, t)
	if out.ErrCode != table.EcCasNotMatch {
		t.Fatalf("Should fail with EcCasNotMatch")
	}
}
Esempio n. 3
0
func TestTableIncr(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"), nil, -21, 0)

	out := myIncr(in, testAuth, getTestWA(), true, t)
	if len(out.Value) != 0 {
		t.Fatalf("Value mismatch: %q", out.Value)
	}
	if out.Score != -21 {
		t.Fatalf("Score mismatch")
	}
}
Esempio n. 4
0
func TestTableGet(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"), nil, 0, 0)

	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")
	}
}
Esempio n. 5
0
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")
	}
}
Esempio n. 6
0
func TestTableZopSetGet(t *testing.T) {
	var in proto.PkgOneOp
	in.PkgFlag |= proto.FlagZop
	in.Cmd = proto.CmdSet
	in.DbId = 1
	in.Seq = 10
	in.KeyValue = getTestKV(2, []byte("row1"), []byte("col1"), []byte("v1"), 30, 0)

	// ZSET
	mySet(in, testAuth, getTestWA(), true, t)

	// ZGET
	in.Cmd = proto.CmdGet
	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")
	}
}