(t *testing.T)
| 2036 | } |
| 2037 | |
| 2038 | func TestStoreCrashRecovery(t *testing.T) { |
| 2039 | tmpDir, _ := ioutil.TempDir("", "mossStore") |
| 2040 | defer os.RemoveAll(tmpDir) |
| 2041 | |
| 2042 | var store *Store |
| 2043 | var coll Collection |
| 2044 | |
| 2045 | var m sync.Mutex |
| 2046 | var waitingForCleanCh chan struct{} |
| 2047 | |
| 2048 | co := CollectionOptions{ |
| 2049 | OnEvent: func(event Event) { |
| 2050 | if event.Kind == EventKindPersisterProgress { |
| 2051 | stats, err := coll.Stats() |
| 2052 | if err == nil && stats.CurDirtyOps <= 0 && |
| 2053 | stats.CurDirtyBytes <= 0 && stats.CurDirtySegments <= 0 { |
| 2054 | m.Lock() |
| 2055 | if waitingForCleanCh != nil { |
| 2056 | waitingForCleanCh <- struct{}{} |
| 2057 | waitingForCleanCh = nil |
| 2058 | } |
| 2059 | m.Unlock() |
| 2060 | } |
| 2061 | } |
| 2062 | }, |
| 2063 | } |
| 2064 | |
| 2065 | ch := make(chan struct{}, 1) |
| 2066 | |
| 2067 | var err error |
| 2068 | |
| 2069 | store, coll, err = OpenStoreCollection(tmpDir, |
| 2070 | StoreOptions{CollectionOptions: co}, |
| 2071 | StorePersistOptions{CompactionConcern: CompactionDisable}) |
| 2072 | |
| 2073 | if err != nil || store == nil { |
| 2074 | t.Errorf("Moss-OpenStoreCollection failed, err: %v", err) |
| 2075 | } |
| 2076 | |
| 2077 | numBatches := 200 |
| 2078 | itemsPerBatch := 100 |
| 2079 | itemCount := 0 |
| 2080 | |
| 2081 | for bi := 0; bi < numBatches; bi++ { |
| 2082 | batch, err1 := coll.NewBatch(itemsPerBatch, itemsPerBatch*15) |
| 2083 | if err1 != nil { |
| 2084 | t.Errorf("Expected NewBatch() to succeed!") |
| 2085 | } |
| 2086 | |
| 2087 | for i := 0; i < itemsPerBatch; i++ { |
| 2088 | k := []byte(fmt.Sprintf("key%d", i)) |
| 2089 | v := []byte(fmt.Sprintf("val%d", i)) |
| 2090 | itemCount++ |
| 2091 | |
| 2092 | batch.Set(k, v) |
| 2093 | } |
| 2094 | |
| 2095 | m.Lock() |
nothing calls this directly
no test coverage detected
searching dependent graphs…