summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-04-22 00:48:35 +0300
committerValery Piashchynski <[email protected]>2021-04-22 00:48:35 +0300
commite4d65a41ec90747a387cfe769f743327959f7105 (patch)
tree2b5245fa0a86197d4699fc840c658ffa86cd957b /tests
parente1e168da92e0dca0e067e08ecb4cf264b9344d45 (diff)
- General interface, update RPC and Has/Set methods
Diffstat (limited to 'tests')
-rw-r--r--tests/composer.json4
-rw-r--r--tests/docker-compose-full.yaml46
-rw-r--r--tests/docker-compose.yaml6
-rw-r--r--tests/plugins/kv/boltdb/plugin_test.go2
-rw-r--r--tests/plugins/kv/configs/.rr-kv-init.yaml30
-rw-r--r--tests/plugins/kv/memcached/plugin_test.go2
-rw-r--r--tests/plugins/kv/memory/plugin_test.go2
-rw-r--r--tests/plugins/kv/storage_plugin_test.go189
8 files changed, 230 insertions, 51 deletions
diff --git a/tests/composer.json b/tests/composer.json
index 543b2053..50178d1f 100644
--- a/tests/composer.json
+++ b/tests/composer.json
@@ -13,5 +13,7 @@
"psr-4": {
"Temporal\\Tests\\": "src"
}
- }
+ },
+ "name": "test/test",
+ "description": "test"
}
diff --git a/tests/docker-compose-full.yaml b/tests/docker-compose-full.yaml
deleted file mode 100644
index 889f7898..00000000
--- a/tests/docker-compose-full.yaml
+++ /dev/null
@@ -1,46 +0,0 @@
-version: '3.5'
-
-services:
- postgresql:
- container_name: temporal-postgresql
- image: postgres:13.1
- environment:
- POSTGRES_PASSWORD: temporal
- POSTGRES_USER: temporal
- ports:
- - 5432:5432
-
- temporal:
- container_name: temporal
- image: temporalio/auto-setup:1.6.3
- depends_on:
- - postgresql
- environment:
- - DB=postgresql
- - DB_PORT=5432
- - POSTGRES_USER=temporal
- - POSTGRES_PWD=temporal
- - POSTGRES_SEEDS=postgresql
- ports:
- - 7233:7233
-
- temporal-admin-tools:
- container_name: temporal-admin-tools
- image: temporalio/admin-tools:1.6.3
- depends_on:
- - temporal
- environment:
- - TEMPORAL_CLI_ADDRESS=temporal:7233
- stdin_open: true
- tty: true
-
- temporal-web:
- container_name: temporal-web
- image: temporalio/web:1.6.2
- depends_on:
- - temporal
- environment:
- - TEMPORAL_GRPC_ENDPOINT=temporal:7233
- - TEMPORAL_PERMIT_WRITE_API=true
- ports:
- - 8088:8088
diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml
index fd1a48bf..67d5476b 100644
--- a/tests/docker-compose.yaml
+++ b/tests/docker-compose.yaml
@@ -4,4 +4,8 @@ services:
memcached:
image: memcached:latest
ports:
- - "0.0.0.0:11211:11211" \ No newline at end of file
+ - "0.0.0.0:11211:11211"
+ redis:
+ image: redis:6
+ ports:
+ - "6379:6379"
diff --git a/tests/plugins/kv/boltdb/plugin_test.go b/tests/plugins/kv/boltdb/plugin_test.go
index 3a4542ff..fad7c7a3 100644
--- a/tests/plugins/kv/boltdb/plugin_test.go
+++ b/tests/plugins/kv/boltdb/plugin_test.go
@@ -15,7 +15,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/kv"
- "github.com/spiral/roadrunner/v2/plugins/kv/boltdb"
+ "github.com/spiral/roadrunner/v2/plugins/kv/drivers/boltdb"
"github.com/spiral/roadrunner/v2/plugins/logger"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/spiral/roadrunner/v2/plugins/server"
diff --git a/tests/plugins/kv/configs/.rr-kv-init.yaml b/tests/plugins/kv/configs/.rr-kv-init.yaml
new file mode 100644
index 00000000..935b952d
--- /dev/null
+++ b/tests/plugins/kv/configs/.rr-kv-init.yaml
@@ -0,0 +1,30 @@
+rpc:
+ listen: tcp://127.0.0.1:6001
+
+
+kv:
+ default:
+ driver: memory
+
+ boltdb-south:
+ driver: boltdb
+ dir: "."
+ file: "rr.db"
+ bucket: "rr"
+ permissions: 0666
+ ttl: 40s
+
+ boltdb-africa:
+ driver: boltdb
+ dir: "."
+ file: "africa.db"
+ bucket: "rr"
+ permissions: 0666
+ ttl: 40
+
+ memcached:
+ driver: memcached
+ addr: [ "localhost:11211" ]
+
+# redis:
+# driver: redis
diff --git a/tests/plugins/kv/memcached/plugin_test.go b/tests/plugins/kv/memcached/plugin_test.go
index 3878ef67..ecbc7722 100644
--- a/tests/plugins/kv/memcached/plugin_test.go
+++ b/tests/plugins/kv/memcached/plugin_test.go
@@ -15,7 +15,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/kv"
- "github.com/spiral/roadrunner/v2/plugins/kv/memcached"
+ "github.com/spiral/roadrunner/v2/plugins/kv/drivers/memcached"
"github.com/spiral/roadrunner/v2/plugins/logger"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/spiral/roadrunner/v2/plugins/server"
diff --git a/tests/plugins/kv/memory/plugin_test.go b/tests/plugins/kv/memory/plugin_test.go
index 528403d0..23d23bc0 100644
--- a/tests/plugins/kv/memory/plugin_test.go
+++ b/tests/plugins/kv/memory/plugin_test.go
@@ -15,7 +15,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
httpPlugin "github.com/spiral/roadrunner/v2/plugins/http"
"github.com/spiral/roadrunner/v2/plugins/kv"
- "github.com/spiral/roadrunner/v2/plugins/kv/memory"
+ "github.com/spiral/roadrunner/v2/plugins/kv/drivers/memory"
"github.com/spiral/roadrunner/v2/plugins/logger"
rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
"github.com/spiral/roadrunner/v2/plugins/server"
diff --git a/tests/plugins/kv/storage_plugin_test.go b/tests/plugins/kv/storage_plugin_test.go
new file mode 100644
index 00000000..6d270d3f
--- /dev/null
+++ b/tests/plugins/kv/storage_plugin_test.go
@@ -0,0 +1,189 @@
+package kv
+
+import (
+ "net"
+ "net/rpc"
+ "os"
+ "os/signal"
+ "sync"
+ "syscall"
+ "testing"
+ "time"
+
+ flatbuffers "github.com/google/flatbuffers/go"
+ endure "github.com/spiral/endure/pkg/container"
+ goridgeRpc "github.com/spiral/goridge/v3/pkg/rpc"
+ "github.com/spiral/roadrunner/v2/plugins/config"
+ "github.com/spiral/roadrunner/v2/plugins/kv"
+ "github.com/spiral/roadrunner/v2/plugins/kv/drivers/boltdb"
+ "github.com/spiral/roadrunner/v2/plugins/kv/drivers/memcached"
+ "github.com/spiral/roadrunner/v2/plugins/kv/drivers/memory"
+ "github.com/spiral/roadrunner/v2/plugins/kv/payload/generated"
+ "github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/plugins/redis"
+ rpcPlugin "github.com/spiral/roadrunner/v2/plugins/rpc"
+ "github.com/stretchr/testify/assert"
+)
+
+func makePayload(b *flatbuffers.Builder, storage string, items []kv.Item) []byte {
+ b.Reset()
+
+ storageOffset := b.CreateString(storage)
+
+ ////////////////////// ITEMS VECTOR ////////////////////////////
+ offset := make([]flatbuffers.UOffsetT, len(items))
+ for i := len(items) - 1; i >= 0; i-- {
+ offset[i] = serializeItems(b, items[i])
+ }
+
+ generated.PayloadStartItemsVector(b, len(offset))
+
+ for i := len(offset) - 1; i >= 0; i-- {
+ b.PrependUOffsetT(offset[i])
+ }
+
+ itemsOffset := b.EndVector(len(offset))
+ ///////////////////////////////////////////////////////////////////
+
+ generated.PayloadStart(b)
+ generated.PayloadAddItems(b, itemsOffset)
+ generated.PayloadAddStorage(b, storageOffset)
+
+ finalOffset := generated.PayloadEnd(b)
+
+ b.Finish(finalOffset)
+
+ return b.Bytes[b.Head():]
+}
+
+func serializeItems(b *flatbuffers.Builder, item kv.Item) flatbuffers.UOffsetT {
+ key := b.CreateString(item.Key)
+ val := b.CreateString(item.Value)
+ ttl := b.CreateString(item.TTL)
+
+ generated.ItemStart(b)
+
+ generated.ItemAddKey(b, key)
+ generated.ItemAddValue(b, val)
+ generated.ItemAddTimeout(b, ttl)
+
+ return generated.ItemEnd(b)
+}
+
+func TestKVInit(t *testing.T) {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ cfg := &config.Viper{
+ Path: "configs/.rr-kv-init.yaml",
+ Prefix: "rr",
+ }
+
+ err = cont.RegisterAll(
+ cfg,
+ &memory.Plugin{},
+ &boltdb.Plugin{},
+ &memcached.Plugin{},
+ &redis.Plugin{},
+ &rpcPlugin.Plugin{},
+ &logger.ZapLogger{},
+ &kv.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ stopCh := make(chan struct{}, 1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 1)
+ t.Run("KvSetTest", kvSetTest)
+ t.Run("KvHasTest", kvHasTest)
+
+ stopCh <- struct{}{}
+
+ wg.Wait()
+
+ _ = os.RemoveAll("rr.db")
+ _ = os.RemoveAll("africa.db")
+}
+
+func kvSetTest(t *testing.T) {
+ conn, err := net.Dial("tcp", "127.0.0.1:6001")
+ assert.NoError(t, err)
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
+ // WorkerList contains list of workers.
+
+ b := flatbuffers.NewBuilder(100)
+ args := makePayload(b, "boltdb-south", []kv.Item{
+ {
+ Key: "key",
+ Value: "val",
+ },
+ })
+
+ var ok bool
+
+ err = client.Call("kv.Set", args, &ok)
+ assert.NoError(t, err)
+ assert.True(t, ok, "Set return result")
+}
+
+func kvHasTest(t *testing.T) {
+ conn, err := net.Dial("tcp", "127.0.0.1:6001")
+ assert.NoError(t, err)
+ client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))
+ // WorkerList contains list of workers.
+
+ b := flatbuffers.NewBuilder(100)
+ args := makePayload(b, "boltdb-south", []kv.Item{
+ {
+ Key: "key",
+ Value: "val",
+ },
+ })
+ var ret map[string]bool
+
+ err = client.Call("kv.Has", args, &ret)
+ assert.NoError(t, err)
+}