Наследование: SqlToGraphiteInterfaces.PluginBase
        public void Should_map_sucessfully()
        {
            string hostname = "hostname";
            var clientName = "someClient";
            var freq = 100;
            var configMapper = new ConfigMapper(hostname, this.stop, this.dataClientFactory, this.graphiteClientFactory, this.log, configRepository);
            var taskSets = new List<TaskSet>();
            var taskSet = new TaskSet { Frequency = freq, Tasks = new List<Task>() };
            string name = new Guid().ToString();
            Job job = new WmiClient();
            job.ClientName = clientName;

            configRepository.Expect(y => y.GetJob(name)).Return(job);
            configRepository.Expect(y => y.GetClient(clientName)).Return(new GraphiteTcpClient());

            taskSet.Tasks.Add(new Task() { JobName = name });
            taskSets.Add(taskSet);
            //Test
            var taskList = configMapper.Map(taskSets);
            //Assert
            Assert.That(taskList.Count, Is.EqualTo(1));
            Assert.That(taskList[0].Frequency, Is.EqualTo(freq));
            Assert.That(taskList[0].Tasks.Count, Is.EqualTo(1));
            Assert.That(taskList[0].Tasks[0].GetType(), Is.EqualTo(typeof(RunableRunTask)));
            configRepository.VerifyAllExpectations();
        }
 public void Should_throw_UnknownDataClientException()
 {
     Job job = new WmiClient();
     assemblyResolver.Expect(x => x.ResolveType(job)).Return(null);
     var ex = Assert.Throws<UnknownDataClientException>(() => this.dataClientFactory.Create(job));
     Assert.That(ex.Message, Is.EqualTo(string.Format("{0}", job.GetType().FullName)));
     assemblyResolver.VerifyAllExpectations();
 }
 public void AddNewJob()
 {
     var jobName = "job1";
     var job = new WmiClient();
     job.Name = jobName;
     job.ClientName = "TcpGraphite";
     repository.AddJob(job);
     var jobs = repository.GetJobs();
     Assert.That(jobs.Count, Is.EqualTo(1));
 }
 public void Should_Resolve_type_sucessfuly()
 {
     var job = new WmiClient();
     var files = new List<string>() { string.Format(@"{0}\SqlToGraphite.Plugin.Wmi.dll", Directory.GetCurrentDirectory()) };
     dir.Expect(x => x.GetFilesInCurrentDirectory(AssemblyResolver.FilesToScan)).Return(files);
     //Test
     assemblyResolver = new AssemblyResolver(this.dir, log);
     var rtn = assemblyResolver.ResolveType(job);
     //Assert
     Assert.That(rtn.FullName, Is.EqualTo(job.GetType().FullName));
     dir.VerifyAllExpectations();
 }
 public void Should_ignore_bad_image_exception_for_not_dot_net_dlls()
 {
     File.WriteAllText("bad.dll", "abc");
     var job = new WmiClient() { Type = "SqlToGraphite.Plugin.Wmi.WmiClient" };
     var files = new List<string>() { string.Format(@"{0}\bad.dll", Directory.GetCurrentDirectory()), string.Format(@"{0}\SqlToGraphite.Plugin.Wmi.dll", Directory.GetCurrentDirectory()) };
     dir.Expect(x => x.GetFilesInCurrentDirectory(AssemblyResolver.FilesToScan)).Return(files);
     //Test
     assemblyResolver = new AssemblyResolver(this.dir, log);
     //Test
     var type = assemblyResolver.ResolveType(job);
     //Assert
     Assert.That(type.FullName, Is.EqualTo(job.GetType().FullName));
     File.Delete("bad.dll");
 }
 public void Should_create_wmi_client()
 {
     var job = new WmiClient { Sql = "someSql", Name = "someName", Username = "******", Password = "******", Hostname = "hostname" };
     assemblyResolver.Expect(x => x.ResolveType(job)).Return(job.GetType());
     //Test
     var o = (WmiClient)this.dataClientFactory.Create(job);
     //Assert
     Assert.That(o.Sql, Is.EqualTo(job.Sql));
     Assert.That(o.Name, Is.EqualTo(job.Name));
     Assert.That(o.Path, Is.EqualTo(job.Path));
     Assert.That(o.Username, Is.EqualTo(job.Username));
     Assert.That(o.Password, Is.EqualTo(job.Password));
     Assert.That(o.Hostname, Is.EqualTo(job.Hostname));
     Assert.That(o, Is.Not.Null);
     Assert.That(o, Is.TypeOf<WmiClient>());
     assemblyResolver.VerifyAllExpectations();
 }
Пример #7
0
 public void Should_run_task_sending_one_result_not_fail_on_exception()
 {
     var result = MockRepository.GenerateMock<IResult>();
     var resultList = new List<IResult> { result };
     var param = new WmiClient();
     var client = new GraphiteTcpClient();
     this.dataClientFactory.Expect(x => x.Create(param)).Return(this.sqlClient);
     this.sqlClient.Expect(x => x.Get()).Return(resultList);
     statsClient.Expect(x => x.Send(resultList)).Throw(new ApplicationException());
     this.graphiteClientFactory.Expect(x => x.Create(client)).Return(this.statsClient);
     IRunTask runTask = new RunableRunTask(param, this.dataClientFactory, this.graphiteClientFactory, this.log, client);
     //Test
     runTask.Process();
     //Assert
     this.sqlClient.VerifyAllExpectations();
     this.dataClientFactory.VerifyAllExpectations();
     this.graphiteClientFactory.VerifyAllExpectations();
     statsClient.VerifyAllExpectations();
 }
        public void Should_throw_exception_if_graphite_client_is_unknown()
        {
            string clientName = "notKnown";
            string jobName = "someJob";
            var job = new WmiClient();
            var msg = "some exception message";
            job.ClientName = clientName;
            job.Name = jobName;
            configRepository.Expect(x => x.GetClient(clientName)).Throw(new ClientNotFoundException(msg));
            configRepository.Expect(x => x.GetJob(jobName)).Return(job);
            string hostname = "hostname";
            var configMapper = new ConfigMapper(hostname, this.stop, this.dataClientFactory, this.graphiteClientFactory, this.log, configRepository);
            var taskSets = new List<TaskSet>();
            var taskSet = new TaskSet { Frequency = 100, Tasks = new List<Task>() };
            var t = new Task { JobName = jobName };

            taskSet.Tasks.Add(t);

            taskSets.Add(taskSet);
            //Test
            var ex = Assert.Throws<ClientNotFoundException>(() => configMapper.Map(taskSets));
            //Assert
            Assert.That(ex.Message, Is.EqualTo(msg));
        }
        public void Should_validate_sucessfully()
        {
            string configXml = this.Add(Add(Add(Blank, TwoHosts), Templates), TwoClients);
            genericSerializer.Expect(x => x.Deserialize<SqlToGraphiteConfig>(configXml)).Return(config);
            this.AddTwoClientsToConfig();

            reader.Expect(x => x.GetXml()).Return(configXml);
            cache.Expect(x => x.HasExpired()).Return(true).Repeat.Once();
            //Test
            repository.Load();

            var job = new WmiClient();
            job.Name = "fred";
            job.ClientName = "ClientName";
            repository.AddJob(job);
            repository.AddHost("hostname", new List<Role> { new Role { Name = "roleName" } });
            repository.AddTask(new TaskDetails("roleName", 1000, "fred"));

            //Assert
            Assert.That(repository.Validate(), Is.EqualTo(true));
            Assert.That(repository.Errors.Count, Is.EqualTo(0));
            reader.VerifyAllExpectations();
            cache.VerifyAllExpectations();
            genericSerializer.VerifyAllExpectations();
        }
        public void Should_generate_test_config_file()
        {
            try
            {
                var log = LogManager.GetLogger("log");
                var encryption = new Encryption();
                var simpleCs = encryption.Encrypt("some Cs");

                log4net.Config.XmlConfigurator.Configure();

                var job1 = new WmiClient { ClientName = "GraphiteTcpClient", Name = "GetNumberOfTransactionsASecond", Hostname = simpleCs, Sql = "some sql" };
                var job2 = new WmiClient { ClientName = "GraphiteUdpClient", Name = "GetNumberOfDeliveryies", Hostname = simpleCs, Sql = "some sql1" };
                var client1 = new GraphiteTcpClient { ClientName = "GraphiteTcpClient", Port = 2003, Hostname = "metrics.london.ttldev.local" };
                var client2 = new GraphiteUdpClient { ClientName = "GraphiteUdpClient", Port = 2003, Hostname = "metrics.london.ttldev.local" };

                var config = new SqlToGraphiteConfig(new AssemblyResolver(new DirectoryImpl(), log), log);
                config.Jobs.Add(job1);
                config.Jobs.Add(job2);

                var host1 = new Host { Name = "TTL001121" };
                var host2 = new Host { Name = "Server1" };
                var role1 = new Role { Name = "ProductionTests" };
                var role2 = new Role { Name = "default" };
                var role3 = new Role { Name = "SqlTests" };

                host1.Roles.Add(role1);
                host1.Roles.Add(role2);
                host2.Roles.Add(role2);
                host2.Roles.Add(role3);
                config.Hosts.Add(host1);
                config.Hosts.Add(host2);

                var template = new Template();
                var wi = new WorkItems { RoleName = role1.Name, TaskSet = new List<TaskSet>() };
                var taskSet = new TaskSet { Frequency = 1000 };
                taskSet.Tasks.Add(new Task { JobName = job1.Name });
                wi.TaskSet.Add(taskSet);
                template.WorkItems.Add(wi);

                var wi1 = new WorkItems { RoleName = role2.Name, TaskSet = new List<TaskSet>() };
                var taskSet1 = new TaskSet { Frequency = 2000 };
                taskSet1.Tasks.Add(new Task { JobName = job2.Name });
                wi1.TaskSet.Add(taskSet1);
                template.WorkItems.Add(wi1);

                var wi2 = new WorkItems { RoleName = role3.Name, TaskSet = new List<TaskSet>() };
                var taskSet2 = new TaskSet { Frequency = 3000 };
                wi2.TaskSet.Add(taskSet2);
                template.WorkItems.Add(wi2);

                config.Templates.Add(template);
                config.Clients = new ListOfUniqueType<Client> { client1, client2 };
                //var genericSerializer = new GenericSerializer(Global.GetNameSpace());
                //string xml = genericSerializer.Serialize(config);
                //Console.WriteLine(xml);
                //var sqlToGraphiteConfig = genericSerializer.Deserialize<SqlToGraphiteConfig>(xml);
                //foreach (var job in sqlToGraphiteConfig.Jobs)
                //{
                    //Console.WriteLine(job.Type);
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #11
0
 public void Should_run_task_sending_two_results()
 {
     var job = new WmiClient();
     var client = new GraphiteTcpClient();
     var result1 = MockRepository.GenerateMock<IResult>();
     var result2 = MockRepository.GenerateMock<IResult>();
     var resultList = new List<IResult> { result1, result2 };
     this.dataClientFactory.Expect(x => x.Create(job)).Return(this.sqlClient);
     this.graphiteClientFactory.Expect(x => x.Create(client)).Return(this.statsClient);
     this.sqlClient.Expect(x => x.Get()).Return(resultList);
     statsClient.Expect(x => x.Send(resultList)).Repeat.Once();
     IRunTask runTask = new RunableRunTask(job, this.dataClientFactory, this.graphiteClientFactory, this.log, client);
     //Test
     runTask.Process();
     //Assert
     this.sqlClient.VerifyAllExpectations();
     this.dataClientFactory.VerifyAllExpectations();
     this.graphiteClientFactory.VerifyAllExpectations();
     statsClient.VerifyAllExpectations();
 }
Пример #12
0
        public void Should_validate_job_if_client_exist()
        {
            var clientName = "cName";
            var c = new GraphiteTcpClient();
            c.ClientName = clientName;

            var jobName = "jobName";
            var job = new WmiClient();
            job.Name = jobName;
            job.ClientName = clientName;

            var wi = CreateWorkItems(jobName, this.rolename1, 100);
            var t = new Template();
            t.WorkItems.Add(wi);
            this.config.Templates.Add(t);
            this.config.Jobs.Add(job);
            //var job = new SqlServer { Name = this.rolename1 };
            //job.ClientName = clientName;
            var h = new Host { Name = this.hostname1 };
            var r = new Role { Name = this.rolename1 };
            h.Roles.Add(r);
            this.config.Clients.Add(c);
            this.config.Hosts.Add(h);
            //config.Jobs.Add(job);
            //Test
            this.config.Validate();
        }