예제 #1
0
func TestDiscardReplica(t *testing.T) {
	for i := 0; i < 10; i++ {
		r := New(0, discard{}, memory.New())
		storagetest.StorageTest(t, r)
		r = New(0, memory.New(), discard{})
		storagetest.StorageTest(t, r)
	}
}
예제 #2
0
func TestErrorReplica(t *testing.T) {

	for i := 0; i < 10; i++ {
		r := New(2, storagetest.Errstore{}, memory.New())
		storagetest.StorageTest(t, r)
		r = New(2, memory.New(), storagetest.Errstore{})
		storagetest.StorageTest(t, r)
	}
}
예제 #3
0
func TestRest(t *testing.T) {
	storage = make(map[string][]byte)
	ts := httptest.NewServer(http.HandlerFunc(handler))
	defer ts.Close()
	r := New(ts.URL)
	storagetest.StorageTest(t, r)
}
예제 #4
0
func TestRedis(t *testing.T) {

	s, err := New("localhost:6379")
	if err != nil {
		t.Skip("error connecting to redis instance on localhost:6379 -- can't test")
		return
	}

	storagetest.StorageTest(t, s)
}
예제 #5
0
func TestFS(t *testing.T) {

	dir, err := ioutil.TempDir(os.TempDir(), "shardedkv-fs-storagetest")

	if err != nil {
		t.Skipf("Unable to create temporary directory: %s", err)
	}

	m := New(dir)
	storagetest.StorageTest(t, m)

	// cleanup
	os.RemoveAll(dir)
}
예제 #6
0
func TestSQL(t *testing.T) {

	f, err := ioutil.TempFile(os.TempDir(), "shardedkv-sql-storagetest")

	if err != nil {
		t.Skipf("unable to create tempfile: %s", err)
	}

	db, err := sql.Open("sqlite3", f.Name())
	if err != nil {
		t.Errorf("error creating sqlite temp file")
		return
	}

	_, err = db.Exec(`
CREATE TABLE Storage (
key VARCHAR(64) NOT NULL,
value VARCHAR(256) NOT NULL
);
        `)

	if err != nil {
		t.Errorf("error creating table: %s", err)
		return
	}
	db.Close()

	var tblConf = TableConfig{
		Table:       "Storage",
		KeyColumn:   "key",
		ValueColumn: "value",
	}

	connector := func() (*sql.DB, error) {
		return sql.Open("sqlite3", f.Name())
	}

	s, err := New(connector, &tblConf)

	if err != nil {
		t.Errorf("error creating sqlite")
		return
	}

	storagetest.StorageTest(t, s)

	os.Remove(f.Name())
}
예제 #7
0
func TestMemory(t *testing.T) {
	m := New()
	storagetest.StorageTest(t, m)
}
예제 #8
0
func TestBackoff(t *testing.T) {
	m := memory.New()
	b := &Storage{Store: m}
	storagetest.StorageTest(t, b)
}