MCPcopy Index your code
hub / github.com/FunctionStream/function-stream / TestStandaloneBasicFunction

Function TestStandaloneBasicFunction

server/server_test.go:67–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

65}
66
67func TestStandaloneBasicFunction(t *testing.T) {
68 ctx, cancel := context.WithCancel(context.Background())
69 defer cancel()
70 s, _ := startStandaloneSvr(t, ctx)
71
72 inputTopic := "test-input-" + strconv.Itoa(rand.Int())
73 outputTopic := "test-output-" + strconv.Itoa(rand.Int())
74
75 funcConf := &model.Function{
76 Runtime: model.RuntimeConfig{
77 Type: common.WASMRuntime,
78 Config: map[string]interface{}{
79 common.RuntimeArchiveConfigKey: "../bin/example_basic.wasm",
80 },
81 },
82 Sources: []model.TubeConfig{
83 {
84 Type: common.MemoryTubeType,
85 Config: (&contube.SourceQueueConfig{
86 Topics: []string{inputTopic},
87 SubName: "test",
88 }).ToConfigMap(),
89 },
90 },
91 Sink: model.TubeConfig{
92 Type: common.MemoryTubeType,
93 Config: (&contube.SinkQueueConfig{
94 Topic: outputTopic,
95 }).ToConfigMap(),
96 },
97 Name: "test-func",
98 Replicas: 1,
99 }
100 err := s.Manager.StartFunction(funcConf)
101 if err != nil {
102 t.Fatal(err)
103 }
104
105 p := &tests.Person{
106 Name: "rbt",
107 Money: 0,
108 }
109 jsonBytes, err := json.Marshal(p)
110 if err != nil {
111 t.Fatal(err)
112 }
113 err = s.Manager.ProduceEvent(inputTopic, contube.NewRecordImpl(jsonBytes, func() {
114 }))
115 if err != nil {
116 t.Fatal(err)
117 }
118
119 event, err := s.Manager.ConsumeEvent(outputTopic)
120 if err != nil {
121 t.Error(err)
122 return
123 }
124 var out tests.Person

Callers

nothing calls this directly

Calls 8

NewRecordImplFunction · 0.92
startStandaloneSvrFunction · 0.85
ErrorMethod · 0.80
StartFunctionMethod · 0.65
ProduceEventMethod · 0.65
ConsumeEventMethod · 0.65
GetPayloadMethod · 0.65
ToConfigMapMethod · 0.45

Tested by

no test coverage detected