Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steadybit/testcontainers
https://github.com/steadybit/testcontainers
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/steadybit/testcontainers
- Owner: steadybit
- License: apache-2.0
- Created: 2022-02-08T08:34:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-12T07:37:37.000Z (about 1 year ago)
- Last Synced: 2025-01-29T05:32:35.164Z (13 days ago)
- Language: Java
- Size: 94.7 KB
- Stars: 14
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Steadybit Testcontainers
## What is it?
Steadybit Testcontainers is a helper library to the [Testcontainers Project](https://testcontainers.org) to implement Resilience Tests.
## Getting Started
> We have a [blog post discussing "Resilience Tests with Testcontainers"](https://www.steadybit.com/blog/resilience-testing-using-testcontainers/) which gives a more detailed explanation.
### 1. Add Steadybit Testcontainers to your project:
Add this to the test dependencies in your `pom.xml`:
```xml
com.steadybit
steadybit-testcontainers
1.0.1
test```
### 2. Add some Chaos to your Testcontainers Test:
Here is an example for delaying the Redis traffic:
```java
@Testcontainers
public class RedisBackedCacheIntTest {
private RedisBackedCache underTest;@Container
public GenericContainer redis = new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine")).withExposedPorts(6379);@BeforeEach
public void setUp() {
underTest = new RedisBackedCache(redis.getHost(), redis.getFirstMappedPort());
}@Test
public void testFindingAnInsertedValue() {
underTest.put("foo", "FOO");Optional foundObject = Steadybit.networkDelayPackages(Duration.ofSeconds(2))
.forContainers(redis)
.exec(() -> {
//this code runs after the attack was started.
//As soon as this lambda exits the attack will be stopped.
return underTest.get("foo", String.class);
});assertTrue("When an object in the cache is retrieved, it can be found", foundObject.isPresent());
assertEquals("When we put a String in to the cache and retrieve it, the value is the same", "FOO", foundObject.get());
}
}
```## Available Attacks
- `networkDelayPackages`: Delays egress tcp/udp network packages for containers (on eth0 by default)
- `networkLoosePackages`: Looses egress tcp/udp network packages for containers (on eth0 by default)
- `networkCorruptPackages`: Corrupts egress tcp/udp network packages for containers (on eth0 by default)
- `networkLimitBandwidth`: Limits tcp/udp network bandwidth for containers (on eth0 by default)
- `networkBlackhole`: Blocks all network traffic for containers
- `networkBlockDns`: Blocks all network traffic for containers on dns port (53)