This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void threadPoolBulkhead() throws InterruptedException { | |
//Only 5 Threads will be the hability to execute a code | |
ThreadPoolBulkhead threadPoolBulkhead = ThreadPoolBulkhead.of("threads", ThreadPoolBulkheadConfig.custom() | |
.coreThreadPoolSize(5) | |
.maxThreadPoolSize(5) | |
.build()); | |
//Decorating the execution of the method and the configuration of the threadPool | |
Supplier<CompletionStage<Void>> withBulkhead = ThreadPoolBulkhead.decorateRunnable(threadPoolBulkhead, this::takeBook); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void retry(){ | |
MockResponse mockResponse = new MockResponse() | |
.setResponseCode(500) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); | |
MockResponse mockResponseSuccess = new MockResponse() | |
.setResponseCode(200) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void circuitBreaker_recover(){ | |
MockResponse mockResponse = new MockResponse() | |
.setResponseCode(500) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); | |
CircuitBreaker circuitBreaker = CircuitBreaker.of("books", CircuitBreakerConfig.custom() | |
.slidingWindowSize(1) | |
.waitDurationInOpenState(Duration.ofMillis(100)) | |
.build()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void countBased_example() throws Exception { | |
MockResponse mockResponse = new MockResponse() | |
.setResponseCode(500) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); | |
CircuitBreaker circuitBreaker = CircuitBreaker.of("books", CircuitBreakerConfig.custom() | |
.slidingWindowSize(4) | |
.permittedNumberOfCallsInHalfOpenState(2) | |
.waitDurationInOpenState(Duration.ofMillis(100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lucasaguiar.resilience; | |
import io.github.resilience4j.timelimiter.TimeLimiter; | |
import io.github.resilience4j.timelimiter.TimeLimiterConfig; | |
import io.vavr.control.Try; | |
import org.assertj.core.api.Assertions; | |
import org.junit.jupiter.api.Test; | |
import java.time.Duration; | |
import java.util.concurrent.Callable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void rateLimiterTest() { | |
MockResponse mockResponse = new MockResponse() | |
.setResponseCode(200) | |
.addHeader("Content-Type", "application/json;charset=utf-8"); | |
//Resilience4J configuration for RateLimiter | |
//Defining that only one request can happend in 100ms window | |
RateLimiterConfig config = RateLimiterConfig.custom() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: greetings-app | |
labels: | |
app: greetings-app | |
spec: | |
replicas: 3 | |
selector: | |
matchLabels: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: greetings-service | |
spec: | |
selector: | |
app: greetings-app | |
ports: | |
- port: 8888 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: greetings-app | |
labels: | |
app: greetings-app | |
spec: | |
replicas: 3 | |
selector: | |
matchLabels: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from InstagramAPI import InstagramAPI | |
import json | |
import datetime | |
import os, errno | |
import requests | |
import logging | |
import logging.handlers | |
import os | |
import sched, time | |
import sys |
NewerOlder