(t *testing.T)
| 619 | } |
| 620 | |
| 621 | func TestChannelCacheStatsOnPrepend(t *testing.T) { |
| 622 | |
| 623 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache) |
| 624 | |
| 625 | db, ctx := setupTestDB(t) |
| 626 | defer db.Close(ctx) |
| 627 | |
| 628 | stats, err := base.NewSyncGatewayStats() |
| 629 | require.NoError(t, err) |
| 630 | |
| 631 | dbstats, err := stats.NewDBStats("", false, false, false, nil, nil) |
| 632 | require.NoError(t, err) |
| 633 | |
| 634 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 635 | collectionID := collection.GetCollectionID() |
| 636 | |
| 637 | testStats := dbstats.Cache() |
| 638 | cache := newSingleChannelCache(collection, channels.NewID("Test1", collectionID), 99, testStats) |
| 639 | cache.options.ChannelCacheMaxLength = 15 |
| 640 | |
| 641 | // Add 9 entries to cache, 3 of each type |
| 642 | cache.addToCache(ctx, testLogEntry(100, "active1", "2-a"), false) |
| 643 | cache.addToCache(ctx, testLogEntry(102, "active2", "2-a"), false) |
| 644 | cache.addToCache(ctx, testLogEntry(104, "removal1", "2-a"), true) |
| 645 | cache.addToCache(ctx, et(106, "tombstone1", "2-a"), false) |
| 646 | cache.addToCache(ctx, testLogEntry(107, "removal2", "2-a"), true) |
| 647 | cache.addToCache(ctx, testLogEntry(108, "removal3", "2-a"), true) |
| 648 | cache.addToCache(ctx, et(110, "tombstone2", "2-a"), false) |
| 649 | cache.addToCache(ctx, et(111, "tombstone3", "2-a"), false) |
| 650 | cache.addToCache(ctx, testLogEntry(112, "active3", "2-a"), false) |
| 651 | |
| 652 | active, tombstones, removals := getCacheUtilization(testStats) |
| 653 | require.Equal(t, 3, active) |
| 654 | assert.Equal(t, 3, tombstones) |
| 655 | assert.Equal(t, 3, removals) |
| 656 | |
| 657 | // Attempt to prepend entries with later sequences already in cache. Shouldn't modify stats (note that prepend expects one overlap) |
| 658 | prependDuplicatesSet := make(LogEntries, 5) |
| 659 | prependDuplicatesSet[0] = (testLogEntry(50, "active1", "1-a")) |
| 660 | prependDuplicatesSet[1] = (et(51, "active2", "1-a")) |
| 661 | prependDuplicatesSet[2] = (testLogEntry(52, "removal1", "1-a")) |
| 662 | prependDuplicatesSet[3] = (et(53, "tombstone1", "1-a")) |
| 663 | prependDuplicatesSet[4] = (testLogEntry(54, "tombstone3", "1-a")) |
| 664 | cache.prependChanges(ctx, prependDuplicatesSet, 50, 99) |
| 665 | |
| 666 | active, tombstones, removals = getCacheUtilization(testStats) |
| 667 | assert.Equal(t, 3, active) |
| 668 | assert.Equal(t, 3, tombstones) |
| 669 | assert.Equal(t, 3, removals) |
| 670 | |
| 671 | // Prepend 10 non-duplicates - 5 active, 5 tombstone. Cache only has room for 6, validate stats |
| 672 | prependSet := make(LogEntries, 11) |
| 673 | prependSet[0] = (testLogEntry(40, "new1", "1-a")) |
| 674 | prependSet[1] = (et(41, "new2", "1-a")) |
| 675 | prependSet[2] = (testLogEntry(42, "new3", "1-a")) |
| 676 | prependSet[3] = (et(43, "new4", "1-a")) |
| 677 | prependSet[4] = (testLogEntry(44, "new5", "1-a")) |
| 678 | prependSet[5] = (et(45, "new6", "1-a")) |
nothing calls this directly
no test coverage detected