Ejemplo n.º 1
0
 public void Should_not_validate_host_if_host_role_does_not_exist()
 {
     var h = new Host { Name = this.hostname1 };
     var r = new Role { Name = this.rolename1 };
     h.Roles.Add(r);
     this.config.Hosts.Add(h);
     //Test
     var ex = Assert.Throws<RoleNotDefinedForHostException>(() => this.config.Validate());
     //Test
     Assert.That(ex.Message, Is.EqualTo(string.Format("The role {0} has not been defined for host {1}", this.rolename1, this.hostname1)));
 }
Ejemplo n.º 2
0
 public void Should_add_single_host()
 {
     var h = new Host { Name = this.hostname1 };
     var r = new Role { Name = this.rolename1 };
     h.Roles.Add(r);
     this.config.Hosts.Add(h);
     //Test
     var sqlToGraphiteConfig = Helper.SerialiseDeserialise(this.config);
     //Assert
     Assert.That(sqlToGraphiteConfig.Hosts[0].Name, Is.EqualTo(this.hostname1));
     Assert.That(sqlToGraphiteConfig.Hosts[0].Roles[0].Name, Is.EqualTo(this.rolename1));
 }
Ejemplo n.º 3
0
 public void Should_add_multiple_hosts_of_same_type()
 {
     var h1 = new Host { Name = this.hostname1 };
     var h2 = new Host { Name = this.hostname2 };
     var r1 = new Role { Name = this.rolename1 };
     var r2 = new Role { Name = this.rolename2 };
     h1.Roles.Add(r1);
     this.config.Hosts.Add(h1);
     h2.Roles.Add(r2);
     this.config.Hosts.Add(h2);
     //Test
     var sqlToGraphiteConfig = Helper.SerialiseDeserialise(this.config);
     //Assert
     Assert.That(sqlToGraphiteConfig.Hosts[0].Name, Is.EqualTo(this.hostname1));
     Assert.That(sqlToGraphiteConfig.Hosts[0].Roles[0].Name, Is.EqualTo(this.rolename1));
     Assert.That(sqlToGraphiteConfig.Hosts[1].Name, Is.EqualTo(this.hostname2));
     Assert.That(sqlToGraphiteConfig.Hosts[1].Roles[0].Name, Is.EqualTo(this.rolename2));
 }
        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());
            }
        }
Ejemplo n.º 5
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();
        }