Skip to content

Commit

Permalink
Merge branch 'chore/fix-build' into issue-298
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Jun 7, 2024
2 parents d697996 + dc2ce2a commit c404aa5
Show file tree
Hide file tree
Showing 137 changed files with 10,978 additions and 10,371 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.7.2
34b9f2c2d303a4c50988182586860b57dca5fa5d
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
43 changes: 30 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,56 @@ jobs:
build:
strategy:
matrix:
scala: [2_12, 2_13]
scala: [2_12, 2_13, 3]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: 8
distribution: temurin
cache: sbt
- name: Set up node.js
uses: actions/setup-node@v4
with:
java-version: 1.8
node-version: "18.16.1"

- name: Mount caches
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.sbt
~/.ivy2/cache
~/.cache/coursier
~/.cache/ms-playwright
key: ${{ runner.os }}-sbt-${{matrix.scala}}-${{ hashFiles('**/*.sbt') }}

- name: Formatting
run: |
sbt scalafmtCheck test:scalafmtCheck scalafmtSbtCheck
sbt scalafmtCheck Test/scalafmtCheck scalafmtSbtCheck
- name: Compile and test (JVM)
run: |
sbt coreJVM${{matrix.scala}}/test e2eJVM${{matrix.scala}}/test
# e2eJVM${{matrix.scala}}/it:test
- name: Compile and test (JS)
run: |
sbt coreJS${{matrix.scala}}/test
- name: Compile and test
- name: Run grpc-web e2e test
if: ${{ matrix.scala != 3 }}
run: |
sbt coreJVM${{matrix.scala}}/test e2eJVM${{matrix.scala}}/test \
coreJS${{matrix.scala}}/test
docker-compose -f ./examples/fullapp/docker-compose.yaml up -d
sbt e2eWebJS${{matrix.scala}}/fastOptJS/webpack e2eWebJVM${{matrix.scala}}/test
docker-compose -f ./examples/fullapp/docker-compose.yaml down
- name: Examples
run: |
cd examples
for d in */ ; do cd "$d" && sbt scalafmtCheck test:scalafmtCheck scalafmtSbtCheck test && cd ../ ; done
.github/workflows/test_examples.sh
# Single final job for mergify.
ci-passed:
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
with:
node-version: '12.x'
- name: Set up JDK 1.8
uses: actions/setup-java@v1
fetch-depth: 0
- uses: actions/setup-node@v4
with:
java-version: 1.8
node-version: '16.x'
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
cache: sbt
- name: Update docs
run: |
git config --global user.name "ZIO-gRPC Docs"
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/test_examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
cd examples

for d in */
do
echo "** Running test for examples/$d"
( cd "$d" && sbt scalafmtCheck Test/scalafmtCheck scalafmtSbtCheck test )
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.log
target
.bsp
.sbt
.idea
.metals
.bloop
Expand Down
11 changes: 8 additions & 3 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
queue_rules:
- name: default
conditions:
- check-success=ci-passed

pull_request_rules:
- name: assign and label scala-steward's PRs
conditions:
Expand All @@ -10,8 +15,8 @@ pull_request_rules:
- name: merge scala-steward's PRs
conditions:
- author=scala-steward
- status-success=ci-passed
- check-success=ci-passed
actions:
merge:
queue:
method: squash
strict: true
name: default
13 changes: 11 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
version = "2.7.5"
version = "3.7.2"
rewrite.rules = [SortImports, RedundantBraces]
maxColumn = 120
align = most
align.preset = most
runner.dialect = scala213source3
fileOverride {
"glob:**/e2e/target/jvm-3/src_managed/main/**" {
runner.dialect = scala3
}
"glob:**/code-gen/target/jvm-3/src_managed/main/**" {
runner.dialect = scala3
}
}
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changelog

## 0.6.1
* Only buffer stream if queue size is positive (#578, #580)

## 0.6.0

### What changed?

* Backpressure queue size is controlled by either
`ZIO_GRPC_BACKPRESSURE_QUEUE_SIZE` environment variable or
`zio_grpc.backpressure_queue_size` system property (previously the names
were hyphenated). Change was made for compatibility with ZIO Config.
* GeneratedServices no longer have a `R` type parameter for generated services. This simplifies the previous APIs and encourages the ZIO 2
style that service dependencies are passed via constructors (see [service pattern](https://zio.dev/reference/service-pattern/))
* Added `E` type parameter that represents the error type.
* Context is now received as a second parameter for each handler. For
convenience, there is a trait that only takes one parameter (the request
type).
* Introduce Transform for effectful transformations for services that do not have context.
* Introduce GTransform for effectful transformations over both context and error type.
* `ZTransform[ContextIn, ContextOut]` is now a type alias to GTransform that
fixes the error channel to StatusException.
* Classes and methods with suffix ClientWithMetadata have been renamed to ClientWithResponseMetadata.
* Removed the `R` type parameter in most APIs.
* ManagedServer renamed to ScopedServer.
* Clean shutdown when a server is ran through a Scope or ZLayer.
* Added backpressure support [docs](https://scalapb.github.io/zio-grpc/docs/backpressure)
* Added client support for response metadata (#428)
* Signifcant server performance improvement ([2.4x faster handling](https://github.com/scalapb/zio-grpc/pull/457#issuecomment-1350234894)) (#457)
* Server can now send response metadata (#418)
* Clients can now access the response metadata sent by server (#428)
* ServiceList now has a `provideLayer` and `provide` that can be used to
satisfy services dependencies.
32 changes: 0 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,5 @@ This library enables you to write purely functional [gRPC](https://grpc.io/) ser
* Uses ZIO's `Stream` to let you easily implement streaming requests.
* Cancellable RPCs: client-side ZIO interruptions are propagated to the server to abort the request and save resources.

## Installation

Find the latest snapshot in [here](https://oss.sonatype.org/content/repositories/snapshots/com/thesamet/scalapb/zio-grpc/zio-grpc-core_2.13/).

Add the following to your `project/plugins.sbt`:

val zioGrpcVersion = "0.4.2"

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0-RC4")

libraryDependencies += "com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % zioGrpcVersion
Add the following to your `build.sbt`:

val grpcVersion = "1.34.0"

PB.targets in Compile := Seq(
scalapb.gen(grpc = true) -> (sourceManaged in Compile).value,
scalapb.zio_grpc.ZioCodeGenerator -> (sourceManaged in Compile).value,
)

libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
"io.grpc" % "grpc-netty" % grpcVersion
)

## Usage

Place your service proto files in `src/main/protobuf`, and the plugin
will generate Scala sources for them. Learn more about how to use [ZIO gRPC generated code](https://scalapb.github.io/zio-grpc/docs/generated-code).

See a full example at the [examples directory](https://github.com/scalapb/zio-grpc/tree/master/examples).

[Link-SonatypeSnapshots]: https://oss.sonatype.org/content/repositories/snapshots/com/thesamet/scalapb/zio-grpc/zio-grpc-core_2.13/ "Sonatype Snapshots"
[Badge-SonatypeSnapshots]: https://img.shields.io/nexus/s/https/oss.sonatype.org/com.thesamet.scalapb.zio-grpc/zio-grpc-core_2.13.svg "Sonatype Snapshots"
53 changes: 53 additions & 0 deletions benchmarks/src/main/protobuf/testservice.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
syntax = "proto3";

option java_multiple_files = true;
option java_package = "scalapb.zio_grpc.helloworld";
option java_outer_classname = "HelloWorldProto";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}

// Sends a litany of greetings
rpc SayHelloStreaming (HelloRequest) returns (stream HelloReply) {}
}

// The actual message exchanged by the client and the server.
message Hello {
string name = 1;
double d = 2;
float f = 3;
bool b = 4;
int32 n = 5;
int64 l = 6;
oneof choice {
string c1 = 7;
bool c2 = 8;
}
message Pet {
enum Color {
BLACK = 0;
WHITE = 1;
BLUE = 2;
RED = 3;
YELLOW = 4;
GREEN = 5;
}
string name = 1;
Color color = 2;
}
repeated Pet pets = 9;
}

// The request message from the client.
message HelloRequest {
Hello request = 1;
}

// The response message from the server.
message HelloReply {
Hello response = 1;
}
17 changes: 17 additions & 0 deletions benchmarks/src/main/scala/scalapb/zio_grpc/GreeterImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scalapb.zio_grpc

import scalapb.zio_grpc.helloworld.testservice.ZioTestservice.Greeter
import scalapb.zio_grpc.helloworld.testservice.{HelloReply, HelloRequest}
import io.grpc.StatusException
import zio.ZIO
import zio.stream.ZStream

class GreeterImpl(size: Long) extends Greeter {

def sayHello(request: HelloRequest): ZIO[Any, StatusException, HelloReply] =
ZIO.succeed(HelloReply(request.request))

def sayHelloStreaming(request: HelloRequest): ZStream[Any, StatusException, HelloReply] =
ZStream.repeat(HelloReply(request.request)).take(size)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package scalapb.zio_grpc

import io.grpc.ManagedChannelBuilder
import io.grpc.ServerBuilder
import scalapb.zio_grpc.helloworld.testservice._
import zio._
import java.time

object ServerStreamingBenchmarkApp extends ZIOAppDefault {

val size = 100000L

val server =
ServerLayer.fromEnvironment[ZioTestservice.Greeter](ServerBuilder.forPort(50051))

val client =
ZLayer.scoped[Server] {
for {
ss <- ZIO.service[Server]
port <- ss.port.orDie
ch = ManagedChannelBuilder.forAddress("localhost", 50051).usePlaintext()
client <- ZioTestservice.GreeterClient.scoped(ZManagedChannel(ch)).orDie
} yield client
}

val service =
ZLayer.succeed[ZioTestservice.Greeter] {
new GreeterImpl(size)
}

def run = ZIO
.foreach(Array(8192, 65536)) { queueSize =>
val props = java.lang.System.getProperties();
props.setProperty("zio-grpc.backpressure-queue-size", queueSize.toString());

for {
_ <- Console.printLine(s"Starting with queue size $queueSize")
cpt <- Ref.make(0)
start <- Clock.instant.flatMap(Ref.make(_))
result <- ZioTestservice.GreeterClient
.sayHelloStreaming(HelloRequest(request = Some(Hello(name = "Testing streaming"))))
.tap(_ => cpt.update(_ + 1))
.tap { _ =>
for {
now <- Clock.instant
started <- start.get
_ <- ZIO.when(time.Duration.between(started, now).getSeconds() >= 10)(
start.set(now) *> cpt.get.flatMap(cpt => Console.printLine(s"Received $cpt messages"))
)
} yield ()
}
.runDrain
.timed
_ <- Console.printLine(s"queue size: $queueSize (${result._1.toMillis()}ms)")
} yield ()
}
.provide(service >+> server >+> client)

}
Loading

0 comments on commit c404aa5

Please sign in to comment.