|
@@ -1,4 +1,4 @@
|
|
-// Copyright 2021-2022 EMQ Technologies Co., Ltd.
|
|
|
|
|
|
+// Copyright 2022 EMQ Technologies Co., Ltd.
|
|
//
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// you may not use this file except in compliance with the License.
|
|
@@ -19,25 +19,19 @@ import (
|
|
"github.com/gdexlab/go-render/render"
|
|
"github.com/gdexlab/go-render/render"
|
|
"github.com/lf-edge/ekuiper/internal/conf"
|
|
"github.com/lf-edge/ekuiper/internal/conf"
|
|
"github.com/lf-edge/ekuiper/internal/topo/context"
|
|
"github.com/lf-edge/ekuiper/internal/topo/context"
|
|
|
|
+ "github.com/lf-edge/ekuiper/internal/topo/memory/pubsub"
|
|
"github.com/lf-edge/ekuiper/internal/topo/state"
|
|
"github.com/lf-edge/ekuiper/internal/topo/state"
|
|
"github.com/lf-edge/ekuiper/pkg/api"
|
|
"github.com/lf-edge/ekuiper/pkg/api"
|
|
"reflect"
|
|
"reflect"
|
|
- "regexp"
|
|
|
|
- "strings"
|
|
|
|
"testing"
|
|
"testing"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-func reset() {
|
|
|
|
- pubTopics = make(map[string]*pubConsumers)
|
|
|
|
- subExps = make(map[string]*subChan)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func TestSharedInmemoryNode(t *testing.T) {
|
|
func TestSharedInmemoryNode(t *testing.T) {
|
|
- reset()
|
|
|
|
|
|
+ pubsub.Reset()
|
|
id := "test_id"
|
|
id := "test_id"
|
|
sinkProps := make(map[string]interface{})
|
|
sinkProps := make(map[string]interface{})
|
|
- sinkProps[IdProperty] = id
|
|
|
|
|
|
+ sinkProps[pubsub.IdProperty] = id
|
|
src := GetSource()
|
|
src := GetSource()
|
|
snk := GetSink()
|
|
snk := GetSink()
|
|
contextLogger := conf.Log.WithField("rule", "test")
|
|
contextLogger := conf.Log.WithField("rule", "test")
|
|
@@ -56,7 +50,7 @@ func TestSharedInmemoryNode(t *testing.T) {
|
|
t.Error(err)
|
|
t.Error(err)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- srcProps[IdProperty] = id
|
|
|
|
|
|
+ srcProps[pubsub.IdProperty] = id
|
|
err = src.Configure(id, srcProps)
|
|
err = src.Configure(id, srcProps)
|
|
if err != nil {
|
|
if err != nil {
|
|
t.Error(err)
|
|
t.Error(err)
|
|
@@ -65,9 +59,9 @@ func TestSharedInmemoryNode(t *testing.T) {
|
|
src.Open(ctx, consumer, errorChannel)
|
|
src.Open(ctx, consumer, errorChannel)
|
|
}()
|
|
}()
|
|
|
|
|
|
- if _, contains := pubTopics[id]; !contains {
|
|
|
|
- t.Errorf("there should be memory node for topic")
|
|
|
|
- }
|
|
|
|
|
|
+ //if _, contains := pubTopics[id]; !contains {
|
|
|
|
+ // t.Errorf("there should be memory node for topic")
|
|
|
|
+ //}
|
|
|
|
|
|
data := make(map[string]interface{})
|
|
data := make(map[string]interface{})
|
|
data["temperature"] = 33.0
|
|
data["temperature"] = 33.0
|
|
@@ -92,94 +86,8 @@ func TestSharedInmemoryNode(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func TestCreateAndClose(t *testing.T) {
|
|
|
|
- reset()
|
|
|
|
- var (
|
|
|
|
- sourceTopics = []string{"h/d1/c1/s2", "h/+/+/s1", "h/d3/#", "h/d1/c1/s2", "h/+/c1/s1"}
|
|
|
|
- sinkTopics = []string{"h/d1/c1/s1", "h/d1/c1/s2", "h/d2/c2/s1", "h/d3/c3/s1", "h/d1/c1/s1"}
|
|
|
|
- chans []chan api.SourceTuple
|
|
|
|
- )
|
|
|
|
- for i, topic := range sinkTopics {
|
|
|
|
- CreatePub(topic)
|
|
|
|
- var (
|
|
|
|
- r *regexp.Regexp
|
|
|
|
- err error
|
|
|
|
- )
|
|
|
|
- if strings.ContainsAny(sourceTopics[i], "+#") {
|
|
|
|
- r, err = getRegexp(sourceTopics[i])
|
|
|
|
- if err != nil {
|
|
|
|
- t.Error(err)
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- c := CreateSub(sourceTopics[i], r, fmt.Sprintf("%d", i), 100)
|
|
|
|
- chans = append(chans, c)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- expPub := map[string]*pubConsumers{
|
|
|
|
- "h/d1/c1/s1": {
|
|
|
|
- count: 2,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{
|
|
|
|
- "1": chans[1],
|
|
|
|
- "4": chans[4],
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- "h/d1/c1/s2": {
|
|
|
|
- count: 1,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{
|
|
|
|
- "0": chans[0],
|
|
|
|
- "3": chans[3],
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- "h/d2/c2/s1": {
|
|
|
|
- count: 1,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{
|
|
|
|
- "1": chans[1],
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- "h/d3/c3/s1": {
|
|
|
|
- count: 1,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{
|
|
|
|
- "1": chans[1],
|
|
|
|
- "2": chans[2],
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- if !reflect.DeepEqual(expPub, pubTopics) {
|
|
|
|
- t.Errorf("Error adding: Expect\n\t%v\nbut got\n\t%v", render.AsCode(expPub), render.AsCode(pubTopics))
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- i := 0
|
|
|
|
- for i < 3 {
|
|
|
|
- CloseSourceConsumerChannel(sourceTopics[i], fmt.Sprintf("%d", i))
|
|
|
|
- RemovePub(sinkTopics[i])
|
|
|
|
- i++
|
|
|
|
- }
|
|
|
|
- expPub = map[string]*pubConsumers{
|
|
|
|
- "h/d1/c1/s1": {
|
|
|
|
- count: 1,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{
|
|
|
|
- "4": chans[4],
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- "h/d1/c1/s2": {
|
|
|
|
- count: 0,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{
|
|
|
|
- "3": chans[3],
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- "h/d3/c3/s1": {
|
|
|
|
- count: 1,
|
|
|
|
- consumers: map[string]chan api.SourceTuple{},
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- if !reflect.DeepEqual(expPub, pubTopics) {
|
|
|
|
- t.Errorf("Error closing: Expect\n\t%v\nbut got\n\t %v", render.AsCode(expPub), render.AsCode(pubTopics))
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func TestMultipleTopics(t *testing.T) {
|
|
func TestMultipleTopics(t *testing.T) {
|
|
- reset()
|
|
|
|
|
|
+ pubsub.Reset()
|
|
var (
|
|
var (
|
|
sourceTopics = []string{"h/d1/c1/s2", "h/+/+/s1", "h/d3/#", "h/d1/c1/s2", "h/+/c1/s1"}
|
|
sourceTopics = []string{"h/d1/c1/s2", "h/+/+/s1", "h/d3/#", "h/d1/c1/s2", "h/+/c1/s1"}
|
|
sinkTopics = []string{"h/d1/c1/s1", "h/d1/c1/s2", "h/d2/c2/s1", "h/d3/c3/s1"}
|
|
sinkTopics = []string{"h/d1/c1/s1", "h/d1/c1/s2", "h/d2/c2/s1", "h/d3/c3/s1"}
|
|
@@ -480,7 +388,7 @@ func TestMultipleTopics(t *testing.T) {
|
|
for c < 3 {
|
|
for c < 3 {
|
|
for i, v := range sinkData {
|
|
for i, v := range sinkData {
|
|
time.Sleep(10 * time.Millisecond)
|
|
time.Sleep(10 * time.Millisecond)
|
|
- Produce(ctx, sinkTopics[i], v[c])
|
|
|
|
|
|
+ pubsub.Produce(ctx, sinkTopics[i], v[c])
|
|
}
|
|
}
|
|
c++
|
|
c++
|
|
}
|
|
}
|