(t *testing.T)
| 235 | } |
| 236 | |
| 237 | func 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 | } |
nothing calls this directly
no test coverage detected