示例#1
0
// TestConcurrentConnection tests simultaenous get/put using
// two handles.
func TestConcurrentConnection(t *testing.T) {
	var err error
	kv1, err1 := libkv.NewStore(
		store.BOLTDB,
		[]string{"/tmp/__boltdbtest"},
		&store.Config{
			Bucket:            "boltDBTest",
			ConnectionTimeout: 1 * time.Second},
	)
	assert.NoError(t, err1)
	assert.NotNil(t, kv1)

	kv2, err2 := libkv.NewStore(
		store.BOLTDB,
		[]string{"/tmp/__boltdbtest"},
		&store.Config{Bucket: "boltDBTest",
			ConnectionTimeout: 1 * time.Second},
	)
	assert.NoError(t, err2)
	assert.NotNil(t, kv2)

	key1 := "TestKV1"
	value1 := []byte("TestVal1")
	err = kv1.Put(key1, value1, nil)
	assert.NoError(t, err)

	key2 := "TestKV2"
	value2 := []byte("TestVal2")
	err = kv2.Put(key2, value2, nil)
	assert.NoError(t, err)

	pair1, err1 := kv1.Get(key1)
	assert.NoError(t, err)
	if assert.NotNil(t, pair1) {
		assert.NotNil(t, pair1.Value)
	}
	assert.Equal(t, pair1.Value, value1)

	pair2, err2 := kv2.Get(key2)
	assert.NoError(t, err)
	if assert.NotNil(t, pair2) {
		assert.NotNil(t, pair2.Value)
	}
	assert.Equal(t, pair2.Value, value2)

	// AtomicPut using kv1 and kv2 should succeed
	_, _, err = kv1.AtomicPut(key1, []byte("TestnewVal1"), pair1, nil)
	assert.NoError(t, err)

	_, _, err = kv2.AtomicPut(key2, []byte("TestnewVal2"), pair2, nil)
	assert.NoError(t, err)

	testutils.RunTestCommon(t, kv1)
	testutils.RunTestCommon(t, kv2)

	kv1.Close()
	kv2.Close()

	_ = os.Remove("/tmp/__boltdbtest")
}
示例#2
0
func TestBoldDBStore(t *testing.T) {
	kv := makeBoltDBClient(t)

	testutils.RunTestCommon(t, kv)
	testutils.RunTestAtomic(t, kv)

	_ = os.Remove("/tmp/not_exist_dir/__boltdbtest")
}
示例#3
0
func TestConsulStore(t *testing.T) {
	kv := makeConsulClient(t)
	backup := makeConsulClient(t)

	testutils.RunTestCommon(t, kv)
	testutils.RunTestAtomic(t, kv)
	testutils.RunTestWatch(t, kv)
	testutils.RunTestLock(t, kv)
	testutils.RunTestTTL(t, kv, backup)
}
示例#4
0
func TestEtcdStore(t *testing.T) {
	kv := makeEtcdClient(t)
	backup := makeEtcdClient(t)

	testutils.RunTestCommon(t, kv)
	testutils.RunTestAtomic(t, kv)
	testutils.RunTestWatch(t, kv)
	testutils.RunTestLock(t, kv)
	testutils.RunTestTTL(t, kv, backup)
	testutils.RunCleanup(t, kv)
}
示例#5
0
func TestZkStore(t *testing.T) {
	kv := makeZkClient(t)
	ttlKV := makeZkClient(t)

	testutils.RunTestCommon(t, kv)
	testutils.RunTestAtomic(t, kv)
	testutils.RunTestWatch(t, kv)
	testutils.RunTestLock(t, kv)
	testutils.RunTestTTL(t, kv, ttlKV)
	testutils.RunCleanup(t, kv)
}