Skip to content

Commit 5b4beb8

Browse files
authored
feat: Ignore eventing.in methods (#1039)
* bump: kalix-proxy 1.0.12 * skip codegen of methods marked with `ignore: true` in Actions and Views * they will be handled by the proxy, without calling the user function * remove update annotation for the ignore methods in Views
1 parent f527dac commit 5b4beb8

File tree

49 files changed

+149
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+149
-166
lines changed

codegen/core/src/main/scala/kalix/codegen/ModelBuilder.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ object ModelBuilder {
309309
streamedInput: Boolean,
310310
streamedOutput: Boolean,
311311
inFromTopic: Boolean,
312-
outToTopic: Boolean) {
312+
outToTopic: Boolean,
313+
ignore: Boolean) {
313314

314315
def isUnary: Boolean = !streamedInput && !streamedOutput
315316
def isStreamIn: Boolean = streamedInput && !streamedOutput
@@ -329,7 +330,8 @@ object ModelBuilder {
329330
streamedInput = method.isClientStreaming,
330331
streamedOutput = method.isServerStreaming,
331332
inFromTopic = eventing.hasIn && eventing.getIn.hasTopic,
332-
outToTopic = eventing.hasOut && eventing.getOut.hasTopic)
333+
outToTopic = eventing.hasOut && eventing.getOut.hasTopic,
334+
ignore = eventing.hasIn && eventing.getIn.getIgnore)
333335
}
334336
}
335337

@@ -549,10 +551,12 @@ object ModelBuilder {
549551
case (method, viewOptions) if viewOptions.hasUpdate =>
550552
Command.from(method)
551553
}
552-
val transformedUpdates = methodDetails.collect {
553-
case (method, viewOptions) if viewOptions.hasUpdate && viewOptions.getUpdate.getTransformUpdates =>
554-
Command.from(method)
555-
}
554+
val transformedUpdates = methodDetails
555+
.collect {
556+
case (method, viewOptions) if viewOptions.hasUpdate && viewOptions.getUpdate.getTransformUpdates =>
557+
Command.from(method)
558+
}
559+
.filterNot(_.ignore)
556560
val queries = methodDetails.collect {
557561
case (method, viewOptions) if viewOptions.hasQuery =>
558562
Command.from(method)

codegen/java-gen/src/main/scala/kalix/codegen/java/ActionServiceSourceGenerator.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ object ActionServiceSourceGenerator {
5757

5858
val packageName = service.messageType.parent.javaPackage
5959
val className = service.className
60+
val commands = service.commands.filterNot(_.ignore)
6061

6162
val imports = generateImports(
6263
service.commandTypes,
6364
packageName,
64-
otherImports = Seq("kalix.javasdk.action.ActionCreationContext") ++ streamImports(service.commands))
65+
otherImports = Seq("kalix.javasdk.action.ActionCreationContext") ++ streamImports(commands))
6566

66-
val methods = service.commands.map { cmd =>
67+
val methods = commands.filterNot(_.ignore).map { cmd =>
6768
val methodName = cmd.name
6869
val input = lowerFirst(cmd.inputType.name)
6970
val inputTypeFullName = cmd.inputType.fullName
@@ -124,13 +125,14 @@ object ActionServiceSourceGenerator {
124125
private[codegen] def abstractActionSource(service: ModelBuilder.ActionService, rootPackage: String): String = {
125126

126127
val packageName = service.messageType.parent.javaPackage
128+
val commands = service.commands.filterNot(_.ignore)
127129
val imports = generateImports(
128130
service.commandTypes,
129131
packageName,
130-
otherImports = streamImports(service.commands) ++
132+
otherImports = streamImports(commands) ++
131133
Seq(s"$rootPackage.Components", s"$rootPackage.ComponentsImpl"))
132134

133-
val methods = service.commands.map { cmd =>
135+
val methods = commands.map { cmd =>
134136
val methodName = cmd.name
135137
val input = lowerFirst(cmd.inputType.name)
136138
val inputTypeFullName = cmd.inputType.fullName
@@ -173,8 +175,9 @@ object ActionServiceSourceGenerator {
173175

174176
val className = service.className
175177
val packageName = service.messageType.parent.javaPackage
178+
val commands = service.commands.filterNot(_.ignore)
176179

177-
val unaryCases = service.commands.filter(_.isUnary).map { cmd =>
180+
val unaryCases = commands.filter(_.isUnary).map { cmd =>
178181
val methodName = cmd.name
179182
val inputTypeFullName = cmd.inputType.fullName
180183

@@ -184,7 +187,7 @@ object ActionServiceSourceGenerator {
184187
|""".stripMargin
185188
}
186189

187-
val streamOutCases = service.commands.filter(_.isStreamOut).map { cmd =>
190+
val streamOutCases = commands.filter(_.isStreamOut).map { cmd =>
188191
val methodName = cmd.name
189192
val inputTypeFullName = cmd.inputType.fullName
190193

@@ -194,7 +197,7 @@ object ActionServiceSourceGenerator {
194197
|""".stripMargin
195198
}
196199

197-
val streamInCases = service.commands.filter(_.isStreamIn).map { cmd =>
200+
val streamInCases = commands.filter(_.isStreamIn).map { cmd =>
198201
val methodName = cmd.name
199202
val inputTypeFullName = cmd.inputType.fullName
200203

@@ -204,7 +207,7 @@ object ActionServiceSourceGenerator {
204207
|""".stripMargin
205208
}
206209

207-
val streamInOutCases = service.commands.filter(_.isStreamInOut).map { cmd =>
210+
val streamInOutCases = commands.filter(_.isStreamInOut).map { cmd =>
208211
val methodName = cmd.name
209212
val inputTypeFullName = cmd.inputType.fullName
210213

codegen/java-gen/src/main/scala/kalix/codegen/java/ActionTestKitGenerator.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ object ActionTestKitGenerator {
3434

3535
val packageName = service.messageType.parent.javaPackage
3636
val className = service.className
37+
val commands = service.commands.filterNot(_.ignore)
3738

3839
val imports = generateImports(
39-
commandTypes(service.commands),
40+
commandTypes(commands),
4041
"",
4142
otherImports = Seq(
4243
"java.util.function.Function",
@@ -49,7 +50,7 @@ object ActionTestKitGenerator {
4950
"kalix.javasdk.testkit.impl.ActionResultImpl",
5051
"kalix.javasdk.testkit.impl.TestKitActionContext",
5152
"kalix.javasdk.testkit.MockRegistry")
52-
++ commandStreamedTypes(service.commands))
53+
++ commandStreamedTypes(commands))
5354

5455
val testKitClassName = s"${className}TestKit"
5556

@@ -99,8 +100,9 @@ object ActionTestKitGenerator {
99100
private[codegen] def generateTestSourceCode(service: ModelBuilder.ActionService): String = {
100101
val className = service.className
101102
val packageName = service.messageType.parent.javaPackage
103+
val commands = service.commands.filterNot(_.ignore)
102104
val imports = generateImports(
103-
commandTypes(service.commands),
105+
commandTypes(commands),
104106
"",
105107
otherImports = Seq(
106108
s"$packageName.$className",
@@ -110,7 +112,7 @@ object ActionTestKitGenerator {
110112
"org.junit.Ignore",
111113
"org.junit.Test",
112114
"static org.junit.Assert.*")
113-
++ commandStreamedTypes(service.commands))
115+
++ commandStreamedTypes(commands))
114116

115117
val testClassName = s"${className}Test"
116118

@@ -141,9 +143,9 @@ object ActionTestKitGenerator {
141143
}
142144

143145
def generateServices(service: ModelBuilder.ActionService): String = {
144-
require(!service.commands.isEmpty, "empty `commands` not allowed")
146+
val commands = service.commands.filterNot(_.ignore)
145147

146-
service.commands
148+
commands
147149
.map { command =>
148150
s"""|public ${selectOutputResult(command)} ${lowerFirst(command.name)}(${selectInputType(command)} ${lowerFirst(
149151
command.inputType.protoName)}, Metadata metadata) {
@@ -161,9 +163,9 @@ object ActionTestKitGenerator {
161163
* Leveraging `generateServices` by setting default Metadata as Metadata.EMPTY
162164
*/
163165
def generateServicesDefault(service: ModelBuilder.ActionService): String = {
164-
require(!service.commands.isEmpty, "empty `commands` not allowed")
166+
val commands = service.commands.filterNot(_.ignore)
165167

166-
service.commands
168+
commands
167169
.map { command =>
168170
s"""|public ${selectOutputResult(command)} ${lowerFirst(command.name)}(${selectInputType(command)} ${lowerFirst(
169171
command.inputType.protoName)}) {
@@ -175,7 +177,9 @@ object ActionTestKitGenerator {
175177
}
176178

177179
def generateTestingServices(service: ModelBuilder.ActionService): String = {
178-
service.commands
180+
val commands = service.commands.filterNot(_.ignore)
181+
182+
commands
179183
.map { command =>
180184
s"""|@Test
181185
|@Ignore("to be implemented")

codegen/java-gen/src/main/scala/kalix/codegen/java/EventSourcedEntityTestKitGenerator.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,15 @@ object EventSourcedEntityTestKitGenerator {
116116
}
117117

118118
def generateServices(service: ModelBuilder.EntityService): String = {
119-
require(!service.commands.isEmpty, "empty `commands` not allowed")
120-
121119
def selectOutput(command: ModelBuilder.Command): String =
122120
if (command.outputType.name == "Empty") {
123121
"Empty"
124122
} else {
125123
command.outputType.fullName
126124
}
127125

128-
service.commands
126+
val commands = service.commands.filterNot(_.ignore)
127+
commands
129128
.map { command =>
130129
s"""|public EventSourcedResult<${selectOutput(command)}> ${lowerFirst(command.name)}(${command.inputType.fullName} command, Metadata metadata) {
131130
| return interpretEffects(() -> entity.${lowerFirst(command.name)}(getState(), command), metadata);
@@ -136,16 +135,15 @@ object EventSourcedEntityTestKitGenerator {
136135
}
137136

138137
def generateServicesDefault(service: ModelBuilder.EntityService): String = {
139-
require(!service.commands.isEmpty, "empty `commands` not allowed")
140-
141138
def selectOutput(command: ModelBuilder.Command): String =
142139
if (command.outputType.name == "Empty") {
143140
"Empty"
144141
} else {
145142
command.outputType.fullName
146143
}
147144

148-
service.commands
145+
val commands = service.commands.filterNot(_.ignore)
146+
commands
149147
.map { command =>
150148
s"""|public EventSourcedResult<${selectOutput(command)}> ${lowerFirst(command.name)}(${command.inputType.fullName} command) {
151149
| return interpretEffects(() -> entity.${lowerFirst(command.name)}(getState(), command), Metadata.EMPTY);
@@ -181,6 +179,7 @@ object EventSourcedEntityTestKitGenerator {
181179

182180
def generateTestSources(service: ModelBuilder.EntityService, entity: ModelBuilder.EventSourcedEntity): String = {
183181
val packageName = entity.messageType.parent.javaPackage
182+
val commands = service.commands.filterNot(_.ignore)
184183
val imports = generateImports(
185184
allRelevantMessageTypes(service, entity),
186185
packageName,
@@ -195,7 +194,7 @@ object EventSourcedEntityTestKitGenerator {
195194
val entityClassName = entity.messageType.name
196195
val testkitClassName = s"${entityClassName}TestKit"
197196

198-
val dummyTestCases = service.commands.map { command =>
197+
val dummyTestCases = commands.map { command =>
199198
s"""|@Test
200199
|@Ignore("to be implemented")
201200
|public void ${lowerFirst(command.name)}Test() {

codegen/scala-gen/src/main/scala/kalix/codegen/scalasdk/impl/ActionServiceSourceGenerator.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ object ActionServiceSourceGenerator {
4747
import Types.Action._
4848

4949
val className = service.className
50+
val commands = service.commands.filterNot(_.ignore)
5051

51-
val methods = service.commands.map { cmd =>
52+
val methods = commands.map { cmd =>
5253
val methodName = cmd.name
5354
val input = lowerFirst(cmd.inputType.name)
5455
val inputType = cmd.inputType
@@ -103,7 +104,8 @@ object ActionServiceSourceGenerator {
103104
import Types.{ Source, NotUsed }
104105
import Types.Action._
105106

106-
val methods = service.commands.map { cmd =>
107+
val commands = service.commands.filterNot(_.ignore)
108+
val methods = commands.map { cmd =>
107109
val methodName = cmd.name
108110
val input = lowerFirst(cmd.inputType.name)
109111
val inputType = cmd.inputType
@@ -146,7 +148,9 @@ object ActionServiceSourceGenerator {
146148
import Types.{ Source, NotUsed }
147149
import Types.Action._
148150

149-
val unaryCases = service.commands.filter(_.isUnary).map { cmd =>
151+
val commands = service.commands.filterNot(_.ignore)
152+
153+
val unaryCases = commands.filter(_.isUnary).map { cmd =>
150154
val methodName = cmd.name
151155
val inputType = cmd.inputType
152156

@@ -155,7 +159,7 @@ object ActionServiceSourceGenerator {
155159
|"""
156160
}
157161

158-
val streamOutCases = service.commands.filter(_.isStreamOut).map { cmd =>
162+
val streamOutCases = commands.filter(_.isStreamOut).map { cmd =>
159163
val methodName = cmd.name
160164
val inputType = cmd.inputType
161165

@@ -164,7 +168,7 @@ object ActionServiceSourceGenerator {
164168
|"""
165169
}
166170

167-
val streamInCases = service.commands.filter(_.isStreamIn).map { cmd =>
171+
val streamInCases = commands.filter(_.isStreamIn).map { cmd =>
168172
val methodName = cmd.name
169173
val inputType = cmd.inputType
170174

@@ -173,7 +177,7 @@ object ActionServiceSourceGenerator {
173177
|"""
174178
}
175179

176-
val streamInOutCases = service.commands.filter(_.isStreamInOut).map { cmd =>
180+
val streamInOutCases = commands.filter(_.isStreamInOut).map { cmd =>
177181
val methodName = cmd.name
178182
val inputType = cmd.inputType
179183

codegen/scala-gen/src/main/scala/kalix/codegen/scalasdk/impl/ActionTestKitGenerator.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,23 @@ object ActionTestKitGenerator {
3333
Seq(testkit(service))
3434

3535
private[codegen] def testkit(service: ModelBuilder.ActionService): File = {
36+
val commands = service.commands.filterNot(_.ignore)
3637
implicit val imports: Imports =
3738
generateImports(
38-
service.commands.map(_.inputType) ++
39-
service.commands.map(_.outputType),
39+
commands.map(_.inputType) ++
40+
commands.map(_.outputType),
4041
service.messageType.parent.scalaPackage,
4142
otherImports = Seq(
4243
"kalix.scalasdk.Metadata",
4344
"kalix.scalasdk.testkit.ActionResult",
4445
"kalix.scalasdk.testkit.impl.ActionResultImpl",
4546
"kalix.scalasdk.action.ActionCreationContext",
4647
"kalix.scalasdk.testkit.impl.TestKitActionContext",
47-
"kalix.scalasdk.testkit.MockRegistry") ++ commandStreamedTypes(service.commands))
48+
"kalix.scalasdk.testkit.MockRegistry") ++ commandStreamedTypes(commands))
4849

4950
val actionClassName = service.className
5051

51-
val methods = service.commands.map { cmd =>
52+
val methods = commands.map { cmd =>
5253
s"""def ${lowerFirst(cmd.name)}(command: ${selectInput(
5354
cmd)}, metadata: Metadata = Metadata.empty): ${selectOutputResult(cmd)} = {\n""" +
5455
" val context = new TestKitActionContext(metadata, mockRegistry)\n" +
@@ -101,20 +102,20 @@ object ActionTestKitGenerator {
101102
}
102103

103104
def test(service: ModelBuilder.ActionService): File = {
104-
105+
val commands = service.commands.filterNot(_.ignore)
105106
implicit val imports: Imports =
106107
generateImports(
107-
service.commands.map(_.inputType) ++ service.commands.map(_.outputType),
108+
commands.map(_.inputType) ++ commands.map(_.outputType),
108109
service.messageType.parent.scalaPackage,
109110
otherImports = Seq(
110111
"kalix.scalasdk.action.Action",
111112
"kalix.scalasdk.testkit.ActionResult",
112113
"org.scalatest.matchers.should.Matchers",
113-
"org.scalatest.wordspec.AnyWordSpec") ++ commandStreamedTypes(service.commands))
114+
"org.scalatest.wordspec.AnyWordSpec") ++ commandStreamedTypes(commands))
114115

115116
val actionClassName = service.className
116117

117-
val testCases = service.commands.map { cmd =>
118+
val testCases = commands.map { cmd =>
118119
s""""handle command ${cmd.name}" in {\n""" +
119120
(if (cmd.isUnary || cmd.isStreamOut)
120121
s"""| val service = ${actionClassName}TestKit(new $actionClassName(_))

0 commit comments

Comments
 (0)