Exemplo n.º 1
0
        public void SmoothPursuitPositiveQuadrant()
        {
            var results = new List<PanTiltTime>();
            var sut = GetSystemUnderTest();
            var resolution = 100;

            var tickEveryMs = Convert.ToInt32(sut.TimeSpan.TotalMilliseconds/resolution);
            var time = TimeSpan.FromSeconds(0);
            var tick = TimeSpan.FromMilliseconds(tickEveryMs);

            for (var timeMs = 0; timeMs <= sut.TimeSpan.TotalMilliseconds; timeMs += tickEveryMs)
            {
                var result = new PanTiltTime();
                time += tick;
                _mockStopwatch.Set(time);
                result.TimeSpan = time;
                result.Setting = sut.GetNextPosition();

                results.Add(result);
            }

            var panPoints = results.ConvertAll(p => p.ToCsv(PanTiltAxis.Horizontal));
            var tiltPoints = results.ConvertAll(p => p.ToCsv(PanTiltAxis.Vertical));

            var csvPan = string.Join("\r\n", panPoints);
            var csvTilt = string.Join("\r\n", tiltPoints);

            Console.WriteLine($"Pan:\r\n{csvPan}");

            Console.WriteLine($"Tilt:\r\n{csvTilt}");
        }
Exemplo n.º 2
0
        public void AssertSequencePattern()
        {
            var dummy = new DummySequencer();
            var goalDistance = 3;
            var lastTrainingDistance = 2;
            var lastRestituteDistance = 0;
            var repeat = 1;
            var e = new SimpleGoaledSequencer<int>(goalDistance, lastTrainingDistance, lastRestituteDistance, repeat, Comparer<int>.Default, dummy);
            var distances = new List<int>();
            while (e.MoveNext())
            {
                var next = e.Current;
                distances.Add(next);
            }

            var expected = "1,2,3";
            var actual = string.Join(",", distances.ConvertAll(x => x.ToString()).ToArray());
            Assert.AreEqual(expected, actual);

            goalDistance = 5;
            repeat = 3;
            lastTrainingDistance = 4;
            expected = "1,2,3,4,4,4,5";
            distances.Clear();
            e = new SimpleGoaledSequencer<int>(goalDistance, lastTrainingDistance, lastRestituteDistance, repeat, Comparer<int>.Default, dummy);
            while (e.MoveNext())
            {
                var next = Convert.ToInt32(e.Current);
                distances.Add(next);
            }
            actual = string.Join(",", distances.ConvertAll(x => x.ToString()).ToArray());
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
    public void TestClassifyPeptideHit()
    {
      List<IIdentifiedSpectrum> spectra = new List<IIdentifiedSpectrum>();
      spectra.Add(new IdentifiedSpectrum() { Rank = 1 });
      spectra.Add(new IdentifiedSpectrum() { Rank = 1 });
      spectra.Add(new IdentifiedSpectrum() { Rank = 2 });
      spectra.Add(new IdentifiedSpectrum() { Rank = 2 });

      new IdentifiedPeptide(spectra[0]) { Sequence = "SE*Q" };
      new IdentifiedPeptide(spectra[1]) { Sequence = "SEQ" };
      new IdentifiedPeptide(spectra[2]) { Sequence = "SEQSEQ" };
      new IdentifiedPeptide(spectra[3]) { Sequence = "SEQSEQSEQ" };

      CalculationItem item = new CalculationItem()
      {
        Peptides = spectra.ConvertAll(m => m.Peptide).ToList()
      };


      item.ClassifyPeptideHit(m => m.Spectrum.Rank.ToString(), new string[] { "1", "2" });

      Assert.AreEqual(2, item.Classifications.Count);
      Assert.AreEqual(2, item.Classifications["1"].PeptideCount);
      Assert.AreEqual(1, item.Classifications["1"].UniquePeptideCount);
      Assert.AreEqual(2, item.Classifications["2"].PeptideCount);
      Assert.AreEqual(2, item.Classifications["2"].UniquePeptideCount);
    }
        public void Can_Delete_from_basic_persistence_provider()
        {
            using (var db = ConnectionString.OpenDbConnection())
            using (var dbCmd = db.CreateCommand())
            {
                dbCmd.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List<int> { 1, 2, 3, 4, 5 };

                var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

                rows.ForEach(x => dbCmd.Insert(x));

                var deleteRowIds = new List<int> { 2, 4 };

                foreach (var row in rows)
                {
                    if (deleteRowIds.Contains(row.Id))
                    {
                        basicProvider.Delete(row);
                    }
                }

                var providerRows = basicProvider.GetByIds<ModelWithFieldsOfDifferentTypes>(rowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                var remainingIds = new List<int>(rowIds);
                deleteRowIds.ForEach(x => remainingIds.Remove(x));

                Assert.That(providerRowIds, Is.EquivalentTo(remainingIds));
            }
        }
        public void Can_support_64_threads_using_the_client_simultaneously()
        {
            var before = Stopwatch.GetTimestamp();

            const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64

#if NETCORE
            List<Task> tasks = new List<Task>();
#else
            var clientAsyncResults = new List<IAsyncResult>();
#endif             
            using (var redisClient = new RedisClient(TestConfig.SingleHost))
            {
                for (var i = 0; i < noOfConcurrentClients; i++)
                {
                    var clientNo = i;
                    var action = (Action)(() => UseClientAsync(redisClient, clientNo));
#if NETCORE
                    tasks.Add(Task.Run(action));
#else                                       
                    clientAsyncResults.Add(action.BeginInvoke(null, null));
#endif
                }
            }
#if NETCORE
            Task.WaitAll(tasks.ToArray());
#else            
            WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());
#endif
            Debug.WriteLine(String.Format("Time Taken: {0}", (Stopwatch.GetTimestamp() - before) / 1000));
        }
		public void Can_support_64_threads_using_the_client_simultaneously()
		{
			var before = Stopwatch.GetTimestamp();

			const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64

			var clientAsyncResults = new List<IAsyncResult>();
			using (var manager = new PooledRedisClientManager(TestConfig.MasterHosts, TestConfig.SlaveHosts))
			{
				manager.GetClient().Run(x => x.FlushAll());

				for (var i = 0; i < noOfConcurrentClients; i++)
				{
					var clientNo = i;
					var action = (Action)(() => UseClientAsync(manager, clientNo));
					clientAsyncResults.Add(action.BeginInvoke(null, null));
				}
			}

			WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());

			Debug.WriteLine(string.Format("Completed in {0} ticks", (Stopwatch.GetTimestamp() - before)));

            RedisStats.ToDictionary().PrintDump();
		}
        protected void RunSimultaneously(
            Func<string[], string[], IRedisClientsManager> clientManagerFactory,
            Action<IRedisClientsManager, int> useClientFn)
        {
            var before = Stopwatch.GetTimestamp();

            const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64

#if NETCORE
            List<Task> tasks = new List<Task>();
#else
            var clientAsyncResults = new List<IAsyncResult>();
#endif             
            using (var manager = clientManagerFactory(TestConfig.MasterHosts, TestConfig.SlaveHosts))
            {
                for (var i = 0; i < noOfConcurrentClients; i++)
                {
                    var clientNo = i;
                    var action = (Action)(() => useClientFn(manager, clientNo));
#if NETCORE
                    tasks.Add(Task.Run(action));
#else                                       
                    clientAsyncResults.Add(action.BeginInvoke(null, null));
#endif
                }
            }

#if NETCORE
            Task.WaitAll(tasks.ToArray());
#else            
            WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());
#endif

            Debug.WriteLine(String.Format("Time Taken: {0}", (Stopwatch.GetTimestamp() - before) / 1000));
        }
Exemplo n.º 8
0
        public void AssertRepetitionProgressionPattern()
        {
            const int pauseAfter = 20;
            const int start = 1;

            Func<int, int> progression = x => x + 1;

            var repetitionExpectedResultPair = new Dictionary<int, string>
                                                   {
                                                       {1, "1,2,3,4,5,6,7,8,9,10,11,12"},
                                                       {2, "1,1,2,2,3,3,4,4,5,5,6,6"},
                                                       {4, "1,1,1,1,2,2,2,2,3,3,3,3"}
                                                   };

            foreach (var pair in repetitionExpectedResultPair)
            {
                var repititions = pair.Key;
                var expected = pair.Value;

                var e = new Sequencer<int>(start, repititions, pauseAfter, progression);
                var results = new List<int>();
                const int noOfElements = 12;

                for (var i = 0; i < noOfElements; i++)
                {
                    e.MoveNext();
                    var next = e.Current;
                    results.Add(next);
                }
                var distances = string.Join(",", results.ConvertAll(x => x.ToString()).ToArray());
                Assert.AreEqual(expected, distances);
            }
        }
Exemplo n.º 9
0
 private List<Assembly> GetAllAssemblies(string path)
 {
     var files = new List<FileInfo>();
     var directoryToSearch = new DirectoryInfo(path);
     files.AddRange(directoryToSearch.GetFiles("*.dll", SearchOption.AllDirectories));
     files.AddRange(directoryToSearch.GetFiles("*.exe", SearchOption.AllDirectories));
     return files.ConvertAll(file => Assembly.LoadFile(file.FullName));
 }
Exemplo n.º 10
0
		public void ConvertAll_LinqExt ()
		{
			// Convert list of ints into list of doubles.
			var sampleObjNumbers = new List<int> (){ 1,2,3,4,5,6,7,8,9,10};
			var sampleIntNumbers = sampleObjNumbers.ConvertAll<double> (x => Convert.ToDouble (x));

			Assert.AreEqual (10, sampleIntNumbers.Count ());
			Assert.IsInstanceOfType (typeof(List<double>), sampleIntNumbers);
			Assert.IsInstanceOfType (typeof(double), sampleIntNumbers.First ());
		}
Exemplo n.º 11
0
        /// <summary>
        /// Calculates the nodes that should be visible in the main window tree view when the specified xen object is hidden.
        /// </summary>
        /// <param name="hiddenObject">The hidden object.</param>
        private ComparableList<IXenObject> CalculatePopulateWithHiddenObject(IXenObject hiddenObject)
        {
            VirtualTreeNode rootNode = MW(() => new MainWindowTreeBuilder(new FlickerFreeTreeView()).CreateNewRootNode(new NavigationPane().Search, NavigationPane.NavigationMode.Infrastructure));

            List<VirtualTreeNode> nodes = new List<VirtualTreeNode>(rootNode.Descendants);

            nodes.RemoveAll(n => hiddenObject.Equals(n.Tag));
            nodes.RemoveAll(n => new List<VirtualTreeNode>(n.Ancestors).Find(nn => hiddenObject.Equals(nn.Tag)) != null);
            return new ComparableList<IXenObject>(nodes.ConvertAll(n => (IXenObject)n.Tag));
        }
        public void Can_Get_UrlHostName()
        {
            var urls = new List<string> { "http://localhost/a", "https://localhost/a",
                "http://localhost:81", "http://localhost:81/", "http://localhost" };

            var httpReqs = urls.ConvertAll(x => new MockUrlHttpRequest { AbsoluteUri = x });
            var hostNames = httpReqs.ConvertAll(x => x.GetUrlHostName());

            Console.WriteLine(hostNames.Dump());

            Assert.That(hostNames.All(x => x == "localhost"));
        }
Exemplo n.º 13
0
        public void ScaledInput(List<object> samples, List<double> labels)
        {
            var people = samples.ConvertAll(x => (Person)x);
            var age = new { Mean = people.Select(x => x.Age).Average(), Deviation = Math.Sqrt( ((double)1/(people.Count - 1)) * people.Select(x => Math.Pow(x.Age - people.Select(xx => xx.Age).Average(), 2)).Sum() ) };
            var height = new { Mean = people.Select(x => x.Height).Average(), Deviation = Math.Sqrt(((double)1 / (people.Count - 1)) * people.Select(x => Math.Pow(x.Height - people.Select(xx => xx.Height).Average(), 2)).Sum()) };

            var algorithm = new FakeAlgorithm(people, labels, new Settings {InputSplitRatio = InputSplitRatio.No});

            Assert.That(algorithm.MyTrainingSetX[0, 0], Is.EqualTo(1), "A column of ones should be added to the input matrix.");
            Assert.That(algorithm.MyTrainingSetX[0, 1], Is.EqualTo(  (people[0].Age - age.Mean) / age.Deviation ));
            Assert.That(algorithm.MyTrainingSetX[0, 2], Is.EqualTo(  (people[0].Height - height.Mean) / height.Deviation ));
            Assert.That(algorithm.MyTrainingSetY[0], Is.EqualTo(labels[0]));
        }
Exemplo n.º 14
0
        public void DefaultInputSplit(List<object> samples, List<double> labels)
        {
            var people = samples.ConvertAll(x => (Person)x);
            var trainingSetSize = (int)Math.Ceiling(((double)2 / 3) * people.Count);
            var crossValidationSetSize = (int)Math.Ceiling(((double)2 / 3) * people.Count);

            var algorithm = new FakeAlgorithm(people, labels, new Settings {ScaleAndNormalize = false});

            AssertInput(algorithm.MyTrainingSetX, algorithm.MyTrainingSetY, people, labels, 0, trainingSetSize);
            AssertInput(algorithm.MyCrossValidationSetX, algorithm.MyCrossValidationSetY, people, labels, trainingSetSize, crossValidationSetSize);
            Assert.That(algorithm.MyTestSetX, Is.Null);
            Assert.That(algorithm.MyTestSetY, Is.Null);
        }
Exemplo n.º 15
0
        public void AssertSequence()
        {
            var dummy = new DummySequencer();
            var e = new GoaledSequencer<int>(10, 8, 7, 3, Comparer<int>.Default, dummy);
            var numbers = new List<int>();
            e.Reset();
            while (e.MoveNext())
            {
                numbers.Add(e.Current);
            }

            const string expected = "1,2,3,4,5,6,7,8,8,8,7,7,7,10";
            var actual = string.Join(",", numbers.ConvertAll(x => x.ToString()).ToArray());
            Assert.AreEqual(expected,actual);
        }
		public void Can_SaveAll_and_select_from_ModelWithFieldsOfDifferentTypes_table_with_no_ids()
		{
			using (var db = OpenDbConnection())
			{
				db.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

				var rowIds = new List<int> { 1, 2, 3, 4, 5 };
				var newRows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(default(int)));

				db.SaveAll(newRows);

				var rows = db.Select<ModelWithFieldsOfDifferentTypes>();

				Assert.That(rows, Has.Count.EqualTo(newRows.Count));
			}
		}
Exemplo n.º 17
0
		public void Can_SaveAll_and_select_from_ModelWithFieldsOfDifferentTypes_table_with_no_ids()
		{
			using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
			{
				db.CreateTable<ModelWithFieldsOfDifferentTypes>(true);
				db.DeleteAll<ModelWithFieldsOfDifferentTypes>();
				var rowIds = new List<int> {1, 2, 3, 4, 5};
				var newRows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(default(int)));

				db.SaveAll(newRows);

				var rows = db.Select<ModelWithFieldsOfDifferentTypes>();

				Assert.That(rows, Has.Count.EqualTo(newRows.Count));
			}
		}
Exemplo n.º 18
0
        public void TestGetReadableColor()
        {
            List<Color> darkColors = new List<Color>();
            darkColors.Add(Color.Black);
            darkColors.Add(Color.DarkBlue);
            darkColors.Add(Color.DarkGreen);
            darkColors.Add(Color.DarkRed);

            Expect(darkColors.ConvertAll<Color>(Palette.GetReadableColor), All.EqualTo(Color.White));

            List<Color> lightColors = new List<Color>();
            lightColors.Add(Color.White);
            lightColors.Add(Color.Yellow);
            lightColors.Add(Color.YellowGreen);
            lightColors.Add(Color.Red);
            lightColors.Add(Color.LightBlue);
            lightColors.Add(Color.Lime);

            Expect(lightColors.ConvertAll<Color>(Palette.GetReadableColor), All.EqualTo(Color.Black));
        }
		public void Can_Delete_ModelWithIdAndName()
		{
			using (var redis = new RedisClient(TestConfig.SingleHost))
			{
				var ids = new List<int> { 1, 2, 3, 4, 5 };
				var tos = ids.ConvertAll(x => ModelWithIdAndName.Create(x));

				redis.StoreAll(tos);

				var deleteIds = new List<int> { 2, 4 };

				redis.DeleteByIds<ModelWithIdAndName>(deleteIds);

				var froms = redis.GetByIds<ModelWithIdAndName>(ids);
				var fromIds = froms.ConvertAll(x => x.Id);

				var expectedIds = ids.Where(x => !deleteIds.Contains(x)).ToList();

				Assert.That(fromIds, Is.EquivalentTo(expectedIds));
			}
		}
		public void Can_Store_from_basic_persistence_provider()
		{
			using (var db = ConnectionString.OpenDbConnection())
			{
				db.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

				var basicProvider = new OrmLitePersistenceProvider(db);

				var rowIds = new List<int> { 1, 2, 3, 4, 5 };

				var rows = rowIds.ConvertAll(x => ModelWithFieldsOfDifferentTypes.Create(x));

				rows.ForEach(x => basicProvider.Store(x));

				var getRowIds = new[] { 2, 4 };
				var providerRows = db.GetByIds<ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
				var providerRowIds = providerRows.ConvertAll(x => x.Id);

				Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
			}
		}
        public void Can_GetByIds_from_basic_persistence_provider()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable<ModelWithFieldsOfDifferentTypes>(true);

                var basicProvider = new OrmLitePersistenceProvider(db);

                var rowIds = new List<int> { 1, 2, 3, 4, 5 };

                var rows = rowIds.ConvertAll(ModelWithFieldsOfDifferentTypes.Create);

                rows.ForEach(x => { x.Id = (int)db.Insert(x, selectIdentity: true); });

                var getRowIds = new[] { rows[1].Id, rows[3].Id };
                var providerRows = basicProvider.GetByIds<ModelWithFieldsOfDifferentTypes>(getRowIds).ToList();
                var providerRowIds = providerRows.ConvertAll(x => x.Id);

                Assert.That(providerRowIds, Is.EquivalentTo(getRowIds));
            }
        }
		public void Can_support_64_threads_using_the_client_simultaneously()
		{
			var before = Stopwatch.GetTimestamp();

			const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64

			var clientAsyncResults = new List<IAsyncResult>();
			using (var redisClient = new RedisClient(TestConfig.SingleHost))
			{
				for (var i = 0; i < noOfConcurrentClients; i++)
				{
					var clientNo = i;
					var action = (Action)(() => UseClientAsync(redisClient, clientNo));
					clientAsyncResults.Add(action.BeginInvoke(null, null));
				}
			}

			WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());

			Console.WriteLine("Time Taken: {0}", (Stopwatch.GetTimestamp() - before) / 1000);
		}
Exemplo n.º 23
0
        public static async Task RunServerStreamingAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running server_streaming");

            var bodySizes = new List<int> { 31415, 9, 2653, 58979 };

            var request = new StreamingOutputCallRequest
            {
                ResponseType = PayloadType.Compressable,
                ResponseParameters = { bodySizes.ConvertAll((size) => new ResponseParameters { Size = size }) }
            };

            using (var call = client.StreamingOutputCall(request))
            {
                var responseList = await call.ResponseStream.ToListAsync();
                foreach (var res in responseList)
                {
                    Assert.AreEqual(PayloadType.Compressable, res.Payload.Type);
                }
                CollectionAssert.AreEqual(bodySizes, responseList.ConvertAll((item) => item.Payload.Body.Length));
            }
            Console.WriteLine("Passed!");
        }
		public void Can_support_64_threads_using_the_client_simultaneously()
		{
			const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64
			var clientUsageMap = new Dictionary<string, int>();

			var clientAsyncResults = new List<IAsyncResult>();
			using (var manager = CreateAndStartManager())
			{
				for (var i = 0; i < noOfConcurrentClients; i++)
				{
					var clientNo = i;
					var action = (Action)(() => UseClient(manager, clientNo, clientUsageMap));
					clientAsyncResults.Add(action.BeginInvoke(null, null));
				}
			}

			WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());

			Debug.WriteLine(TypeSerializer.SerializeToString(clientUsageMap));

			var hostCount = 0;
			foreach (var entry in clientUsageMap)
			{
				Assert.That(entry.Value, Is.GreaterThanOrEqualTo(5), "Host has unproportianate distrobution: " + entry.Value);
				Assert.That(entry.Value, Is.LessThanOrEqualTo(30), "Host has unproportianate distrobution: " + entry.Value);
				hostCount += entry.Value;
			}

			Assert.That(hostCount, Is.EqualTo(noOfConcurrentClients), "Invalid no of clients used");
		}
Exemplo n.º 25
0
	    public void Test_multithread_errors()
	    {
	        var times = 1000;
	        var count = 0;
	        var errors = new List<Exception>();
            times.Times(i => 
                ThreadPool.QueueUserWorkItem(x => {
                    Interlocked.Increment(ref count);
                    try {
                        Assert200(Host + "/rockstars?View=Json", "[{\"");
                    }
                    catch (Exception ex) {
                        errors.Add(ex);
                    }
                }));

            while (count < times)
	            Thread.Sleep(100);

	        var errMsgs = errors.ConvertAll(x => x.Message);
            errMsgs.PrintDump();
	        
            Assert.That(errors.Count, Is.EqualTo(0));
	    }
Exemplo n.º 26
0
 private ComparableList<IXenObject> Populate()
 {
     VirtualTreeNode rootNode = MW(() => new MainWindowTreeBuilder(new FlickerFreeTreeView()).CreateNewRootNode(new NavigationPane().Search, NavigationPane.NavigationMode.Infrastructure));
     List<VirtualTreeNode> nodes = new List<VirtualTreeNode>(rootNode.Descendants);
     return new ComparableList<IXenObject>(nodes.ConvertAll(n => (IXenObject)n.Tag));
 }
        public void Can_open_multiple_nested_connections()
        {
            var factory = new OrmLiteConnectionFactory(Config.SqliteMemoryDb, SqliteDialect.Provider);
            factory.RegisterConnection("sqlserver", Config.SqlServerBuildDb, SqlServerDialect.Provider);
            factory.RegisterConnection("sqlite-file", Config.SqliteFileDb, SqliteDialect.Provider);

            var results = new List<Person>();
            using (var db = factory.OpenDbConnection())
            {
                db.DropAndCreateTable<Person>();
                db.Insert(new Person { Id = 1, Name = "1) :memory:" });
                db.Insert(new Person { Id = 2, Name = "2) :memory:" });

                using (var db2 = factory.OpenDbConnection("sqlserver"))
                {
                    db2.CreateTable<Person>(true);
                    db2.Insert(new Person { Id = 3, Name = "3) Database1.mdf" });
                    db2.Insert(new Person { Id = 4, Name = "4) Database1.mdf" });

                    using (var db3 = factory.OpenDbConnection("sqlite-file"))
                    {
                        db3.CreateTable<Person>(true);
                        db3.Insert(new Person { Id = 5, Name = "5) db.sqlite" });
                        db3.Insert(new Person { Id = 6, Name = "6) db.sqlite" });

                        results.AddRange(db.Select<Person>());
                        results.AddRange(db2.Select<Person>());
                        results.AddRange(db3.Select<Person>());
                    }
                }
            }

            results.PrintDump();
            var ids = results.ConvertAll(x => x.Id);
            Assert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, ids);
        }
Exemplo n.º 28
0
        public void SSL_can_support_64_threads_using_the_client_simultaneously()
        {
            var results = 100.Times(x => ModelWithFieldsOfDifferentTypes.Create(x));
            var testData = TypeSerializer.SerializeToString(results);

            var before = Stopwatch.GetTimestamp();

            const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64

            var clientAsyncResults = new List<IAsyncResult>();
            using (var manager = new PooledRedisClientManager(TestConfig.MasterHosts, TestConfig.SlaveHosts))
            {
                manager.GetClient().Run(x => x.FlushAll());

                for (var i = 0; i < noOfConcurrentClients; i++)
                {
                    var clientNo = i;
                    var action = (Action)(() => UseClientAsync(manager, clientNo, testData));
                    clientAsyncResults.Add(action.BeginInvoke(null, null));
                }
            }

            WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());

            Debug.WriteLine(String.Format("Completed in {0} ticks", (Stopwatch.GetTimestamp() - before)));
        }
Exemplo n.º 29
0
        public static async Task RunServerStreamingAsync(TestService.ITestServiceClient client)
        {
            Console.WriteLine("running server_streaming");

            var bodySizes = new List<int> { 31415, 9, 2653, 58979 };

            var request = StreamingOutputCallRequest.CreateBuilder()
            .SetResponseType(PayloadType.COMPRESSABLE)
            .AddRangeResponseParameters(bodySizes.ConvertAll(
                (size) => ResponseParameters.CreateBuilder().SetSize(size).Build()))
            .Build();

            using (var call = client.StreamingOutputCall(request))
            {
                var responseList = await call.ResponseStream.ToListAsync();
                foreach (var res in responseList)
                {
                    Assert.AreEqual(PayloadType.COMPRESSABLE, res.Payload.Type);
                }
                CollectionAssert.AreEqual(bodySizes, responseList.ConvertAll((item) => item.Payload.Body.Length));
            }
            Console.WriteLine("Passed!");
        }
Exemplo n.º 30
0
 public string DumpParams(List<KeyValuePair<string, string>> parameters)
 {
     return string.Join("\n", parameters.ConvertAll(kv => string.Format("{0}={1}", kv.Key, kv.Value)).ToArray());
 }