TestBackingStoreCV: - Perform a Get on a doc by cv that is not currently in the rev cache, assert we get cache miss - Perform a Get again on the same doc and assert we get cache hit - Perform a Get on doc that doesn't exist, so misses cache and will fail on retrieving doc from bucket - Try a Get aga
(t *testing.T)
| 524 | // - Perform a Get on doc that doesn't exist, so misses cache and will fail on retrieving doc from bucket |
| 525 | // - Try a Get again on the same doc and assert it wasn't loaded into the cache as it doesn't exist |
| 526 | func TestBackingStoreCV(t *testing.T) { |
| 527 | cacheHitCounter, cacheMissCounter, cacheNumItems, memoryBytesCounted, getDocumentCounter, getRevisionCounter := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 528 | |
| 529 | backingStoreMap := CreateTestSingleBackingStoreMap(&testBackingStore{[]string{"not_found"}, &getDocumentCounter, &getRevisionCounter}, testCollectionID) |
| 530 | cacheOptions := &RevisionCacheOptions{ |
| 531 | MaxItemCount: 10, |
| 532 | MaxBytes: 0, |
| 533 | } |
| 534 | cache := NewLRURevisionCache(cacheOptions, backingStoreMap, &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &memoryBytesCounted) |
| 535 | |
| 536 | // Get Rev for the first time - miss cache, but fetch the doc and revision to store |
| 537 | cv := Version{SourceID: "test", Value: 123} |
| 538 | docRev, err := cache.GetWithCV(base.TestCtx(t), "doc1", &cv, testCollectionID, RevCacheOmitDelta, false) |
| 539 | assert.NoError(t, err) |
| 540 | assert.Equal(t, "doc1", docRev.DocID) |
| 541 | assert.NotNil(t, docRev.Channels) |
| 542 | assert.Equal(t, "test", docRev.CV.SourceID) |
| 543 | assert.Equal(t, uint64(123), docRev.CV.Value) |
| 544 | assert.Equal(t, int64(0), cacheHitCounter.Value()) |
| 545 | assert.Equal(t, int64(1), cacheMissCounter.Value()) |
| 546 | assert.Equal(t, int64(1), getDocumentCounter.Value()) |
| 547 | assert.Equal(t, int64(1), getRevisionCounter.Value()) |
| 548 | |
| 549 | // Perform a get on the same doc as above, check that we get cache hit |
| 550 | docRev, err = cache.GetWithCV(base.TestCtx(t), "doc1", &cv, testCollectionID, RevCacheOmitDelta, false) |
| 551 | assert.NoError(t, err) |
| 552 | assert.Equal(t, "doc1", docRev.DocID) |
| 553 | assert.Equal(t, "test", docRev.CV.SourceID) |
| 554 | assert.Equal(t, uint64(123), docRev.CV.Value) |
| 555 | assert.Equal(t, int64(1), cacheHitCounter.Value()) |
| 556 | assert.Equal(t, int64(1), cacheMissCounter.Value()) |
| 557 | assert.Equal(t, int64(1), getDocumentCounter.Value()) |
| 558 | assert.Equal(t, int64(1), getRevisionCounter.Value()) |
| 559 | |
| 560 | // Doc doesn't exist, so miss the cache, and fail when getting the doc |
| 561 | cv = Version{SourceID: "test11", Value: 100} |
| 562 | docRev, err = cache.GetWithCV(base.TestCtx(t), "not_found", &cv, testCollectionID, RevCacheOmitDelta, false) |
| 563 | |
| 564 | assertHTTPError(t, err, 404) |
| 565 | assert.Nil(t, docRev.BodyBytes) |
| 566 | assert.Equal(t, int64(1), cacheHitCounter.Value()) |
| 567 | assert.Equal(t, int64(2), cacheMissCounter.Value()) |
| 568 | assert.Equal(t, int64(2), getDocumentCounter.Value()) |
| 569 | assert.Equal(t, int64(1), getRevisionCounter.Value()) |
| 570 | |
| 571 | // Rev still doesn't exist, make sure it wasn't cached |
| 572 | docRev, err = cache.GetWithCV(base.TestCtx(t), "not_found", &cv, testCollectionID, RevCacheOmitDelta, false) |
| 573 | assertHTTPError(t, err, 404) |
| 574 | assert.Nil(t, docRev.BodyBytes) |
| 575 | assert.Equal(t, int64(1), cacheHitCounter.Value()) |
| 576 | assert.Equal(t, int64(3), cacheMissCounter.Value()) |
| 577 | assert.Equal(t, int64(3), getDocumentCounter.Value()) |
| 578 | assert.Equal(t, int64(1), getRevisionCounter.Value()) |
| 579 | } |
| 580 | |
| 581 | // Ensure internal properties aren't being incorrectly stored in revision cache |
| 582 | func TestRevisionCacheInternalProperties(t *testing.T) { |
nothing calls this directly
no test coverage detected