/// <summary> /// The method tests the cancellation of server. /// </summary> /// <param name="cancel"> /// The flag indicating whether need to cancel the operation. /// </param> private static void TestCancellable(bool cancel) { IGridionServer server; using (server = GridionServerFactory.RegisterNewServer(GridionServerConfiguration.GetDefault())) { Assert.IsFalse(server.IsListening, "server.IsListening"); using (var cts = new CancellationTokenSource()) { server.StartListenAsync(cts.Token); if (cancel) { cts.Cancel(); Assert.IsFalse(server.IsListening, "server.IsListening"); } else { Assert.IsTrue(server.IsListening, "server.IsListening"); } } } Assert.IsFalse(server.IsListening, "server.IsListening"); }
/// <summary> /// Initializes a new instance of the <see cref="GridionServer" /> class. /// </summary> /// <param name="id"> /// The <see cref="IGridionServer" /> ID. /// </param> /// <param name="listener"> /// The <see cref="TcpListener" />. /// </param> /// <param name="configuration"> /// The <see cref="IGridionServer" /> configuration. /// </param> internal GridionServer(GridionServerId id, TcpListener listener, GridionServerConfiguration configuration) { this.id = id; this.listener = listener; this.Configuration = configuration; this.logger = this.Configuration.Logger; }
///// <summary> ///// The collection of initiated lists on the node. ///// </summary> // private readonly ConcurrentDictionary<string, object> listMap = new ConcurrentDictionary<string, object>(); ///// <summary> ///// The collection of initiated queue on the node. ///// </summary> // private readonly ConcurrentDictionary<string, object> queueMap = new ConcurrentDictionary<string, object>(); ///// <summary> ///// The collection of initiated sets on the node. ///// </summary> // private readonly ConcurrentDictionary<string, object> setMap = new ConcurrentDictionary<string, object>(); /// <summary> /// Initializes a new instance of the <see cref="Node" /> class. /// </summary> /// <param name="configuration">The server configuration.</param> /// <param name="curator">The cluster curator.</param> /// <param name="logger">The logger.</param> /// <exception cref="GridionException"> /// When there are presented some issues with server initialization then a <see cref="GridionException" /> is thrown. /// </exception> public Node( GridionServerConfiguration configuration, IClusterCurator curator, ILogger logger) { Should.NotBeNull(configuration, nameof(configuration)); Should.NotBeNull(curator, nameof(curator)); Should.NotBeNull(logger, nameof(logger)); this.gridionServer = GridionServerFactory.RegisterNewServer(configuration); this.inMessengerService = new MemoryMessengerService(curator); this.outMessengerService = new MemoryMessengerService(curator); this.logger = logger; }
/// <summary> /// Starts a new instance of <see cref="IGridionServer" />. /// </summary> /// <param name="configuration"> /// The configuration of <see cref="IGridionServer" />. /// </param> /// <returns> /// a started <see cref="IGridionServer" /> instance. /// </returns> internal static IGridionServer RegisterNewServer(GridionServerConfiguration configuration) { Should.NotBeNull(configuration, nameof(configuration)); lock (LockObject) { var serverId = BuildServerId(configuration.Address); if (TcpListeners.ContainsKey(serverId)) { throw new GridionException($"The server with address {configuration.Address} is already exists."); } var listener = new TcpListenerWrapper(IPAddress.Parse(configuration.Host), configuration.Port); TcpListeners[serverId] = listener; IGridionServer server = new GridionServer(serverId, listener, configuration); return(server); } }
public void GridionServerCannotRunOnSamePortTest() { using (var server = GridionServerFactory.RegisterNewServer(new GridionServerConfiguration("127.0.0.1", 24000))) { using (var cts = new CancellationTokenSource()) { server.StartListenAsync(cts.Token); Assert.IsTrue(server.IsListening, "server.IsListening"); Assert.ThrowsException <GridionException>( () => { var configuration2 = new GridionServerConfiguration("127.0.0.1", 24000); GridionServerFactory.RegisterNewServer(configuration2); }, "The expected exception hasn't been thrown."); } } }
public void GridionClientServerTest() { var serverConfiguration = GridionServerConfiguration.GetDefault(); using (var server = GridionServerFactory.RegisterNewServer(serverConfiguration)) { using (var cts = new CancellationTokenSource()) { server.StartListenAsync(cts.Token); Assert.IsTrue(server.IsListening, "server.IsListening"); var client = GridionClientFactory.Create(); var clientConfiguration = new GridionClientConfiguration(serverConfiguration.Host, serverConfiguration.Port); client.Connect(clientConfiguration.Host, clientConfiguration.Port); Assert.IsTrue(server.IsListening, "server.IsListening"); Assert.IsTrue(client.IsConnected, "client.IsConnected"); } } }
/// <summary> /// Validates <see cref="GridionServerConfiguration" /> instance. /// </summary> /// <param name="configuration"> /// The configuration to validate. /// </param> internal static void Validate(GridionServerConfiguration configuration) { Should.NotBeNull(configuration, nameof(configuration)); Should.BeTrue(IPAddress.TryParse(configuration.Host, out _), nameof(configuration.Host)); Should.BePositive(configuration.Port, nameof(configuration.Port)); }