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

Function TestStatefulFunction

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

Source from the content-addressed store, hash-verified

235}
236
237func TestStatefulFunction(t *testing.T) {
238 ctx, cancel := context.WithCancel(context.Background())
239 defer cancel()
240 s, httpAddr := startStandaloneSvr(t, ctx,
241 WithRuntimeFactoryBuilder("mock", func(configMap common.ConfigMap) (api.FunctionRuntimeFactory, error) {
242 return &MockRuntimeFactory{}, nil
243 }))
244
245 input := "input"
246 output := "output"
247 funcConf := &model.Function{
248 Name: "test-func",
249 Runtime: model.RuntimeConfig{
250 Type: "mock",
251 },
252 Sources: []model.TubeConfig{
253 {
254 Type: common.MemoryTubeType,
255 Config: (&contube.SourceQueueConfig{
256 Topics: []string{input},
257 SubName: "test",
258 }).ToConfigMap(),
259 },
260 },
261 Sink: model.TubeConfig{
262 Type: common.MemoryTubeType,
263 Config: (&contube.SinkQueueConfig{
264 Topic: "output",
265 }).ToConfigMap(),
266 },
267 Replicas: 1,
268 }
269 err := s.Manager.StartFunction(funcConf)
270 if err != nil {
271 t.Fatal(err)
272 }
273
274 cfg := adminclient.NewConfiguration()
275 cfg.Host = httpAddr
276 cli := adminclient.NewAPIClient(cfg)
277
278 _, err = cli.StateAPI.SetState(ctx, "key").Body("hello").Execute()
279 assert.Nil(t, err)
280
281 err = s.Manager.ProduceEvent(input, contube.NewRecordImpl(nil, func() {
282 }))
283 assert.Nil(t, err)
284
285 _, err = s.Manager.ConsumeEvent(output)
286 assert.Nil(t, err)
287
288 result, _, err := cli.StateAPI.GetState(ctx, "key").Execute()
289 assert.Nil(t, err)
290 assert.Equal(t, "hello!", result)
291}

Callers

nothing calls this directly

Calls 11

NewRecordImplFunction · 0.92
startStandaloneSvrFunction · 0.85
SetStateMethod · 0.80
StartFunctionMethod · 0.65
ProduceEventMethod · 0.65
ConsumeEventMethod · 0.65
GetStateMethod · 0.65
ToConfigMapMethod · 0.45
ExecuteMethod · 0.45
BodyMethod · 0.45

Tested by

no test coverage detected