Esempio n. 1
0
func TestKSCountConcurrent(t *testing.T) {
	t.Log("TestPutAndGet started")
	ks := NewInMemoryStorage()
	max := 10000
	for i := 0; i < max; i++ {
		go func(j int) {
			var d = []byte(` data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							 data data data ..... data asdfghjklòzxcvbnm,wertyuiop
							fghjklòdsfasdgfdasgsfadjgklfdagjkldfajglfdjdsgdfgfdgfdg
							qwertyuiopdfghjklzxcvbnm,12345678901234567890qwertyuiobn
			`)
			data := storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(j), d, "default", 60, 0)
			ks.Put(&data)
			//fmt.Println("Put data "+data.Key)
		}(i)
	}
	time.Sleep(11 * 1e8)
	var count = ks.Count()
	if count != max {
		t.Fatal("Incorrect count " + strconv.Itoa(count))
	} else {
		t.Log("Correct count " + strconv.Itoa(count))
	}
}
Esempio n. 2
0
func TestKSPutAndGet(t *testing.T) {
	t.Log("TestPutAndGet started")
	ks := NewInMemoryStorage()
	var data = storage.NewMetaDataObj("test", []byte("test string"), "default", 60, 0)
	ks.Put(&data)
	res, ok := ks.Get("test")
	if ok != nil {
		t.Fail()
	} else {
		t.Log(res.Key)
	}
}
Esempio n. 3
0
func TestPutAndGet(t *testing.T) {
	t.Log("TestPutAndGet started")
	coll := NewCollection()
	var d = []byte("test string")
	var data = storage.NewMetaDataObj("test", d, "default", 60, 1)
	coll.Put(&data)
	res, ok := coll.Get("test")
	if !ok {
		t.Fail()
	} else {
		t.Log(res.Key)
	}
}
Esempio n. 4
0
func TestKSCount(t *testing.T) {
	t.Log("TestPutAndGet started")
	ks := NewInMemoryStorage()
	max := 1000
	for i := 0; i < max; i++ {
		var data = storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(i), []byte("test string"), "default", 60, 0)
		ks.Put(&data)
	}
	var count = ks.Count()
	if count != max {
		t.Fatal("Incorrect count " + strconv.Itoa(count))
	} else {
		t.Log("Correct count " + strconv.Itoa(count))
	}
}
Esempio n. 5
0
func TestKSPutAndGetLoop(t *testing.T) {
	t.Log("TestPutAndGet started")
	ks := NewInMemoryStorage()
	for i := 0; i < 1000; i++ {
		var data = storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(i), []byte("test string"), "default", 60, 0)
		ks.Put(&data)
	}
	for i := 0; i < 1000; i++ {
		_, ok := ks.Get("testloopkey_" + strconv.Itoa(i))
		if ok != nil {
			t.Fatal("key " + "testloopkey_" + strconv.Itoa(i) + " not found")
		} else {
			//fmt.Println(res.Key)
		}
	}
}
Esempio n. 6
0
func _TestCount(t *testing.T) {
	t.Log("TestPutAndGet started")
	coll := NewCollection()
	max := 1000
	for i := 0; i < max; i++ {
		var d = []byte("test string")
		var data = storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(i), d, "default", 60, 1)
		coll.Put(&data)
	}
	var count = coll.Count()
	if count != max {
		t.Fatal("Incorrect count " + strconv.Itoa(count))
	} else {
		t.Log("Correct count " + strconv.Itoa(count))
	}
}
Esempio n. 7
0
func TestPutAndGetLoopMutex(t *testing.T) {
	t.Log("TestPutAndGet started")
	coll := NewMutexCollection()
	for i := 0; i < 1000; i++ {
		var d = []byte("test string")
		var data = storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(i), d, "default", 60, 1)
		coll.Put(&data)
	}
	for i := 0; i < 1000; i++ {
		_, ok := coll.Get("testloopkey_" + strconv.Itoa(i))
		if !ok {
			t.Fatal("key " + "testloopkey_" + strconv.Itoa(i) + " not found")
		} else {
			//fmt.Println(res.Key)
		}
	}
}
Esempio n. 8
0
func TestPutLoop(t *testing.T) {
	t.Log("TestPutLoop started")
	coll := NewCollection()
	operationNumber := 100000
	resultChan := make(chan (bool), operationNumber)
	startTime := time.Now()
	for i := 0; i < operationNumber; i++ {
		go func(j int) {
			var d = []byte("test string")
			data := storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(j), d, "default", 60, 1)
			coll.Put(&data)
			resultChan <- true
		}(i)
	}
	for i := 0; i < operationNumber; i++ {
		<-resultChan
	}
	t.Logf("All done: %d - elapsed time = %s", len(resultChan), time.Since(startTime))
}
Esempio n. 9
0
func _TestCountConcurrent(t *testing.T) {
	t.Log("TestPutAndGet started")
	coll := NewCollection()
	max := 100000
	for i := 0; i < max; i++ {
		go func(j int) {
			var d = []byte("test string")
			data := storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(j), d, "default", 60, 1)
			coll.Put(&data)
			//fmt.Println("Put data "+data.Key)
		}(i)
	}
	time.Sleep(20 * 1e9)
	var count = coll.Count()
	if count != max {
		t.Fatal("Incorrect count " + strconv.Itoa(count))
	} else {
		t.Log("Correct count " + strconv.Itoa(count))
	}
}
Esempio n. 10
0
func TestGetLoopMutex(t *testing.T) {
	t.Log("TestGetLoopMutex started")
	coll := NewMutexCollection()
	operationNumber := 100000
	for i := 0; i < operationNumber; i++ {
		var d = []byte("test string")
		data := storage.NewMetaDataObj("testloopkey_"+strconv.Itoa(i), d, "default", 60, 1)
		coll.Put(&data)
	}
	t.Logf("Number of object: %d", coll.Count())
	startTime := time.Now()
	resultChan := make(chan (bool), operationNumber)
	for i := 0; i < operationNumber; i++ {
		go func(j int) {
			_, _ = coll.Get("testloopkey_" + strconv.Itoa(i))
			resultChan <- true
		}(i)
	}
	for i := 0; i < operationNumber; i++ {
		<-resultChan
	}
	t.Logf("All done: %d - elapsed time = %s", len(resultChan), time.Since(startTime))
}