Пример #1
0
func TestTableDump(t *testing.T) {
	// Dump
	var in proto.PkgDumpReq
	in.Cmd = proto.CmdDump
	in.DbId = 2
	in.Seq = 20
	in.TableId = 2
	in.PkgFlag |= proto.FlagDumpSlotStart
	in.StartSlotId = 0
	in.EndSlotId = 65535

	out := myDump(in, testAuth, t)
	if len(out.Kvs) != 10 {
		t.Fatalf("Invalid KV number: %d", len(out.Kvs))
	}
	if out.PkgFlag&proto.FlagDumpEnd == 0 {
		t.Fatalf("Dump should end")
	}
	for i := 0; i < len(out.Kvs); i++ {
		j := i
		idx := 4 - i
		if i >= 5 {
			j = i - 5
			idx = 9 - i
		}

		if out.Kvs[i].ErrCode != 0 {
			t.Fatalf("ErrCode is 0")
		}
		if out.Kvs[i].TableId != 2 {
			t.Fatalf("TableId mismatch")
		}

		if bytes.Compare(out.Kvs[i].RowKey, []byte("row2")) == 0 {
			if bytes.Compare(out.Kvs[i].ColKey, []byte(fmt.Sprintf("col%d", idx))) != 0 {
				t.Fatalf("ColKey mismatch")
			}
			if out.Kvs[i].Score != int64(j*10) {
				t.Fatalf("Score mismatch")
			}
			if bytes.Compare(out.Kvs[i].Value, []byte(fmt.Sprintf("v%d", idx))) != 0 {
				t.Fatalf("Value mismatch")
			}
		} else {
			if bytes.Compare(out.Kvs[i].RowKey, []byte("row1")) != 0 {
				t.Fatalf("RowKey mismatch")
			}
			if bytes.Compare(out.Kvs[i].ColKey, []byte(fmt.Sprintf("col%d", j))) != 0 {
				t.Fatalf("ColKey mismatch")
			}
			if out.Kvs[i].Score != int64(j*10+10) {
				t.Fatalf("Score mismatch")
			}
			if bytes.Compare(out.Kvs[i].Value, []byte(fmt.Sprintf("v%d", j))) != 0 {
				t.Fatalf("Value mismatch")
			}
		}
	}
}
Пример #2
0
func (c *Context) goDump(oneTable bool, tableId, colSpace uint8,
	rowKey, colKey []byte, score int64, startSlotId, endSlotId uint16,
	done chan *Call) (*Call, error) {
	call := c.cli.newCall(proto.CmdDump, done)
	if call.err != nil {
		return call, call.err
	}

	var p proto.PkgDumpReq
	p.Seq = call.seq
	p.DbId = c.dbId
	p.Cmd = call.cmd
	if oneTable {
		p.PkgFlag |= proto.FlagDumpTable
	}
	p.StartSlotId = startSlotId
	p.EndSlotId = endSlotId
	p.TableId = tableId
	p.RowKey = rowKey
	p.ColKey = colKey
	p.SetColSpace(colSpace)
	p.SetScore(score)

	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
	}

	call.ctx = dumpContext{oneTable, tableId,
		startSlotId, endSlotId, startSlotId, false}

	c.cli.sending <- call

	return call, nil
}