Пример #1
0
// OrderTest tests the ordering of the streamed entries while reading from the
// CreateFunc created graphstore.Service.
func OrderTest(t *testing.T, create CreateFunc, batchSize int) {
	gs, destroy, err := create()
	testutil.FatalOnErrT(t, "CreateFunc error: %v", err)
	defer func() {
		testutil.FatalOnErrT(t, "gs close error: %v", gs.Close(ctx))
		testutil.FatalOnErrT(t, "DestroyFunc error: %v", destroy())
	}()

	updates := make([]spb.WriteRequest_Update, batchSize)
	req := &spb.WriteRequest{
		Source: &spb.VName{},
		Update: make([]*spb.WriteRequest_Update, batchSize),
	}
	for i := 0; i < 1024; i++ {
		randVName(req.Source, keySize)

		for j := 0; j < batchSize; j++ {
			randUpdate(&updates[j], keySize)
			req.Update[j] = &updates[j]
		}

		testutil.FatalOnErrT(t, "write error: %v", gs.Write(ctx, req))
	}

	var lastEntry *spb.Entry
	testutil.FatalOnErrT(t, "entryLess error: %v",
		gs.Scan(ctx, new(spb.ScanRequest), func(entry *spb.Entry) error {
			if compare.Entries(lastEntry, entry) != compare.LT {
				return fmt.Errorf("expected {%v} < {%v}", lastEntry, entry)
			}
			return nil
		}))
}
Пример #2
0
func dedupEntries(rd stream.EntryReader) stream.EntryReader {
	return func(f func(*spb.Entry) error) error {
		var last *spb.Entry
		return rd(func(e *spb.Entry) error {
			if compare.Entries(last, e) != compare.EQ {
				last = e
				return f(e)
			}
			return nil
		})
	}
}
Пример #3
0
func (s *GraphStore) insert(e *spb.Entry) {
	i := sort.Search(len(s.entries), func(i int) bool {
		return compare.Entries(e, s.entries[i]) == compare.LT
	})
	if i == len(s.entries) {
		s.entries = append(s.entries, e)
	} else if i < len(s.entries) && compare.EntriesEqual(e, s.entries[i]) {
		s.entries[i] = e
	} else if i == 0 {
		s.entries = append([]*spb.Entry{e}, s.entries...)
	} else {
		s.entries = append(s.entries[:i], append([]*spb.Entry{e}, s.entries[i:]...)...)
	}
}
Пример #4
0
func (entryLesser) Less(a, b interface{}) bool {
	return compare.Entries(a.(*spb.Entry), b.(*spb.Entry)) == compare.LT
}