protected override void ProcessRecord() { try { WriteVerbose($"[{DateTime.UtcNow}] Initializing Orleans Grain Client"); switch (ParameterSetName) { case FilePathSet: WriteVerbose($"[{DateTime.UtcNow}] Using config file at '{ConfigFilePath}'..."); if (string.IsNullOrWhiteSpace(ConfigFilePath)) { throw new ArgumentNullException(nameof(ConfigFilePath)); } GrainClient.Initialize(ConfigFilePath); break; case FileSet: WriteVerbose($"[{DateTime.UtcNow}] Using provided config file..."); if (ConfigFile == null) { throw new ArgumentNullException(nameof(ConfigFile)); } GrainClient.Initialize(ConfigFile); break; case ConfigSet: WriteVerbose($"[{DateTime.UtcNow}] Using provided 'ClientConfiguration' object..."); if (Config == null) { throw new ArgumentNullException(nameof(Config)); } GrainClient.Initialize(Config); break; case EndpointSet: WriteVerbose($"[{DateTime.UtcNow}] Using default Orleans Grain Client initializer"); if (GatewayAddress == null) { throw new ArgumentNullException(nameof(GatewayAddress)); } GrainClient.Initialize(GatewayAddress, OverrideConfig); break; default: WriteVerbose($"[{DateTime.UtcNow}] Using default Orleans Grain Client initializer"); GrainClient.Initialize(); break; } if (Timeout != TimeSpan.Zero) { GrainClient.SetResponseTimeout(Timeout); } } catch (Exception ex) { WriteError(new ErrorRecord(ex, ex.GetType().Name, ErrorCategory.InvalidOperation, this)); } }
public async Task NoReconnectionToGatewayNotReturnedByManager() { // Reduce timeout for this test GrainClient.SetResponseTimeout(TimeSpan.FromSeconds(1)); var connectionCount = 0; var timeoutCount = 0; // Fake Gateway var port = HostedCluster.ClusterConfiguration.PrimaryNode.Port + 2; var endpoint = new IPEndPoint(IPAddress.Loopback, port); var evt = new SocketAsyncEventArgs(); evt.Completed += (sender, args) => { connectionCount++; TestGatewayManager.Gateways.Remove(endpoint.ToGatewayUri()); }; // Add the fake gateway and wait the refresh from the client TestGatewayManager.Gateways.Add(endpoint.ToGatewayUri()); await Task.Delay(200); using (var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) { // Start the fake gw socket.Bind(endpoint); socket.Listen(1); socket.AcceptAsync(evt); // Make a bunch of calls for (var i = 0; i < 100; i++) { try { var g = GrainFactory.GetGrain <ISimpleGrain>(i); await g.SetA(i); } catch (TimeoutException) { timeoutCount++; } } socket.Close(); } // Check that we only connected once to the fake GW Assert.Equal(1, connectionCount); Assert.Equal(1, timeoutCount); }
public void BasicActivation_Reentrant_RecoveryAfterExpiredMessage() { List <Task> promises = new List <Task>(); TimeSpan prevTimeout = GrainClient.GetResponseTimeout(); // set short response time and ask to do long operation, to trigger expired msgs in the silo queues. TimeSpan shortTimeout = TimeSpan.FromMilliseconds(1000); GrainClient.SetResponseTimeout(shortTimeout); ITestGrain grain = GrainClient.GrainFactory.GetGrain <ITestGrain>(GetRandomGrainId()); int num = 10; for (long i = 0; i < num; i++) { Task task = grain.DoLongAction(TimeSpan.FromMilliseconds(shortTimeout.TotalMilliseconds * 3), "A_" + i); promises.Add(task); } try { Task.WhenAll(promises).Wait(); }catch (Exception) { logger.Info("Done with stress iteration."); } // wait a bit to make sure expired msgs in the silo is trigered. Thread.Sleep(TimeSpan.FromSeconds(10)); // set the regular response time back, expect msgs ot succeed. GrainClient.SetResponseTimeout(prevTimeout); logger.Info("About to send a next legit request that should succeed."); grain.DoLongAction(TimeSpan.FromMilliseconds(1), "B_" + 0).Wait(); logger.Info("The request succeeded."); }