Represents a thread-safe Int32 value.
Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountServer"/> class.
        /// </summary>
        public AccountServer(IClock clock)
        {
            this.clock = clock;

            this.activeAccounts = new Dictionary<int, ActiveAccount>(256);
            this.currentSessionId = new AtomicInteger(0);
        }
Ejemplo n.º 2
0
        public void CompareExchange_Should_Return_Old_Value_When_Comparand_Matches()
        {
            var i = new AtomicInteger(123);

            var old = i.CompareExchange(123, 321);

            old.Should().Be(123);
        }
Ejemplo n.º 3
0
        public void CompareExchange_Should_Return_Current_Value_When_Comparand_Does_Not_Match()
        {
            var i = new AtomicInteger(123);

            var current = i.CompareExchange(234, 432);

            current.Should().Be(123);
        }
Ejemplo n.º 4
0
        public void CompareExchange_Should_Not_Set_New_Value_When_Comparand_Does_Not_Match()
        {
            var i = new AtomicInteger(123);

            i.CompareExchange(234, 432);

            i.Value.Should().Be(123);
        }
Ejemplo n.º 5
0
        public void Decrement_Should_Return_Decreased_Value()
        {
            var i = new AtomicInteger(123);

            var current = i.Decrement();

            current.Should().Be(122);
        }
Ejemplo n.º 6
0
        public void CompareExchange_Should_Set_New_Value_When_Comparand_Matches()
        {
            var i = new AtomicInteger(123);

            i.CompareExchange(123, 321);

            i.Value.Should().Be(321);
        }
Ejemplo n.º 7
0
        public void Decrement_Should_Set_Decreased_Value()
        {
            var i = new AtomicInteger(123);

            i.Decrement();

            i.Value.Should().Be(122);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Extracts a <see cref="Int32"/> from an instance of <see cref="AtomicInteger"/>.
        /// </summary>
        /// <param name="atomicInteger">The <see cref="AtomicInteger"/> to extract the value of.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="atomicInteger" /> is <see langword="null"/>.
        /// </exception>
        /// <returns>the value of the <see cref="AtomicInteger"/>.</returns>
        public static int ToInt32(AtomicInteger atomicInteger)
        {
            if (atomicInteger == null)
            {
                throw new InvalidCastException();
            }

            return atomicInteger.value;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientBase" /> class.
        /// </summary>
        /// <param name="serverSession">The network session to bind the instance to.</param>
        /// <param name="packetFactory">The <see cref="IPacketFactory" /> to use for this client.</param>
        /// <param name="logger">The logger to use for this client.</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the parameters is <see langword="null" />.</exception>
        protected ClientBase(IServerSession serverSession, IPacketFactory packetFactory, ILogger logger)
        {
            Guard.NotNull(() => serverSession, serverSession);
            Guard.NotNull(() => packetFactory, packetFactory);

            this.isDisposed = false;
            this.sentPings = new AtomicInteger(0);

            this.ServerSession = this.InitializeSession(serverSession);
            this.PacketFactory = packetFactory;
            this.Logger = logger;

            this.keepAliveTimer = this.InitializeTimer();
            this.keepAliveTimer.Start();
        }
Ejemplo n.º 10
0
        public void ToInt32_Should_Return_Value_As_Int32()
        {
            var i = new AtomicInteger(123);

            i.ToInt32().Should().Be(123);
        }
Ejemplo n.º 11
0
        public void ToInt32_Should_Return_Value_As_Int32()
        {
            var i = new AtomicInteger(123);

            i.ToInt32().Should().Be(123);
        }
Ejemplo n.º 12
0
        public void ExchangeWith_Should_Return_Old_Value()
        {
            var i = new AtomicInteger(123);

            var old = i.ExchangeWith(321);

            old.Should().Be(123);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveChannel"/> class.
 /// </summary>
 public ActiveChannel()
 {
     this.channelLoad = 0;
 }
Ejemplo n.º 14
0
        public void Implicit_Cast_From_Int32_Should_Set_Value()
        {
            AtomicInteger i = 123;

            i.Value.Should().Be(123);
        }
Ejemplo n.º 15
0
        public void Static_ToInt32_Should_Throw_On_Null()
        {
            Action action = () => AtomicInteger.ToInt32(null);

            action.ShouldThrow <InvalidCastException>();
        }
Ejemplo n.º 16
0
        public void Static_ToInt32_Should_Return_Value_As_Int32()
        {
            var i = new AtomicInteger(123);

            AtomicInteger.ToInt32(i).Should().Be(123);
        }
Ejemplo n.º 17
0
        public void Constructor_Should_Set_Value()
        {
            var i = new AtomicInteger(123);

            i.Value.Should().Be(123);
        }
Ejemplo n.º 18
0
 public void Explicit_Cast_To_Int32_Should_Return_Value()
 {
     var i = new AtomicInteger(123);
     var cast = (int)i;
     cast.Should().Be(123);
 }
Ejemplo n.º 19
0
        public void Increment_Should_Set_Increased_Value()
        {
            var i = new AtomicInteger(123);

            i.Increment();

            i.Value.Should().Be(124);
        }
Ejemplo n.º 20
0
        public void Static_ToInt32_Should_Return_Value_As_Int32()
        {
            var i = new AtomicInteger(123);

            AtomicInteger.ToInt32(i).Should().Be(123);
        }
Ejemplo n.º 21
0
        public void ExchangeWith_Should_Set_New_Value()
        {
            var i = new AtomicInteger(123);

            i.ExchangeWith(321);

            i.Value.Should().Be(321);
        }
Ejemplo n.º 22
0
        public void Constructor_Should_Set_Value()
        {
            var i = new AtomicInteger(123);

            i.Value.Should().Be(123);
        }