internal  Task<bool> Save(ConsulClient consul,TableVersion newVersion=null)
 {
     if (newVersion!=null)
     {
         Version = newVersion.Version;
     }
     _kvEntry.SetValue(JsonConvert.SerializeObject(this,Formatting.Indented));
     return  consul.PutKV(_kvEntry, (newVersion!=null) ? (object)new  { cas=newVersion.VersionEtag } : new object{ });
 }
示例#2
0
 public MembershipTableData(TableVersion version)
 {
     Members = (new List<Tuple<MembershipEntry, string>>()).AsReadOnly();
     Version = version;
 }
示例#3
0
 public MembershipTableData(List<Tuple<MembershipEntry, string>> list, TableVersion version)
 {
     // put deads at the end, just for logging.
     list.Sort(
        (x, y) =>
        {
            if (x.Item1.Status.Equals(SiloStatus.Dead)) return 1; // put Deads at the end
            if (y.Item1.Status.Equals(SiloStatus.Dead)) return -1; // put Deads at the end
            return String.Compare(x.Item1.InstanceName, y.Item1.InstanceName, StringComparison.Ordinal);
        });
     Members = list.AsReadOnly();
     Version = version;
 }
示例#4
0
        public async Task GatewaySelection_SqlServer()
        {
            string testName = Guid.NewGuid().ToString();// TestContext.TestName;

            Guid serviceId = Guid.NewGuid();

            GlobalConfiguration cfg = new GlobalConfiguration
            {
                ServiceId = serviceId,
                DeploymentId = testName,
                DataConnectionString = TestHelper.TestUtils.GetSqlConnectionString()
            };

            var membership = new SqlMembershipTable();
            var logger = LogManager.GetLogger(membership.GetType().Name);
            await membership.InitializeMembershipTable(cfg, true, logger);

            IMembershipTable membershipTable = membership;

            // Pre-populate gateway table with data
            int count = 1;
            foreach (Uri gateway in gatewayAddressUris)
            {
                output.WriteLine("Adding gataway data for {0}", gateway);

                SiloAddress siloAddress = gateway.ToSiloAddress();
                Assert.IsNotNull(siloAddress, "Unable to get SiloAddress from Uri {0}", gateway);

                MembershipEntry MembershipEntry = new MembershipEntry
                {
                    SiloAddress = siloAddress,
                    HostName = gateway.Host,
                    Status = SiloStatus.Active,
                    ProxyPort = gateway.Port,
                    StartTime = DateTime.UtcNow
                };

                var tableVersion = new TableVersion(count, Guid.NewGuid().ToString());

                output.WriteLine("Inserting gataway data for {0} with TableVersion={1}", MembershipEntry, tableVersion);

                bool ok = await membershipTable.InsertRow(MembershipEntry, tableVersion);
                count++;
                Assert.IsTrue(ok, "Membership record should have been written OK but were not: {0}", MembershipEntry);

                output.WriteLine("Successfully inserted Membership row {0}", MembershipEntry);
            }

            MembershipTableData data = await membershipTable.ReadAll();
            Assert.IsNotNull(data, "MembershipTableData returned");
            Assert.AreEqual(gatewayAddressUris.Count, data.Members.Count, "Number of gateway records read");

            IGatewayListProvider listProvider = membership;

            Test_GatewaySelection(listProvider);
        }
示例#5
0
 public MembershipTableData(TableVersion version)
 {
     Members = (new List <Tuple <MembershipEntry, string> >()).AsReadOnly();
     Version = version;
 }
 public Task<bool> UpdateRow(MembershipEntry entry, string etag, TableVersion tableVersion)
 {
     throw new NotImplementedException();
 }
 public Task<bool> InsertRow(MembershipEntry entry, TableVersion tableVersion)
 {
     throw new NotImplementedException();
 }
 public MembershipTableData(List <Tuple <MembershipEntry, string> > list, TableVersion version)
 {
     Members = list;
     Version = version;
 }
 internal bool CanBeUpdated(TableVersion tableVersion)
 {
     return (_kvEntry.ModifyIndex.ToString() == tableVersion.VersionEtag);
 }
示例#10
0
 public MembershipTableData(List<Tuple<MembershipEntry, string>> list, TableVersion version)
 {
     // put deads at the end, just for logging.
     list.Sort(
        (x, y) =>
        {
            if (x.Item1.Status.Equals(SiloStatus.Dead)) return 1; // put Deads at the end
            return 1;
        });
     Members = list.AsReadOnly();
     Version = version;
 }