public void ToJson_Correct()
        {
            JsonLeaseInfo jinfo = new JsonLeaseInfo()
            {
                RenewalIntervalInSecs      = 100,
                DurationInSecs             = 200,
                RegistrationTimestamp      = 1457973741708,
                LastRenewalTimestamp       = 1457973741708,
                LastRenewalTimestampLegacy = 1457973741708,
                EvictionTimestamp          = 1457973741708,
                ServiceUpTimestamp         = 1457973741708
            };

            LeaseInfo result = LeaseInfo.FromJson(jinfo);

            jinfo = result.ToJson();

            Assert.Equal(100, result.RenewalIntervalInSecs);
            Assert.Equal(200, result.DurationInSecs);
            Assert.Equal(1457973741708, DateTimeConversions.ToJavaMillis(new DateTime(result.RegistrationTimestamp, DateTimeKind.Utc)));
            Assert.Equal(1457973741708, DateTimeConversions.ToJavaMillis(new DateTime(result.LastRenewalTimestamp, DateTimeKind.Utc)));
            Assert.Equal(1457973741708, DateTimeConversions.ToJavaMillis(new DateTime(result.LastRenewalTimestampLegacy, DateTimeKind.Utc)));
            Assert.Equal(1457973741708, DateTimeConversions.ToJavaMillis(new DateTime(result.EvictionTimestamp, DateTimeKind.Utc)));
            Assert.Equal(1457973741708, DateTimeConversions.ToJavaMillis(new DateTime(result.ServiceUpTimestamp, DateTimeKind.Utc)));
        }
Esempio n. 2
0
        internal JsonLeaseInfo ToJson()
        {
            var jinfo = new JsonLeaseInfo()
            {
                RenewalIntervalInSecs      = RenewalIntervalInSecs,
                DurationInSecs             = DurationInSecs,
                RegistrationTimestamp      = DateTimeConversions.ToJavaMillis(new DateTime(RegistrationTimestamp, DateTimeKind.Utc)),
                LastRenewalTimestamp       = DateTimeConversions.ToJavaMillis(new DateTime(LastRenewalTimestamp, DateTimeKind.Utc)),
                LastRenewalTimestampLegacy = DateTimeConversions.ToJavaMillis(new DateTime(LastRenewalTimestampLegacy, DateTimeKind.Utc)),
                EvictionTimestamp          = DateTimeConversions.ToJavaMillis(new DateTime(EvictionTimestamp, DateTimeKind.Utc)),
                ServiceUpTimestamp         = DateTimeConversions.ToJavaMillis(new DateTime(ServiceUpTimestamp, DateTimeKind.Utc))
            };

            return(jinfo);
        }
Esempio n. 3
0
        public JsonLeaseInfo ToJson()
        {
            JsonLeaseInfo jinfo = new JsonLeaseInfo()
            {
                RenewalIntervalInSecs      = this.RenewalIntervalInSecs,
                DurationInSecs             = this.DurationInSecs,
                RegistrationTimestamp      = DateTimeConversions.ToJavaMillis(new DateTime(this.RegistrationTimestamp, DateTimeKind.Utc)),
                LastRenewalTimestamp       = DateTimeConversions.ToJavaMillis(new DateTime(this.LastRenewalTimestamp, DateTimeKind.Utc)),
                LastRenewalTimestampLegacy = DateTimeConversions.ToJavaMillis(new DateTime(this.LastRenewalTimestampLegacy, DateTimeKind.Utc)),
                EvictionTimestamp          = DateTimeConversions.ToJavaMillis(new DateTime(this.EvictionTimestamp, DateTimeKind.Utc)),
                ServiceUpTimestamp         = DateTimeConversions.ToJavaMillis(new DateTime(this.ServiceUpTimestamp, DateTimeKind.Utc))
            };

            return(jinfo);
        }
Esempio n. 4
0
        internal static LeaseInfo FromJson(JsonLeaseInfo jinfo)
        {
            LeaseInfo info = new LeaseInfo();

            if (jinfo != null)
            {
                info.RenewalIntervalInSecs      = jinfo.RenewalIntervalInSecs;
                info.DurationInSecs             = jinfo.DurationInSecs;
                info.RegistrationTimestamp      = DateTimeConversions.FromJavaMillis(jinfo.RegistrationTimestamp).Ticks;
                info.LastRenewalTimestamp       = DateTimeConversions.FromJavaMillis(jinfo.LastRenewalTimestamp).Ticks;
                info.LastRenewalTimestampLegacy = DateTimeConversions.FromJavaMillis(jinfo.LastRenewalTimestampLegacy).Ticks;
                info.EvictionTimestamp          = DateTimeConversions.FromJavaMillis(jinfo.EvictionTimestamp).Ticks;
                info.ServiceUpTimestamp         = DateTimeConversions.FromJavaMillis(jinfo.ServiceUpTimestamp).Ticks;
            }
            return(info);
        }
Esempio n. 5
0
        public void Deserialize_GoodJson()
        {
            var    json      = @"
{   
    'renewalIntervalInSecs':30,
    'durationInSecs':90,
    'registrationTimestamp':1457714988223,
    'lastRenewalTimestamp':1457716158319,
    'evictionTimestamp':0,
    'serviceUpTimestamp':1457714988223
}";
            Stream stream    = TestHelpers.StringToStream(json);
            var    leaseInfo = JsonLeaseInfo.Deserialize(stream);

            Assert.NotNull(leaseInfo);
            Assert.Equal(30, leaseInfo.RenewalIntervalInSecs);
            Assert.Equal(90, leaseInfo.DurationInSecs);
            Assert.Equal(1457714988223, leaseInfo.RegistrationTimestamp);
            Assert.Equal(1457716158319, leaseInfo.LastRenewalTimestamp);
            Assert.Equal(0, leaseInfo.EvictionTimestamp);
            Assert.Equal(1457714988223, leaseInfo.ServiceUpTimestamp);
        }