Urgent.News

What's breaking now, across thousands of outlets.

Tech

Making HTTP Fail on Purpose: Building a Small Chaos Library for Java - Flaky HTTP

I recently built and open-sourced Flaky HTTP , a small Java 11 library for deliberately making HTTP calls less reliable. That may sound like an unusual goal. Most of the time, we work hard to make HTTP calls reliable. We add retries, timeouts, circuit breakers, fallbacks, caches, and monitoring. But eventually we need to answer a more difficult question: How do we know any of that behavior…

Flaky HTTP is a lightweight Java 11 library designed to intentionally make HTTP calls less reliable. It may seem counterintuitive, but ensuring HTTP reliability is crucial. Developers often incorporate retries, timeouts, circuit breakers, fallbacks, caches, and monitoring to achieve this. However, validating the effectiveness of these reliability mechanisms can be challenging.

The initial concept was straightforward: wrap Java's standard HttpClient, introduce controlled latency or synthetic HTTP errors to specific requests, and maintain the rest of the application unaltered. This led to several noteworthy design choices regarding API design, asynchronous cancellation, response body handling, deterministic testing, and the distinction between application-level failure injection and genuine network chaos.

This article extends beyond a mere release announcement, aiming to elucidate the library's purpose, internal workings, utility, and limitations. TL;DR Flaky HTTP is a lightweight wrapper around Java 11's java.net.http.HttpClient, offering the following capabilities:

1. Introducing fixed or random latency

2. Delivering synthetic HTTP errors with configurable probability

3. Targeting requests using full-URI regular expressions

4. Managing synchronous and asynchronous calls

5. Propagating cancellation for delayed asynchronous operations

6. Functioning without additional runtime dependencies beyond Java 11

The Maven coordinate for the library is com.tapadyuti:flaky-http:1.0.0. The simplest way to set up a test with deterministic failure is by creating a FlakyConfig object with a failure rate of 1.0 and an error status of 503. Subsequently, every targeted call returns an empty synthetic 503 response, bypassing the network. To adjust the test for slowness without an HTTP error, replace 1.0 with 0.0 and apply a LatencyStrategy.fixed(500) strategy.

Flaky HTTP is intended for integration tests, resilience tests, local development, and controlled demonstrations. It should not replace a network proxy or a full chaos-engineering platform.

The underlying architecture, codebase, and implementation decisions are entirely my own creation. The inspiration stemmed from the desire to simplify the testing of HTTP integrations, where failure setups often become more intricate than the behavior being tested. Developers may need to modify mock servers, add proxy rules, adjust container networking, or create unique test doubles for every client abstraction. Flaky HTTP provides a more streamlined solution for a common case scenario.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Grand Theft Auto VI Targets 30fps On Release

In an era when gaming at 60fps is the norm, there’s some less-than-ideal news about Grand Theft Auto VI. It looks like the devs at Rockstar Games are only targeting 30fps for the game as it runs on the PS5.

More from Friday 28 August →