Skip to content

kartones-forks/bazel-bootcamp

 
 

Repository files navigation

Bazel Bootcamp

Before you get started

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

Exercise 1: Hello, Bazel!

Let's execute a Java binary.

  1. Edit: java/src/main/java/bazel/bootcamp/BUILD
  2. Add a java_binary target for the HelloBazelBootcamp.java file
  3. Run the binary using bazel run //java/src/main/java/bazel/bootcamp:HelloBazelBootcamp

Exercise 2: Go server

Let's compile and run the server code.

  1. The Go BUILD files can be fully generated by Gazelle. Run gazelle with bazel run //:gazelle
  2. Run the go binary using bazel run //go/cmd/server
  3. Go to http://localhost:8081 to see results (there won't be any logs yet): curl http://localhost:8081

Exercise 3: Java client

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.

  1. Edit the BUILD file for logger.proto
  2. Edit the BUILD file for JavaLoggingClientLibrary.java
  3. Edit the BUILD file for JavaLoggingClient.java
  4. bazel run the Java binary you wrote
  5. bazel run the Go binary from Section 2
  6. Send messages from the client to the server and view them on http://localhost:8081

Exercise 4: Java client unit tests

Let's make Bazel also run the java unit tests.

  1. Edit the BUILD file for JavaLoggingClientLibraryTest.java
    HintNames matter for tests. The java_test for this file should be named JavaLoggingClientLibraryTest
  2. Edit the BUILD file for JavaLoggingClientTest.java
  3. Run the tests using bazel test

Exercise 5: Integration test

There is an integration test that uses both the go server binary, and the java client binary. Let's run it through Bazel.

  1. Edit the BUILD file for integrationtest.sh
  2. Run the test using bazel test and make sure that it passes
  3. 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.
    HintYou may need to modify the BUILD file again to make this work
    HintMaybe because of the nature of the test you can't run it concurrently, and needs to be run sequentially?

Exercise 6: Queries

The slides contain some examples you can try by yourself.

You can also use as reference the Official query guide.

Releases

No releases published

Packages

No packages published

Languages

  • Starlark 63.8%
  • Java 19.5%
  • Go 14.6%
  • Shell 2.1%