<commit_before>package com.jiaxy.tgd;

import org.junit.Test;

import java.util.Date;

/**
 * Title: <br>
 * <p>
 * Description: <br>
 * </p>
 * <br>
 *
 * @author <a href=mailto:<EMAIL>>taobaorun</a>
 *         <br>
 * @since 2016/04/26 22:19
 */
public class RateLimiterTest {


    @Test
    public void testTBGetToken() throws Exception {
        RateLimiter limiter = RateLimiter.builder().
                withToekPerSecond(1).
                withType(RateLimiter.RateLimiterType.TB).
                build();
        for ( int i = 0 ;i < 10;i++){
            limiter.getToken(1);
            System.out.println(i+".================="+new Date());
        }
    }

    @Test
    public void testFFTBGetToken() throws Exception {
        RateLimiter limiter = RateLimiter.builder().
                withToekPerSecond(1).
                withType(RateLimiter.RateLimiterType.FFTB).
                build();
        for ( int i = 0 ;i < 1000;i++){
            try {
                limiter.getToken(1);
                System.out.println(i+".================="+new Date());
            } catch (Exception e){
                Thread.sleep(500);
//                e.printStackTrace()
                System.out.println(e.getMessage());
            }
        }
    }
}<commit_msg>add fail fast token bucket<commit_after>package com.jiaxy.tgd;

import org.junit.Test;

import java.util.Date;

/**
 * Title: <br>
 * <p>
 * Description: <br>
 * </p>
 * <br>
 *
 * @author <a href=mailto:<EMAIL>>taobaorun</a>
 *         <br>
 * @since 2016/04/26 22:19
 */
public class RateLimiterTest {


    @Test
    public void testTBGetToken() throws Exception {
        RateLimiter limiter = RateLimiter.builder().
                withToekPerSecond(1).
                withType(RateLimiter.RateLimiterType.TB).
                build();
        for ( int i = 0 ;i < 10;i++){
            limiter.getToken(1);
            System.out.println(i+".================="+new Date());
        }
    }

    @Test
    public void testFFTBGetToken() throws Exception {
        RateLimiter limiter = RateLimiter.builder().
                withToekPerSecond(1).
                withType(RateLimiter.RateLimiterType.FFTB).
                build();
        for ( long i = 0 ;i < Long.MAX_VALUE;i++){
            try {
                limiter.getToken(1);
                System.out.println(i+".================="+new Date());
            } catch (Exception e){
                Thread.sleep(500);
//                e.printStackTrace()
                System.out.println(e.getMessage());
            }
        }
    }

    @Test
    public void testMultiFFBGetToken() throws Exception {
        final RateLimiter limiter = RateLimiter.builder().
                withToekPerSecond(1).
                withType(RateLimiter.RateLimiterType.FFTB).
                build();
        for ( int j = 0 ;j < 3;j++){
             new Thread(new Runnable() {
                public void run() {
                     for ( long i = 0 ;i < Long.MAX_VALUE;i++){
                        try {
                            limiter.getToken(1);
                            System.out.println(i+".================="+new Date());
                        } catch (Exception e){
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e1) {
                            }
                        }
                    }
                }
            }).start();
        }
    }
}
{'fraction_non_alphanumeric': 0.1487603305785124, 'fraction_numerical': 0.016813907096038756, 'mean_word_length': 1.4123711340206186, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6266843', 'n_tokens_mistral': 1064, 'n_tokens_neox': 981, 'n_words': 192}