(t *testing.T)
| 377 | } |
| 378 | |
| 379 | func TestBackingStoreMemoryCalculation(t *testing.T) { |
| 380 | testCases := []struct { |
| 381 | name string |
| 382 | UseCVCache bool |
| 383 | }{ |
| 384 | { |
| 385 | name: "Rev cache pathway", |
| 386 | UseCVCache: false, |
| 387 | }, |
| 388 | { |
| 389 | name: "CV cache pathway", |
| 390 | UseCVCache: true, |
| 391 | }, |
| 392 | } |
| 393 | for _, testCase := range testCases { |
| 394 | t.Run(testCase.name, func(t *testing.T) { |
| 395 | cacheHitCounter, cacheMissCounter, getDocumentCounter, getRevisionCounter, cacheNumItems, memoryBytesCounted := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 396 | backingStoreMap := CreateTestSingleBackingStoreMap(&testBackingStore{[]string{"doc2"}, &getDocumentCounter, &getRevisionCounter}, testCollectionID) |
| 397 | maxBytes := int64(235) |
| 398 | cacheOptions := &RevisionCacheOptions{ |
| 399 | MaxItemCount: 10, |
| 400 | MaxBytes: maxBytes, |
| 401 | } |
| 402 | cache := NewLRURevisionCache(cacheOptions, backingStoreMap, &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &memoryBytesCounted) |
| 403 | ctx := base.TestCtx(t) |
| 404 | var err error |
| 405 | |
| 406 | var docRev DocumentRevision |
| 407 | if testCase.UseCVCache { |
| 408 | docRev, err = cache.GetWithCV(ctx, "doc1", &Version{Value: 123, SourceID: "test"}, testCollectionID, RevCacheOmitDelta, false) |
| 409 | require.NoError(t, err) |
| 410 | } else { |
| 411 | docRev, err = cache.GetWithRev(ctx, "doc1", "1-abc", testCollectionID, RevCacheOmitDelta) |
| 412 | require.NoError(t, err) |
| 413 | } |
| 414 | assert.Equal(t, "doc1", docRev.DocID) |
| 415 | assert.NotNil(t, docRev.History) |
| 416 | assert.NotNil(t, docRev.Channels) |
| 417 | |
| 418 | currMemStat := memoryBytesCounted.Value() |
| 419 | // assert stats is incremented by appropriate bytes on doc rev |
| 420 | assert.Equal(t, docRev.MemoryBytes, currMemStat) |
| 421 | |
| 422 | // Test get active code pathway of a load from bucket |
| 423 | docRev, err = cache.GetActive(ctx, "doc", testCollectionID) |
| 424 | require.NoError(t, err) |
| 425 | assert.Equal(t, "doc", docRev.DocID) |
| 426 | assert.NotNil(t, docRev.History) |
| 427 | assert.NotNil(t, docRev.Channels) |
| 428 | |
| 429 | newMemStat := currMemStat + docRev.MemoryBytes |
| 430 | // assert stats is incremented by appropriate bytes on doc rev |
| 431 | assert.Equal(t, newMemStat, memoryBytesCounted.Value()) |
| 432 | |
| 433 | // test fail load event doesn't increment memory stat |
| 434 | if testCase.UseCVCache { |
| 435 | docRev, err = cache.GetWithCV(ctx, "doc2", &Version{Value: 123, SourceID: "test"}, testCollectionID, RevCacheOmitDelta, false) |
| 436 | assertHTTPError(t, err, 404) |
nothing calls this directly
no test coverage detected