Skip to content

Instantly share code, notes, and snippets.

View xlucasdemelo's full-sized avatar
🇪🇸

Lucas Aguiar xlucasdemelo

🇪🇸
View GitHub Profile
@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);
@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");
@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());
@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))
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;
@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()
apiVersion: apps/v1
kind: Deployment
metadata:
name: greetings-app
labels:
app: greetings-app
spec:
replicas: 3
selector:
matchLabels:
@xlucasdemelo
xlucasdemelo / deployment.yml
Created April 2, 2020 15:39
Creating a service in kubernetes
---
apiVersion: v1
kind: Service
metadata:
name: greetings-service
spec:
selector:
app: greetings-app
ports:
- port: 8888
@xlucasdemelo
xlucasdemelo / deployment.yml
Created April 2, 2020 15:06
Kubernetes-service
apiVersion: apps/v1
kind: Deployment
metadata:
name: greetings-app
labels:
app: greetings-app
spec:
replicas: 3
selector:
matchLabels:
@xlucasdemelo
xlucasdemelo / instagram-request.py
Last active January 3, 2019 23:31
Scripts to search a person name by instagram followers
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