Example #1
0
        /// <summary>
        /// Writes a known inconsistent state to the storage and asserts an exception will be thrown.
        /// </summary>
        /// <returns>The <see cref="InconsistentStateException"/> thrown by the provider. This can be further inspected
        /// by the storage specific asserts.</returns>
        internal async Task <InconsistentStateException> PersistenceStorage_WriteInconsistentFailsWithInconsistentStateException()
        {
            //Some version not expected to be in the storage for this type and ID.
            var inconsistentStateVersion = RandomUtilities.GetRandom <int>().ToString(CultureInfo.InvariantCulture);

            var    inconsistentState = CommonStorageUtilities.GetTestReferenceAndState(RandomUtilities.GetRandom <long>(), inconsistentStateVersion);
            string grainTypeName     = GrainTypeGenerator.GetGrainType <Guid>();
            var    exception         = await Record.ExceptionAsync(() => Store_WriteRead(grainTypeName, inconsistentState.Item1, inconsistentState.Item2));

            Assert.NotNull(exception);
            Assert.IsType <InconsistentStateException>(exception);

            return((InconsistentStateException)exception);
        }
Example #2
0
        /// <summary>
        /// Writes to storage and tries to re-write the same state with NULL as ETag, as if the grain was just created.
        /// </summary>
        /// <returns>The <see cref="InconsistentStateException"/> thrown by the provider. This can be further inspected
        /// by the storage specific asserts.</returns>
        internal async Task <InconsistentStateException> PersistenceStorage_WriteDuplicateFailsWithInconsistentStateException()
        {
            //A grain with a random ID will be arranged to the database. Then its state is set to null to simulate the fact
            //it is like a second activation after a one that has succeeded to write.
            string grainTypeName     = GrainTypeGenerator.GetGrainType <Guid>();
            var    inconsistentState = this.GetTestReferenceAndState(RandomUtilities.GetRandom <long>(), null);
            var    grainReference    = inconsistentState.Item1;
            var    grainState        = inconsistentState.Item2;

            await Store_WriteRead(grainTypeName, inconsistentState.Item1, inconsistentState.Item2);

            grainState.ETag = null;
            var exception = await Record.ExceptionAsync(() => Store_WriteRead(grainTypeName, grainReference, grainState));

            Assert.NotNull(exception);
            Assert.IsType <InconsistentStateException>(exception);

            return((InconsistentStateException)exception);
        }