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

Function TestAllDocsOnly

db/database_test.go:1746–1857  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1744}
1745
1746func TestAllDocsOnly(t *testing.T) {
1747
1748 base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache)
1749
1750 // Lower the log max length so no more than 50 items will be kept.
1751 cacheOptions := DefaultCacheOptions()
1752 cacheOptions.ChannelCacheMaxLength = 50
1753
1754 db, ctx := setupTestDBWithCacheOptions(t, cacheOptions)
1755 defer db.Close(ctx)
1756 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
1757
1758 collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout)
1759
1760 collectionID := collection.GetCollectionID()
1761
1762 // Trigger creation of the channel cache for channel "all"
1763 _, err := db.changeCache.getChannelCache().getSingleChannelCache(ctx, channels.NewID("all", collectionID))
1764 require.NoError(t, err)
1765
1766 ids := make([]AllDocsEntry, 100)
1767 for i := 0; i < 100; i++ {
1768 channels := []string{"all"}
1769 if i%10 == 0 {
1770 channels = append(channels, "KFJC")
1771 }
1772 body := Body{"serialnumber": int64(i), "channels": channels}
1773 ids[i].DocID = fmt.Sprintf("alldoc-%02d", i)
1774 revid, _, err := collection.Put(ctx, ids[i].DocID, body)
1775 ids[i].RevID = revid
1776 ids[i].Sequence = uint64(i + 1)
1777 ids[i].Channels = channels
1778 assert.NoError(t, err, "Couldn't create document")
1779 }
1780
1781 alldocs, err := allDocIDs(ctx, collection.DatabaseCollection)
1782 assert.NoError(t, err, "AllDocIDs failed")
1783 require.Len(t, alldocs, 100)
1784 for i, entry := range alldocs {
1785 assert.True(t, entry.Equal(ids[i]))
1786 }
1787
1788 // Now delete one document and try again:
1789 _, _, err = collection.DeleteDoc(ctx, ids[23].DocID, DocVersion{RevTreeID: ids[23].RevID})
1790 assert.NoError(t, err, "Couldn't delete doc 23")
1791
1792 alldocs, err = allDocIDs(ctx, collection.DatabaseCollection)
1793 assert.NoError(t, err, "AllDocIDs failed")
1794 require.Len(t, alldocs, 99)
1795 for i, entry := range alldocs {
1796 j := i
1797 if i >= 23 {
1798 j++
1799 }
1800 assert.True(t, entry.Equal(ids[j]))
1801 }
1802
1803 // Inspect the channel log to confirm that it's only got the last 50 sequences.

Callers

nothing calls this directly

Calls 15

UnmarshalMethod · 0.95
SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
SetTypeAlias · 0.92
DefaultCacheOptionsFunction · 0.85
allDocIDsFunction · 0.85
getChangesFunction · 0.85
waitForSequenceMethod · 0.80
GetChangeLogMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected