コード例 #1
0
        public async Task CanStoreActivation()
        {
            var timeout = new CancellationTokenSource(1000).Token;

            var(activator, identity, pid) = await GetActivatedClusterIdentity(timeout);

            var activation = await _storage.TryGetExistingActivation(identity, timeout);

            activation.Should().NotBeNull();
            activation !.MemberId.Should().Be(activator.Id);
            activation !.Pid.Should().BeEquivalentTo(pid);
        }
コード例 #2
0
        public void ShouldReturnValidPidObject()
        {
            var expected = new Pid()
            {
                YearSegment     = 92,
                MontSegment     = 7,
                DaySegment      = 11,
                RegionSegment   = 346,
                OrderSegment    = 5,
                GenderSegment   = 6,
                ChecksumSegment = 6
            };

            var actual = _pidDataExtractionService.Segregate(9207113466);

            Assert.IsNotNull(actual);
            expected.Should().BeEquivalentTo(actual);
        }
コード例 #3
0
        public async Task WillNotRemoveCurrentActivationByPrevMember()
        {
            var timeout = new CancellationTokenSource(1000).Token;

            var(originalActivator, identity, origPid) = await GetActivatedClusterIdentity(timeout);

            await _storage.RemoveActivation(identity, origPid, timeout);

            var(newActivator, _, newPid) = await GetActivatedClusterIdentity(timeout, identity : identity);

            await _storage.RemoveMember(originalActivator.Id, timeout);

            var activation = await _storage.TryGetExistingActivation(identity, timeout);

            activation.Should().NotBeNull();
            activation !.MemberId.Should().Be(newActivator.Id);
            activation !.Pid.Should().BeEquivalentTo(newPid);
        }
コード例 #4
0
        public async Task DoesNotRemoveIfIdDoesNotMatch()
        {
            var timeout = new CancellationTokenSource(1000).Token;

            var(activator, identity, pid) = await GetActivatedClusterIdentity(timeout);

            var differentPid = Activate(activator, identity);

            var activation = await _storage.TryGetExistingActivation(identity, timeout);

            await _storage.RemoveActivation(identity, differentPid, timeout);

            var afterRemoval = await _storage.TryGetExistingActivation(identity, timeout);

            activation.Should().NotBeNull();
            activation !.MemberId.Should().Be(activator.Id);
            activation !.Pid.Should().BeEquivalentTo(pid);

            afterRemoval.Should().NotBeNull("Removal pid did not match id, even if it matched cluster identity");
        }
コード例 #5
0
        public async Task CannotTakeLockWhenAlreadyActivated()
        {
            var activator = GetFakeActivator();
            var timeout   = new CancellationTokenSource(1000).Token;
            var identity  = new ClusterIdentity {
                Kind = "thing", Identity = NextId().ToString()
            };
            var spawnLock = await _storage.TryAcquireLock(identity, timeout);

            var pid = Activate(activator, identity);
            await _storage.StoreActivation(activator.Id, spawnLock !, pid, timeout);

            var activation = await _storage.TryGetExistingActivation(identity, timeout);

            activation.Should().NotBeNull();
            activation !.MemberId.Should().Be(activator.Id);
            activation !.Pid.Should().BeEquivalentTo(pid);

            var noLock = await _storage.TryAcquireLock(identity, timeout);

            noLock.Should().BeNull("Since the activation is active, it should not be possible to take the lock");
        }
コード例 #6
0
        public async Task CanWaitForActivation()
        {
            var activator = GetFakeActivator();
            var timeout   = CancellationTokens.WithTimeout(15 * 1000);
            var identity  = new ClusterIdentity {
                Kind = "thing", Identity = NextId().ToString()
            };
            var spawnLock = await _storage.TryAcquireLock(identity, timeout);

            var pid = Activate(activator, identity);

            _ = SafeTask.Run(async() => {
                await Task.Delay(500, timeout);
                await _storage.StoreActivation(activator.Id, spawnLock !, pid, timeout);
            }, timeout
                             );
            var activation = await _storage.WaitForActivation(identity, timeout);

            activation.Should().NotBeNull();
            activation !.MemberId.Should().Be(activator.Id);
            activation !.Pid.Should().BeEquivalentTo(pid);
        }
コード例 #7
0
        public void ShouldReturnValidResult()
        {
            _pidObject = new Pid()
            {
                YearSegment     = 92,
                MontSegment     = 07,
                DaySegment      = 11,
                RegionSegment   = 346,
                OrderSegment    = 5,
                GenderSegment   = 6,
                ChecksumSegment = 6
            };

            _pidDataExtractionService.Setup(x => x.Segregate(It.IsAny <string>()))
            .Returns(_pidObject);

            var actual = _pidValidationService.Validate(9207113466);

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Pid);
            _pidObject.Should().BeEquivalentTo(actual.Pid);
            Assert.AreEqual(PidValidationStatus.Valid, actual.ValidationStatus);
        }