Maven
Şu satırı dahil ederiz
<dependency><groupId>org.testcontainers</groupId> <artifactId>toxiproxy</artifactId> <version>1.18.3</version> <scope>test</scope> </dependency>
ToxiproxyContainer kullanılarak yaratılır
latency metodu
ÖrnekŞöyle yaparız
import eu.rekawek.toxiproxy.Proxy;import eu.rekawek.toxiproxy.ToxiproxyClient;import eu.rekawek.toxiproxy.model.ToxicDirection;@Testcontainerspublic class ToxiproxyExample {@Containerprivate static ToxiproxyContainer toxiproxy = new ToxiproxyContainer();@Containerprivate static PostgreSQLContainer<?> database = new PostgreSQLContainer<>("postgres:11.19-bullseye")@Rulepublic ToxiproxyClient toxiproxyClient = new ToxiproxyClient(toxiproxy.getHost(), toxiproxy.getControlPort());@Testpublic void testApplicationWithLatency() {// ToxicDirection.DOWNSTREAM is from client to DB// Create a toxic that adds 100 milliseconds of latency to the connection to the DB.toxiproxyClient.toxics().latency("database", ToxicDirection.DOWNSTREAM, 100);// Try to connect to the database.try (var connection = DriverManager.getConnection(database.getHost() + ":" + database.getMappedPort(5432), "postgres", "postgres")) {// Do something with the connection.}// Remove the toxic.toxiproxyClient.toxics().get("database").remove();}}
Hiç yorum yok:
Yorum Gönder