TestRevCacheOperationsCV: - Create doc revision, put the revision into the cache - Perform a get on that doc by cv and assert that it has correctly been handled - Updated doc revision and upsert the cache - Get the updated doc by cv and assert iot has been correctly handled - Peek the doc by cv and
(t *testing.T)
| 1704 | // - Peek the rev id cache for the same doc and assert that doc also has been updated in that lookup cache |
| 1705 | // - Remove the doc by cv, and asser that the doc is gone |
| 1706 | func TestRevCacheOperationsCV(t *testing.T) { |
| 1707 | |
| 1708 | cacheHitCounter, cacheMissCounter, cacheNumItems, memoryBytesCounted, getDocumentCounter, getRevisionCounter := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 1709 | cacheOptions := &RevisionCacheOptions{ |
| 1710 | MaxItemCount: 10, |
| 1711 | MaxBytes: 0, |
| 1712 | } |
| 1713 | cache := NewLRURevisionCache(cacheOptions, CreateTestSingleBackingStoreMap(&testBackingStore{[]string{"test_doc"}, &getDocumentCounter, &getRevisionCounter}, testCollectionID), &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &memoryBytesCounted) |
| 1714 | |
| 1715 | cv := Version{SourceID: "test", Value: 123} |
| 1716 | documentRevision := DocumentRevision{ |
| 1717 | DocID: "doc1", |
| 1718 | RevID: "1-abc", |
| 1719 | BodyBytes: []byte(`{"test":"1234"}`), |
| 1720 | Channels: base.SetOf("chan1"), |
| 1721 | History: Revisions{"start": 1}, |
| 1722 | CV: &cv, |
| 1723 | } |
| 1724 | cache.Put(base.TestCtx(t), documentRevision, testCollectionID) |
| 1725 | |
| 1726 | docRev, err := cache.GetWithCV(base.TestCtx(t), "doc1", &cv, testCollectionID, RevCacheOmitDelta, false) |
| 1727 | require.NoError(t, err) |
| 1728 | assert.Equal(t, "doc1", docRev.DocID) |
| 1729 | assert.Equal(t, base.SetOf("chan1"), docRev.Channels) |
| 1730 | assert.Equal(t, "test", docRev.CV.SourceID) |
| 1731 | assert.Equal(t, uint64(123), docRev.CV.Value) |
| 1732 | assert.Equal(t, int64(1), cacheHitCounter.Value()) |
| 1733 | assert.Equal(t, int64(0), cacheMissCounter.Value()) |
| 1734 | |
| 1735 | documentRevision.BodyBytes = []byte(`{"test":"12345"}`) |
| 1736 | |
| 1737 | cache.Upsert(base.TestCtx(t), documentRevision, testCollectionID) |
| 1738 | |
| 1739 | docRev, err = cache.GetWithCV(base.TestCtx(t), "doc1", &cv, testCollectionID, RevCacheOmitDelta, false) |
| 1740 | require.NoError(t, err) |
| 1741 | assert.Equal(t, "doc1", docRev.DocID) |
| 1742 | assert.Equal(t, base.SetOf("chan1"), docRev.Channels) |
| 1743 | assert.Equal(t, "test", docRev.CV.SourceID) |
| 1744 | assert.Equal(t, uint64(123), docRev.CV.Value) |
| 1745 | assert.Equal(t, []byte(`{"test":"12345"}`), docRev.BodyBytes) |
| 1746 | assert.Equal(t, int64(2), cacheHitCounter.Value()) |
| 1747 | assert.Equal(t, int64(0), cacheMissCounter.Value()) |
| 1748 | |
| 1749 | // remove the doc rev from the cache and assert that the document is no longer present in cache |
| 1750 | cache.RemoveWithCV(base.TestCtx(t), "doc1", &cv, testCollectionID) |
| 1751 | assert.Equal(t, 0, len(cache.cache)) |
| 1752 | assert.Equal(t, 0, len(cache.hlvCache)) |
| 1753 | assert.Equal(t, 0, cache.lruList.Len()) |
| 1754 | } |
| 1755 | |
| 1756 | func BenchmarkRevisionCacheRead(b *testing.B) { |
| 1757 | base.SetUpBenchmarkLogging(b, base.LevelDebug, base.KeyAll) |
nothing calls this directly
no test coverage detected