MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestInitializeEmptyCache

Function TestInitializeEmptyCache

db/change_cache_test.go:1512–1557  ·  view source on GitHub ↗

Trigger initialization of empty cache, then write and validate a subsequent changes request returns expected data.

(t *testing.T)

Source from the content-addressed store, hash-verified

1510
1511// Trigger initialization of empty cache, then write and validate a subsequent changes request returns expected data.
1512func TestInitializeEmptyCache(t *testing.T) {
1513
1514 base.SetUpTestLogging(t, base.LevelInfo, base.KeyChanges)
1515
1516 // Increase the cache max size
1517 cacheOptions := DefaultCacheOptions()
1518 cacheOptions.ChannelCacheMaxLength = 50
1519
1520 db, ctx := setupTestDBWithCacheOptions(t, cacheOptions)
1521 defer db.Close(ctx)
1522 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
1523 collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout)
1524
1525 cacheWaiter := db.NewDCPCachingCountWaiter(t)
1526 docCount := 0
1527 // Write docs to non-queried channel first, to increase cache.nextSequence
1528 for i := 0; i < 10; i++ {
1529 channels := []string{"islands"}
1530 body := Body{"serialnumber": int64(i), "channels": channels}
1531 docID := fmt.Sprintf("loadCache-ch-%d", i)
1532 _, _, err := collection.Put(ctx, docID, body)
1533 assert.NoError(t, err, "Couldn't create document")
1534 docCount++
1535 }
1536
1537 // Issue getChanges for empty channel
1538 changes := getChanges(t, collection, channels.BaseSetOf(t, "zero"), getChangesOptionsWithCtxOnly(t))
1539 changesCount := len(changes)
1540 assert.Equal(t, 0, changesCount)
1541
1542 // Write some documents to channel zero
1543 for i := 0; i < 10; i++ {
1544 channels := []string{"zero"}
1545 body := Body{"serialnumber": int64(i), "channels": channels}
1546 docID := fmt.Sprintf("loadCache-z-%d", i)
1547 _, _, err := collection.Put(ctx, docID, body)
1548 assert.NoError(t, err, "Couldn't create document")
1549 docCount++
1550 }
1551
1552 cacheWaiter.Add(docCount)
1553 cacheWaiter.Wait()
1554
1555 changes = getChanges(t, collection, channels.BaseSetOf(t, "zero"), getChangesOptionsWithCtxOnly(t))
1556 assert.Len(t, changes, 10)
1557}
1558
1559// Trigger initialization of the channel cache under load via getChanges. Ensures validFrom handling correctly
1560// sets query/cache boundaries

Callers

nothing calls this directly

Calls 13

SetUpTestLoggingFunction · 0.92
DefaultCacheOptionsFunction · 0.85
getChangesFunction · 0.85
CloseMethod · 0.65
PutMethod · 0.65
LenMethod · 0.65
EqualMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected