<commit_before>package org.voovan.test.tools.cache;

import junit.framework.TestCase;
import org.voovan.Global;
import org.voovan.tools.TEnv;
import org.voovan.tools.cache.RedisLock;
import org.voovan.tools.cache.RedisMap;

import java.util.ArrayList;

/**
 * 类文字命名
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class RedisLockUnit extends TestCase{

    private RedisLock redisLock;

    public volatile static int x = 0;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        redisLock = new RedisLock("127.0.0.1", 6379, 2000, 100, "DisLock_1", null);
    }

    public void testLockTest(){
        RedisMap redisMap = new RedisMap();
        redisMap.clear();

        ArrayList jj = new ArrayList();

        for(int i=0;i<200;i++) {
            final int t = i;
            int finalI = i;
            Global.getThreadPool().execute(new Runnable() {
                @Override
                public void run() {
                    redisLock.lock(1000*60, 500);
                    System.out.println(Long.toString(System.nanoTime())+ "\tlock");
                    int lock = (int)Math.random()*300;
                    TEnv.sleep(lock);
                    x++;
                    System.out.println(Long.toString(System.nanoTime())+ "\tunlock");
                    redisLock.unLock();

                }
            });
        }

        int xx = 60*1000;
        while(xx>0){
            TEnv.sleep(1);
            xx--;
        }
    }
}
<commit_msg>fix: 分布式锁 bug 修复<commit_after>package org.voovan.test.tools.cache;

import org.voovan.Global;
import org.voovan.tools.TEnv;
import org.voovan.tools.cache.RedisLock;
import org.voovan.tools.cache.RedisMap;
import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.concurrent.Semaphore;

/**
 * 类文字命名
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class RedisLockUnit extends TestCase{

    private RedisLock redisLock;

    Semaphore semaphore = new Semaphore(1);

    public volatile static int x = 0;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        redisLock = new RedisLock("127.0.0.1", 6379, 2000, 100, "DisLock_1", null);
    }

    public void testLockTest(){
        RedisMap redisMap = new RedisMap();
        redisMap.clear();

        ArrayList jj = new ArrayList();

        for(int i=0;i<200;i++) {
            final int t = i;
            int finalI = i;
            Global.getThreadPool().execute(new Runnable() {
                @Override
                public void run() {
                    while(!redisLock.lock(1000*60, 5000)){
                        TEnv.sleep(1);
                    }
                    boolean locked = semaphore.tryAcquire();
                    System.out.println(Long.toString(System.nanoTime())+ "\tlock " + x + " " + locked);
                    int lock = (int)Math.random()*300;
                    TEnv.sleep(lock);
                    x++;
                    if(locked) {
                        semaphore.release();
                    }
                    System.out.println(Long.toString(System.nanoTime())+ "\tunlock " + x);
                    while(!redisLock.unLock()){
                        TEnv.sleep(1);
                    }

                }
            });
        }

        int xx = 60*1000;
        while(xx>0){
            TEnv.sleep(1);
            xx--;
        }
    }
}

{'fraction_non_alphanumeric': 0.12353269983230855, 'fraction_numerical': 0.025712688652878703, 'mean_word_length': 1.6550445103857567, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3523058', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1068, 'n_words': 217}