private string[] ProcessRequest() { var queries = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" }; Console.WriteLine("Testing {0} started", client.GetType()); var result = Task.WhenAll(queries.Select( async query => { var timer = Stopwatch.StartNew(); try { var clientResult = await client.ProcessRequestAsync(query, TimeSpan.FromSeconds(6)); clientResult.Should().Be(Encoding.UTF8.GetString(ClusterHelpers.GetBase64HashBytes(query))); Console.WriteLine("Query \"{0}\" successful ({1} ms)", query, timer.ElapsedMilliseconds); return(clientResult); } catch (TimeoutException) { Console.WriteLine($"Query \"{query}\" timeout ({timer.ElapsedMilliseconds} ms) {DateTime.Now.TimeOfDay}"); throw; } }).ToArray()).GetAwaiter().GetResult(); Console.WriteLine("Testing {0} finished", client.GetType()); return(result); }
public void TestPrimaryFailoverWhileLockHeld() { var client = Utils.GetClient(); var quorum = client.GetQuorum(quorumName); var database = client.GetDatabase(databaseName); var table = database.GetTable(tableName); var counter = Interlocked.Increment(ref testLockFailureExceptionCounter); byte[] majorKey = Utils.StringToByteArray("TestPrimaryFailoverWhileLockHeld" + counter); client.StartTransaction(quorum, majorKey); // make primary sleep and lose lease var query = ClusterHelpers.SleepAction(debugKey, sleepInterval); ClusterHelpers.PrimaryShardServerHTTPAction(client, quorum, query); table.Set("x", "x"); try { client.CommitTransaction(); } catch (TransactionException e) { return; } Assert.Fail("Missed exception due to primary failover"); }
public void TestClass_GetPartitionCount_FabricClient() { FabricClient client = new FabricClient(); int count = ClusterHelpers.GetPartitionCountAsync(serviceUri).GetAwaiter().GetResult(); Assert.AreEqual(2, count); }
protected TimeSpan[] ProcessRequests(double timeout, int take = 20) { var addresses = clusterServers .Select(cs => $"http://127.0.0.1:{cs.ServerOptions.Port}/{cs.ServerOptions.MethodName}/") .ToArray(); var client = CreateClient(addresses); Console.WriteLine("Testing {0} started", client.GetType()); var result = Task.WhenAll(Enumerable.Range(0, take).Select(i => i.ToString("x8")).Select( async query => { var timer = Stopwatch.StartNew(); try { var clientResult = await client.ProcessRequestAsync(query, TimeSpan.FromMilliseconds(timeout)); timer.Stop(); clientResult.Should().Be(Encoding.UTF8.GetString(ClusterHelpers.GetBase64HashBytes(query))); timer.ElapsedMilliseconds.Should().BeLessThan((long)timeout + Epsilon); Console.WriteLine("Query \"{0}\" successful ({1} ms)", query, timer.ElapsedMilliseconds); return(timer.Elapsed); } catch (TimeoutException) { Console.WriteLine("Query \"{0}\" timeout ({1} ms)", query, timer.ElapsedMilliseconds); throw; } }).ToArray()).GetAwaiter().GetResult(); Console.WriteLine("Testing {0} finished", client.GetType()); return(result); }
protected TimeSpan[] ProcessRequests(double timeout) { var addresses = this.clusterServers .Select(cs => $"http://localhost:{cs.ServerOptions.Port}/{cs.ServerOptions.MethodName}/") .ToArray(); var client = CreateClient(addresses); Thread.Sleep(1000); var queries = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" }; Console.WriteLine("Testing {0} started", client.GetType()); var result = Task.WhenAll(queries.Select( async query => { var timer = Stopwatch.StartNew(); try { var clientResult = await client.ProcessRequestAsync(query, TimeSpan.FromMilliseconds(timeout)); timer.Stop(); clientResult.Should().Be(Encoding.UTF8.GetString(ClusterHelpers.GetBase64HashBytes(query))); Console.WriteLine("Query \"{0}\" successful ({1} ms)", query, timer.ElapsedMilliseconds); return(timer.Elapsed); } catch (TimeoutException) { Console.WriteLine("Query \"{0}\" timeout ({1} ms)", query, timer.ElapsedMilliseconds); throw; } }).ToArray()).GetAwaiter().GetResult(); Console.WriteLine("Testing {0} finished", client.GetType()); return(result); }
/// <summary> /// QueueClient constructor. /// </summary> /// <param name="serviceUri">Uri of the service in the format fabric:/[app]/[svc].</param> /// <param name="listenerName">String containing the name of the listener. Default to 'SvcEndpoint'</param> /// <param name="retryPolicy">RetryPolocy instance. Defaults to <see name="RetryPolicy"/>.DefaultFixed.</param> /// <remarks>There is quite a bit of overhead to creating an instance of QueueClient. Create one per service and reuse.</remarks> public HttpQueueClient(Uri serviceUri, string listenerName = "SvcEndpoint", RetryPolicy retryPolicy = null) { Guard.ArgumentNotNull(serviceUri, nameof(serviceUri)); _serviceUri = serviceUri; _listenerName = listenerName; // Create the retry policy _retryPolicy = retryPolicy ?? RetryPolicy.DefaultFixed; // var handler = new HttpClientHandler() { ClientCertificateOptions = ClientCertificateOption.Automatic }; // Initialize the HttpClient and the ServiceFabricEndpointResolver. _http = new HttpClient(handler); //_endpointResolver = new PartitionEndpointResolver(clusterEndpoint, TimeSpan.FromMinutes(10), _http); // Get the number of partitions configured for this service. ServicePartitionCount = ClusterHelpers.GetPartitionCountAsync(serviceUri).GetAwaiter().GetResult(); Guard.ArgumentNotZeroOrNegativeValue(ServicePartitionCount, nameof(ServicePartitionCount)); // Allocate and initialize the partition map, which caches ResolvedServicePartition instances. // The map caches the ResolvedServicePartition and also the ServicePartitionKey so it doesn't have to be created for each call. _partitionMap = new Tuple <ServicePartitionKey, ResolvedServicePartition> [ServicePartitionCount]; for (int i = 0; i < ServicePartitionCount; i++) { _partitionMap[i] = new Tuple <ServicePartitionKey, ResolvedServicePartition>(new ServicePartitionKey((long)i), null); } // Choose a random partition to start with Guard.ArgumentInRange(ServicePartitionCount, 1, int.MaxValue, nameof(ServicePartitionCount)); _currentDequeuePartition = RandomThreadSafe.Instance.Next(0, ServicePartitionCount - 1); currentEnqueuePartition = RandomThreadSafe.Instance.Next(0, ServicePartitionCount - 1); }