package com.izouma.nineth;

import io.github.bucket4j.*;
import io.github.bucket4j.distributed.proxy.ProxyManager;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.Duration;

public class Bucket4jTest extends ApplicationTests {
    @Autowired
    private ProxyManager<String> buckets;

    @Test
    public void test() {
        Bucket bucket =  buckets.builder().build("test", () -> (BucketConfiguration.builder()
                .addLimit(Bandwidth.classic(10, Refill.intervally(10, Duration.ofMinutes(10))))
                .build()));
        for (int i = 0; i < 20; i++) {
            System.out.println(bucket.tryConsume(1));
        }
    }
}
