Follow these slides both to learn about Bazel and to get more context on the exercises.
You should have installed:
- Bazel (optionally Bazelisk)
- Java JDK (e.g.
sudo apt install openjdk-11-jdk
). Note: Tested with JDK 11, and at least JDK 19 has issues under MacOS. java -version
should work
Let's execute a Java binary.
- Edit:
java/src/main/java/bazel/bootcamp/BUILD
- Add a
java_binary
target for theHelloBazelBootcamp.java
file - Run the binary using
bazel run //java/src/main/java/bazel/bootcamp:HelloBazelBootcamp
Let's compile and run the server code.
- The Go
BUILD
files can be fully generated by Gazelle. Run gazelle withbazel run //:gazelle
- Run the go binary using
bazel run //go/cmd/server
- Go to http://localhost:8081 to see results (there won't be any logs yet):
curl http://localhost:8081
Now let's compile and run the client code. It uses GRPC so we'll need to build the proto files and link them as dependencies.
- Edit the
BUILD
file forlogger.proto
java_proto_library
documentationjava_grpc_library
documentation (look towards the bottom of the page for Bazel related documentation)
- Edit the
BUILD
file forJavaLoggingClientLibrary.java
- Edit the
BUILD
file forJavaLoggingClient.java
bazel run
the Java binary you wrotebazel run
the Go binary from Section 2- Send messages from the client to the server and view them on http://localhost:8081
Let's make Bazel also run the java unit tests.
- Edit the
BUILD
file forJavaLoggingClientLibraryTest.java
Hint
Names matter for tests. Thejava_test
for this file should be namedJavaLoggingClientLibraryTest
- Edit the
BUILD
file forJavaLoggingClientTest.java
- Run the tests using
bazel test
There is an integration test that uses both the go server binary, and the java client binary. Let's run it through Bazel.
- Edit the
BUILD
file forintegrationtest.sh
- Run the test using
bazel test
and make sure that it passes - Now run the test using
bazel test <target> --runs_per_test=10
. It will fail, so you might need to find how to fix it.Hint
You may need to modify theBUILD
file again to make this workHint
Maybe because of the nature of the test you can't run it concurrently, and needs to be run sequentially?
The slides contain some examples you can try by yourself.
You can also use as reference the Official query guide.