Skip to content

Commit

Permalink
updates to work with rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gregns1 committed Nov 7, 2023
1 parent 2eed297 commit 1ac3b1a
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 121 deletions.
34 changes: 17 additions & 17 deletions rest/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2276,8 +2276,8 @@ func TestUpdateExistingAttachment(t *testing.T) {

btc.Run(func(t *testing.T) {
// Add doc1 and doc2
doc1Version := rt.PutDoc(doc1ID, `{}`)
doc2Version := rt.PutDoc(doc2ID, `{}`)
doc1Version := btc.rt.PutDoc(doc1ID, `{}`)
doc2Version := btc.rt.PutDoc(doc2ID, `{}`)

require.NoError(t, btc.rt.WaitForPendingChanges())

Expand All @@ -2296,8 +2296,8 @@ func TestUpdateExistingAttachment(t *testing.T) {
doc2Version, err = btc.PushRev("doc2", doc2Version, []byte(`{"key": "val", "_attachments": {"attachment": {"data": "`+attachmentBData+`"}}}`))
require.NoError(t, err)

assert.NoError(t, rt.WaitForVersion(doc1ID, doc1Version))
assert.NoError(t, rt.WaitForVersion(doc2ID, doc2Version))
assert.NoError(t, btc.rt.WaitForVersion(doc1ID, doc1Version))
assert.NoError(t, btc.rt.WaitForVersion(doc2ID, doc2Version))

_, err = btc.rt.GetSingleTestDatabaseCollection().GetDocument(base.TestCtx(t), "doc1", db.DocUnmarshalAll)
require.NoError(t, err)
Expand All @@ -2307,7 +2307,7 @@ func TestUpdateExistingAttachment(t *testing.T) {
doc1Version, err = btc.PushRev("doc1", doc1Version, []byte(`{"key": "val", "_attachments":{"attachment":{"digest":"sha1-SKk0IV40XSHW37d3H0xpv2+z9Ck=","length":11,"content_type":"","stub":true,"revpos":3}}}`))
require.NoError(t, err)

assert.NoError(t, rt.WaitForVersion(doc1ID, doc1Version))
assert.NoError(t, btc.rt.WaitForVersion(doc1ID, doc1Version))

doc1, err := btc.rt.GetSingleTestDatabaseCollection().GetDocument(base.TestCtx(t), "doc1", db.DocUnmarshalAll)
assert.NoError(t, err)
Expand All @@ -2333,7 +2333,7 @@ func TestPushUnknownAttachmentAsStub(t *testing.T) {

btc.Run(func(t *testing.T) {
// Add doc1 and doc2
doc1Version := rt.PutDoc(doc1ID, `{}`)
doc1Version := btc.rt.PutDoc(doc1ID, `{}`)

require.NoError(t, btc.rt.WaitForPendingChanges())

Expand All @@ -2353,7 +2353,7 @@ func TestPushUnknownAttachmentAsStub(t *testing.T) {
doc1Version, err = btc.PushRev(doc1ID, doc1Version, []byte(fmt.Sprintf(`{"key": "val", "_attachments":{"attachment":{"digest":"%s","length":%d,"content_type":"%s","stub":true,"revpos":1}}}`, digest, length, contentType)))
require.NoError(t, err)

require.NoError(t, rt.WaitForVersion(doc1ID, doc1Version))
require.NoError(t, btc.rt.WaitForVersion(doc1ID, doc1Version))

// verify that attachment exists on document and was persisted
attResponse := btc.rt.SendAdminRequest("GET", "/{{.keyspace}}/doc1/attachment", "")
Expand All @@ -2380,8 +2380,8 @@ func TestMinRevPosWorkToAvoidUnnecessaryProveAttachment(t *testing.T) {

btc.Run(func(t *testing.T) {
// Push an initial rev with attachment data
initialVersion := rt.PutDoc(docID, `{"_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
err = rt.WaitForPendingChanges()
initialVersion := btc.rt.PutDoc(docID, `{"_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
err := btc.rt.WaitForPendingChanges()
assert.NoError(t, err)

// Replicate data to client and ensure doc arrives
Expand Down Expand Up @@ -2416,8 +2416,8 @@ func TestAttachmentWithErroneousRevPos(t *testing.T) {
btc.Run(func(t *testing.T) {
// Create rev 1 with the hello.txt attachment
const docID = "doc"
version := rt.PutDoc(docID, `{"val": "val", "_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
err := rt.WaitForPendingChanges()
version := btc.rt.PutDoc(docID, `{"val": "val", "_attachments": {"hello.txt": {"data": "aGVsbG8gd29ybGQ="}}}`)
err := btc.rt.WaitForPendingChanges()
assert.NoError(t, err)

// Pull rev and attachment down to client
Expand Down Expand Up @@ -2597,9 +2597,9 @@ func TestCBLRevposHandling(t *testing.T) {
)

btc.Run(func(t *testing.T) {
doc1Version := rt.PutDoc(doc1ID, `{}`)
doc2Version := rt.PutDoc(doc2ID, `{}`)
require.NoError(t, rt.WaitForPendingChanges())
doc1Version := btc.rt.PutDoc(doc1ID, `{}`)
doc2Version := btc.rt.PutDoc(doc2ID, `{}`)
require.NoError(t, btc.rt.WaitForPendingChanges())

err := btc.StartOneshotPull()
assert.NoError(t, err)
Expand All @@ -2616,8 +2616,8 @@ func TestCBLRevposHandling(t *testing.T) {
doc2Version, err = btc.PushRev(doc2ID, doc2Version, []byte(`{"key": "val", "_attachments": {"attachment": {"data": "`+attachmentBData+`"}}}`))
require.NoError(t, err)

assert.NoError(t, rt.WaitForVersion(doc1ID, doc1Version))
assert.NoError(t, rt.WaitForVersion(doc2ID, doc2Version))
assert.NoError(t, btc.rt.WaitForVersion(doc1ID, doc1Version))
assert.NoError(t, btc.rt.WaitForVersion(doc2ID, doc2Version))

_, err = btc.rt.GetSingleTestDatabaseCollection().GetDocument(base.TestCtx(t), "doc1", db.DocUnmarshalAll)
require.NoError(t, err)
Expand All @@ -2628,7 +2628,7 @@ func TestCBLRevposHandling(t *testing.T) {
doc1Version, err = btc.PushRev(doc1ID, doc1Version, []byte(`{"key": "val", "_attachments":{"attachment":{"digest":"sha1-wzp8ZyykdEuZ9GuqmxQ7XDrY7Co=","length":11,"content_type":"","stub":true,"revpos":2}}}`))
require.NoError(t, err)

assert.NoError(t, rt.WaitForVersion(doc1ID, doc1Version))
assert.NoError(t, btc.rt.WaitForVersion(doc1ID, doc1Version))

// Update doc1, don't change attachment, use revpos=generation of revid, as CBL 2.x does. Should not proveAttachment on digest match.
doc1Version, err = btc.PushRev(doc1ID, doc1Version, []byte(`{"key": "val", "_attachments":{"attachment":{"digest":"sha1-wzp8ZyykdEuZ9GuqmxQ7XDrY7Co=","length":11,"content_type":"","stub":true,"revpos":4}}}`))
Expand Down
37 changes: 17 additions & 20 deletions rest/blip_api_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestBlipPushPullV2AttachmentV2Client(t *testing.T) {

// Create doc revision with attachment on SG.
bodyText := `{"greetings":[{"hi": "alice"}],"_attachments":{"hello.txt":{"data":"aGVsbG8gd29ybGQ="}}}`
version := rt.PutDoc(docID, bodyText)
version := btc.rt.PutDoc(docID, bodyText)

data, ok := btc.WaitForVersion(docID, version)
assert.True(t, ok)
Expand All @@ -74,7 +74,7 @@ func TestBlipPushPullV2AttachmentV2Client(t *testing.T) {
_, ok = btc.pushReplication.WaitForMessage(2)
assert.True(t, ok)

respBody := rt.GetDocVersion(docID, version)
respBody := btc.rt.GetDocVersion(docID, version)

assert.Equal(t, docID, respBody[db.BodyId])
greetings := respBody["greetings"].([]interface{})
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestBlipPushPullV2AttachmentV3Client(t *testing.T) {

// Create doc revision with attachment on SG.
bodyText := `{"greetings":[{"hi": "alice"}],"_attachments":{"hello.txt":{"data":"aGVsbG8gd29ybGQ="}}}`
version := rt.PutDoc(docID, bodyText)
version := btc.rt.PutDoc(docID, bodyText)

data, ok := btc.WaitForVersion(docID, version)
assert.True(t, ok)
Expand All @@ -141,7 +141,7 @@ func TestBlipPushPullV2AttachmentV3Client(t *testing.T) {
_, ok = btc.pushReplication.WaitForMessage(2)
assert.True(t, ok)

respBody := rt.GetDocVersion(docID, version)
respBody := btc.rt.GetDocVersion(docID, version)

assert.Equal(t, docID, respBody[db.BodyId])
greetings := respBody["greetings"].([]interface{})
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestBlipProveAttachmentV2(t *testing.T) {
// Create two docs with the same attachment data on SG - v2 attachments intentionally result in two copies,
// CBL will still de-dupe attachments based on digest, so will still try proveAttachmnet for the 2nd.
doc1Body := fmt.Sprintf(`{"greetings":[{"hi": "alice"}],"_attachments":{"%s":{"data":"%s"}}}`, attachmentName, attachmentDataB64)
doc1Version := rt.PutDoc(doc1ID, doc1Body)
doc1Version := btc.rt.PutDoc(doc1ID, doc1Body)

data, ok := btc.WaitForVersion(doc1ID, doc1Version)
require.True(t, ok)
Expand All @@ -207,9 +207,9 @@ func TestBlipProveAttachmentV2(t *testing.T) {

// create doc2 now that we know the client has the attachment
doc2Body := fmt.Sprintf(`{"greetings":[{"howdy": "bob"}],"_attachments":{"%s":{"data":"%s"}}}`, attachmentName, attachmentDataB64)
doc2Version := rt.PutDoc(doc2ID, doc2Body)
doc2Version := btc.rt.PutDoc(doc2ID, doc2Body)

data, ok = btc.WaitForRev(doc2ID, doc2RevID)
data, ok = btc.WaitForVersion(doc2ID, doc2Version)
require.True(t, ok)
bodyTextExpected = fmt.Sprintf(`{"greetings":[{"howdy":"bob"}],"_attachments":{"%s":{"revpos":1,"length":%d,"stub":true,"digest":"%s"}}}`, attachmentName, len(attachmentData), attachmentDigest)
require.JSONEq(t, bodyTextExpected, string(data))
Expand Down Expand Up @@ -254,15 +254,15 @@ func TestBlipProveAttachmentV2Push(t *testing.T) {
doc1Version, err := btc.PushRev(doc1ID, EmptyDocVersion(), []byte(doc1Body))
require.NoError(t, err)

err = rt.WaitForVersion(doc1ID, doc1Version)
err = btc.rt.WaitForVersion(doc1ID, doc1Version)
require.NoError(t, err)

// create doc2 now that we know the server has the attachment - SG should still request the attachment data from the client.
doc2Body := fmt.Sprintf(`{"greetings":[{"howdy": "bob"}],"_attachments":{"%s":{"data":"%s"}}}`, attachmentName, attachmentDataB64)
doc2Version, err := btc.PushRev(doc2ID, EmptyDocVersion(), []byte(doc2Body))
require.NoError(t, err)

err = rt.WaitForVersion(doc2ID, doc2Version)
err = btc.rt.WaitForVersion(doc2ID, doc2Version)
require.NoError(t, err)

assert.Equal(t, int64(2), btc.rt.GetDatabase().DbStats.CBLReplicationPush().DocPushCount.Value())
Expand Down Expand Up @@ -292,9 +292,6 @@ func TestBlipPushPullNewAttachmentCommonAncestor(t *testing.T) {
err = btc.StoreRevOnClient(docID, "2-abc", []byte(bodyText))
require.NoError(t, err)

response := btc.rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc/_blipsync", "")
fmt.Println(response.Code, response.Body.String())

bodyText = `{"greetings":[{"hi":"alice"}],"_attachments":{"hello.txt":{"revpos":2,"length":11,"stub":true,"digest":"sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0="}}}`
revId, err := btc.PushRevWithHistory(docID, "", []byte(bodyText), 2, 0)
require.NoError(t, err)
Expand Down Expand Up @@ -536,7 +533,7 @@ func TestBlipAttachNameChange(t *testing.T) {
// Use revpos 2 to simulate revpos bug in CBL 2.8 - 3.0.0
version, err = client1.PushRev("doc", version, []byte(`{"key":"val","_attachments":{"attach":{"revpos":2,"content_type":"","length":11,"stub":true,"digest":"`+digest+`"}}}`))
require.NoError(t, err)
err = rt.WaitForVersion("doc", version)
err = client1.rt.WaitForVersion("doc", version)
require.NoError(t, err)

// Check if attachment is still in bucket
Expand Down Expand Up @@ -571,10 +568,10 @@ func TestBlipLegacyAttachNameChange(t *testing.T) {
CreateDocWithLegacyAttachment(t, client1.rt, docID, rawDoc, attKey, attBody)

// Get the document and grab the revID.
docVersion, _ := rt.GetDoc(docID)
docVersion, _ := client1.rt.GetDoc(docID)

// Store the document and attachment on the test client
err = client1.StoreRevOnClient(docID, docVersion.RevID, rawDoc)
err := client1.StoreRevOnClient(docID, docVersion.RevID, rawDoc)

require.NoError(t, err)
client1.AttachmentsLock().Lock()
Expand All @@ -592,7 +589,7 @@ func TestBlipLegacyAttachNameChange(t *testing.T) {
docVersion, err = client1.PushRev("doc", docVersion, []byte(`{"key":"val","_attachments":{"attach":{"revpos":2,"content_type":"test/plain","length":2,"stub":true,"digest":"`+digest+`"}}}`))
require.NoError(t, err)

err = rt.WaitForVersion("doc", docVersion)
err = client1.rt.WaitForVersion("doc", docVersion)
require.NoError(t, err)

resp := client1.rt.SendAdminRequest("GET", "/{{.keyspace}}/doc/attach", "")
Expand Down Expand Up @@ -623,10 +620,10 @@ func TestBlipLegacyAttachDocUpdate(t *testing.T) {
// Create a document with legacy attachment.
CreateDocWithLegacyAttachment(t, client1.rt, docID, rawDoc, attKey, attBody)

version, _ := rt.GetDoc(docID)
version, _ := client1.rt.GetDoc(docID)

// Store the document and attachment on the test client
err = client1.StoreRevOnClient(docID, version.RevID, rawDoc)
err := client1.StoreRevOnClient(docID, version.RevID, rawDoc)
require.NoError(t, err)
client1.AttachmentsLock().Lock()
client1.Attachments()[digest] = attBody
Expand All @@ -643,7 +640,7 @@ func TestBlipLegacyAttachDocUpdate(t *testing.T) {
version, err = client1.PushRev("doc", version, []byte(`{"key":"val1","_attachments":{"`+attName+`":{"revpos":2,"content_type":"text/plain","length":2,"stub":true,"digest":"`+digest+`"}}}`))
require.NoError(t, err)

err = rt.WaitForVersion("doc", version)
err = client1.rt.WaitForVersion("doc", version)
require.NoError(t, err)

resp := client1.rt.SendAdminRequest("GET", fmt.Sprintf("/{{.keyspace}}/doc/%s", attName), "")
Expand Down Expand Up @@ -692,7 +689,7 @@ func TestAttachmentComputeStat(t *testing.T) {

// Create doc revision with attachment on SG.
bodyText := `{"greetings":[{"hi": "alice"}],"_attachments":{"hello.txt":{"data":"aGVsbG8gd29ybGQ="}}}`
version := rt.PutDoc(docID, bodyText)
version := btc.rt.PutDoc(docID, bodyText)

// Wait for the document to be replicated to client.
data, ok := btc.WaitForVersion(docID, version)
Expand Down
28 changes: 14 additions & 14 deletions rest/blip_api_collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestBlipGetCollections(t *testing.T) {
rtConfig := &RestTesterConfig{GuestEnabled: true}
btc := NewBlipTesterClientOptsWithRT(&BlipTesterClientOpts{
SkipCollectionsInitialization: true,
NumCollectionsNeeded: 1,
NumCollectionsRequired: 1,
})
defer btc.Close()

Expand Down Expand Up @@ -244,8 +244,8 @@ func TestCollectionsReplication(t *testing.T) {
const docID = "doc1"

btc.Run(func(t *testing.T) {
version := rt.PutDoc(docID, "{}")
require.NoError(t, rt.WaitForPendingChanges())
version := btc.rt.PutDoc(docID, "{}")
require.NoError(t, btc.rt.WaitForPendingChanges())

btcCollection := btc.SingleCollection()

Expand All @@ -262,19 +262,19 @@ func TestBlipReplicationMultipleCollections(t *testing.T) {
GuestEnabled: true,
}

btc := NewBlipTesterClientOptsWithRT(&BlipTesterClientOpts{NumCollectionsNeeded: 2})
btc := NewBlipTesterClientOptsWithRT(&BlipTesterClientOpts{NumCollectionsRequired: 2})
defer btc.Close()

btc.Run(func(t *testing.T) {
docName := "doc1"
body := `{"foo":"bar"}`
versions := make([]DocVersion, 0, len(rt.GetKeyspaces()))
for _, keyspace := range rt.GetKeyspaces() {
resp := rt.SendAdminRequest(http.MethodPut, "/"+keyspace+"/"+docName, `{"foo":"bar"}`)
versions := make([]DocVersion, 0, len(btc.rt.GetKeyspaces()))
for _, keyspace := range btc.rt.GetKeyspaces() {
resp := btc.rt.SendAdminRequest(http.MethodPut, "/"+keyspace+"/"+docName, `{"foo":"bar"}`)
RequireStatus(t, resp, http.StatusCreated)
versions = append(versions, DocVersionFromPutResponse(t, resp))
}
require.NoError(t, rt.WaitForPendingChanges())
require.NoError(t, btc.rt.WaitForPendingChanges())

// start all the clients first
for _, collectionClient := range btc.collectionClients {
Expand All @@ -299,32 +299,32 @@ func TestBlipReplicationMultipleCollectionsMismatchedDocSizes(t *testing.T) {
GuestEnabled: true,
}

btc := NewBlipTesterClientOptsWithRT(&BlipTesterClientOpts{NumCollectionsNeeded: 2})
btc := NewBlipTesterClientOptsWithRT(&BlipTesterClientOpts{NumCollectionsRequired: 2})
defer btc.Close()

btc.Run(func(t *testing.T) {
body := `{"foo":"bar"}`
collectionDocIDs := make(map[string][]string)
collectionVersions := make(map[string][]DocVersion)
require.Len(t, rt.GetKeyspaces(), 2)
for i, keyspace := range rt.GetKeyspaces() {
require.Len(t, btc.rt.GetKeyspaces(), 2)
for i, keyspace := range btc.rt.GetKeyspaces() {
// intentionally create collections with different size replications to ensure one collection finishing won't cancel another one
docCount := 10
if i == 0 {
docCount = 1
}
blipName := rt.getCollectionsForBLIP()[i]
blipName := btc.rt.getCollectionsForBLIP()[i]
for j := 0; j < docCount; j++ {
docName := fmt.Sprintf("doc%d", j)
resp := rt.SendAdminRequest(http.MethodPut, "/"+keyspace+"/"+docName, body)
resp := btc.rt.SendAdminRequest(http.MethodPut, "/"+keyspace+"/"+docName, body)
RequireStatus(t, resp, http.StatusCreated)

version := DocVersionFromPutResponse(t, resp)
collectionVersions[blipName] = append(collectionVersions[blipName], version)
collectionDocIDs[blipName] = append(collectionDocIDs[blipName], docName)
}
}
require.NoError(t, rt.WaitForPendingChanges())
require.NoError(t, btc.rt.WaitForPendingChanges())

// start all the clients first
for _, collectionClient := range btc.collectionClients {
Expand Down
Loading

0 comments on commit 1ac3b1a

Please sign in to comment.