github.com/tristanwietsma/metastore@v0.0.0-20140902015055-9569a04d7e4a/metastore_test.go (about)

     1  /*
     2  Copyright 2013 Tristan Wietsma
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8       http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package metastore
    18  
    19  import "testing"
    20  
    21  func TestMetaStore(t *testing.T) {
    22  	var M MetaStore
    23  	M.Init(1000)
    24  
    25  	h := M.GetHasher()
    26  	idx := h([]byte("key123"))
    27  	if idx != 334 {
    28  		t.Errorf("Wrong bucket index. Got %d; should be 334.", idx)
    29  		return
    30  	}
    31  
    32  	M.Bucket[idx].Set("key123", "value567")
    33  	value, ok := M.Bucket[idx].Get("key123")
    34  	if value != "value567" || !ok {
    35  		t.Errorf("Set-Get failed.")
    36  	}
    37  }
    38  
    39  func BenchmarkSet(b *testing.B) {
    40  	var M MetaStore
    41  	M.Init(1000)
    42  	h := M.GetHasher()
    43  	idx := h([]byte("key123"))
    44  	M.Bucket[idx].Set("key123", "value567")
    45  }
    46  
    47  func TestMetaStoreFlushAll(t *testing.T) {
    48  	var M MetaStore
    49  	M.Init(1000)
    50  	M.Set("key123", "value567")
    51  	M.FlushAll()
    52  	_, ok := M.Get("key123")
    53  	if ok {
    54  		t.Errorf("FlushAll failed")
    55  	}
    56  }