Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion db/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ func (db *DatabaseCollectionWithUser) AddDocInstanceToChangeEntry(ctx context.Co
}
if options.IncludeDocs {
var err error
// TODO: CBG-4776 - fetch by CV with sane APIs
err = db.AddDocToChangeEntryUsingRevCache(ctx, entry, revID)
if err != nil {
base.WarnfCtx(ctx, "Changes feed: error getting revision body for %q (%s): %v", base.UD(entry.ID), revID, err)
Expand Down
2 changes: 1 addition & 1 deletion rest/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ func TestAllDocsCV(t *testing.T) {
defer rt.Close()

const docID = "foo"
docVersion := rt.PutDocDirectly(docID, db.Body{"foo": "bar"})
docVersion := rt.PutDoc(docID, `{"foo": "bar"}`)

testCases := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion rest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ func TestPvDeltaReadAndWrite(t *testing.T) {
version1, _ := rt.GetDoc(docID)

// update the above doc, this should push CV to PV and adds a new CV
version2 := rt.UpdateDocDirectly(docID, version1, db.Body{"new": "update!"})
version2 := rt.UpdateDoc(docID, version1, `{"new": "update!"}`)
newDoc, _, err := collection.GetDocWithXattrs(ctx, existingHLVKey, db.DocUnmarshalAll)
require.NoError(t, err)
casV2 := newDoc.Cas
Expand Down
11 changes: 5 additions & 6 deletions rest/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2320,8 +2320,8 @@ func TestUpdateExistingAttachment(t *testing.T) {
btcRunner.StartPull(btc.id)
btcRunner.StartPush(btc.id)

doc1Version := rt.PutDocDirectly(doc1ID, db.Body{})
doc2Version := rt.PutDocDirectly(doc2ID, db.Body{})
doc1Version := rt.PutDoc(doc1ID, `{}`)
doc2Version := rt.PutDoc(doc2ID, `{}`)

btcRunner.WaitForVersion(btc.id, doc1ID, doc1Version)
btcRunner.WaitForVersion(btc.id, doc2ID, doc2Version)
Expand Down Expand Up @@ -2375,7 +2375,7 @@ func TestPushUnknownAttachmentAsStub(t *testing.T) {
btcRunner.StartPush(btc.id)

// Add doc1
doc1Version := rt.PutDocDirectly(doc1ID, db.Body{})
doc1Version := rt.PutDoc(doc1ID, `{}`)

btcRunner.WaitForVersion(btc.id, doc1ID, doc1Version)

Expand Down Expand Up @@ -2587,9 +2587,8 @@ func TestCBLRevposHandling(t *testing.T) {
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, nil)
defer btc.Close()

startingBody := db.Body{"foo": "bar"}
doc1Version1 := rt.PutDocDirectly(doc1ID, startingBody)
doc2Version1 := rt.PutDocDirectly(doc2ID, startingBody)
doc1Version1 := rt.PutDoc(doc1ID, `{"foo": "bar"}`)
doc2Version1 := rt.PutDoc(doc2ID, `{"foo": "bar"}`)

rt.WaitForPendingChanges()
btcRunner.StartOneshotPull(btc.id)
Expand Down
6 changes: 3 additions & 3 deletions rest/blip_api_collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func TestCollectionsReplication(t *testing.T) {
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, nil)
defer btc.Close()

version := btc.rt.PutDocDirectly(docID, db.Body{})
version := btc.rt.PutDoc(docID, `{}`)

btc.rt.WaitForPendingChanges()
btcRunner.StartOneshotPull(btc.id)
Expand All @@ -279,7 +279,7 @@ func TestBlipReplicationMultipleCollections(t *testing.T) {
body := `{"foo":"bar"}`
versions := make([]DocVersion, 0, len(btc.rt.GetKeyspaces()))
for _, collection := range btc.rt.GetDbCollections() {
docVersion := rt.PutDocDirectlyInCollection(collection, docName, db.Body{"foo": "bar"})
docVersion := rt.PutDocInCollection(collection.Name, docName, `{"foo": "bar"}`)
versions = append(versions, docVersion)
}
btc.rt.WaitForPendingChanges()
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestBlipReplicationMultipleCollectionsMismatchedDocSizes(t *testing.T) {
blipName := btc.rt.getCollectionsForBLIP()[i]
for j := 0; j < docCount; j++ {
docName := fmt.Sprintf("doc%d", j)
version := rt.PutDocDirectlyInCollection(collection, docName, db.Body{"foo": "bar"})
version := rt.PutDocInCollection(collection.Name, docName, `{"foo": "bar"}`)

collectionVersions[blipName] = append(collectionVersions[blipName], version)
collectionDocIDs[blipName] = append(collectionDocIDs[blipName], docName)
Expand Down
59 changes: 29 additions & 30 deletions rest/blip_api_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ func TestSendReplacementRevision(t *testing.T) {
rt.CreateUser(alice, userChannels)

docID := test.name
version1 := rt.PutDocDirectly(docID, JsonToMap(t, fmt.Sprintf(`{"foo":"bar","channels":["%s"]}`, rev1Channel)))
version1 := rt.PutDoc(docID, fmt.Sprintf(`{"foo":"bar","channels":["%s"]}`, rev1Channel))
updatedVersion := make(chan DocVersion)
collection, ctx := rt.GetSingleTestDatabaseCollection()

Expand Down Expand Up @@ -2110,13 +2110,13 @@ func TestBlipPullRevMessageHistory(t *testing.T) {

const docID = "doc1"
// create doc1 rev 1-0335a345b6ffed05707ccc4cbc1b67f4
version1 := rt.PutDocDirectly(docID, db.Body{"hello": "world!"})
version1 := rt.PutDoc(docID, `{"hello": "world!"}`)

data := btcRunner.WaitForVersion(client.id, docID, version1)
assert.Equal(t, `{"hello":"world!"}`, string(data))

// create doc1 rev 2-959f0e9ad32d84ff652fb91d8d0caa7e
version2 := rt.UpdateDocDirectly(docID, version1, db.Body{"hello": "alice"})
version2 := rt.UpdateDoc(docID, version1, `{"hello": "alice"}`)

data = btcRunner.WaitForVersion(client.id, docID, version2)
assert.Equal(t, `{"hello":"alice"}`, string(data))
Expand Down Expand Up @@ -2171,7 +2171,7 @@ func TestPullReplicationUpdateOnOtherHLVAwarePeer(t *testing.T) {
_ = btcRunner.WaitForVersion(client.id, docID, version1)

// update the above doc
version2 := rt.UpdateDocDirectly(docID, version1, db.Body{"hello": "world!"})
version2 := rt.UpdateDoc(docID, version1, `{"hello": "world!"}`)

data := btcRunner.WaitForVersion(client.id, docID, version2)
assert.Equal(t, `{"hello":"world!"}`, string(data))
Expand Down Expand Up @@ -2224,15 +2224,15 @@ func TestActiveOnlyContinuous(t *testing.T) {
btc := btcRunner.NewBlipTesterClientOptsWithRT(rt, nil)
defer btc.Close()

version := rt.PutDocDirectly(docID, db.Body{"test": true})
version := rt.PutDoc(docID, `{"test": true}`)

// start an initial pull
btcRunner.StartPullSince(btc.id, BlipTesterPullOptions{Continuous: true, Since: "0", ActiveOnly: true})
rev := btcRunner.WaitForVersion(btc.id, docID, version)
assert.Equal(t, `{"test":true}`, string(rev))

// delete the doc and make sure the client still gets the tombstone replicated
deletedVersion := rt.DeleteDocDirectly(docID, version)
deletedVersion := rt.DeleteDoc(docID, version)

rev = btcRunner.WaitForVersion(btc.id, docID, deletedVersion)
assert.Equal(t, `{}`, string(rev))
Expand Down Expand Up @@ -2312,7 +2312,7 @@ func TestRemovedMessageWithAlternateAccess(t *testing.T) {
defer btc.Close()

const docID = "doc"
version := rt.PutDocDirectly(docID, db.Body{"channels": []string{"A", "B"}})
version := rt.PutDoc(docID, `{"channels": ["A", "B"]}`)

changes := rt.WaitForChanges(1, "/{{.keyspace}}/_changes?since=0&revocations=true", "user", true)
assert.Equal(t, "doc", changes.Results[0].ID)
Expand All @@ -2321,7 +2321,7 @@ func TestRemovedMessageWithAlternateAccess(t *testing.T) {
btcRunner.StartOneshotPull(btc.id)
_ = btcRunner.WaitForVersion(btc.id, docID, version)

version = rt.UpdateDocDirectly(docID, version, db.Body{"channels": []string{"B"}})
version = rt.UpdateDoc(docID, version, `{"channels": ["B"]}`)

changes = rt.WaitForChanges(1, fmt.Sprintf("/{{.keyspace}}/_changes?since=%s&revocations=true", changes.Last_Seq), "user", true)
assert.Equal(t, docID, changes.Results[0].ID)
Expand All @@ -2330,9 +2330,9 @@ func TestRemovedMessageWithAlternateAccess(t *testing.T) {
btcRunner.StartOneshotPull(btc.id)
_ = btcRunner.WaitForVersion(btc.id, docID, version)

version = rt.UpdateDocDirectly(docID, version, db.Body{"channels": []string{}})
version = rt.UpdateDoc(docID, version, `{"channels": []}`)
const docMarker = "docmarker"
docMarkerVersion := rt.PutDocDirectly(docMarker, db.Body{"channels": []string{"!"}})
docMarkerVersion := rt.PutDoc(docMarker, `{"channels": ["!"]}`)

changes = rt.WaitForChanges(2, fmt.Sprintf("/{{.keyspace}}/_changes?since=%s&revocations=true", changes.Last_Seq), "user", true)
assert.Equal(t, "doc", changes.Results[0].ID)
Expand Down Expand Up @@ -2365,14 +2365,14 @@ func TestRemovedMessageWithAlternateAccess(t *testing.T) {
}

// TestRemovedMessageWithAlternateAccessAndChannelFilteredReplication tests the following scenario:
// User has access to channel A and B
// Document rev 1 is in A and B
// Document rev 2 is in channel C
// Document rev 3 is in channel B
// User issues changes requests with since=0 for channel A
// Revocation should not be issued because the user currently has access to channel B, even though they didn't
// have access to the removal revision (rev 2). CBG-2277

//
// User has access to channel A and B
// Document rev 1 is in A and B
// Document rev 2 is in channel C
// Document rev 3 is in channel B
// User issues changes requests with since=0 for channel A
// Revocation should not be issued because the user currently has access to channel B, even though they didn't
// have access to the removal revision (rev 2). CBG-2277
func TestRemovedMessageWithAlternateAccessAndChannelFilteredReplication(t *testing.T) {
defer db.SuspendSequenceBatching()()
base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
Expand All @@ -2395,7 +2395,7 @@ func TestRemovedMessageWithAlternateAccessAndChannelFilteredReplication(t *testi
const (
docID = "doc"
)
version := rt.PutDocDirectly(docID, db.Body{"channels": []string{"A", "B"}})
version := rt.PutDoc(docID, `{"channels": ["A", "B"]}`)

changes := rt.WaitForChanges(1, "/{{.keyspace}}/_changes?since=0&revocations=true", "user", true)
assert.Equal(t, docID, changes.Results[0].ID)
Expand All @@ -2404,7 +2404,7 @@ func TestRemovedMessageWithAlternateAccessAndChannelFilteredReplication(t *testi
btcRunner.StartOneshotPull(btc.id)
_ = btcRunner.WaitForVersion(btc.id, docID, version)

version = rt.UpdateDocDirectly(docID, version, db.Body{"channels": []string{"C"}})
version = rt.UpdateDoc(docID, version, `{"channels": ["C"]}`)
rt.WaitForPendingChanges()

// At this point changes should send revocation, as document isn't in any of the user's channels
Expand All @@ -2417,7 +2417,7 @@ func TestRemovedMessageWithAlternateAccessAndChannelFilteredReplication(t *testi

_ = rt.UpdateDoc(docID, version, `{"channels": ["B"]}`)
markerID := "docmarker"
markerVersion := rt.PutDocDirectly(markerID, db.Body{"channels": []string{"A"}})
markerVersion := rt.PutDoc(markerID, `{"channels": ["A"]}`)
rt.WaitForPendingChanges()

// Revocation should not be sent over blip, as document is now in user's channels - only marker document should be received
Expand Down Expand Up @@ -2756,7 +2756,6 @@ func TestProcessRevIncrementsStat(t *testing.T) {
require.EqualValues(t, 0, pullStats.HandlePutRevCount.Value())

const docID = "doc"
// need to have this return CV too, pending CBG-4751
version := remoteRT.CreateTestDoc(docID)

assert.NoError(t, ar.Start(activeCtx))
Expand Down Expand Up @@ -2873,7 +2872,7 @@ func TestSendRevisionNoRevHandling(t *testing.T) {
recievedNoRevs <- msg
}

version := rt.PutDocDirectly(docName, db.Body{"foo": "bar"})
version := rt.PutDoc(docName, `{"foo": "bar"}`)

// Make the LeakyBucket return an error
leakyDataStore.SetGetRawCallback(func(key string) error {
Expand Down Expand Up @@ -2932,7 +2931,7 @@ func TestUnsubChanges(t *testing.T) {
// Sub changes
btcRunner.StartPull(btc.id)

doc1Version := rt.PutDocDirectly(doc1ID, db.Body{"key": "val1"})
doc1Version := rt.PutDoc(doc1ID, `{"key": "val1"}`)
_ = btcRunner.WaitForVersion(btc.id, doc1ID, doc1Version)

activeReplStat := rt.GetDatabase().DbStats.CBLReplicationPull().NumPullReplActiveContinuous
Expand All @@ -2943,7 +2942,7 @@ func TestUnsubChanges(t *testing.T) {
base.RequireWaitForStat(t, activeReplStat.Value, 0)

// Confirm no more changes are being sent
doc2Version := rt.PutDocDirectly(doc2ID, db.Body{"key": "val1"})
doc2Version := rt.PutDoc(doc2ID, `{"key": "val1"}`)
err := rt.WaitForConditionWithOptions(func() bool {
_, found := btcRunner.GetVersion(btc.id, "doc2", doc2Version)
return found
Expand Down Expand Up @@ -3110,7 +3109,7 @@ func TestBlipRefreshUser(t *testing.T) {
})
defer btc.Close()

version := rt.PutDocDirectly(docID, db.Body{"channels": []string{"chan1"}})
version := rt.PutDoc(docID, `{"channels": ["chan1"]}`)

// Start a regular one-shot pull
btcRunner.StartPullSince(btc.id, BlipTesterPullOptions{Continuous: true, Since: "0"})
Expand Down Expand Up @@ -3164,8 +3163,8 @@ func TestImportInvalidSyncGetsNoRev(t *testing.T) {
Username: bob,
})
defer btc.Close()
version := rt.PutDocDirectly(docID, JsonToMap(t, `{"some":"data", "channels":["ABC"]}`))
version2 := rt.PutDocDirectly(docID2, JsonToMap(t, `{"some":"data", "channels":["ABC"]}`))
version := rt.PutDoc(docID, `{"some":"data", "channels":["ABC"]}`)
version2 := rt.PutDoc(docID2, `{"some":"data", "channels":["ABC"]}`)
rt.WaitForPendingChanges()

// get changes resident in channel cache
Expand Down Expand Up @@ -3336,7 +3335,7 @@ func TestBlipDatabaseClose(t *testing.T) {

// put a doc, and make sure blip connection is established
markerDoc := "markerDoc"
markerDocVersion := rt.PutDocDirectly(markerDoc, db.Body{"mark": "doc"})
markerDocVersion := rt.PutDoc(markerDoc, `{"mark": "doc"}`)
rt.WaitForPendingChanges()
btcRunner.StartPull(btc.id)

Expand Down Expand Up @@ -3553,7 +3552,7 @@ func TestBlipPullConflict(t *testing.T) {
docID = "doc1"
)
rt.CreateUser(alice, []string{"*"})
sgVersion := rt.PutDocDirectly(docID, db.Body{"actor": "sg"})
sgVersion := rt.PutDoc(docID, `{"actor": "sg"}`)

opts := &BlipTesterClientOpts{
Username: alice,
Expand Down
Loading
Loading