package com.roy.distId;

import me.ahoo.cosid.machine.MachineId;
import me.ahoo.cosid.snowflake.SnowflakeId;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

/**
 * Author： roy
 * Description：
 **/
@SpringBootTest
@RunWith(SpringRunner.class)
public class SnowFlakeTest {

    @Resource
    private MachineId machineId;

    @Resource
    private SnowflakeId snowflakeId;

    @Test
    public void snowflakeTest(){
        System.out.println("machineId:"+machineId.getMachineId());
//        for (int i = 0; i < 100; i++) {
//            long generated = snowflakeId.generate();
//            System.out.println("snowflakeId: "+ generated);
//
//            int seqmask=(1<<12)-1;
//            //获取二进制后12位- Sequence
//            long sequence = generated & seqmask;
//            System.out.println("sequence:"+sequence);
//            int machineMask = (1<<22)-1;
//            //获取二进制后22位 - MachineId|Sequence
//            long machineAseq = generated & machineMask;
//            System.out.println("machineAseq:"+machineAseq);
//            //获取机器位
//            long machineId = (machineAseq-sequence)>> 12;
//            System.out.println("machineId:"+machineId);
//            System.out.println(">>>>>>>>>>>>>");
//        }
    }
}
