-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from tcz717/turnip-dev
Heartbeat on RpcClient and Timeout on RpcServer
- Loading branch information
Showing
22 changed files
with
608 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
root = true | ||
|
||
[*.cs] | ||
end_of_line = lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SimCivil.Contract | ||
{ | ||
public interface IConnectionControl | ||
{ | ||
void Noop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using SimCivil.Contract; | ||
|
||
namespace SimCivil.Gate | ||
{ | ||
class GatewayConnectionControl : IConnectionControl | ||
{ | ||
/// <summary> | ||
/// An empty request for keeping alive | ||
/// </summary> | ||
public void Noop() | ||
{ | ||
// An empty request for keeping alive | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Orleans; | ||
using SimCivil.Contract; | ||
using SimCivil.Contract.Model; | ||
using SimCivil.Orleans.Interfaces; | ||
using SimCivil.Rpc; | ||
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; | ||
|
||
namespace SimCivil.IntegrationTest.Testcase | ||
{ | ||
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; } | ||
|
||
public HeartbeatTest(ILogger<HeartbeatTest> logger, IClusterClient cluster) | ||
{ | ||
RoleName = nameof(HeartbeatTest) + Interlocked.Increment(ref _id); | ||
Logger = logger; | ||
Cluster = cluster; | ||
} | ||
|
||
private void NewClient() | ||
{ | ||
Client = new RpcClient( | ||
new IPEndPoint( | ||
Dns.GetHostAddresses(Dns.GetHostName()).First(ip => ip.AddressFamily == AddressFamily.InterNetwork), | ||
20170)); | ||
} | ||
|
||
public Guid GetEntityId() | ||
{ | ||
var rm = Client.Import<IRoleManager>(); | ||
|
||
return Task.Factory.StartNew(() => rm.GetRoleList().Result).Result.First().Id; | ||
} | ||
|
||
public Task Stop() | ||
{ | ||
Client.Disconnect(); | ||
IsRunning = false; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public async Task Test() | ||
{ | ||
IsRunning = true; | ||
NewClient(); | ||
await Client.ConnectAsync(); | ||
await RegisterAndLogin(); | ||
|
||
// 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.UseRole((await rm.GetRoleList()).First().Id); | ||
|
||
await Task.Delay(15000); | ||
Client.Disconnect(); | ||
Client.Dispose(); | ||
Logger.LogInformation($"{RoleName} client disconnected"); | ||
await Task.Delay(1000); | ||
|
||
// Create a client without heartbeat and wait | ||
NewClient(); | ||
Client.HeartbeatDelay = int.MaxValue; | ||
await Client.ConnectAsync(); | ||
await Login(); | ||
|
||
rm = Client.Import<IRoleManager>(); | ||
await rm.UseRole((await rm.GetRoleList()).First().Id); | ||
|
||
await Task.Delay(10000); | ||
Client.Disconnect(); | ||
Client.Dispose(); | ||
Logger.LogInformation($"{RoleName} client disconnected"); | ||
await Task.Delay(1000); | ||
|
||
Logger.LogInformation($"{RoleName} test end"); | ||
} | ||
|
||
protected async Task RegisterAndLogin(string _name = null, string password = "") | ||
{ | ||
var name = _name ?? RoleName; | ||
await Cluster.GetGrain<IAccount>(name).Register(password); | ||
Logger.LogInformation($"Role \"{RoleName}\" Created"); | ||
await Login(name, password); | ||
} | ||
|
||
protected async Task Login(string name = null, string password = "") | ||
{ | ||
var auth = Client.Import<IAuth>(); | ||
await auth.LogInAsync(name ?? RoleName, password); | ||
|
||
Logger.LogInformation($"Role \"{RoleName}\" login"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.