コード例 #1
0
        public void Run()
        {
            var timeProxy   = new TimeProxyImpl();
            var workerCount = 1 << ChronokeeperWorkerImpl.kWorkerBits;

            ChronokeeperWorker[] workers = Util.Generate(
                workerCount,
                workerId => new ChronokeeperWorkerImpl(
                    new ChronokeeperWorkerConfigurationImpl {
                DatacenterId = 0,
                WorkerId     = workerId
            },
                    timeProxy
                    )
                );
            var       testObj            = new ChronokeeperServiceImpl(workers);
            const int kSequentialIdCount = 1000;
            var       sequentialIds      = new long[kSequentialIdCount];

            for (var i = 0; i < kSequentialIdCount; i++)
            {
                sequentialIds[i] = testObj.GenerateSequentialId();
                if (i % workerCount == workerCount - 1)
                {
                    Thread.Sleep(10); // 1 centisecond = chronokeeper clock precision
                }
            }
            sequentialIds.ForEach(x => Debug.WriteLine(x.ToString("X")));
            AssertTrue(sequentialIds.SequenceEqual(sequentialIds.OrderBy(x => x)));
        }
コード例 #2
0
 public void Run() {
    var timeProxy = new TimeProxyImpl();
    var workerCount = 1 << ChronokeeperWorkerImpl.kWorkerBits;
    ChronokeeperWorker[] workers = Util.Generate(
       workerCount, 
       workerId => new ChronokeeperWorkerImpl(
          new ChronokeeperWorkerConfigurationImpl {
             DatacenterId = 0,
             WorkerId = workerId
          },
          timeProxy
       )
    );
    var testObj = new ChronokeeperServiceImpl(workers);
    const int kSequentialIdCount = 1000;
    var sequentialIds = new long[kSequentialIdCount];
    for (var i = 0; i < kSequentialIdCount; i++) {
       sequentialIds[i] = testObj.GenerateSequentialId();
       if (i % workerCount == workerCount - 1) {
          Thread.Sleep(10); // 1 centisecond = chronokeeper clock precision
       }
    }
    sequentialIds.ForEach(x => Debug.WriteLine(x.ToString("X")));
    AssertTrue(sequentialIds.SequenceEqual(sequentialIds.OrderBy(x => x)));
 }
コード例 #3
0
 public ChronokeeperServiceImplTests()
 {
     this.testObj = new ChronokeeperServiceImpl(new[] { workerA, workerB, workerC });
 }
コード例 #4
0
 public ChronokeeperServiceImplTests() {
    this.testObj = new ChronokeeperServiceImpl(new[] { workerA, workerB, workerC });
 }