How do we test views using integration tests?


I have been trying to find a way to test views. Since I do not find any example yet I tried using integration test to test things out. However when I run the test, I do get the error:

{“timestamp”:“2022-12-11T08:04:35.204Z”,“thread”:“”,“logger”:“kalix.javasdk.impl.DiscoveryImpl”,“message”:“Error reported from Kalix system: KLX-00121 An incoming event for the view [CustomerByCityStreaming] was missing the subject id attribute ce-subject, view updates are stalled.\n\nEach update passed to a view must have a subject id, used as a primary key in the view, each unique subject-id can only have one entry in the view, if the update comes from a message broker the subject id is defined with the cloud event attribute [ce-subject]. \n\nAt customer/view/customer_view.proto:134:1:\nservice CustomerByCityStreaming {\n option (kalix.codegen) = {\n view: {}\n };\n\n // update methods omitted”,“context”:“default”,“severity”:“ERROR”}

What I had in the test was:

private val viewClient = testKit.getGrpcClient(classOf[CustomerByCityStreaming])

  val result =
    viewClient.processCustomerCreated(CustomerCreated(Some(CustomerState("1", "", "name", None))))

  result.futureValue shouldBe Customer("1", "", "name", None)

Is there any example that I can follow or how do we properly test view code? Thanks for your help.

Hi @wpoosanguansit it looks like you are trying to test a view based on the entity events stream (or some Although it is possible from the gRPC perspective, you shouldn’t send events by hand in this case. This might corrupt the view state. There is no ViewTestKit yet, but you can stay with integration tests. Simply run some command against your entity, to produce expected events, “consumed” later by the view.

Some examples of a ValueEntity IT tests: kalix-jvm-sdk/ShoppingCartServiceIntegrationSpec.scala at main · lightbend/kalix-jvm-sdk · GitHub

1 Like

Thank you. I will check that out.