Exemplo n.º 1
0
        public void TestReplicaStatus()
        {
            var replica = new ReplicaInfo();

            Assert.IsTrue(replica.Status != ReplicaStatus.None);

            // - None
            replica.Status = ReplicaStatus.None;
            Assert.IsTrue(replica.IsReadOnly() == false);
            Assert.IsTrue(replica.IsReadable() == false);
            Assert.IsTrue(replica.IsWriteOnly() == false);
            Assert.IsTrue(replica.IsWritable() == false);

            // - RO
            replica.Status = ReplicaStatus.ReadOnly;
            Assert.IsTrue(replica.IsReadOnly() == true);
            Assert.IsTrue(replica.IsReadable() == true);
            Assert.IsTrue(replica.IsWriteOnly() == false);
            Assert.IsTrue(replica.IsWritable() == false);

            // WO
            replica.Status = ReplicaStatus.WriteOnly;
            Assert.IsTrue(replica.IsReadOnly() == false);
            Assert.IsTrue(replica.IsReadable() == false);
            Assert.IsTrue(replica.IsWriteOnly() == true);
            Assert.IsTrue(replica.IsWritable() == true);

            // RW
            replica.Status = ReplicaStatus.ReadWrite;
            Assert.IsTrue(replica.IsReadOnly() == false);
            Assert.IsTrue(replica.IsReadable() == true);
            Assert.IsTrue(replica.IsWriteOnly() == false);
            Assert.IsTrue(replica.IsWritable() == true);
        }
        public void DeserializeProperties_should_ignore_null_and_empty_values()
        {
            var dict = new Dictionary <string, string>
            {
                { "a", "a-value" },
                { "b", null },
                { "c", "" },
                { "d", " " }
            };

            var replicaInfo = new ReplicaInfo(
                "default",
                "vostok",
                "doesntmatter",
                dict);

            var serialized   = ReplicaNodeDataSerializer.Serialize(replicaInfo);
            var deserialized = ReplicaNodeDataSerializer.Deserialize(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica, serialized);

            deserialized.Properties.Should()
            .BeEquivalentTo(
                new Dictionary <string, string>
            {
                { "a", "a-value" },
                { "d", " " }
            });
        }
Exemplo n.º 3
0
        protected void DeleteReplicaNode(ReplicaInfo replicaInfo)
        {
            var path   = PathHelper.BuildReplicaPath(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica);
            var delete = ZooKeeperClient.Delete(path);

            delete.IsSuccessful.Should().BeTrue();
        }
Exemplo n.º 4
0
        protected void CreateReplicaNode(ReplicaInfo replicaInfo, bool persistent = true)
        {
            var data = ReplicaNodeDataSerializer.Serialize(replicaInfo);
            var path = PathHelper.BuildReplicaPath(replicaInfo.Environment, replicaInfo.Application, replicaInfo.Replica);

            CreateOrUpdate(path, data, persistent);
        }
Exemplo n.º 5
0
        public void Should_return_same_topology_instance_if_nothing_changed()
        {
            var replica1 = new ReplicaInfo("default", "vostok", "https://github.com/vostok1");
            var replica2 = new ReplicaInfo("default", "vostok", "https://github.com/vostok2");

            CreateEnvironmentNode("default");

            CreateApplicationNode("default", "vostok");

            CreateReplicaNode(replica1);

            using (var locator = GetServiceLocator())
            {
                var topo1 = locator.Locate("default", "vostok");
                var topo2 = locator.Locate("default", "vostok");
                ReferenceEquals(topo1, topo2).Should().BeTrue();

                CreateEnvironmentNode("default", "parent");
                var topo3 = locator.Locate("default", "vostok");
                ReferenceEquals(topo2, topo3).Should().BeTrue();

                CreateReplicaNode(replica2);

                // ReSharper disable once AccessToDisposedClosure
                Action action = () => ReferenceEquals(topo3, locator.Locate("default", "vostok")).Should().BeFalse();
                action.ShouldPassIn(DefaultTimeout);
            }
        }
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <returns>The object Value.</returns>
        internal static ReplicaInfo GetFromJsonProperties(JsonReader reader)
        {
            ReplicaInfo obj      = null;
            var         propName = reader.ReadPropertyName();

            if (!propName.Equals("ServiceKind", StringComparison.OrdinalIgnoreCase))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is ServiceKind.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("Stateful", StringComparison.OrdinalIgnoreCase))
            {
                obj = StatefulServiceReplicaInfoConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("Stateless", StringComparison.OrdinalIgnoreCase))
            {
                obj = StatelessServiceInstanceInfoConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown ServiceKind.");
            }

            return(obj);
        }
Exemplo n.º 7
0
        protected bool ReplicaRegistered(ReplicaInfo replica)
        {
            var path   = PathHelper.BuildReplicaPath(replica.Environment, replica.Application, replica.Replica);
            var exists = ZooKeeperClient.Exists(path);

            return(exists.Exists);
        }
Exemplo n.º 8
0
        public void ResolveConflictLocalWins(SyncConflict conflict)
        {
            if (_closed)
            {
                throw new InvalidOperationException();
            }

            var tickCount       = _store.IncrementLocalRepilcaTickCount();
            var modifiedReplica = new ReplicaInfo
            {
                ReplicaId        = _store.GetLocalReplicaId(),
                ReplicaTickCount = tickCount
            };
            var resolvedStatus = conflict.LocalItemInfo.Deleted ? SyncStatus.Delete : SyncStatus.Update;
            var data           = JObject.Parse("{item:{itemRefs:[]}}");

            if (resolvedStatus != SyncStatus.Delete)
            {
                var builder = SyncUtil.JsonItemFromSyncableItemInfo(conflict.LocalItemInfo);
                _store.BuildItemData(conflict.LocalItemInfo, builder);
                data = new JObject {
                    { "item", builder }
                };
            }

            using (var connection = _syncSessionDbConnectionProvider.GetSyncSessionDbConnection(_localSessionId))
            {
                SessionDbHelper.ResolveItemWithData(connection, conflict.RemoteItemInfo, resolvedStatus, modifiedReplica,
                                                    data);
            }
        }
Exemplo n.º 9
0
        public void Should_locate_multiple_registered_ServiceBeacon_services_in_multiple_environments()
        {
            var replica11 = new ReplicaInfo("A", "vostok", "https://github.com/vostok/A1");
            var replica12 = new ReplicaInfo("A", "vostok", "https://github.com/vostok/A2");
            var replica2  = new ReplicaInfo("A", "not-vostok", "https://github.com/not-vostok/A");
            var replica3  = new ReplicaInfo("B", "vostok", "https://github.com/vostok/B");

            CreateEnvironmentNode("A");
            CreateEnvironmentNode("B");

            using (var beacon11 = GetServiceBeacon(replica11))
                using (var beacon12 = GetServiceBeacon(replica12))
                    using (var beacon2 = GetServiceBeacon(replica3))
                        using (var beacon3 = GetServiceBeacon(replica2))
                        {
                            beacon11.Start();
                            beacon12.Start();
                            beacon2.Start();
                            beacon3.Start();
                            WaitReplicaRegistered(replica11);
                            WaitReplicaRegistered(replica12);
                            WaitReplicaRegistered(replica2);
                            WaitReplicaRegistered(replica3);

                            using (var locator = GetServiceLocator())
                            {
                                ShouldLocateImmediately(locator, "A", "vostok", replica11.Replica, replica12.Replica);
                                ShouldLocateImmediately(locator, "A", "not-vostok", replica2.Replica);
                                ShouldLocateImmediately(locator, "B", "vostok", replica3.Replica);
                            }
                        }
        }
Exemplo n.º 10
0
        public void Should_skip_environment_with_application_if_specified()
        {
            var replicaParent = new ReplicaInfo("parent", "vostok", "https://github.com/vostok/parent");
            var replicaChild  = new ReplicaInfo("child", "vostok", "https://github.com/vostok/child");

            CreateEnvironmentNode("parent");
            CreateEnvironmentNode("child", "parent", new Dictionary <string, string> {
                { EnvironmentInfoKeys.SkipIfEmpty, "True" }
            });

            CreateApplicationNode("child", "vostok");
            CreateApplicationNode("parent", "vostok");

            CreateReplicaNode(replicaParent);

            using (var locator = GetServiceLocator())
            {
                ShouldLocate(locator, "child", "vostok", replicaParent.Replica);
                ShouldLocate(locator, "parent", "vostok", replicaParent.Replica);

                CreateReplicaNode(replicaChild);

                ShouldLocate(locator, "child", "vostok", replicaChild.Replica);
                ShouldLocate(locator, "parent", "vostok", replicaParent.Replica);
            }
        }
Exemplo n.º 11
0
        public void Should_locate_registered_ServiceBeacon_service_with_custom_path_escaper()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            ZooKeeperClient.Create("/service-discovery/v2/ZGVmYXVsdA==", CreateMode.Persistent);

            using (var beacon = new ServiceBeacon(
                       ZooKeeperClient,
                       replica,
                       new ServiceBeaconSettings
            {
                IterationPeriod = 60.Seconds(),
                MinimumTimeBetweenIterations = 100.Milliseconds(),
                ZooKeeperNodesPathEscaper = new CustomPathEscaper()
            },
                       Log))
            {
                beacon.Start();
                WaitNodeExists("/service-discovery/v2/ZGVmYXVsdA==/dm9zdG9r/aHR0cHM6Ly9naXRodWIuY29tL3Zvc3Rvaw==");

                using (var locator = new ServiceLocator(
                           ZooKeeperClient,
                           new ServiceLocatorSettings
                {
                    ZooKeeperNodesPathEscaper = new CustomPathEscaper()
                },
                           Log))
                {
                    ShouldLocateImmediately(locator, replica.Environment, replica.Application, replica.Replica);
                }
            }
        }
Exemplo n.º 12
0
        public void Should_track_environment_properties()
        {
            var replicaParent = new ReplicaInfo("parent", "vostok", "https://github.com/vostok/parent");

            CreateEnvironmentNode("parent");
            CreateEnvironmentNode("child", "parent", new Dictionary <string, string> {
                { EnvironmentInfoKeys.SkipIfEmpty, "True" }
            });

            CreateApplicationNode("child", "vostok");
            CreateApplicationNode("parent", "vostok");

            CreateReplicaNode(replicaParent);

            using (var locator = GetServiceLocator())
            {
                ShouldLocate(locator, "child", "vostok", replicaParent.Replica);
                ShouldLocate(locator, "parent", "vostok", replicaParent.Replica);

                CreateEnvironmentNode("child", "parent", new Dictionary <string, string> {
                    { EnvironmentInfoKeys.SkipIfEmpty, "False" }
                });

                ShouldLocate(locator, "child", "vostok");
                ShouldLocate(locator, "parent", "vostok", replicaParent.Replica);
            }
        }
Exemplo n.º 13
0
        /// <exception cref="System.IO.IOException"/>
        private void TestRbwReplicas(MiniDFSCluster cluster, bool isCorrupt)
        {
            FSDataOutputStream @out = null;
            FileSystem         fs   = cluster.GetFileSystem();
            Path src = new Path("/test.txt");

            try
            {
                int fileLen = 515;
                // create some rbw replicas on disk
                byte[] writeBuf = new byte[fileLen];
                new Random().NextBytes(writeBuf);
                @out = fs.Create(src);
                @out.Write(writeBuf);
                @out.Hflush();
                DataNode dn = cluster.GetDataNodes()[0];
                foreach (FsVolumeSpi v in Dataset(dn).GetVolumes())
                {
                    FsVolumeImpl volume     = (FsVolumeImpl)v;
                    FilePath     currentDir = volume.GetCurrentDir().GetParentFile().GetParentFile();
                    FilePath     rbwDir     = new FilePath(currentDir, "rbw");
                    foreach (FilePath file in rbwDir.ListFiles())
                    {
                        if (isCorrupt && Block.IsBlockFilename(file))
                        {
                            new RandomAccessFile(file, "rw").SetLength(fileLen - 1);
                        }
                    }
                }
                // corrupt
                cluster.RestartDataNodes();
                cluster.WaitActive();
                dn = cluster.GetDataNodes()[0];
                // check volumeMap: one rwr replica
                string     bpid     = cluster.GetNamesystem().GetBlockPoolId();
                ReplicaMap replicas = Dataset(dn).volumeMap;
                NUnit.Framework.Assert.AreEqual(1, replicas.Size(bpid));
                ReplicaInfo replica = replicas.Replicas(bpid).GetEnumerator().Next();
                NUnit.Framework.Assert.AreEqual(HdfsServerConstants.ReplicaState.Rwr, replica.GetState
                                                    ());
                if (isCorrupt)
                {
                    NUnit.Framework.Assert.AreEqual((fileLen - 1) / 512 * 512, replica.GetNumBytes());
                }
                else
                {
                    NUnit.Framework.Assert.AreEqual(fileLen, replica.GetNumBytes());
                }
                Dataset(dn).Invalidate(bpid, new Block[] { replica });
            }
            finally
            {
                IOUtils.CloseStream(@out);
                if (fs.Exists(src))
                {
                    fs.Delete(src, false);
                }
                fs.Close();
            }
        }
Exemplo n.º 14
0
        public void Should_track_application_properties()
        {
            var replica    = new ReplicaInfo("default", "vostok", "https://github.com/vostok");
            var properties = new Dictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            };

            CreateEnvironmentNode("default");

            CreateApplicationNode("default", "vostok", properties);

            CreateReplicaNode(replica);

            using (var locator = GetServiceLocator())
            {
                // ReSharper disable once PossibleNullReferenceException
                locator.Locate("default", "vostok").Properties.Should().BeEquivalentTo(properties);

                for (var times = 0; times < 5; times++)
                {
                    properties["iteration"] = times.ToString();
                    CreateApplicationNode("default", "vostok", properties);

                    // ReSharper disable once AccessToDisposedClosure
                    // ReSharper disable once PossibleNullReferenceException
                    Action action = () => { locator.Locate("default", "vostok").Properties.Should().BeEquivalentTo(properties); };

                    action.ShouldPassIn(DefaultTimeout);
                }
            }
        }
Exemplo n.º 15
0
        public void Should_locate_registered_ServiceBeacon_services_and_ignore_daemons_without_port()
        {
            var service1 = new ReplicaInfo("default", "vostok", "https://github.com/vostok/1");
            var service2 = new ReplicaInfo("default", "vostok", "https://github.com/vostok/2");
            var daemon   = new ReplicaInfo("default", "vostok", "pid(123)");

            CreateEnvironmentNode("default");
            CreateApplicationNode("default", "vostok");

            using (var service1Beacon = GetServiceBeacon(service1))
                using (var locator = GetServiceLocator())
                {
                    service1Beacon.Start();
                    WaitReplicaRegistered(service1);
                    ShouldLocateImmediately(locator, "default", "vostok", service1.Replica);

                    using (var daemonBeacon = GetServiceBeacon(daemon))
                    {
                        daemonBeacon.Start();
                        WaitReplicaRegistered(daemon);

                        Thread.Sleep(0.5.Seconds());
                        ShouldLocateImmediately(locator, "default", "vostok", service1.Replica);

                        using (var service2Beacon = GetServiceBeacon(service2))
                        {
                            service2Beacon.Start();
                            WaitReplicaRegistered(service2);
                            ShouldLocate(locator, "default", "vostok", service1.Replica, service2.Replica);
                        }
                    }
                }
        }
        public void TryCreatePermanentReplicaAsync_should_return_true_and_create_new_replica_environment_and_application_if_they_do_not_exist()
        {
            var replicaInfo             = new ReplicaInfo("default", "vostok", "replica1", GetProperties());
            var serviceDiscoveryManager = new ServiceDiscoveryManager(GetZooKeeperClient(), log: Log);

            serviceDiscoveryManager.TryCreatePermanentReplicaAsync(replicaInfo)
            .GetAwaiter()
            .GetResult()
            .Should()
            .BeTrue();

            serviceDiscoveryManager
            .GetAllReplicasAsync(replicaInfo.Environment, replicaInfo.Application)
            .GetAwaiter()
            .GetResult()
            .Should()
            .BeEquivalentTo("replica1");

            serviceDiscoveryManager
            .GetEnvironmentAsync("default")
            .GetAwaiter()
            .GetResult()
            .Should()
            .NotBeNull();

            serviceDiscoveryManager
            .GetApplicationAsync("default", "vostok")
            .GetAwaiter()
            .GetResult()
            .Should()
            .NotBeNull();
        }
Exemplo n.º 17
0
        /// <exception cref="System.IO.IOException"/>
        public static bool UnlinkBlock <_T0>(FsDatasetSpi <_T0> fsd, ExtendedBlock block, int
                                             numLinks)
            where _T0 : FsVolumeSpi
        {
            ReplicaInfo info = ((FsDatasetImpl)fsd).GetReplicaInfo(block);

            return(info.UnlinkBlock(numLinks));
        }
Exemplo n.º 18
0
        public void Should_not_throw_immediately_disposed()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            using (GetServiceBeacon(replica))
            {
            }
        }
Exemplo n.º 19
0
        public virtual void TestRecoverReplicas()
        {
            Configuration conf = new HdfsConfiguration();

            conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, 1024L);
            conf.SetInt(DFSConfigKeys.DfsClientWritePacketSizeKey, 512);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build();

            cluster.WaitActive();
            try
            {
                FileSystem fs = cluster.GetFileSystem();
                for (int i = 0; i < 4; i++)
                {
                    Path fileName = new Path("/test" + i);
                    DFSTestUtil.CreateFile(fs, fileName, 1, (short)1, 0L);
                    DFSTestUtil.WaitReplication(fs, fileName, (short)1);
                }
                string   bpid = cluster.GetNamesystem().GetBlockPoolId();
                DataNode dn   = cluster.GetDataNodes()[0];
                IEnumerator <ReplicaInfo> replicasItor = Dataset(dn).volumeMap.Replicas(bpid).GetEnumerator
                                                             ();
                ReplicaInfo replica = replicasItor.Next();
                CreateUnlinkTmpFile(replica, true, true);
                // rename block file
                CreateUnlinkTmpFile(replica, false, true);
                // rename meta file
                replica = replicasItor.Next();
                CreateUnlinkTmpFile(replica, true, false);
                // copy block file
                CreateUnlinkTmpFile(replica, false, false);
                // copy meta file
                replica = replicasItor.Next();
                CreateUnlinkTmpFile(replica, true, true);
                // rename block file
                CreateUnlinkTmpFile(replica, false, false);
                // copy meta file
                cluster.RestartDataNodes();
                cluster.WaitActive();
                dn = cluster.GetDataNodes()[0];
                // check volumeMap: 4 finalized replica
                ICollection <ReplicaInfo> replicas = Dataset(dn).volumeMap.Replicas(bpid);
                NUnit.Framework.Assert.AreEqual(4, replicas.Count);
                replicasItor = replicas.GetEnumerator();
                while (replicasItor.HasNext())
                {
                    NUnit.Framework.Assert.AreEqual(HdfsServerConstants.ReplicaState.Finalized, replicasItor
                                                    .Next().GetState());
                }
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Helper function to return the RTableConfig
        /// Note that even if 3 (say) accounts are specified in the xml,
        /// the test codes can specify that only accounts #0 and #2 are used to construct the RTable.
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="convertXStoreTableMode"></param>
        /// <param name="readViewHeadIndex"></param>
        /// <returns></returns>
        private ReplicatedTableConfiguration GetRTableConfiguration(long viewId, bool convertXStoreTableMode, int readViewHeadIndex = 0)
        {
            if (viewId <= 0)
            {
                throw new Exception(string.Format("GetRTableConfigText() was called with invalid viewId {0}", viewId));
            }

            // 1 - Create a default view
            var viewConfig = new ReplicatedTableConfigurationStore
            {
                ViewId            = viewId,
                ReadViewHeadIndex = readViewHeadIndex,
            };

            int numberOfStorageAccounts = this.rtableTestConfiguration.StorageInformation.AccountNames.Count();

            for (int i = 0; i < this.actualStorageAccountsUsed.Count; i++)
            {
                int index = this.actualStorageAccountsUsed[i];
                if (index < 0 || index > numberOfStorageAccounts)
                {
                    throw new Exception(string.Format("this.actualStorageAccountsUsed[{0}] = {1} is out of range.", i, index));
                }

                ReplicaInfo replica = new ReplicaInfo
                {
                    StorageAccountName = this.rtableTestConfiguration.StorageInformation.AccountNames[index],
                    Status             = ReplicaStatus.ReadWrite,
                };

                if (readViewHeadIndex != 0 && i < readViewHeadIndex)
                {
                    replica.Status = ReplicaStatus.WriteOnly;
                }

                viewConfig.ReplicaChain.Add(replica);
            }

            // 2 - Create a default table config. that references the "DefaultView"
            var tableConfig = new ReplicatedTableConfiguredTable
            {
                TableName       = DefaultTableConfigName,
                ViewName        = DefaultViewName,
                ConvertToRTable = convertXStoreTableMode,
                UseAsDefault    = true,
            };

            // 3 - Create the final RTable configuration
            ReplicatedTableConfiguration configuration = new ReplicatedTableConfiguration();

            configuration.SetView(DefaultViewName, viewConfig);
            configuration.SetTable(tableConfig);

            return(configuration);
        }
Exemplo n.º 21
0
        protected ServiceBeacon GetServiceBeacon(ReplicaInfo replica, ZooKeeperClient client = null, Func <bool> registrationAllowedProvider = null)
        {
            client = client ?? ZooKeeperClient;
            var settings = new ServiceBeaconSettings
            {
                IterationPeriod = 60.Seconds(),
                MinimumTimeBetweenIterations = 100.Milliseconds(),
                RegistrationAllowedProvider  = registrationAllowedProvider
            };

            return(new ServiceBeacon(client, replica, settings, Log));
        }
Exemplo n.º 22
0
        public void Should_ignore_cycled_if_resolved()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            CreateEnvironmentNode("default", "default");
            CreateReplicaNode(replica);

            using (var locator = GetServiceLocator())
            {
                ShouldLocate(locator, "default", "vostok", replica.Replica);
            }
        }
 private static void AssertEquals(ReplicaInfo originalInfo, ReplicaRecoveryInfo recoveryInfo
                                  )
 {
     NUnit.Framework.Assert.AreEqual(originalInfo.GetBlockId(), recoveryInfo.GetBlockId
                                         ());
     NUnit.Framework.Assert.AreEqual(originalInfo.GetGenerationStamp(), recoveryInfo.GetGenerationStamp
                                         ());
     NUnit.Framework.Assert.AreEqual(originalInfo.GetBytesOnDisk(), recoveryInfo.GetNumBytes
                                         ());
     NUnit.Framework.Assert.AreEqual(originalInfo.GetState(), recoveryInfo.GetOriginalReplicaState
                                         ());
 }
Exemplo n.º 24
0
        /// <summary>
        /// Get the meta information of the replica that matches both block id
        /// and generation stamp
        /// </summary>
        /// <param name="bpid">block pool id</param>
        /// <param name="block">block with its id as the key</param>
        /// <returns>the replica's meta information</returns>
        /// <exception cref="System.ArgumentException">if the input block or block pool is null
        ///     </exception>
        internal virtual ReplicaInfo Get(string bpid, Block block)
        {
            CheckBlockPool(bpid);
            CheckBlock(block);
            ReplicaInfo replicaInfo = Get(bpid, block.GetBlockId());

            if (replicaInfo != null && block.GetGenerationStamp() == replicaInfo.GetGenerationStamp
                    ())
            {
                return(replicaInfo);
            }
            return(null);
        }
        protected ISyncableItemInfo getSyncableItemInfoFrom(ReplicaItemId reposItemId)
        {
            IReplicaInfo created = new ReplicaInfo {
                ReplicaId = Adapter.GetGlobalReplicaIdForLocalReplicaId(reposItemId.CreationReplicaLocalId), ReplicaTickCount = reposItemId.CreationTickCount
            };
            IReplicaInfo modified = new ReplicaInfo {
                ReplicaId = Adapter.GetGlobalReplicaIdForLocalReplicaId(reposItemId.ModificationReplicaLocalId), ReplicaTickCount = reposItemId.ModificationTickCount
            };

            return(new SyncableItemInfo {
                ItemType = reposItemId.ItemType.ToString(), Created = created, Modified = modified, Deleted = false
            });
        }
        public void AddReplicaTest()
        {
            Assert.IsTrue(this.repTable.Exists(), "RTable does not exist");

            View   v           = this.configurationWrapper.GetWriteView();
            int    index       = v.Chain.Count - 1;
            string accountName = v.GetReplicaInfo(index).StorageAccountName;

            List <ReplicaInfo> replicas = new List <ReplicaInfo>();

            for (int i = 0; i <= index; i++)
            {
                replicas.Add(v.Chain[i].Item1);
            }

            //Just add the last replica again at the head to simulate a new replica addition
            ReplicaInfo newReplica = new ReplicaInfo()
            {
                StorageAccountName = accountName,
            };

            //Add the new replica at the head
            replicas.Insert(0, newReplica);

            int readViewHeadIndex = 1;

            this.UpdateConfiguration(replicas, readViewHeadIndex);

            // validate all state
            Assert.IsFalse(this.configurationWrapper.IsViewStable(), "View = {0}", this.configurationWrapper.GetWriteView().IsStable);
            View readView  = this.configurationWrapper.GetReadView();
            View writeView = this.configurationWrapper.GetWriteView();
            long viewIdAfterFirstUpdate = writeView.ViewId;

            // Actually, both read and write views point to the same view
            Assert.IsTrue(readView == writeView);

            int  headIndex          = 0;
            long readViewHeadViewId = readView.GetReplicaInfo(readViewHeadIndex).ViewInWhichAddedToChain;

            Assert.IsTrue(writeView.GetReplicaInfo(headIndex).ViewInWhichAddedToChain == readViewHeadViewId + 1);

            //Now, make the read and write views the same
            this.UpdateConfiguration(replicas, 0);
            // validate all state
            Assert.IsTrue(this.configurationWrapper.IsViewStable());
            readView  = this.configurationWrapper.GetReadView();
            writeView = this.configurationWrapper.GetWriteView();
            Assert.IsTrue(readView == writeView);
            Assert.IsTrue(readView.ViewId == viewIdAfterFirstUpdate + 1);
        }
        public void GetApplicationAsync_should_return_not_null_if_application_exists()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            CreateApplicationNode(replica.Environment, replica.Application);

            var serviceDiscoveryManager = new ServiceDiscoveryManager(GetZooKeeperClient(), log: Log);

            serviceDiscoveryManager.GetApplicationAsync(replica.Environment, replica.Application)
            .GetAwaiter()
            .GetResult()
            .Should()
            .BeEquivalentTo(new ApplicationInfo(replica.Environment, replica.Application, null));
        }
        public void GetEnvironmentAsync_should_return_not_null_if_environment_exists()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            CreateEnvironmentNode(replica.Environment);

            var serviceDiscoveryManager = new ServiceDiscoveryManager(GetZooKeeperClient(), log: Log);

            serviceDiscoveryManager.GetEnvironmentAsync(replica.Environment)
            .GetAwaiter()
            .GetResult()
            .Should()
            .NotBeNull();
        }
Exemplo n.º 29
0
        public void TestToString()
        {
            var replica = new ReplicaInfo();

            string acc = "some_name";
            string key = "some_key";
            int    whenAddedToChain = 8;

            replica.StorageAccountName      = acc;
            replica.StorageAccountKey       = key;
            replica.ViewInWhichAddedToChain = whenAddedToChain;
            replica.Status = ReplicaStatus.ReadWrite;

            Assert.IsTrue(replica.ToString() == string.Format("Account Name: {0}, AccountKey: {1}, ViewInWhichAddedToChain: {2}, Status: {3}", acc, "***********", whenAddedToChain, ReplicaStatus.ReadWrite));
        }
Exemplo n.º 30
0
        public void Start_should_create_node()
        {
            var replica = new ReplicaInfo("default", "vostok", "https://github.com/vostok");

            CreateEnvironmentNode(replica.Environment);

            using (var beacon = GetServiceBeacon(replica))
            {
                ReplicaRegistered(replica).Should().BeFalse();

                beacon.Start();
                beacon.WaitForInitialRegistrationAsync().ShouldCompleteIn(DefaultTimeout);

                ReplicaRegistered(replica).Should().BeTrue();
            }
        }