Skip to content

Commit

Permalink
Remove locks and use bool for timeout (#51)
Browse files Browse the repository at this point in the history
* Fix #49 Add WriteStateAsync() to key methods

* Add WriteStateAsync in model update

* Modify Inspect API to show detailed data

* clean code in Timeout system

* Remove locks and use bool for timeout
  • Loading branch information
panyz522 authored May 25, 2019
1 parent 3aa786e commit a6742a0
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 225 deletions.
68 changes: 47 additions & 21 deletions SimCivil.IntegrationTest/Testcase/HeartbeatTest.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
using Microsoft.Extensions.Logging;
using Orleans;
using SimCivil.Contract;
using SimCivil.Contract.Model;
using SimCivil.Orleans.Interfaces;
using SimCivil.Rpc;
// Copyright (c) 2017 TPDT
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// SimCivil - SimCivil.IntegrationTest - HeartbeatTest.cs
// Create Date: 2019/05/08
// Update Date: 2019/05/19

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Diagnostics.Debug;

using Microsoft.Extensions.Logging;

using Orleans;

using SimCivil.Contract;
using SimCivil.Contract.Model;
using SimCivil.Orleans.Interfaces;
using SimCivil.Rpc;

namespace SimCivil.IntegrationTest.Testcase
{
class HeartbeatTest : IIntegrationTest
internal class HeartbeatTest : IIntegrationTest
{
private static int _id;
protected RpcClient Client { get; private set; }
public IClusterClient Cluster { get; }
public bool IsRunning { get; private set; }
public ILogger<HeartbeatTest> Logger { get; }
public string RoleName { get; set; }
private static int _id;
protected RpcClient Client { get; private set; }
public IClusterClient Cluster { get; }
public bool IsRunning { get; private set; }
public ILogger<HeartbeatTest> Logger { get; }
public string RoleName { get; set; }

public HeartbeatTest(ILogger<HeartbeatTest> logger, IClusterClient cluster)
{
RoleName = nameof(HeartbeatTest) + Interlocked.Increment(ref _id);
Logger = logger;
Cluster = cluster;
Logger = logger;
Cluster = cluster;
}

private void NewClient()
Expand All @@ -51,6 +76,7 @@ public Task Stop()
{
Client.Disconnect();
IsRunning = false;

return Task.CompletedTask;
}

Expand All @@ -63,7 +89,7 @@ public async Task Test()

// Create a client with heartbeat and wait
var rm = Client.Import<IRoleManager>();
await rm.CreateRole(new CreateRoleOption { Gender = Gender.Male, Name = RoleName, Race = Race.Human });
await rm.CreateRole(new CreateRoleOption {Gender = Gender.Male, Name = RoleName, Race = Race.Human});
await rm.UseRole((await rm.GetRoleList()).First().Id);

await Task.Delay(15000);
Expand All @@ -90,9 +116,9 @@ public async Task Test()
Logger.LogInformation($"{RoleName} test end");
}

protected async Task RegisterAndLogin(string _name = null, string password = "")
protected async Task RegisterAndLogin(string name = null, string password = "")
{
var name = _name ?? RoleName;
name = name ?? RoleName;
await Cluster.GetGrain<IAccount>(name).Register(password);
Logger.LogInformation($"Role \"{RoleName}\" Created");
await Login(name, password);
Expand All @@ -106,4 +132,4 @@ protected async Task Login(string name = null, string password = "")
Logger.LogInformation($"Role \"{RoleName}\" login");
}
}
}
}
Loading

0 comments on commit a6742a0

Please sign in to comment.