Orleans Initial Contact (2) test cases and orleans Use Cases
Return to navigation]
After a brief understanding of Orleans, we can use several examples to deepen our impression.
I. Quick Start example
This example is also followed by Microsoft Orleans Getting Started Guide (https://www.cnblogs.com/endv/p/6147976.html) This article made
The example in the previous note illustrates the development steps, the class libraries to be referenced, and how the client calls them. The following example shows how to create a unit test,
1. Create
This time, we use Orleans Tools for Visual Studio to create Orleans projects.
First, use the template to create
Sample. Interfaces1
Sample. Implements1
Server1
For more information about the three projects, see the second example in the previous document.
Next we will create a unit test library Sample. Test1
Reference project Sample. Implements1, Sample. Interfaces1
REFERENCE The NuGet package Microsoft. Orleans. TestingHost
The project structure is as follows:
We create a test class named UserServiceTest, inherited from Orleans Test Library TestingSiloHost
The test code is as follows:
namespace Sample.Test
{
[TestClass]
public class UserServiceTest: TestingSiloHost
{
[ClassCleanup]
public static void ClassCleanup()
{
// Optional.
// By default, the next test class which uses TestignSiloHost will
// cause a fresh Orleans silo environment to be created.
StopAllSilosIfRunning();
}
[TestMethod]
public async void TestExist()
{
var grain = GrainFactory.GetGrain<IUserService>(10);
bool bo = await grain.Exist("18612478956");
Assert.IsTrue(bo);
}
}
}
Remember to add two configuration files,
ClientConfigurationForTesting. xml
<?xml version="1.0" encoding="utf-8" ?>
<ClientConfiguration xmlns="urn:orleans">
<Gateway Address="localhost" Port="40000"/>
<!-- To turn tracing off, set DefaultTraceLevel="Off" and have no overrides.
For the trace log file name, {0} is replaced by "Client" and {1} is the current time. -->
<Tracing DefaultTraceLevel="Info" TraceToConsole="false" TraceToFile="{0}-{1}.log" BulkMessageLimit="1000">
<TraceLevelOverride LogPrefix="Runtime" TraceLevel="Info" />
<TraceLevelOverride LogPrefix="Application" TraceLevel="Info" />
<TraceLevelOverride LogPrefix="AssemblyLoader" TraceLevel="Warning" />
</Tracing>
<Statistics MetricsTableWriteInterval="300s" PerfCounterWriteInterval="30s" LogWriteInterval="300s" WriteLogStatisticsToTable="true" StatisticsCollectionLevel="Info"/>
<Messaging ResponseTimeout="30s" ClientSenderBuckets="8192" MaxResendCount="0"/>
</ClientConfiguration>
OrleansConfigurationForTesting. xml
<?xml version="1.0" encoding="utf-8"?>
<OrleansConfiguration xmlns="urn:orleans">
<Globals>
<StorageProviders>
<Provider Type="Orleans.Storage.MemoryStorage" Name="MemoryStore" />
<Provider Type="Orleans.Storage.MemoryStorage" Name="Default" />
<!--<Provider Type="Orleans.Storage.AzureTableStorage" Name="AzureStore"/>-->
</StorageProviders>
<SeedNode Address="localhost" Port="22222"/>
<Messaging ResponseTimeout="30s"/>
</Globals>
<Defaults>
<Networking Address="localhost" Port="22222"/>
<ProxyingGateway Address="localhost" Port="40000" />
<Tracing DefaultTraceLevel="Info" TraceToConsole="false" TraceToFile="{0}-{1}.log" PropagateActivityId="false" BulkMessageLimit="1000">
<TraceLevelOverride LogPrefix="Application" TraceLevel="Info" />
<!--
<TraceLevelOverride LogPrefix="Runtime.Dispatcher" TraceLevel="Verbose" />
<TraceLevelOverride LogPrefix="AssemblyLoader.Silo" TraceLevel="Warning" />
-->
</Tracing>
<Statistics MetricsTableWriteInterval="30s" PerfCounterWriteInterval="30s" LogWriteInterval="300s" WriteLogStatisticsToTable="true" StatisticsCollectionLevel="Info"/>
</Defaults>
</OrleansConfiguration>
Change the xml file property to: copy if it is newer
The test project structure is as follows:
As described in the document, the test project has been compiled and can be tested directly. However, when I debug test, an error occurs, as shown in:
No solution is found for this problem. Next we will start to learn about the official documents and tutorials provided in the official documents.