Sunday, August 11, 2019

Vertical and Horizontal Scaling

Vertical scaling is known as Scale up.
It is a process of adding resource to increase power of an existing server
Example: Adding CPU or Memory

Horizontal scaling is known as Scale Out.
It is a process of adding more servers.
Example: More than one server will be processing the input request from user

Benefits of moving to cloud

Few of the advantage of using cloud are

  • Cost-Effective: Pay-as-you-go - It is consumption based model. 
  • Scalable: Support both vertical & horizontal scaling
  • Elastic: It is easy to scale in & scale out depending on business need.
  • Reliable: data backup, disaster recovery and data replication
  • Reduced IT workforce - Cloud provider is responsible for maintaining physical hardware.

Sunday, March 24, 2019

Moq Sample:

Class to be unit tested:

public class A
{
    B _objectB;
    C _objectC;

    public A(B objectB, C objectC)
    {
        _objectB = objectB;
        _objectC = objectC;
    }
    public virtual int Operation(int number1, int number2)
    {
        int result = 0;

        result += _objectB.Multiply(number1, number2);
        result += _objectC.Divide(number1, number2);

        return result;
    }
}

Unit testing with mocking:

using Moq;
using Xunit;

public class ATest
{
    [Fact]
    public void Operation_MockDependencies_ShouldPass()
    {
        //Arrange
        Mock mockB = new Mock();
        Mock mockC = new Mock();
        var sut = new A(mockB.Object, mockC.Object);
        int number1 = 10;
        int number2 = 5;

        mockB.Setup(x => x.Multiply(number1, number2)).Returns(10);
        mockC.Setup(x => x.Divide(number1, number2)).Returns(25);

        //Act
        var result = sut.Operation(number1, number2);

        //Assert
        Assert.Equal(35, result);
    }
}

What is Moq


  • Moq is a mocking framework for .NET
  • Pronounce as “Mock-you” or “Mock”
  • It helps to isolate dependencies in unit testing
  • Nuget packages
  • Moq (4.10.1)
  • Reference: https://github.com/moq/moq4


xUnit sample

Class to be unit tested:

public class A
{
    B _objectB;
    C _objectC;

    public A(B objectB, C objectC)
    {
        _objectB = objectB;
        _objectC = objectC;
    }
    public virtual int Operation(int number1, int number2)
    {
        int result = 0;

        result += _objectB.Multiply(number1, number2);
        result += _objectC.Divide(number1, number2);

        return result;
    }
}

Unit test:

using Xunit;
public class ATest
{
    [Fact]
    public void Operation_WithCorrectParameters_ShouldPass()
    {
        //Arrange
        int number1 = 10;
        int number2 = 5;
        var sut = new A(new B(), new C());

        //Act
        var result = sut.Operation(number1, number2);

        //Assert
        Assert.Equal(52, result);
    }

}

What is xUnit


  • xUnit is unit testing tool for .NET framework
  • It is free & Open Source (Licensed under Apache)
  • Supports .NET core
  • Nuget packages
  • xunit (2.4.1)
  • Xunit.runner.visualstudio (2.4.1)
  • Reference: https://xunit.github.io/


Sunday, November 25, 2018

Fault domain and update domain with Azure

Both are availability settings.
It ensures availability of virtual machines during unforeseen situations or during upgrades.

Fault domain:

  • Fault domain is racks of computers.
  • Set of hardware components that share a single point of failure
  • In a data center, rack of computers can be fault domain, which might be sharing same power source or network connection
  • To minimize impact of possible hardware failure, Microsoft Azure deploys instances to at least 2 or more fault domains

Update domain:
  • Upgrade domain keep your application running during upgrades
  • Take down instances one by one, so that at any given time at least one running instance serving request
  • There will be 5 upgrade domains by default, it can increase up to 21

Conclusion
  • Fault domain - for unplanned failures
  • Update domain - for planned maintenance operations

References: