Skip to content

Commit

Permalink
fix codegen for services with multiple RPCs (#166)
Browse files Browse the repository at this point in the history
#132 introduced a bug that caused the code generator to emit
bad code for services that expose multiple RPCs. This change
fixes the error and adds a test case to avoid future regressions.
  • Loading branch information
ccmtaylor authored Sep 29, 2020
1 parent 74c8deb commit c6e6841
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class TwinagleServicePrinter(
s"""
|object $serviceName {
| implicit val asProtoService: $AsProtoService[$serviceName] = (service: $serviceName) => $ProtoService(Seq(
|${m.methods.map(protoRpc).mkString("\n")}
|${m.methods.map(protoRpc).mkString(",\n")}
| ))
|
| def server(service: $serviceName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package proto.test;

message MMRequest {}

message MMResponse {}

service MultiMethod {
rpc Rpc1(MMRequest) returns (MMResponse);
rpc Rpc2(MMRequest) returns (MMResponse);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package proto.test

import com.twitter.util.Future
import com.soundcloud.twinagle.ServerBuilder

import org.specs2.mutable.Specification

class MultiMethodServiceSpec extends Specification {

// if this compiles, we're good
"ServerBuilder allows building services that contain multiple RPCs" in {
val svc = new MultiMethodService {
override def rpc1(req: MMRequest): Future[MMResponse] = Future.value(MMResponse())
override def rpc2(req: MMRequest): Future[MMResponse] = Future.value(MMResponse())
}


val httpService = ServerBuilder()
.register(svc)
.build

new MultiMethodClientProtobuf(httpService)
new MultiMethodClientJson(httpService)
ok
}
}

0 comments on commit c6e6841

Please sign in to comment.