Skip to content

Commit 8945b25

Browse files
committed
Add Wire-based impl
1 parent b84bc72 commit 8945b25

File tree

12 files changed

+722
-0
lines changed

12 files changed

+722
-0
lines changed

jacodb-ets/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ dependencies {
1212
api(project(":jacodb-api-common"))
1313
api(project(":jacodb-ets:grpc-client"))
1414
api(project(":jacodb-ets:grpc-server"))
15+
api(project(":jacodb-ets:wire-client"))
16+
api(project(":jacodb-ets:wire-server"))
1517

1618
implementation(Libs.kotlin_logging)
1719
implementation(Libs.slf4j_simple)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id("com.squareup.wire") version "5.3.1"
3+
}
4+
5+
dependencies {
6+
protoSource(project(":jacodb-ets:wire-protos"))
7+
runtimeOnly("com.squareup.wire:wire-runtime:5.3.1")
8+
api("com.squareup.wire:wire-grpc-client:5.3.1")
9+
}
10+
11+
wire {
12+
kotlin {
13+
rpcRole = "client"
14+
}
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.service
18+
19+
import com.squareup.wire.GrpcMethod
20+
import greeter2.HelloReply
21+
import greeter2.HelloRequest
22+
23+
fun main() {
24+
val port = 50051
25+
// val greeter: GreeterClient = grpcClient(port).create()
26+
// val request = HelloRequest(name = "Kotlin")
27+
// val response = greeter.SayHello().executeBlocking(request)
28+
// println("Response: \"${response.message}\"")
29+
30+
// Below is the manual way to create a gRPC call.
31+
// We use it here to make 'path' contain 'greeter' instead of 'greeter2',
32+
val client = grpcClient(port)
33+
val call = client.newCall(
34+
GrpcMethod(
35+
path = "/greeter.Greeter/SayHello",
36+
requestAdapter = HelloRequest.ADAPTER,
37+
responseAdapter = HelloReply.ADAPTER
38+
)
39+
)
40+
val request = HelloRequest(name = "Kotlin")
41+
val response: HelloReply = call.executeBlocking(request)
42+
println("Response: \"${response.message}\"")
43+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.service
18+
19+
import manager2.ManagerClient
20+
import manager2.GetSceneRequest
21+
22+
fun main() {
23+
val port = 50051
24+
val manager: ManagerClient = grpcClient(port).create()
25+
val path = "TODO"
26+
val request = GetSceneRequest(path)
27+
val scene = manager.GetScene().executeBlocking(request)
28+
println("scene = $scene")
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.service
18+
19+
import com.squareup.wire.GrpcClient
20+
import okhttp3.OkHttpClient
21+
import okhttp3.Protocol
22+
23+
const val DEFAULT_PORT = 7777
24+
25+
fun grpcClient(port: Int = DEFAULT_PORT): GrpcClient {
26+
val okClient = OkHttpClient.Builder()
27+
.protocols(listOf(Protocol.H2_PRIOR_KNOWLEDGE))
28+
.build()
29+
return GrpcClient.Builder()
30+
.client(okClient)
31+
.baseUrl("http://0.0.0.0:$port")
32+
.build()
33+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id("com.squareup.wire") version "5.3.1"
3+
}
4+
5+
dependencies {
6+
runtimeOnly("com.squareup.wire:wire-runtime:5.3.1")
7+
}
8+
9+
wire {
10+
protoLibrary = true
11+
kotlin {
12+
rpcRole = "none"
13+
}
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
syntax = "proto3";
2+
package greeter2;
3+
4+
option java_multiple_files = true;
5+
6+
// The greeter service definition.
7+
service Greeter {
8+
// Sends a greeting
9+
rpc SayHello(HelloRequest) returns (HelloReply);
10+
}
11+
12+
// The request message containing the user's name.
13+
message HelloRequest {
14+
string name = 1;
15+
}
16+
17+
// The response message containing the greetings
18+
message HelloReply {
19+
string message = 1;
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
package manager2;
3+
4+
option java_multiple_files = true;
5+
6+
import "model.proto";
7+
8+
service Manager {
9+
rpc GetScene(GetSceneRequest) returns (model2.Scene);
10+
}
11+
12+
message GetSceneRequest {
13+
string path = 1;
14+
optional bool infer_types = 2;
15+
}

0 commit comments

Comments
 (0)