Beispiel #1
0
func (a *Ins) Put(topicName string, msgs []*message.Ins) (int, error) {
	var err rpc.PutError
	a.doReq(rpc.MPut, []rpc.Item{
		rpc.NewString(topicName),
		rpc.NewMsgs(msgs),
	}, rpc.NewStruct(&err))
	return err.N, err.Err
}
Beispiel #2
0
func (a *Ins) Get(topicName string, offset int64, size int) error {
	var err rpc.Error
	a.doReq(rpc.MGet, []rpc.Item{
		rpc.NewString(topicName),
		rpc.NewInt64(uint64(offset)),
		rpc.NewInt64(uint64(size)),
	}, &err)
	return err.Err()
}
Beispiel #3
0
// make a new one if not found
// TODO: there is two locks here
func (i *Ins) findIno(name string, blkBit uint) *Inode {
	ino, _ := NewInode(rpc.NewString(name), blkBit)
	off := i.cp.GetInoOffset(name)
	if off > 0 {
		err := ino.PRead(utils.NewBufio(utils.NewReader(i.rfd, off)))
		if err != nil {
			logex.Error(err)
		}
	}
	return ino
}
Beispiel #4
0
func (a *Ins) Delete(topicName string) error {
	perr := rpc.NewError(nil)
	a.doReq(rpc.MDelete, []rpc.Item{
		rpc.NewString(topicName),
	}, perr)
	err := perr.Err()
	if err == nil {
		return nil
	}
	if err.Error() == ErrTopicNotFound.Error() {
		err = ErrTopicNotFound.Trace()
	}
	return err
}
Beispiel #5
0
func BenchmarkApiPing(b *testing.B) {
	que, ln := runServer(b)
	defer closeServer(que, ln)
	payload := rpc.NewString(strings.Repeat("h", 40000))

	api, err := New(addr)
	if err != nil {
		b.Fatal(err)
	}
	defer api.Close()

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		api.Ping(payload)
	}
	b.StopTimer()

}
Beispiel #6
0
func TestInode(t *testing.T) {
	var err error
	defer utils.TDefer(t, &err)
	InoName := rpc.NewString("inode")
	bit := uint(4)

	ino, err := NewInode(InoName, bit)
	if err != nil {
		return
	}

	if ino.blkSize != 1<<4 {
		err = logex.NewError("blkSize not expect")
		return
	}

	ino.ExtBlks(0, 12*(1<<4))
	if ino.blkOff != 12 {
		err = logex.Define("block size not expect")
		return
	}

	buf := bytes.NewBuffer(nil)
	if err = ino.PWrite(buf); err != nil {
		return
	}

	ino2, err := ReadInode(buf, bit)
	if err != nil {
		return
	}
	if !reflect.DeepEqual(ino, ino2) {
		err = logex.Define("ino not expect")
		return
	}

	err = nil
	return
}