protected override ServerWrapper StartNewServer() { var ctx = CreateContext(); Router = new RouterServer <TestRouterModel, TestShardModel, TestUserModel>(); Router.InitializeServer(ctx, new DirectServerProvider(), 0, new DirectServerProvider(), 1); Router.StartShardServer(); Router.StartUserServer(); lock (routerMap) { routerMap.Add(Router.ShardContext.ApplicationName + "SHARD", Router); routerMap.Add(Router.UserContext.ApplicationName + "USER", Router); } return(null); }
public void Initialize() { Router = new RouterServer <TestRouterModel, TestShardModel, TestUserModel>(); Shards = new List <ShardClient <TestRouterModel, TestShardModel, TestUserModel> >(); Users = new List <UserClient <TestRouterModel, TestShardModel, TestUserModel> >(); for (int i = 0; i < ShardCount; i++) { Shards.Add(new ShardClient <TestRouterModel, TestShardModel, TestUserModel>()); } for (int i = 0; i < UserCount; i++) { Users.Add(new UserClient <TestRouterModel, TestShardModel, TestUserModel>()); } string name = Guid.NewGuid().ToString(); Router.InitializeServer(GetContext(name, 0), new DirectServerProvider(), 0, new DirectServerProvider(), 1); foreach (var shard in Shards) { shard.InitializeClient(GetContext(name, 0), new DirectClientProvider()); } foreach (var user in Users) { user.InitializeClient(GetContext(name, 1), new DirectClientProvider()); } Router.StartShardServer(); Router.StartUserServer(); foreach (var shard in Shards) { shard.StartClient(); } foreach (var user in Users) { user.StartClient(); } }
public void Initialize() { INetContext ctx = new NetContext(); ctx.IPAddress = Guid.NewGuid().ToString(); ctx.Port = 0; var router = new RouterServer <TestRouterModel, TestShardModel, TestUserModel>(); router.InitializeServer(ctx, new DirectServerProvider(), 0, new DirectServerProvider(), 1); router.CreatePassthrough <TestPacket>(); router.StartShardServer(); router.StartUserServer(); this.Router = new RouterContainer() { Router = router, }; Shards = new List <ShardContainer>(); Users = new List <UserContainer>(); ShardsReceived = new List <ShardContainer>(); UsersReceived = new List <UserContainer>(); for (int i = 0; i < 5; i++) { var shard = new ShardClient <TestRouterModel, TestShardModel, TestUserModel>(); var user = new UserClient <TestRouterModel, TestShardModel, TestUserModel>(); var shctx = ctx.Clone(); var usctx = ctx.Clone(); shctx.Port = 0; usctx.Port = 1; shard.InitializeClient(shctx, new DirectClientProvider()); user.InitializeClient(usctx, new DirectClientProvider()); var shch = shard.CreateUserChannel <TestPacket>(); var usch = user.CreateShardChannel <TestPacket>(); var shcont = new ShardContainer() { Shard = shard, Passthrough = shch, }; var uscont = new UserContainer() { User = user, Passthrough = usch, }; shch.Receive += (e) => ShardsReceived.Add(shcont); usch.Receive += (e) => UsersReceived.Add(uscont); shard.StartClient(); user.StartClient(); Shards.Add(shcont); Users.Add(uscont); } var tick = Environment.TickCount; bool run = true; while (run) { int ct = 0; Router.Router.UpdateServer(); foreach (var sh in Shards) { sh.Shard.UpdateClient(); if (sh.Shard.Model != null) { ct++; } } foreach (var us in Users) { us.User.UpdateClient(); if (us.User.Model != null) { ct++; } } if (ct == Users.Count + Shards.Count) { run = false; } Assert.IsFalse(Environment.TickCount - tick > 200); } }