public void RoundTripSerialization()
        {
            var initial = MockGroupMembershipHelper.MockGroupMembership();

            var split = JsonConvert.DeserializeObject <GroupMembership[]>(JsonConvert.SerializeObject(initial.Split()));

            Assert.AreEqual((UserCount / ChunkSize) + 1, split.Length);

            foreach (var chunk in split)
            {
                Assert.AreEqual(initial.Destination, chunk.Destination);
                Assert.AreEqual(initial.SyncJobRowKey, chunk.SyncJobRowKey);
                Assert.AreEqual(initial.SyncJobPartitionKey, chunk.SyncJobPartitionKey);
            }

            foreach (var nonlastChunk in split.Take(split.Length - 1))
            {
                Assert.IsFalse(nonlastChunk.IsLastMessage);
                Assert.AreEqual(ChunkSize, nonlastChunk.SourceMembers.Count);
            }

            Assert.IsTrue(split.Last().IsLastMessage);
            Assert.AreEqual(UserCount % ChunkSize, split.Last().SourceMembers.Count);

            var rejoined = GroupMembership.Merge(split);

            Assert.AreEqual(initial.Destination, rejoined.Destination);
            Assert.AreEqual(initial.SyncJobRowKey, rejoined.SyncJobRowKey);
            Assert.AreEqual(initial.SyncJobPartitionKey, rejoined.SyncJobPartitionKey);
            CollectionAssert.AreEqual(initial.SourceMembers, rejoined.SourceMembers);
        }
예제 #2
0
        public void SplitsAndJoins()
        {
            var initial = MockGroupMembershipHelper.MockGroupMembership();
            var split   = initial.Split();

            Assert.AreEqual((UserCount / ChunkSize) + 1, split.Length);

            foreach (var chunk in split)
            {
                Assert.AreEqual(initial.Sources, chunk.Sources);
                Assert.AreEqual(initial.Destination, chunk.Destination);
                Assert.AreEqual(initial.SyncJobRowKey, chunk.SyncJobRowKey);
                Assert.AreEqual(initial.SyncJobPartitionKey, chunk.SyncJobPartitionKey);
                Assert.IsFalse(chunk.Errored);
            }

            foreach (var nonlastChunk in split.Take(split.Length - 1))
            {
                Assert.IsFalse(nonlastChunk.IsLastMessage);
                Assert.AreEqual(ChunkSize, nonlastChunk.SourceMembers.Count);
            }

            Assert.IsTrue(split.Last().IsLastMessage);
            Assert.AreEqual(UserCount % ChunkSize, split.Last().SourceMembers.Count);

            var rejoined = GroupMembership.Merge(split);

            Assert.AreEqual(initial.Sources, rejoined.Sources);
            Assert.AreEqual(initial.Destination, rejoined.Destination);
            Assert.AreEqual(initial.SyncJobRowKey, rejoined.SyncJobRowKey);
            Assert.AreEqual(initial.SyncJobPartitionKey, rejoined.SyncJobPartitionKey);
            CollectionAssert.AreEqual(initial.SourceMembers, rejoined.SourceMembers);
            Assert.IsFalse(rejoined.Errored);
        }
        public GroupMembershipMessage[] MakeMembershipMessages()
        {
            int messageNumber = 0;

            return(MockGroupMembershipHelper.MockGroupMembership().Split().Select(x => new GroupMembershipMessage
            {
                Body = x,
                LockToken = (messageNumber++).ToString()
            }).ToArray());
        }
        public void DefaultSerializationSizeWorks()
        {
            // https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quotas
            const int maxMessageSize     = 256 * 1024;                   // 256 kilobytes
            const int largestSafePayload = maxMessageSize - (64 * 1024); // minus the maximum header size

            var initial = MockGroupMembershipHelper.MockGroupMembership();

            foreach (var chunk in initial.Split())
            {
                var serialized = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(chunk));
                Assert.IsTrue(serialized.Length <= largestSafePayload);
            }
        }