In the previous article in this series I introduced the Windows Azure Platform and described the three basic components of Windows Azure, the Compute and Storage services and the Fabric Controller.

Let’s now take a look at how Windows Azure scales out.

The windows Azure Compute Service can run many kinds of applications.  The primary purpose, however, of the Windows Azure Platform is to support applications that have large numbers of simultaneous users.  After a while scaling-up, using bigger and bigger machines to support more and more users, is no longer possible.  So Windows Azure is designed to support applications that scale out, using multiple instances of the same code running on multiple machines.

To accomplish this, a Windows Azure application can have multiple instances, with each instance executing in its own virtual machine (VM). Each VM is provided by a hypervisor (based on Hyper-V) that’s been modified for use in Microsoft’s cloud, and it provides a Windows interface to the instance it contains.

Figure 1: A typical Windows Azure Application Running on Multiple Virtual Machines
Azure_Dev_11

Windows Azure currently supports two instance types – a Web Role Instance and a Worker Role instance (Figure 1).

As its name suggests a Web Role can receive incoming HTTP or HTTPS requests and a Web Role instance includes IIS7 to provide this support.  Developers can use ASP.NET in the Web Role but they are not restricted to this technology – PHP or other web technologies can also be used.

Worker roles are similar to Web Roles but they do not have IIS7 installed and so they cannot receive Web requests (HTTP or HTTPS) directly.  They are usually used to process background tasks.

A Windows Azure Application can consist of all Web Roles or all Worker Roles but typically will be a combination of the two.  If an applications load increases more instances can be launched, depending on the load this may mean more Web Role instances, more Worker Role instances or both.  If the load then decreases the extra instances can be stopped.

In a production environment this is managed through the Windows Azure Portal.  In a development environment the developer can configure the initial configuration by modifying the properties of the Cloud Service.

If we go back to the “Hello Cloud” Application we created in the first article, we can see that in the HelloCloudService project there is a Roles folder which contains a single “Role” – the Hello Cloud Web Role, that is the other project in the solution (Figure 2)

Figure 2: The Hello Cloud Solution in Solution Explorer
Azure_Dev_5

If we right-click on the HelloCloud role in the Roles folder, and select Properties, we can configure this Role.

Figure 3: Configuring the Hello Cloud Web Role
Azure_Dev_12

We can set the size of the VM and the number of instances to launch, when first deployed.  The VMs can be Small, Medium, Large or Extra Large.  Each type has a different number of CPU cores, system RAM and local Storage – see http://msdn.microsoft.com/en-us/library/ee814754.aspx for the exact configuration of the available VMs.

In a multi-Role Application, each Role can be separately configured and customized for the expected demand, and once launched the Windows Azure Portal can be used to add or delete running instances according to demand.

In the next article we will take a look at the Storage Service and how that can be used in Windows Azure applications.


In the previous article in this blog series on Windows Azure, I showed how you can download the tools that Microsoft provides to develop your own Windows Azure application and we developed our very first “Hello Cloud” application.

So far – so good.  But what is Windows Azure and why should we care?

Lets first look at what Microsoft says on its Windows Azure site.

The Windows Azure platform offers a flexible, familiar environment for developers to create cloud applications and services. With Windows Azure, you can shorten your time to market and adapt as demand for your service grows.

There are a number of key words and phrases in this marketing statement.

  • Platform – Windows Azure is a platform – as a platform it will provide a number of key services.
  • Cloud Applications and Services – Windows Azure allows developers to create cloud applications and services.  ie it is not for writing desktop applications or even simple web sites
  • Shorten … Time to Market – As Windows Azure is based on technologies that we already know it can reduce the time it takes developers to create Azure applications
  • Adapt as Demand .. Grows – Windows Azure provides easy configurable scalability which allows you to scale your application to meet demand.  This can be scaling up to meet increasing demand AND equally scaling back to meet reduced demand.

There are four major components that make up the Windows Azure Platform.

  • Windows Azure – the windows Azure Operating System
  • SQL Azure – A cloud service based on the familiar SQL Server.
  • AppFabric – Services which allow you t “connect” cloud services with “on-premise” applications
  • Codenamed “Dallas” – A standards based information marketplace

This is summarized in Figure 1 (from www.windowsAzure.com)

Figure 1: The Windows Azure Platform
 Azure_Dev_8

 

Windows Azure

Windows Azure is the backbone of the Windows Azure Platform.  windows Azure runs on machines in Microsoft Data Centres.  Rather than an Operating System that can be installed on an individual PC, Windows Azure is a service that runs in the cloud.  While ii is not strictly an Operating System (OS), users can install applications that run on Windows Azure, so in many respects it looks like an OS.

Figure 2: Windows Azure runs in Microsoft Data Centres
Azure_Dev_9

There are three main components to Windows Azure.

  • Compute – The Compute service runs Windows Azure applications
  • Storage – The Storage service stores data in Blobs, Tables and Queues
  • Fabric – The Fabric service provides a common way to manage and monitor applications
Figure 3: The three main components of Windows Azure
Azure_Dev_10

This has been a very brief overview of what Windows Azure is.  In the next, article I will look more deeply at the Compute Service and how windows Azure scales out.


Posted in: Azure  Tags: , ,

In a previous article in this series of blog posts, I introduced Moq (Mock-you) – the mocking framework we are using in DotNetNuke to generate Mock objects for testing.

In this article I will start to dive deeper into this framework by looking at the unusually named “It” class.

What is “It”?

“It” is a static helper class that provides 4 static methods that allows testers to match a method invocation with an arbitrary value, with a value in a specified range, or even one that matches a given predicate.

The four methods it provides are:

  1. Is<TValue>(Expression<Predicate<TValue>>)
  2. IsAny<TValue>
  3. IsInRange<TValue>(TValue from, TValue to, Range rangeKind)
  4. IsRegex(string regex) (+ overloads)

The name of the class, while it appears strange, allows us to write readable tests.

For example, continuing our use of the VocabularyController class, lets look at a test for the AddVocabulary method.  Listing 1 shows the AddVocabulary method.

Listing 1: The AddVocabulary method of VocabularyController
   1:  Public Function AddVocabulary(ByVal vocabulary As Vocabulary) As Integer _
   2:                          Implements IVocabularyController.AddVocabulary
   3:      'Argument Contract
   4:      Requires.NotNull("vocabulary", vocabulary)
   5:      Requires.PropertyNotNullOrEmpty("vocabulary", "Name", vocabulary.Name)
   6:      Requires.PropertyNotNegative("vocabulary", "ScopeTypeId", vocabulary.ScopeTypeId)
   7:   
   8:      vocabulary.VocabularyId = _DataService.AddVocabulary(vocabulary, _
   9:                                      UserController.GetCurrentUserInfo.UserID)
  10:   
  11:      'Refresh Cache
  12:      DataCache.RemoveCache(_CacheKey)
  13:   
  14:      Return vocabulary.VocabularyId
  15:  End Function

As in the previous article, one of the tests we need to write is a test that confirms that the VocabularyId property of the vocabulary is set to the value returned from the call to the DataService (line 8).

Listing 2: Testing that the VocabularyController’s AddVocabulary method sets the VocabularyId correctly.
   1:  [Test]
   2:  public void VocabularyController_AddVocabulary_Sets_ValidId_On_Valid_Vocabulary()
   3:  {
   4:      //Arrange
   5:      Mock<IDataService> mockDataService = new Mock<IDataService>();
   6:      mockDataService.Setup(ds => ds.AddVocabulary(It.IsAny<Vocabulary>(), It.IsAny<int>()))
   7:                    .Returns(Constants.VOCABULARY_AddVocabularyId);
   8:   
   9:      VocabularyController vocabularyController = new VocabularyController(mockDataService.Object);
  10:   
  11:      Vocabulary vocabulary = ContentTestHelper.CreateValidVocabulary();
  12:   
  13:      //Act
  14:      vocabularyController.AddVocabulary(vocabulary);
  15:   
  16:      //Assert
  17:      Assert.AreEqual<int>(Constants.VOCABULARY_AddVocabularyId, vocabulary.VocabularyId);
  18:  }

In this example we make use of the “It” class in the Setup method of the Mock.  This code is pretty self-explanatory.  In the set up, as long as the mock DataService’s AddVocabulary method is given any Vocabulary instance (It.IsAny<Vocabulary>()) and any integer (It.IsAny<int>()) it should return a known VocabularyId (Constants.VOCABULARY.AddVocabularyId).

The beauty of this class is it is clear what the methods are being used for.

It.IsAny<IFoo>() – means accept any instance of IFoo

It.Is<int>(i => i%2 == 0) – means accept any even number (or any integer which is divisible by 2)

For example:

// given any value return true
mock.Setup(foo => foo.Execute(It.IsAny<string>())).Returns(true);


// given any even number return true
mock.Setup(foo => foo.Add(It.Is<int>(i => i % 2 == 0))).Returns(true); 


// If the value is between 1 and 10 return true
mock.Setup(foo => foo.Add(It.IsInRange<int>(0, 10, Range.Inclusive))).Returns(true); 


// If the string matches the Regex [a-d]+, return "foo"
mock.Setup(x => x.Execute(It.IsRegex("[a-d]+", RegexOptions.IgnoreCase))).Returns("foo");
 

We can also use it in the Assert phase to verify that a method was called with a particular value..

// assert Execute was called - with any string
mock.Verify(foo => foo.Execute(It.IsAny<string>()));


// assert Add was called with an even number
mock.Verify(foo => foo.Add(It.Is<int>(i => i % 2 == 0))); 


// assert Add was called with a value between 1 and 10 return
mock.Verify(foo => foo.Add(It.IsInRange<int>(0, 10, Range.Inclusive))); 

The “It” class provides readable matching conditions and is an important part of the Moq framework.  In the next part of this series I will continue to dive deeper into this awesome mocking framework.


Posted in: Testing  Tags: , , ,

 Search Blog

 Calendar

«  February 2012  »
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011
View posts in large calendar

 Tags

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012 Thoughts from the Wet Coast