(t *testing.T)
| 1481 | } |
| 1482 | |
| 1483 | func TestRevCacheCapacityStat(t *testing.T) { |
| 1484 | testCases := []struct { |
| 1485 | name string |
| 1486 | UseCVCache bool |
| 1487 | }{ |
| 1488 | { |
| 1489 | name: "Rev cache pathway", |
| 1490 | UseCVCache: false, |
| 1491 | }, |
| 1492 | { |
| 1493 | name: "CV cache pathway", |
| 1494 | UseCVCache: true, |
| 1495 | }, |
| 1496 | } |
| 1497 | for _, testCase := range testCases { |
| 1498 | t.Run(testCase.name, func(t *testing.T) { |
| 1499 | cacheHitCounter, cacheMissCounter, getDocumentCounter, getRevisionCounter, cacheNumItems, cacheMemoryStat := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 1500 | backingStoreMap := CreateTestSingleBackingStoreMap(&testBackingStore{[]string{"badDoc"}, &getDocumentCounter, &getRevisionCounter}, testCollectionID) |
| 1501 | cacheOptions := &RevisionCacheOptions{ |
| 1502 | MaxItemCount: 4, |
| 1503 | MaxBytes: 0, |
| 1504 | } |
| 1505 | cache := NewLRURevisionCache(cacheOptions, backingStoreMap, &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &cacheMemoryStat) |
| 1506 | ctx := base.TestCtx(t) |
| 1507 | var err error |
| 1508 | |
| 1509 | assert.Equal(t, int64(0), cacheNumItems.Value()) |
| 1510 | assert.Equal(t, int64(len(cache.cache)), cacheNumItems.Value()) |
| 1511 | |
| 1512 | // Create a new doc + asert num items increments |
| 1513 | cache.Put(ctx, documentRevisionForCacheTest("doc1", `{"test":"1234"}`), testCollectionID) |
| 1514 | assert.Equal(t, int64(1), cacheNumItems.Value()) |
| 1515 | assert.Equal(t, int64(len(cache.cache)), cacheNumItems.Value()) |
| 1516 | |
| 1517 | // test not found doc, assert that the stat isn't incremented |
| 1518 | if testCase.UseCVCache { |
| 1519 | cv := Version{SourceID: "test", Value: 123} |
| 1520 | _, err = cache.GetWithCV(ctx, "badDoc", &cv, testCollectionID, false, false) |
| 1521 | require.Error(t, err) |
| 1522 | } else { |
| 1523 | _, err = cache.GetWithRev(ctx, "badDoc", "1-abc", testCollectionID, false) |
| 1524 | require.Error(t, err) |
| 1525 | } |
| 1526 | assert.Equal(t, int64(1), cacheNumItems.Value()) |
| 1527 | assert.Equal(t, int64(len(cache.cache)), cacheNumItems.Value()) |
| 1528 | |
| 1529 | // Get on a doc that doesn't exist in cache, assert num items increments |
| 1530 | var docRev DocumentRevision |
| 1531 | if testCase.UseCVCache { |
| 1532 | cv := Version{SourceID: "test", Value: 123} |
| 1533 | docRev, err = cache.GetWithCV(ctx, "doc2", &cv, testCollectionID, false, false) |
| 1534 | require.NoError(t, err) |
| 1535 | } else { |
| 1536 | docRev, err = cache.GetWithRev(ctx, "doc2", "1-abc", testCollectionID, false) |
| 1537 | require.NoError(t, err) |
| 1538 | } |
| 1539 | assert.Equal(t, "doc2", docRev.DocID) |
| 1540 | assert.Equal(t, int64(2), cacheNumItems.Value()) |
nothing calls this directly
no test coverage detected