MCPcopy Create free account
hub / github.com/couchbase/moss / TestStoreCompactMaxSegments

Function TestStoreCompactMaxSegments

store_test.go:1979–2036  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1977}
1978
1979func TestStoreCompactMaxSegments(t *testing.T) {
1980 tmpDir, _ := ioutil.TempDir("", "mossStore")
1981 defer os.RemoveAll(tmpDir)
1982
1983 var store *Store
1984 var coll Collection
1985
1986 var err error
1987
1988 store, coll, err = OpenStoreCollection(tmpDir,
1989 StoreOptions{
1990 CompactionPercentage: 100, CompactionLevelMaxSegments: 5,
1991 CompactionLevelMultiplier: 100000},
1992 StorePersistOptions{CompactionConcern: CompactionAllow})
1993
1994 if err != nil || store == nil {
1995 t.Errorf("Moss-OpenStoreCollection failed, err: %v", err)
1996 }
1997
1998 numBatches := 200
1999 itemsPerBatch := 100
2000 itemCount := 0
2001
2002 for bi := 0; bi < numBatches; bi++ {
2003 batch, err1 := coll.NewBatch(itemsPerBatch, itemsPerBatch*15)
2004 if err1 != nil {
2005 t.Errorf("Expected NewBatch() to succeed!")
2006 }
2007
2008 for i := 0; i < itemsPerBatch; i++ {
2009 k := []byte(fmt.Sprintf("key%d", i))
2010 v := []byte(fmt.Sprintf("val%d", i))
2011 itemCount++
2012
2013 batch.Set(k, v)
2014 }
2015
2016 err1 = coll.ExecuteBatch(batch, WriteOptions{})
2017 if err1 != nil {
2018 t.Errorf("Expected ExecuteBatch() to work!")
2019 }
2020 waitForPersistence(coll)
2021 }
2022
2023 sstats, err := store.Stats()
2024 if err != nil {
2025 t.Errorf("expected no stats err")
2026 }
2027 if sstats == nil {
2028 t.Errorf("expected non-nil stats")
2029 }
2030 if sstats["total_persists"].(uint64) <= 0 {
2031 t.Errorf("expected >0 total_persists")
2032 }
2033 if sstats["total_compactions"].(uint64) <= 0 {
2034 t.Errorf("expected >0 total_compactions")
2035 }
2036}

Callers

nothing calls this directly

Calls 6

NewBatchMethod · 0.95
SetMethod · 0.95
ExecuteBatchMethod · 0.95
StatsMethod · 0.95
OpenStoreCollectionFunction · 0.85
waitForPersistenceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…