MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / WriteDirect

Function WriteDirect

db/util_testing.go:731–773  ·  view source on GitHub ↗

WriteDirect will write a document named doc-{sequence} with a given set of channels. This is used to simulate out of order sequence writes by bypassing typical Sync Gateway CRUD functions.

(t *testing.T, collection *DatabaseCollection, channelArray []string, sequence uint64)

Source from the content-addressed store, hash-verified

729
730// WriteDirect will write a document named doc-{sequence} with a given set of channels. This is used to simulate out of order sequence writes by bypassing typical Sync Gateway CRUD functions.
731func WriteDirect(t *testing.T, collection *DatabaseCollection, channelArray []string, sequence uint64) {
732 key := fmt.Sprintf("doc-%v", sequence)
733
734 rev := "1-a"
735 chanMap := make(map[string]*channels.ChannelRemoval, 10)
736 chanSetMap := base.Set{}
737
738 for _, channel := range channelArray {
739 chanMap[channel] = nil
740 chanSetMap[channel] = struct{}{}
741 }
742
743 revInf := RevInfo{
744 ID: rev,
745 Channels: chanSetMap,
746 }
747 revTree := RevTree{
748 rev: &revInf,
749 }
750
751 syncData := &SyncData{
752 RevAndVersion: channels.RevAndVersion{
753 RevTreeID: rev,
754 },
755 Sequence: sequence,
756 Channels: chanMap,
757 TimeSaved: time.Now(),
758 History: revTree,
759 }
760 body := fmt.Sprintf(`{"key": "%s"}`, key)
761 if base.TestUseXattrs() {
762
763 opts := &sgbucket.MutateInOptions{
764 MacroExpansion: macroExpandSpec(base.SyncXattrName),
765 }
766 ctx := base.TestCtx(t)
767 _, err := collection.dataStore.WriteWithXattrs(ctx, key, 0, 0, []byte(body), map[string][]byte{base.SyncXattrName: base.MustJSONMarshal(t, syncData)}, nil, opts)
768 require.NoError(t, err)
769 } else {
770 _, err := collection.dataStore.Add(key, 0, base.MustJSONMarshal(t, Body{base.SyncPropertyName: syncData, "key": key}))
771 require.NoError(t, err)
772 }
773}
774
775// GetIndexPartitionCount returns the number of partitions for a given index. This function queries index nodes directly and would not be suitable for production use, since this port is not generally accessible.
776func GetIndexPartitionCount(t testing.TB, bucket *base.GocbV2Bucket, dsName sgbucket.DataStoreName, indexName string) uint32 {

Calls 6

TestUseXattrsFunction · 0.92
TestCtxFunction · 0.92
MustJSONMarshalFunction · 0.92
macroExpandSpecFunction · 0.85
WriteWithXattrsMethod · 0.45
AddMethod · 0.45