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

Function TestQueryChannelsActiveOnlyWithLimit

db/query_test.go:353–535  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

351}
352
353func TestQueryChannelsActiveOnlyWithLimit(t *testing.T) {
354 if base.TestsDisableGSI() {
355 t.Skip("This test is Couchbase Server and UseViews=false only")
356 }
357
358 db, ctx := setupTestDBAllowConflicts(t)
359 defer db.Close(ctx)
360 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
361 collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout)
362 docIdFlagMap := make(map[string]uint8)
363 var startSeq, endSeq uint64
364 body := Body{"channels": []string{"ABC"}}
365
366 checkFlags := func(entries LogEntries) {
367 for _, entry := range entries {
368 assert.Equal(t, docIdFlagMap[entry.DocID], entry.Flags, "Flags mismatch for doc %v", entry.DocID)
369 }
370 }
371
372 // Create 10 added documents
373 for i := 1; i <= 10; i++ {
374 id := "created" + strconv.Itoa(i)
375 doc, revId, err := collection.PutExistingRevWithBody(ctx, id, body, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV)
376 require.NoError(t, err, "Couldn't create document")
377 require.Equal(t, "1-a", revId)
378 docIdFlagMap[doc.ID] = uint8(0x0)
379 if i == 1 {
380 startSeq = doc.Sequence
381 }
382 endSeq = doc.Sequence
383 }
384
385 // Create 10 deleted documents
386 for i := 1; i <= 10; i++ {
387 id := "deleted" + strconv.Itoa(i)
388 _, revId, err := collection.PutExistingRevWithBody(ctx, id, body, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV)
389 require.NoError(t, err, "Couldn't create document")
390 require.Equal(t, "1-a", revId)
391
392 body[BodyDeleted] = true
393 doc, revId, err := collection.PutExistingRevWithBody(ctx, id, body, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV)
394 require.NoError(t, err, "Couldn't create document")
395 require.Equal(t, "2-a", revId, "Couldn't create tombstone revision")
396
397 docIdFlagMap[doc.ID] = channels.Deleted // 1 = Deleted(1)
398 endSeq = doc.Sequence
399 }
400
401 // Create 10 branched documents (two branches, one branch is tombstoned)
402 for i := 1; i <= 10; i++ {
403 body["sound"] = "meow"
404 id := "branched" + strconv.Itoa(i)
405 _, revId, err := collection.PutExistingRevWithBody(ctx, id, body, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV)
406 require.NoError(t, err, "Couldn't create document revision 1-a")
407 require.Equal(t, "1-a", revId)
408
409 body["sound"] = "bark"
410 _, revId, err = collection.PutExistingRevWithBody(ctx, id, body, []string{"2-b", "1-a"}, false, ExistingVersionWithUpdateToHLV)

Callers

nothing calls this directly

Calls 10

TestsDisableGSIFunction · 0.92
NewChannelMapperFunction · 0.92
TestCtxFunction · 0.92
CloseMethod · 0.65
LenMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected