public void Can_Be_Initialized_And_Terminated_Multiple_Times() { var grpcConfig = new GrpcConfig( host: "127.0.0.1", port: 40405, serverShutdownDeadlineMs: 2000, serverMaxNumberOfRpcs: 100, clientRpcTimeoutMs: 10000 ); var sdCfg = new SDConfig( endpoints: "http://127.0.0.1:2379", etcdPrefix: "pitaya/", heartbeatTTLSec: 10, logHeartbeat: false, logServerSync: false, logServerDetails: false, syncServersIntervalSec: 10, maxNumberOfRetries: 0 ); var server = new Server( id: "myserverid", type: "myservertype", metadata: "", hostname: "", frontend: false ); for (var i = 0; i < 2; ++i) { PitayaCluster.Initialize(grpcConfig, sdCfg, server, NativeLogLevel.Debug); PitayaCluster.Terminate(); } }
public void Can_Fail_Initialization_Multiple_Times() { var natsConfig = new NatsConfig( endpoint: "http://127.0.0.1:4222", connectionTimeoutMs: 1000, requestTimeoutMs: 5000, serverShutdownDeadlineMs: 10 * 1000, serverMaxNumberOfRpcs: int.MaxValue, maxConnectionRetries: 3, maxPendingMessages: 100, reconnectBufSize: 4 * 1024 * 1024); var sdCfg = new SDConfig( endpoints: "127.0.0.1:123123123", etcdPrefix: "pitaya/", serverTypeFilters: new List <string>(), heartbeatTTLSec: 10, logHeartbeat: false, logServerSync: false, logServerDetails: false, syncServersIntervalSec: 10, maxNumberOfRetries: 0, retryDelayMilliseconds: 0 ); var server = new Server( id: "id", type: "type", metadata: "", hostname: "", frontend: false ); for (var i = 0; i < 10; ++i) { Assert.Throws <PitayaException>(() => { PitayaCluster.Initialize(natsConfig, sdCfg, server, NativeLogLevel.Debug); }); } PitayaCluster.Terminate(); }
public void Can_Fail_Initialization_Multiple_Times() { var grpcConfig = new GrpcConfig( host: "127.0.0.1", port: 40405, serverShutdownDeadlineMs: 2000, serverMaxNumberOfRpcs: 100, clientRpcTimeoutMs: 10000 ); var sdCfg = new SDConfig( endpoints: "127.0.0.1:123123123", etcdPrefix: "pitaya/", serverTypeFilters: new List <string>(), heartbeatTTLSec: 10, logHeartbeat: false, logServerSync: false, logServerDetails: false, syncServersIntervalSec: 10, maxNumberOfRetries: 0, retryDelayMilliseconds: 0 ); var server = new Server( id: "id", type: "type", metadata: "", hostname: "", frontend: false ); for (var i = 0; i < 10; ++i) { Assert.Throws <PitayaException>(() => { PitayaCluster.Initialize(grpcConfig, sdCfg, server, NativeLogLevel.Debug); }); } PitayaCluster.Terminate(); }
public void Can_Be_Initialized_And_Terminated_Multiple_Times() { var natsConfig = new NatsConfig( endpoint: "http://127.0.0.1:4222", connectionTimeoutMs: 1000, requestTimeoutMs: 5000, serverShutdownDeadlineMs: 10 * 1000, serverMaxNumberOfRpcs: int.MaxValue, maxConnectionRetries: 3, maxPendingMessages: 100); var sdCfg = new SDConfig( endpoints: "http://127.0.0.1:2379", etcdPrefix: "pitaya/", serverTypeFilters: new List <string>(), heartbeatTTLSec: 10, logHeartbeat: false, logServerSync: false, logServerDetails: false, syncServersIntervalSec: 10, maxNumberOfRetries: 0 ); var server = new Server( id: "myserverid", type: "myservertype", metadata: "", hostname: "", frontend: false ); for (var i = 0; i < 2; ++i) { PitayaCluster.Initialize(natsConfig, sdCfg, server, NativeLogLevel.Debug); PitayaCluster.Terminate(); } }
static void Main(string[] args) { Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); string serverId = System.Guid.NewGuid().ToString(); var sdConfig = new SDConfig( endpoints: "http://127.0.0.1:2379", etcdPrefix: "pitaya/", serverTypeFilters: new List <string>(), heartbeatTTLSec: 60, logHeartbeat: true, logServerSync: true, logServerDetails: true, syncServersIntervalSec: 30, maxNumberOfRetries: 0, retryDelayMilliseconds: 0); var sv = new Server( id: serverId, type: "csharp", metadata: "", hostname: "localhost", frontend: false); var natsConfig = new NatsConfig( endpoint: "127.0.0.1:4222", connectionTimeoutMs: 2000, requestTimeoutMs: 1000, serverShutdownDeadlineMs: 3, serverMaxNumberOfRpcs: 100, maxConnectionRetries: 3, maxPendingMessages: 1000, reconnectBufSize: 4 * 1024 * 1024); var grpcConfig = new GrpcConfig( host: "127.0.0.1", port: 5444, serverShutdownDeadlineMs: 2000, serverMaxNumberOfRpcs: 200, clientRpcTimeoutMs: 10000 ); Dictionary <string, string> constantTags = new Dictionary <string, string> { { "game", "game" }, { "serverType", "svType" } }; var statsdMR = new StatsdMetricsReporter("localhost", 5000, "game", constantTags); MetricsReporters.AddMetricReporter(statsdMR); var prometheusMR = new PrometheusMetricsReporter("default", "game", 9090); MetricsReporters.AddMetricReporter(prometheusMR); PitayaCluster.AddSignalHandler(() => { Logger.Info("Calling terminate on cluster"); PitayaCluster.Terminate(); Logger.Info("Cluster terminated, exiting app"); Environment.Exit(1); //Environment.FailFast("oops"); }); try { PitayaCluster.Initialize( grpcConfig, sdConfig, sv, NativeLogLevel.Debug, new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Console.WriteLine("Server was added"); Console.WriteLine(" id: " + server.id); Console.WriteLine(" type: " + server.type); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Console.WriteLine("Server was removed"); Console.WriteLine(" id: " + server.id); Console.WriteLine(" type: " + server.type); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } })); //PitayaCluster.Initialize(natsConfig, sdConfig, sv, NativeLogLevel.Debug, ""); } catch (PitayaException exc) { Logger.Error("Failed to create cluster: {0}", exc.Message); Environment.Exit(1); } Logger.Info("pitaya lib initialized successfully :)"); var tr = new TestRemote(); PitayaCluster.RegisterRemote(tr); var th = new TestHandler(); PitayaCluster.RegisterHandler(th); Thread.Sleep(1000); TrySendRpc(); Console.ReadKey(); PitayaCluster.Terminate(); }
void OnApplicationQuit() { Debug.Log("Destroying pitaya cluster"); PitayaCluster.Terminate(); }
private static void Main(string[] args) { Logger.SetLevel(LogLevel.INFO); var serverId = System.Guid.NewGuid().ToString(); var sdConfig = new SDConfig( endpoints: "http://127.0.0.1:2379", etcdPrefix: "pitaya/", heartbeatTTLSec: 60, logHeartbeat: true, logServerSync: true, logServerDetails: true, syncServersIntervalSec: 30, maxNumberOfRetries: 0); var sv = new Server( id: serverId, type: "csharp", metadata: "", hostname: "localhost", frontend: false); var grpcConfig = new GrpcConfig( host: "127.0.0.1", port: 5444, serverShutdownDeadlineMs: 3000, serverMaxNumberOfRpcs: 500, clientRpcTimeoutMs: 10000 ); PitayaCluster.AddSignalHandler(() => { Logger.Info("Calling terminate on cluster"); PitayaCluster.Terminate(); Logger.Info("Cluster terminated, exiting app"); Environment.Exit(1); }); PitayaCluster.RegisterHandler(new UserHandler()); PitayaCluster.SetSerializer(new JSONSerializer()); // Using json serializer for easier interop with pitaya-cli try { PitayaCluster.Initialize( grpcConfig, sdConfig, sv, NativeLogLevel.Debug, new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Console.WriteLine($"Server added: {server}"); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Console.WriteLine($"Server removed: {server}"); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } }) ); } catch (PitayaException exc) { Logger.Error("Failed to create cluster: {0}", exc.Message); Environment.Exit(1); } while (true) { Thread.Sleep(10); } //// }
static void Main(string[] args) { Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); var constantTags = new Dictionary<string, string> { {"game", "game"}, {"serverType", "svType"} }; AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs args) => { Console.WriteLine("shutting down pitaya cluster"); PitayaCluster.Terminate(); }; var customMetrics = new CustomMetrics(); customMetrics.AddHistogram( "my_histogram", new HistogramBuckets(HistogramBucketKind.Linear, 1, 2, 10), "Some test histogram", new []{"my_label"}); var metricsParameters = new MetricsConfiguration( true, "127.0.0.1", "8000", "myns", customMetrics); try { PitayaCluster.Initialize( "exampleapp", "csharp.toml", new Server( id: Guid.NewGuid().ToString(), kind: "csharp", metadata: "{}", hostname: "ololo", frontend: false ), NativeLogLevel.Debug, NativeLogKind.Console, (msg) => { Console.Write($"C# Log: {msg}"); }, metricsParameters, new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Console.WriteLine("Server was added"); Console.WriteLine(" id: " + server.Id); Console.WriteLine(" kind: " + server.Kind); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Console.WriteLine("Server was removed"); Console.WriteLine(" id: " + server.Id); Console.WriteLine(" kind: " + server.Kind); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } })); } catch (PitayaException exc) { Logger.Error("Failed to create cluster: {0}", exc.Message); Environment.Exit(1); } Logger.Info("pitaya lib initialized successfully :)"); PitayaCluster.RegisterRemote(new TestRemote()); PitayaCluster.RegisterHandler(new TestHandler()); TrySendRpc(); PitayaCluster.WaitShutdownSignal(); }