Beispiel #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)));
        }
 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)));
 }
Beispiel #3
0
 public ChronokeeperServiceImplTests()
 {
     this.testObj = new ChronokeeperServiceImpl(new[] { workerA, workerB, workerC });
 }
 public ChronokeeperServiceImplTests() {
    this.testObj = new ChronokeeperServiceImpl(new[] { workerA, workerB, workerC });
 }