Crunch Projects

Crunch JVM Test validator

  • Coalesce all our unit and integration tests around:
    • JUnit 5 tests and AssertJ assertions for Java/Kotlin, or:
    • JUnit 5 tests and Strikt assertions for Kotlin
  • In general, use static analysis to apply and enforce our own test quality rules
  • Ultimately, use whatever automation we can to make it easier to move between projects, to write efficient tests, and harder to write bad tests by mistake.

Add this Maven plugin to your project to enable automatic validation of JVM tests against our standards:

<plugin>
    <groupId>uk.co.crunch</groupId>
    <artifactId>crunch-tests-maven-plugin</artifactId>
</plugin>

Wire Maven Plugin

Wire is an independent implementation of the Protocol Buffers schema language and binary encoding from Square that’s specifically designed for Android, Java, and Kotlin.

When Square decided they could not maintain Wire’s existing Maven plugin and removed it from their repo with version 3.0.3, we re-implemented it in our fork, and brought it up to the latest v. 3.2.2.

We use this in many of our busiest services for schema-driven inter-service messaging, as follows:

<dependency>
    <groupId>com.squareup.wire</groupId>
    <artifactId>wire-runtime</artifactId>
    <version>3.2.2</version>
</dependency>

[...]

<plugin>
    <groupId>uk.co.crunch</groupId>
    <artifactId>wire-maven-plugin</artifactId>
    <version>3.2.2</version>
    <executions>
        <execution>
            <configuration>
                <protoPaths>${basedir}/shared-message-schemas</protoPaths>
                <protoFiles>
                    <param>uk/co/crunch/example.proto</param>
                </protoFiles>
            </configuration>
        </execution>
    </executions>
</plugin>

A simplified Prometheus API for Java

  • API geared aimed at application developers rather than Prometheus experts.
  • Name-based metrics; no need to create instances or handle registration.
  • Cleaner timer / summary syntax, via resource/try
  • Aim is to simplify Prometheus adoption, reduce excessive code intrusion.
  • Lexical compatibility with Codahale/Dropwizard Metrics API, simplifying complete migration.
  • Regular Prometheus API can always be used directly for more advanced cases (unclear what those might be).

Example

class Example {
    private final PrometheusMetrics metrics;

    public void onUserLogin(Object event) {
        metrics.gauge("Sessions.open").inc();
        metrics.counter("Sessions.total").inc();
    }

    public String handleLogin() {
        try (Context timer = metrics.summary("Sessions.handleLogin").time()) {
            return "Login handled!";
        }
    }
}

A simplified Prometheus API for Kotlin

  • API geared aimed at application developers rather than Prometheus experts.
  • Name-based metrics; no need to create instances or handle registration.
  • Cleaner timer / summary syntax, via resource/try
  • Aim is to simplify Prometheus adoption, reduce excessive code intrusion.
  • Lexical compatibility with Codahale/Dropwizard Metrics API, simplifying complete migration.
  • Regular Prometheus API can always be used directly for more advanced cases (unclear what those might be).

Example

class Example(private val metrics: PrometheusMetrics) {

    fun onUserLogin(event: Any) {
        metrics.gauge("Sessions.open").inc()
    }

    fun onUserLogout(event: Any) {
        metrics.gauge("Sessions.open").dec()
    }

    fun onError(event: Any) {
        metrics.error("generic", "Generic errors")
    }

    fun handleLogin(): String {
        metrics.timer("Sessions.handleLogin").time().use { return "Login handled!" }
    }
}