Test Environment on Windows

After you have successfully created the development environment described by the .NET Development Environment page, it’s high time to create a test environment where you can do integration test and – what is more important – local end-to-end solution development tasks.

You can create the following types of environment:

  • Local Azure Development Storage based environment
  • Microsoft SQL Express 2012+ based environment
  • PostgreSql (9.4+) based environment
  • PostgreSQL (9.4+) based environment with Cassandra (2.1+) Telemetry storage

When you create a test environment you should choose one of those environments above. Of course you can switch between these environments easily after the basic infrastructure components are up and running.

Please note that the default folder for the test environment is c:\Thriot .

This tutorial supposes the release v0.6 of source code.

Common steps to follow for every environments:

  • Get the source code from GitHub: https://github.com/kpocza/thriot
  • Ensure that you can run Windows Powershell scripts locally by entering the following command in Windows Powershell:
    Set-ExecutionPolicy RemoteSigned. You must run this command as a local Administrator.
  • Ensure that you have Visual Studio 2015 (or .NET development tool). You will need dnvm and dnx (v. 1.0.0-beta6)

To build the Local Azure test environment run the following steps (skip this step for non-Azure development):

  • Install Azure SDK along with the bundled storage emulator
  • Install Microsoft SQL 2012 Express (at least) with windows auth enabled
  • Run the following command from Windows Powershell in the Service\Build\ folder:  .\build.ps1 -config azure -configtmt azure -configmsg sql -copyConfigs yes -linuxify no -queueconfig no . This command build the following: azure main storage, sql-based messaging, the build package will include config files, do not target Linux.
  • Ensure that you see no red messages during build. If you see red it means that you don’t have the necessary development tools to build .NET applications on your system.
  • The output will go to the output\{CURRENTDATE}_azure folder under the Build folder

To build the SQL (Express) test environment run the following steps (skip this step for non-SQL development):

  • Install Microsoft SQL 2012 Express (at least) with windows auth enabled
  • Run the following command from Windows Powershell in the Service\Build\ folder: .\build.ps1 -config sql -configtmt sql -configmsg sql -copyConfigs yes -linuxify no -queueconfig no . This command builds the following: sql main storage, sql-based messaging, the build package will include config files, do not target Linux.
  • Ensure that you see no red messages during build. If you see red it means that you don’t have the necessary development tools to build .NET applications on your system.
  • The output will go to the output\{CURRENTDATE}_sql folder under the Build folder

To build the PostgreSql test environment run the following steps (skip this step for non-PostgreSQL development):

  • Install PostgreSql 9.4
  • Run the following command from Windows Powershell in the Service\Build\ folder: .\build.ps1 -config pgsql -configtmt pgsql -configmsg pgsql -copyConfigs yes -linuxify no -queueconfig no . This command builds the following: PostgreSql main storage, Postgresql-based messaging, the build package will include config files, do not target Linux.
  • Ensure that you see no red messages during build. If you see red it means that you don’t have the necessary development tools to build .NET applications on your system.
  • The output will go to the output\{CURRENTDATE}_pgsql folder under the Build folder

To build the PostgreSql + Cassandra test environment run the following steps (skip this step for non-PostgreSQL+Cassandra development):

  • Install PostgreSql 9.4
  • Install Cassandra 2.1 (machine host name (alias) ubuntucas1)
  • Run the following command from Windows Powershell in the Service\Build\ folder: .\build.ps1 -config pgsql -configtmt cassandra -configmsg pgsql -copyConfigs yes -linuxify no -queueconfig no . This command builds the following: PostgreSql main storage, Postgresql-based messaging, and Cassandra telemetry, the build package will include config files, do not target Linux.
  • Ensure that you see no red messages during build. If you see red it means that you don’t have the necessary development tools to build .NET applications on your system.
  • The output will go to the output\{CURRENTDATE}_pgsql folder under the Build folder

Build result

Any time you can rerun the build using the latest source code to get the latest functionality.

After the successful build you should copy the content of the build output for example to the c:\Thiot folder. See the following folder structure for reference:

image1

Setup local IIS (common steps for all environments)

At least the following IIS subfeatures should be installed to run Thriot:

image2

Adding HttpPlatformHandler

Install Http Platform Handler as follows: http://www.iis.net/downloads/microsoft/httpplatformhandler

It may be already installed on some environments, eg. Visual Studio 2015 dev machines.

Config tweaks for ASP.NET5 RC1

The configuration files folder is located at the following places respectively:
  1. c:\Thriot\api\approot\packages\Thriot.Management.WebApi\1.0.0\root\config\
  2. c:\Thriot\pap\approot\packages\Thriot.Platform.WebApi\1.0.0\root\config\
  3. c:\Thriot\rapi\approot\packages\Thriot.Reporting.WebApi\1.0.0\root\config\
  4. c:\Thriot\msvc\approot\packages\Thriot.Messaging.WebApi\1.0.0\root\config\

If you are running an asp.net5 rc1 app under a virtual directory in IIS you need to do some workaround to support virtual directories. Thriot implements this by vdir.json config files.

vdir.json shoud look like this:

{“VDIR”: “/api”}
{“VDIR”: “/papi”}
{“VDIR”: “/rapi”}
{“VDIR”: “/msvc”}

respectively for management, platform, reporting and messaging services (they are reachable under api,thriot.io/management, etc). The vdir.json has to be put under the regular config directory as the other configurations.

Creating websites (common steps for all environments)

Create the root website that will host the Central website:

siteaspnet5

Create api Application for the Management API (right click the Thriot website / add application) – c:\Thriot\api\wwwroot:

api

 

Create papi Application for the Platform API- c:\Thriot\papi\wwwroot:

papi

 

Create rapi Application for the Reporting API- c:\Thriot\rapi\wwwroot:

rapi

 

Create the msvc Application for the Messaging Services API- c:\Thriot\msvc\wwwroot:

msvc

 

The final structure should look like this if you look at the website in IIS Manager:

siteaspnet5_2

Create log folder with appropriate permissions:

  • Create c:\Thriot\log folder
  • Add write permission to the Application Pool identity (iis apppool\thriot) to the c:\Thriot\log folder in the following way:

image9

  • Press Ok here and check the Allow checkbox at Modify rights:

image10

Press Ok here (twice), too.

 

Create Messaging Database in SQL Express (common steps for Azure and SQL Express):

  • Install Microsoft SQL Express 2012+ with Management Studio
  • Login to the local (.\SQLEXPRESS) instance with Management Studio
  • Create the ThriotMessaging Database by right clicking on the Databases node on the left-side tree

msgdbcreate

  • Under Security/Login create user account for the IIS application pool to have dbowner permissions on the ThriotMessaging database by clicking the New Login menu item:
  • Set the user name to IIS Apppool\Thriot:

image12

  • Set the dbowner role on the ThriotMessaging DB:

image13

  • Click OK
  • After selecting the ThriotMessaging database hit New Query:

msgdbhit

  • Copy the content of the Service\Messaging\Scripts\Sql\CreateDB.sql to the SQL Management Studio and hit the Execute button. You should see the following result:

image15

Finalizing local Azure Test environment (skip this step for non-Azure development):

  • Ensure that you previously completed the Azure-related section
  • Run Service\Misc\Thriot.CreateAzureStorage\bin\Debug\Thriot.CreateAzureStorage.exe to create the necessary tables in the Azure Table Storage emulator
  • Since the website is hosted by IIS on the default port you should change the configuration settings in the Settings table of Azure Development Storage with Visual Studio/Service Explorer/Azure function (remove the 12345 port numbers)

image16

  • Restart IIS in order to successfully load the new settings (ensure the IIS apps know the up-to-date settings)
  • Start the Websocket service from command line by executing the following command: c:\Thriot\websocketservice\Thriot.Platform.WebsocketService.exe . You should see the Started message.
  • Open the Client\DotNet\Thriot.Client.DotNet.sln solution
  • Do a full build
  • Select TestRunSettings\IISDevAzure.runsettings in Test/Test Settings/Select Test Settings file menu option
  • Run all integration tests. Correct all environmental issues until all tests turn green

integtestsucc

  • Now you can access the website at http://localhost. Play with it, register devices, try to use it with the client libraries of your favorite platform.

Finalizing SQL Expres based Test environment (skip this for non-SQL development):

  • Ensure that you previously completed the SQL-related section
  • Create a database named Thriot in the local .\SQLEXPRESS instance
  • Run Service\Misc\Thriot.CreateSqlStorage\bin\Debug\Thriot.CreateSqlStorage.exe to create the necessary tables in the Thriot databse (change the connection string settings if you chose and other database or SQL instance)
  • Create a database named ThriotTelemetry in the local .\SQLEXPRESS instance
  • Add dbowner permissions to the iis apppool\thriot user to both databases above (ThriotMessaging should already have this permission)
  • Since we are running under IIS the following changes should be applied to the settings:

image17

  • Restart IIS in order to successfully load the new settings (ensure the IIS apps know the up-to-date settings)
  • Start the Websocket service from command line by executing the following command: c:\Thriot\websocketservice\Thriot.Platform.WebsocketService.exe . You should see the Started message.
  • Open the Client\DotNet\Thriot.Client.DotNet.sln solution
  • Do a full build
  • Select TestRunSettings\IISDevSql.runsettings in Test/Test Settings/Select Test Settings file menu option
  • Run all integration tests. Correct all environmental issues until all tests turn green

integtestsucc

  • Now you can access the website at http://localhost. Play with it, register devices, try to use it with the client libraries of your favorite platform.

Finalizing PostgreSql based Test environment (skip this step for non-PostgreSql environment)

  • Create the following users (aka login roles) thriot, thriotmessaging, thriottelemetry with the same passwords as the usernames. Use Pgadmin III.
  • Create the following databases Thriot, ThriotMessaging, ThriotTelemetry, set the previously created users as owners for these Dbs, respectively
  • Do a full rebuild in PgSql configuration
  • Execute Service\Misc\Thriot.CreateSqlStorage\bin\PgSql\Thriot.CreateSqlStorage.exe
  • Login as thriotmessagin user to PostgreSql and run the Service\Messaging\Scripts\PgSql\CreateDB.sql script against the ThriotMessaging database
  • Since we are running under IIS and PostgreSql the following changes should be applied to the settings:

pgsql

  • Restart IIS in order to successfully load the new settings (ensure the IIS apps know the up-to-date settings)
  • Start the Websocket service from command line by executing the following command: c:\Thriot\websocketservice\Thriot.Platform.WebsocketService.exe . You should see the Started message.
  • Open the Client\DotNet\Thriot.Client.DotNet.sln solution
  • Do a full build
  • Select TestRunSettings\IISDevPgSql.runsettings in Test/Test Settings/Select Test Settings file menu option
  • Run all integration tests. Correct all environmental issues until all tests turn green

pgsql

Finalizing PostgreSql + Cassandra based Test environment

  • Create the following users (aka login roles) thriot, thriotmessaging with the same passwords as the usernames. Use Pgadmin III.
  • Create the following databases Thriot, ThriotMessaging, set the previously created users as owners for these Dbs, respectively
  • Do a full rebuild in PgSql configuration
  • Execute Service\Misc\Thriot.CreateSqlStorage\bin\PgSql\Thriot.CreateSqlStorage.exe
  • Login as thriotmessagin user to PostgreSql and run the Service\Messaging\Scripts\PgSql\CreateDB.sql script against the ThriotMessaging database
  • Since we are running under IIS and PostgreSql the following changes should be applied to the settings:

pgsql

  • Basic installarion procedure for a single node Cassandra 2.1 cluster (https://www.digitalocean.com/community/tutorials/how-to-install-cassandra-and-run-a-single-node-cluster-on-a-ubuntu-vps). Replace with Java 1.8 and Cassandra 2.1. Of course you’d better install 3 or 5 nodes interconnected to each other.
  • Restart IIS in order to successfully load the new settings (ensure the IIS apps know the up-to-date settings)
  • Start the Websocket service from command line by executing the following command: c:\Thriot\websocketservice\Thriot.Platform.WebsocketService.exe . You should see the Started message.
  • Open the Client\DotNet\Thriot.Client.DotNet.sln solution
  • Do a full build
  • Select TestRunSettings\IISDevPgSqlCassandra.runsettings in Test/Test Settings/Select Test Settings file menu option
  • Run all integration tests. Correct all environmental issues until all tests turn green

pgsql

 

Upgrading

To upgrade to a newer/newest version do the following steps:

  1. Get the latest source snapshot
  2. Do a full rebuild with the appropriate configuration
  3. Update the binaries
  4. Execute the Management storage creator applications (CreateAzureStorage or CreateSqlStorage) which won’t delete any data just upgrade the DB schema
  5. For the Messaging storage execute the appropriate CreateDB.sql script for Sql or PgSql targets
  6. Execute all unit/integration tests
Advertisements