BizTalk Server などのコンピューター アプリケーション サーバーは、ユーザーに代わって特定のタスクを実行するように設計されています。 これらのタスクは、アプリケーション サーバーが認識するプロトコルを使用して、アプリケーション サーバーが認識する標準に準拠したメッセージとしてアプリケーション サーバーに送信されるクライアント要求として開始されます。 たとえば、クライアントは SMTP プロトコルを使用してインターネット電子メール メッセージを電子メール サーバーに送信することで、電子メールの処理を開始できます。 同様に、Web サーバーはクライアント HTML または ASP 要求を処理し、データベース サーバーはクライアント SQL 要求を処理し、BizTalk Server は、多数の業界標準プロトコルを使用して、複数の業界標準の標準に準拠して書式設定されたクライアント メッセージを処理できます。 通常、アプリケーション サーバーのワークロード容量は、アプリケーション サーバーが特定の期間内に処理できるメッセージの数によって測定されます。 BizTalk Server のワークロード容量は、同様に、"1 秒あたりに受信されたドキュメント"、"1 秒あたりに処理されたドキュメント"、"1 秒あたりに完了したオーケストレーション" の平均数 (忙しい稼働日や稼働日など) として長期間にわたって測定されます。 Visual Studio 2010 ロード テスト機能では、サーバー アプリケーションに同時にアクセスする最大数百人のユーザーのロード プロファイルをシミュレートできます。 このロード テスト機能は、選択した主要業績評価指標のリアルタイム メトリックと、将来の分析のためにこれらのメトリックをデータベースに格納する機能を提供します。 このドキュメントでは、単体テストの作成方法、ロード テストの作成方法、BizTalk Server アプリケーションの最大持続可能なスループット (MST) を決定するために必要なパフォーマンス カウンター データをキャプチャするようにロード テストを構成する方法など、BizTalk Server アプリケーションのロード テストを目的とした Visual Studio テスト プロジェクトの使用について説明します。
BizTalk Server にドキュメントを送信するための Visual Studio 単体テストの作成
Visual Studio 単体テストでは、単体テストのサポートを提供するいくつかのクラスを提供する Microsoft.VisualStudio.TestTools.UnitTesting (https://go.microsoft.com/fwlink/?LinkID=132293) 名前空間を参照します。 特に重要なのは、 UnitTesting (https://go.microsoft.com/fwlink/?LinkID=132293) 名前空間には、単体テストに提供される情報を格納する Microsoft.VisualStudio.TestTools.UnitTesting.TestContext (https://go.microsoft.com/fwlink/?LinkID=208233) クラスが含まれており、テスト メソッドを定義するために Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute (https://go.microsoft.com/fwlink/?LinkID=208235) クラスが使用されます。 BizTalk Server のロード テストのために、テスト メソッドでは、読み込むメッセージと、メッセージの送信先となるエンドポイント/URL を指定する必要があります。 エンドポイント/URL は、対応する BizTalk 受信場所が作成されるときに、BizTalk Server へのメッセージ エントリ ポイントとして機能します。
図の目的上、このトピックのサンプル コードでは、System.ServiceModel.ChannelFactory(TChannel) (https://go.microsoft.com/fwlink/?LinkID=208238) クラスを使用して、WCF net.tcp エンドポイントを使用し、BizTalk WCF-Custom 受信アダプターによって監視されるサービス エンドポイントにメッセージを送信するテスト メソッドについて説明します。 テスト メッセージのサービス エンドポイントは、テスト プロジェクトのアプリケーション構成 (app.config) ファイルで定義されます。
Visual Studio 単体テストの詳細については、「 単体テストの構造 (https://go.microsoft.com/fwlink/?LinkID=208232)」を参照してください。
以下のセクションの手順に従って、1 台以上の BizTalk Server コンピューターにドキュメントを送信する単体テストを含むテスト プロジェクトを作成します。 これらの手順は、Visual Studio 2010 Ultimate Edition を使用して完了しました。
Visual Studio 2010 テスト プロジェクト のオプションを設定する
Visual Studio 2010 Ultimate Edition を起動します。 [ スタート] をクリックし、[ すべてのプログラム] をポイントし、 Microsoft Visual Studio 2010 をポイントして、[ Microsoft Visual Studio 2010] をクリックします。
Visual Studio 2010 で、[ ツール ] をクリックし、[ オプション ] をクリックして [オプション] ダイアログ ボックスを表示します。
クリックして [テスト ツール ] を展開し、[ テスト プロジェクト ] をクリックして、新しいテスト プロジェクトを作成するためのオプションを表示します。
既定の テスト プロジェクト言語をVisual C# テスト プロジェクトに設定します。
新 しい各テスト プロジェクトに追加されるファイルを選択するオプションの下で、既定ではVisual C# テスト プロジェクトを選択し、 単体テストを除く Visual C# テスト プロジェクトのすべてのテストの種類をオフにします。
[OK] をクリックして、オプション ダイアログ ボックスを閉じます。
テスト プロジェクトを使用して新しい Visual Studio 2010 ソリューションを作成する
Visual Studio 2010 Ultimate コンピューターに C:\Projects フォルダーを作成します。
Visual Studio 2010 で、[ ファイル] をクリックし、[ 新規作成] をポイントし、[ プロジェクト ] をクリックして [ 新しいプロジェクト ] ダイアログ ボックスを表示します。
[ インストールされているテンプレート ] で、 Visual C# をクリックして展開し、[ テスト] をクリックします。
[ 新しいプロジェクト ] ダイアログ ボックスの下部で、次のオプションを指定します。
名前:BTSLoad
Location:C:\Projects\
ソリューション名:LoadTest
[ソリューションのディレクトリを作成する] オプションがオンになっていることを確認し、[OK] をクリックします。
BTSLoad プロジェクトにフォルダーを追加します。このフォルダーには、BizTalk Server に送信されるテスト メッセージが含まれます。 ソリューション エクスプローラーで、BTSLoad プロジェクトを右クリックし、[ 追加] をポイントして、[ 新しいフォルダー] をクリックします。 テキスト NewFolder1 が強調表示されたフォルダー アイコンが BTSLoad プロジェクトの下に表示され、「 TestMessages」 と入力して強調表示されたテキストを変更し、 Enter キーを押してフォルダー C:\Projects\LoadTest\BTSLoad\TestMessages を作成します。
テスト プロジェクトのコードを更新し、アプリケーション構成ファイルをテスト プロジェクトに追加する
ソリューション エクスプローラーでクリックして UnitTest1.cs を選択し、既存のコードを次のサンプル コードリストに置き換えます。
#region Using Directives using System; using System.IO; using System.Diagnostics; using System.Text; using System.Configuration; using System.Collections.Generic; using System.Linq; using System.Xml; using System.ServiceModel; using System.ServiceModel.Channels; using Microsoft.VisualStudio.TestTools.UnitTesting; #endregion namespace Microsoft.BizTalk.Samples { [TestClass] public class BTSLoadTest { #region Constants private const int MaxBufferSize = 2097152; private const string Source = "BTS Load Test"; private const string Star = "*"; private const string TestMessageFolderParameter = "testMessageFolder"; private const string TestMessageFolderDefault = @"C:\Projects\LoadTest\BTSLoad\TestMessages"; private const string TestMessageFolderFormat = @"Test Message Folder = {0}"; private const string TestXmlDocument = "testxmldocument.xml"; #endregion #region Private Instance Fields private TestContext testContextInstance; #endregion #region Private ThreadStatic Fields [ThreadStatic] private static ChannelFactory<IRequestChannel> channelFactory; [ThreadStatic] private static IRequestChannel channel = null; [ThreadStatic] private static byte[] buffer = null; #endregion #region Private Static Fields private static string testMessageFolder = null; #endregion #region Public Instance Constructor public BTSLoadTest() { } #endregion #region Public Static Constructor static BTSLoadTest() { try { testMessageFolder = ConfigurationManager.AppSettings[TestMessageFolderParameter]; if (string.IsNullOrEmpty(testMessageFolder)) { testMessageFolder = TestMessageFolderDefault; } } catch (Exception ex) { Trace.WriteLine(ex.Message); EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error); } } #endregion #region Public Properties /// <summary> ///Gets or sets the test context which provides ///information about and functionality for the current test run. ///</summary> public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #endregion #region Test Methods [TestMethod] public void BTSMessaging() { InvokeBizTalkReceiveLocation("BTSMessagingEP", testMessageFolder, TestXmlDocument, MessageVersion.Default, SessionMode.Allowed); } [TestMethod] public void BTSMessaging2() { InvokeBizTalkReceiveLocation("BTSMessagingEP2", testMessageFolder, TestXmlDocument, MessageVersion.Default, SessionMode.Allowed); } [TestMethod] public void BTSOrchestration() { InvokeBizTalkReceiveLocation("BTSOrchestrationEP", testMessageFolder, TestXmlDocument, MessageVersion.Default, SessionMode.Allowed); } #endregion #region Helper Methods public void InvokeBizTalkReceiveLocation(string endpointConfigurationName, string requestMessageFolder, string requestMessageName, MessageVersion messageVersion, SessionMode sessionMode) { XmlTextReader xmlTextReader = null; Message requestMessage = null; Message responseMessage = null; try { if (channel == null || channel.State != CommunicationState.Opened) { channelFactory = new ChannelFactory<IRequestChannel>(endpointConfigurationName); channelFactory.Endpoint.Contract.SessionMode = sessionMode; channel = channelFactory.CreateChannel(); } if (buffer == null) { string path = Path.Combine(requestMessageFolder, requestMessageName); string message; using (StreamReader reader = new StreamReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) { message = reader.ReadToEnd(); } buffer = Encoding.UTF8.GetBytes(message); } MemoryStream stream = new MemoryStream(buffer); xmlTextReader = new XmlTextReader(stream); requestMessage = Message.CreateMessage(messageVersion, Star, xmlTextReader); TestContext.BeginTimer(requestMessageName); responseMessage = channel.Request(requestMessage); } catch (FaultException ex) { HandleException(ex); throw; } catch (CommunicationException ex) { HandleException(ex); throw; } catch (TimeoutException ex) { HandleException(ex); throw; } catch (Exception ex) { HandleException(ex); throw; } finally { TestContext.EndTimer(requestMessageName); CloseObjects(xmlTextReader, requestMessage, responseMessage); } } private void HandleException(Exception ex) { try { Trace.WriteLine(ex.Message); EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error); } catch (Exception) { } } private void CloseObjects(XmlTextReader xmlTextReader, Message requestMessage, Message responseMessage) { try { if (xmlTextReader != null) { xmlTextReader.Close(); } if (requestMessage != null) { requestMessage.Close(); } if (responseMessage != null) { responseMessage.Close(); } } catch (Exception) { } } #endregion } }
アプリケーション構成ファイルをテスト プロジェクトに追加します。
ソリューション エクスプローラーで、BTSLoad プロジェクトを右クリックし、[ 追加] をポイントし、[ 新しい項目] をクリックします。
[ 新しい項目の追加 ] ダイアログ ボックスの [ インストールされているテンプレート] で、[ 全般] をクリックします。
表示される項目の一覧で、[ アプリケーション構成ファイル ] をクリックし、[ 追加] をクリックします。
ソリューション エクスプローラーで app.config ファイルを選択し、app.config ファイルの内容を次のサンプル コードリストに置き換えます。
Von Bedeutung
このファイルで定義されているクライアント エンドポイントごとに、 BizTalk Server コンピューター は、ロード テストを実行する BizTalk Server コンピューターの実際の名前のプレースホルダーです。
<configuration> <system.serviceModel> <!-- Bindings used by client endpoints --> <bindings> <netTcpBinding> <binding name="netTcpBinding" closeTimeout="01:10:00" openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="100" maxBufferPoolSize="1048576" maxBufferSize="10485760" maxConnections="400" maxReceivedMessageSize="10485760"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> <security mode="None"> <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> <message clientCredentialType="Windows" /> </security> </binding> </netTcpBinding> </bindings> <client> <!-- Client endpoints used to exchange messages with WCF Receive Locations --> <!-- BTSMessagingEP --> <endpoint address="net.tcp://BizTalk Server Computer:8123/btsloadtest" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="System.ServiceModel.Channels.IRequestChannel" name="BTSMessagingEP" /> <endpoint address="net.tcp://BizTalk Server Computer:8123/btsloadtest" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="System.ServiceModel.Channels.IRequestChannel" name="BTSMessagingEP" /> <!-- BTSOrchestrationEP --> <endpoint address="net.tcp://BizTalk Server Computer:8122/btsloadtest" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="System.ServiceModel.Channels.IRequestChannel" name="BTSOrchestrationEP" /> </client> </system.serviceModel> <appSettings> <!-- Folder containing test messages --> <add key="testMessageFolder" value="C:\Projects\LoadTest\BTSLoad\TestMessages" /> <add key="ClientSettingsProvider.ServiceUri" value="" /> </appSettings> </configuration>
Visual Studio 2010 の [ ファイル ] メニューをクリックし、[ すべて保存] をクリックします。
プロジェクトにテスト メッセージを追加する
この例では、BizTalk Server の受信場所と送信ポートはパススルー パイプラインを使用するように構成され、ドキュメントの検証は実行されません。 プロジェクトにテスト メッセージを追加するには、次の手順に従います。
メモ帳を起動します。 [スタート] をクリックし、[実行] をクリックし、[実行] ダイアログ ボックスに「メモ帳」と入力します。
次のテキストをメモ帳にコピーし、"C:\Projects\LoadTest\BTSLoad\TestMessages\TestXmlDocument.xml" として保存します
<BTSLoadTest xmlns="http://Microsoft.BizTalk.Samples.BTSLoadTest"> <MessageText> This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. This is sample message text. </MessageText> </BTSLoadTest>
メモ帳を閉じます。
Von Bedeutung
ロード テストに複数のロード テスト エージェント コンピューターが使用されている場合は、すべてのロード テスト エージェント コンピューターで同じファイル名を使用して、このファイルを同じパスに保存する必要があります。
プロジェクトに必要な参照を追加し、テスト プロジェクトをビルドする
ソリューション エクスプローラーで、BTSLoad プロジェクトの [参照 ] フォルダーを右クリックし、[ 参照の追加] をクリックします。
[参照の追加] ダイアログ ボックスで、[ .NET ] タブをクリックし、Ctrl + クリック キーボード/マウスの組み合わせを使用して、次の .NET 名前空間を同時に選択します。
System.Configuration
System.Runtime.Serialization
System.ServiceModel.Channels
System.ServiceModel
System.Web.Extensions
System.Xml
名前空間を選択した後、[ OK] をクリックして、これらのアセンブリを BTSLoad テスト プロジェクトへの参照として追加します。
BTSLoad プロジェクトを右クリックし、[ビルド] をクリックして、プロジェクトを BTSLoad アセンブリにコンパイルします。