2023-06-18 18:33:17 -06:00
|
|
|
package graphvent
|
2023-04-08 15:23:40 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-07-23 17:57:47 -06:00
|
|
|
"runtime/debug"
|
2023-06-22 15:50:42 -06:00
|
|
|
badger "github.com/dgraph-io/badger/v3"
|
2023-04-08 15:23:40 -06:00
|
|
|
)
|
|
|
|
|
2023-08-31 19:50:32 -06:00
|
|
|
var SimpleListenerNodeType = NewNodeType("SIMPLE_LISTENER")
|
2023-07-27 00:30:24 -06:00
|
|
|
|
|
|
|
func NewSimpleListener(ctx *Context, buffer int) (*Node, *ListenerExt) {
|
|
|
|
listener_extension := NewListenerExt(buffer)
|
2023-07-27 11:33:11 -06:00
|
|
|
listener := NewNode(ctx,
|
2023-07-28 15:07:38 -06:00
|
|
|
nil,
|
2023-07-27 11:33:11 -06:00
|
|
|
SimpleListenerNodeType,
|
2023-07-28 13:45:14 -06:00
|
|
|
10,
|
2023-07-27 15:27:14 -06:00
|
|
|
nil,
|
2023-07-27 11:33:11 -06:00
|
|
|
listener_extension,
|
2023-08-11 13:01:32 -06:00
|
|
|
NewLockableExt(nil))
|
2023-07-27 00:30:24 -06:00
|
|
|
|
|
|
|
return listener, listener_extension
|
|
|
|
}
|
|
|
|
|
2023-07-25 21:43:15 -06:00
|
|
|
func logTestContext(t * testing.T, components []string) *Context {
|
2023-06-23 10:10:25 -06:00
|
|
|
db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
|
2023-06-20 22:36:18 -06:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-07-25 21:43:15 -06:00
|
|
|
ctx, err := NewContext(db, NewConsoleLogger(components))
|
|
|
|
fatalErr(t, err)
|
2023-07-27 00:30:24 -06:00
|
|
|
|
2023-08-07 20:26:02 -06:00
|
|
|
err = ctx.RegisterNodeType(SimpleListenerNodeType, []ExtType{ListenerExtType, LockableExtType})
|
2023-07-27 00:30:24 -06:00
|
|
|
fatalErr(t, err)
|
|
|
|
|
2023-07-25 21:43:15 -06:00
|
|
|
return ctx
|
2023-06-20 22:36:18 -06:00
|
|
|
}
|
|
|
|
|
2023-07-09 14:30:30 -06:00
|
|
|
func testContext(t * testing.T) * Context {
|
2023-07-27 00:30:24 -06:00
|
|
|
return logTestContext(t, []string{})
|
2023-06-20 20:48:48 -06:00
|
|
|
}
|
|
|
|
|
2023-06-23 10:10:25 -06:00
|
|
|
func fatalErr(t * testing.T, err error) {
|
2023-06-20 20:48:48 -06:00
|
|
|
if err != nil {
|
2023-07-23 17:57:47 -06:00
|
|
|
debug.PrintStack()
|
2023-06-20 20:48:48 -06:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-05-29 19:17:52 -06:00
|
|
|
}
|