Пример #1
0
func init() {
	smForBenchmark = New()
	err := test.InserterBasic(smForBenchmark, "Benchmark")
	if err != nil {
		panic(err.Error())
	}
	smForBenchmarkThread = New()
	err = test.InserterBasic(smForBenchmarkThread, "BenchmarkThreads")
	if err != nil {
		panic(err.Error())
	}
}
Пример #2
0
func TestEachMethods(t *testing.T) {
	sm := New()
	err := test.InserterBasic(sm, "Each")
	if err != nil {
		t.Fatalf(err.Error())
	}

	stop := make(chan error, 1)
	var index int
	sm.Each(func(mp api.Mapper) {
		if mp.Len() != len(test.UniqMap) {
			stop <- fmt.Errorf("Not equal.")
			mp.Stop()
			return
		}
		if v, found := test.UniqMap[mp.Key()]; !found || mp.Value().(string) != v {
			stop <- fmt.Errorf("Key '%s' not found.", mp.Key())
			mp.Stop()
			return
		}
		index++
		if index == mp.Len() {
			stop <- nil
		}
	})
	err = <-stop
	close(stop)
	if err != nil {
		t.Fatalf(err.Error())
	}
}
Пример #3
0
func TestUpdateMethods(t *testing.T) {
	sm := newTest()
	err := test.InserterBasic(sm, "Update")
	if err != nil {
		t.Fatalf(err.Error())
	}

	rndKeys := test.Data[rand.Intn(len(test.Data)-1)]
	newData := make(map[string]string, len(rndKeys))
	done := make(chan *test.Item, len(rndKeys))
	for k, _ := range rndKeys {
		tt := &test.Item{
			K:    k,
			V:    test.RandString(test.SizeItem),
			Done: done,
		}
		update(sm, tt)
	}
	for tt := range done {
		newData[tt.K] = tt.V
		if len(newData) >= len(rndKeys) {
			break
		}
	}
	for k, v := range newData {
		if val, found := sm.Find(k); !found || val.(string) != v {
			t.Fatalf("Cannot found key '%s'", k)
		}
	}
}
Пример #4
0
func init() {
	smUnsafeForBenchmark = newUnsafeTest()
	err := test.InserterBasic(smUnsafeForBenchmark, "BenchmarkUnsafe")
	if err != nil {
		panic(err.Error())
	}
}
Пример #5
0
func init() {
	smForBenchmark = newTest()
	err := test.InserterBasic(smForBenchmark, "Benchmark")
	if err != nil {
		panic(err.Error())
	}
	err = testWaitN(smForBenchmark, test.CntWorks*test.CntItems)
	if err != nil {
		panic(err.Error())
	}
	smForBenchmarkThread = newTest()
	err = test.InserterBasic(smForBenchmarkThread, "BenchmarkThreads")
	if err != nil {
		panic(err.Error())
	}
	err = testWaitN(smForBenchmarkThread, test.CntWorks*test.CntItems)
	if err != nil {
		panic(err.Error())
	}
}
Пример #6
0
func TestInsertMethods(t *testing.T) {
	sm := New()
	err := test.InserterBasic(sm, "Insert")
	if err != nil {
		t.Fatalf(err.Error())
	}
	if sm.Len() != test.CntWorks*test.CntItems {
		t.Fatal("Not equal.")
	}
	if err := test.FinderBasic(sm); err != nil {
		t.Fatalf(err.Error())
	}
}
Пример #7
0
func TestInsertMethods(t *testing.T) {
	sm := newTest()
	err := test.InserterBasic(sm, "Insert")
	if err != nil {
		t.Fatalf(err.Error())
	}
	err = testWaitN(sm, test.CntWorks*test.CntItems)
	if err != nil {
		t.Fatalf(err.Error())
	}
	if err := test.FinderBasic(sm); err != nil {
		t.Fatalf(err.Error())
	}
}
Пример #8
0
func TestDeleteMethods(t *testing.T) {
	sm := New()
	err := test.InserterBasic(sm, "Delete")
	if err != nil {
		t.Fatalf(err.Error())
	}

	rndKeys := test.Data[rand.Intn(len(test.Data)-1)]
	for k, _ := range rndKeys {
		sm.Delete(k)
	}
	for k, _ := range rndKeys {
		if _, found := sm.Find(k); found {
			t.Fatalf("Key '%s' not deleted!", k)
		}
	}
}