Esempio n. 1
0
        internal static List <ReplicationUnit> GroupByRelicationUnit(ActorStateTable.ActorStateEnumerator enumerator)
        {
            var replicationUnits = new List <ReplicationUnit>();

            while (enumerator.PeekNext() != null)
            {
                var peek            = enumerator.PeekNext();
                var replicationUnit = new ReplicationUnit(peek.SequenceNumber, peek.Type);

                do
                {
                    replicationUnit.ActorStateDataWrapperList.Add(enumerator.GetNext());
                    peek = enumerator.PeekNext();
                }while (peek != null && peek.SequenceNumber == replicationUnit.SequenceNumber);

                replicationUnits.Add(replicationUnit);
            }

            return(replicationUnits);
        }
Esempio n. 2
0
        /// <summary>
        /// This function verifies snapshot when the replication units are uniform
        /// i.e. they either contain update entries or delete entries.
        /// </summary
        internal static void VerifyStateTableSnapshot(
            ActorStateTable stateTable,
            Dictionary <ActorStateType, int> statesPerReplication,
            ActorStateTable.ActorStateEnumerator enumerator,
            long expectedCommittedSequenceNumber,
            long expectedKnownSequenceNumber,
            long expectedCount)
        {
            var actualCommittedSequenceNumber = stateTable.GetHighestCommittedSequenceNumber();
            var actualKnownSequenceNumber     = stateTable.GetHighestKnownSequenceNumber();

            TestLog(
                "ActorStateTable committed:{0} known:{1}",
                stateTable.GetHighestCommittedSequenceNumber(),
                stateTable.GetHighestKnownSequenceNumber());

            FailTestIf(
                expectedCommittedSequenceNumber != actualCommittedSequenceNumber,
                "Committed sequence number: expected:{0} actual:{1}",
                expectedCommittedSequenceNumber,
                actualCommittedSequenceNumber);

            FailTestIf(
                expectedKnownSequenceNumber != actualKnownSequenceNumber,
                "Known sequence number: expected:{0} actual:{1}",
                expectedKnownSequenceNumber,
                actualKnownSequenceNumber);

            // Group the actor state by replication unit
            var replicationUnits = GroupByRelicationUnit(enumerator);

            long actualCount        = 0;
            long lastSequenceNumber = 0;

            foreach (var replicationUnit in replicationUnits)
            {
                TestLog(
                    "[{0}] '{1}' {2}",
                    replicationUnit.SequenceNumber,
                    replicationUnit.StateType,
                    replicationUnit.GetKeyString());

                FailTestIf(
                    replicationUnit.SequenceNumber <= lastSequenceNumber,
                    "Sequence number: previous:{0} current:{1}",
                    lastSequenceNumber,
                    replicationUnit.SequenceNumber);

                if ((replicationUnit.SequenceNumber == actualCommittedSequenceNumber) &&
                    replicationUnit.IsLastActorStateDelete)
                {
                    FailTestIf(
                        replicationUnit.ActorStateCount != 1,
                        "States in replication unit at end of committed entry list: IsDelete:{0} ActualStateCount:{1} ExpectedStateCount:1",
                        replicationUnit.IsLastActorStateDelete,
                        replicationUnit.ActorStateCount);
                }
                else if (replicationUnit.SequenceNumber <= actualCommittedSequenceNumber)
                {
                    // The replication unit should only contain update entries
                    FailTestIf(
                        replicationUnit.ActorStateCount != statesPerReplication[replicationUnit.StateType],
                        "States in replication unit: ActualCount:{0} ExpectedCount:{1}",
                        replicationUnit.ActorStateCount,
                        statesPerReplication[replicationUnit.StateType]);

                    FailTestIf(
                        replicationUnit.ActorStateUpdateCount != statesPerReplication[replicationUnit.StateType],
                        "Update states in replication unit: ActualUpdateCount:{0} ExpectedUpdateCount:{1}",
                        replicationUnit.ActorStateUpdateCount,
                        statesPerReplication[replicationUnit.StateType]);
                }
                else
                {
                    // The replication unit should only contain either update entries or  delete entries
                    if (replicationUnit.IsLastActorStateDelete)
                    {
                        FailTestIf(
                            replicationUnit.ActorStateUpdateCount != 0,
                            "States in replication unit: IsDelete:{0} ActualUpdateStateCount:{1} ExpectedUpdateStateCount:0",
                            replicationUnit.IsLastActorStateDelete,
                            replicationUnit.ActorStateUpdateCount);

                        FailTestIf(
                            replicationUnit.ActorStateCount != statesPerReplication[replicationUnit.StateType],
                            "States in replication unit: IsDelete:{0} ActualStateCount:{1} ExpectedStateCount:{2}",
                            replicationUnit.IsLastActorStateDelete,
                            replicationUnit.ActorStateCount,
                            statesPerReplication[replicationUnit.StateType]);
                    }
                    else
                    {
                        FailTestIf(
                            replicationUnit.ActorStateUpdateCount != statesPerReplication[replicationUnit.StateType],
                            "States in replication unit: IsDelete:{0} ActualUpdateStateCount:{1} ExpectedUpdateStateCount:{2}",
                            replicationUnit.IsLastActorStateDelete,
                            replicationUnit.ActorStateUpdateCount,
                            statesPerReplication[replicationUnit.StateType]);

                        FailTestIf(
                            replicationUnit.ActorStateCount != statesPerReplication[replicationUnit.StateType],
                            "States in replication unit: IsDelete:{0} ActualStateCount:{1} ExpectedStateCount:{2}",
                            replicationUnit.IsLastActorStateDelete,
                            replicationUnit.ActorStateCount,
                            statesPerReplication[replicationUnit.StateType]);
                    }
                }

                foreach (var actorStateDataWrapper in replicationUnit.ActorStateDataWrapperList)
                {
                    string dataString = GetDataString(actorStateDataWrapper);

                    TestLog(
                        "[{0}] '{1}' {2} {3}",
                        actorStateDataWrapper.SequenceNumber,
                        actorStateDataWrapper.Type,
                        actorStateDataWrapper.Key,
                        dataString);

                    FailTestIf(
                        actorStateDataWrapper.SequenceNumber != replicationUnit.SequenceNumber,
                        "Sequence number same as replication unit: RU ={0} ActorState={1}",
                        replicationUnit.SequenceNumber,
                        actorStateDataWrapper.SequenceNumber);

                    FailTestIf(
                        actorStateDataWrapper.SequenceNumber != replicationUnit.SequenceNumber,
                        "State type same as replication unit: RU ={0} ActorState={1}",
                        replicationUnit.StateType,
                        actorStateDataWrapper.Type);

                    FailTestIf(string.IsNullOrEmpty(dataString), "Data not null or empty");
                }

                lastSequenceNumber = replicationUnit.SequenceNumber;
                actualCount       += replicationUnit.ActorStateDataWrapperList.Count;
            }

            FailTestIf(
                expectedCount != actualCount,
                "Total: expected:{0} actual:{1}\n",
                expectedCount,
                actualCount);
        }