public void Should_throw_exception_if_unknown_type()
 {
     var graphiteParams = new GraphiteParams("hostname", 8125);
     var taskParams = new TaskParams("path", "sql", "cs", "wmi", "name", "unknown");
     var ex = Assert.Throws<UnknownGraphiteClientTypeException>(() => clientFactory.Create(graphiteParams, taskParams));
     Assert.That(ex.Message, Is.EqualTo("Unknown Graphite Client Type: unknown"));
 }
 private Task CreateTask(string hostName, GraphiteClient client, SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask item)
 {
     var graphiteParams = new GraphiteParams(hostName, client.Port);
     var taskParams = new TaskParams(item.path, item.sql, item.connectionstring, item.type, item.name, item.client);
     var task = new Task(taskParams, this.dataClientFactory, this.graphiteClientFactory, graphiteParams, log);
     return task;
 }
 public void Should_get_results()
 {
     var param = new TaskParams("path", "SELECT [dbms_id] FROM [msdb].[dbo].[MSdbms]", ConnectionString, "SqlServer", "name", "statsdudp");
     var log = MockRepository.GenerateMock<ILog>();
     var sqlServerClient = new SqlServerClient(log, param);
     var results = sqlServerClient.Get();
     Assert.That(results.Count, Is.EqualTo(8));
 }
 public void Should_get_multiple_results()
 {
     var param = new TaskParams("path", "SELECT  23 , 'name' FROM    dual CONNECT BY  level <= 8", ConnectionString, "SqlServer", "name", "statsdudp");
     var log = MockRepository.GenerateMock<ILog>();
     var client = new OracleClient(log, param);
     var results = client.Get();
     Assert.That(results.Count, Is.EqualTo(8));
 }
Exemple #5
0
 public Task(TaskParams taskParams, IDataClientFactory dataClientFactory, IGraphiteClientFactory graphiteClientFactory, GraphiteParams graphiteParams, ILog log)
 {
     this.taskParams = taskParams;
     this.dataClientFactory = dataClientFactory;
     this.graphiteClientFactory = graphiteClientFactory;
     this.graphiteParams = graphiteParams;
     this.log = log;
 }
        public void Should_create_oracle_client()
        {
            var taskParams = new TaskParams("path", "sql", "cs", OracleType, "name", "client");
            var o = this.dataClientFactory.Create(taskParams);

            Assert.That(o, Is.Not.Null);
            Assert.That(o, Is.TypeOf(typeof(OracleClient)));
            Assert.That(o, Is.TypeOf<OracleClient>());
        }
        public void Should_create_sql_server_client()
        {
            var taskParams = new TaskParams("path", "sql", "cs", SqlServerType, "name", "client");
            var o = this.dataClientFactory.Create(taskParams);

            Assert.That(o, Is.Not.Null);
            Assert.That(o, Is.TypeOf(typeof(SqlServerClient)));
            Assert.That(o, Is.TypeOf<SqlServerClient>());
        }
        public void Should_create_wmi_client_lowercase()
        {
            var taskParams = new TaskParams("path", "sql", "cs", WmiType, "name", "client");
            var o = this.dataClientFactory.Create(taskParams);

            Assert.That(o, Is.Not.Null);
            Assert.That(o, Is.TypeOf(typeof(WmiClient)));
            Assert.That(o, Is.TypeOf<WmiClient>());
        }
        public void Should_create_statsd_client_uppercase()
        {
            var graphiteParams = new GraphiteParams("localhost", 8125);
            var taskParams = new TaskParams("path", "sql", "cs", "wmi", "name", "STATSduDp");
            var o = clientFactory.Create(graphiteParams, taskParams);

            Assert.That(o, Is.Not.Null);
            Assert.That(o, Is.TypeOf(typeof(StatsdClient)));
            Assert.That(o, Is.TypeOf<StatsdClient>());
        }
        public void Should_create_native_graphitetcp_client()
        {
            var taskParams = new TaskParams("path", "sql", "cs", "wmi", "name", "graphitetcp");
            var graphiteParams = new GraphiteParams("hostname", 8125);
            var o = clientFactory.Create(graphiteParams, taskParams);

            Assert.That(o, Is.Not.Null);
            Assert.That(o, Is.TypeOf(typeof(GraphiteTcpClient)));
            Assert.That(o, Is.TypeOf<GraphiteTcpClient>());
        }
        public ISqlClient Create(TaskParams taskParams)
        {
            var t = Type.GetType(taskParams.Type);
            if (t == null)
            {
                throw new UnknownDataClientException(taskParams.Type);
            }

            var obj = Activator.CreateInstance(t, new object[] { log, taskParams });
            return (ISqlClient)obj;
        }
 public void Should_get_wmi_data()
 {
     var log = MockRepository.GenerateMock<ILog>();
     var taskParams = new TaskParams("path", "SELECT PercentFreeSpace, Name FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk Where Name <> '_Total'", string.Empty, "wmi", "nme", "statsdudp");
     var wmiClient = new WmiClient(log, taskParams);
     var results = wmiClient.Get();
     Assert.That(results[0].Value, Is.GreaterThan(0));
     Assert.That(results[0].Name == "C" || results[0].Name == "D");
     Assert.That(results[1].Value, Is.GreaterThan(0));
     Assert.That(results[1].Name == "C" || results[1].Name == "D");
 }
 public void Should_get_result()
 {
     var name = Guid.NewGuid().ToString();
     var param = new TaskParams("path", "SELECT COUNT(*) as count FROM [master].[dbo].[spt_monitor]", ConnectionString, "SqlServer", name, "Statsdudp");
     var log = MockRepository.GenerateMock<ILog>();
     var sqlServerClient = new SqlServerClient(log, param);
     //Test
     var results = sqlServerClient.Get();
     //Asset
     Assert.That(results.Count, Is.EqualTo(1));
     Assert.That(results[0].Name, Is.EqualTo(name));
     Assert.That(results.Count, Is.EqualTo(1));
 }
 public void Should_get_result()
 {
     var name = Guid.NewGuid().ToString();
     var sql = string.Format("SELECT level, '{0}',  to_date('2012-FEB-03 00:00:01', 'YYYY-MON-DD HH24:MI:SS') FROM    dual CONNECT BY  level <= 100", name);
     var param = new TaskParams("path", sql, ConnectionString, "Oracle", name, "Statsdudp");
     var log = MockRepository.GenerateMock<ILog>();
     var client = new OracleClient(log, param);
     //Test
     var results = client.Get();
     //Asset
     Assert.That(results.Count, Is.EqualTo(100));
     Assert.That(results[0].Name, Is.EqualTo(name));
     Assert.That(results[0].TimeStamp, Is.EqualTo(new DateTime(2012, 02, 03, 00, 00, 01)));
 }
 public void Should_get_result_with_date_and_name_set_in_select()
 {
     var name = Guid.NewGuid().ToString();
     var sql = string.Format("SELECT  '{0}',  to_date('2012-FEB-03 00:00:01', 'YYYY-MON-DD HH24:MI:SS') , 234 FROM    dual CONNECT BY  level <= 1", name);
     var param = new TaskParams("path", sql, ConnectionString, "Oracle", name, "Statsdudp");
     var log = MockRepository.GenerateMock<ILog>();
     var client = new OracleClient(log, param);
     //Test
     var results = client.Get();
     //Asset
     Assert.That(results.Count, Is.EqualTo(1));
     Assert.That(results[0].Name, Is.EqualTo(name));
     Assert.That(results[0].Path, Is.EqualTo("path"));
     Assert.That(results[0].Value, Is.EqualTo(234));
 }
 public void Should_get_result_with_date_and_name_set_in_select()
 {
     var name = Guid.NewGuid().ToString();
     var param = new TaskParams("path", "SELECT 234 , DATEADD(day,11,GETDATE()), 'someName'", ConnectionString, "SqlServer", name, "statsdudp");
     var log = MockRepository.GenerateMock<ILog>();
     var sqlServerClient = new SqlServerClient(log, param);
     //Test
     var results = sqlServerClient.Get();
     //Asset
     var futureDate = DateTime.Now.Add(new TimeSpan(11, 0, 0, 0));
     Assert.That(results.Count, Is.EqualTo(1));
     Assert.That(results[0].Name, Is.EqualTo("someName"));
     Assert.That(results[0].Path, Is.EqualTo("path"));
     Assert.That(results[0].Value, Is.EqualTo(234));
 }
 public void Should_try_controller()
 {
     var log = LogManager.GetLogger("log");
     log4net.Config.XmlConfigurator.Configure();
     //var host = "metrics.london.ttldev.local";
     //var port = 2003;
     //var connectionString = "Data Source=nuget.london.ttldev.local;Initial Catalog=GoReportingSvn3;User Id=sa;Password=!bcde1234;";
     //var sqlGetter = new SqlGetter(connectionString, host, port, log);
     //var sql = "SELECT [Assigned],DateDiff(s,[Scheduled],[Assigned]) FROM [GoReportingSvn3].[dbo].[V_BuildStateTransition] where Scheduled > '2012-01-01'";
     //sqlGetter.Process("owain.test.Tlsvn3.Assigned", sql);
     var ds = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.244.127.11)(PORT=1532)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=tracslg2)));User Id=temp_ttl_user;Password=tt1r34dj0b;";
     var taskParam = new TaskParams("ThePath", "SELECT concat(dm_code,concat('_',current_ds_code)) AS dm, COUNT(DISTINCT (d.ID)) AS dm_count FROM DELIVERIES D WHERE d.tr_ID >= (SELECT TR_ID FROM TRANSACTION_FIRSTOFDAY WHERE date_of_tr = TRUNC(SYSDATE)) GROUP BY dm_code, current_ds_code", ds, "Oracle", "name", "graphiteudp");
     var tasks = new List<ITask> { new Task(taskParam, new DataClientFactory(log), new GraphiteClientFactory(log), new GraphiteParams("hostname", 1234), log) };
     var set = new TaskSet(tasks, new Stop(), 1000);
     var sleep = new Sleeper();
     var stop = new Stop();
     var controller = new Controller(set, sleep, stop, log);
     controller.Process();
 }
 public void Should_run_task_sending_one_result()
 {
     var result = MockRepository.GenerateMock<IResult>();
     var resultList = new List<IResult> { result };
     var param = new TaskParams("path", "sql", "cs", "SqlServer", "name", "client");
     this.dataClientFactory.Expect(x => x.Create(param)).Return(this.sqlClient);
     this.sqlClient.Expect(x => x.Get()).Return(resultList);
     statsClient.Expect(x => x.Send(result));
     var graphiteParams = new GraphiteParams("host", 1234);
     this.graphiteClientFactory.Expect(x => x.Create(graphiteParams, param)).Return(this.statsClient);
     ITask task = new Task(param, this.dataClientFactory, this.graphiteClientFactory, graphiteParams, log);
     //Test
     task.Process();
     //Assert
     this.sqlClient.VerifyAllExpectations();
     this.dataClientFactory.VerifyAllExpectations();
     this.graphiteClientFactory.VerifyAllExpectations();
     statsClient.VerifyAllExpectations();
 }
        public void Should_get_result_with_date()
        {
            var name = Guid.NewGuid().ToString();
            var param = new TaskParams(
                "path", "SELECT 234 , DATEADD(day,11,GETDATE())", ConnectionString, "SqlServer", name, "statsdudp");

            var log = MockRepository.GenerateMock<ILog>();
            var sqlServerClient = new SqlServerClient(log, param);
            //Test
            var results = sqlServerClient.Get();
            //Asset
            var futureDate = DateTime.Now.Add(new TimeSpan(11, 0, 0, 0));
            Assert.That(results.Count, Is.EqualTo(1));
            Assert.That(results[0].Name, Is.EqualTo(name));
            Assert.That(results[0].Value, Is.EqualTo(234));
            Assert.That(results[0].TimeStamp.Day, Is.EqualTo(futureDate.Day));
            Assert.That(results[0].TimeStamp.Hour, Is.EqualTo(futureDate.Hour));
            Assert.That(results[0].TimeStamp.Minute, Is.EqualTo(futureDate.Minute));
            Assert.That(results[0].TimeStamp.Year, Is.EqualTo(futureDate.Year));
        }
        public IStatsClient Create(GraphiteParams graphiteParams, TaskParams taskParams)
        {
            var clientType = taskParams.Client.ToLower();
            log.Debug(string.Format("Creating a graphite client of type: {0} with values {1} {2}", taskParams.Client, graphiteParams.Hostname, graphiteParams.Port));
            if (clientType == "graphitetcp")
            {
                return new GraphiteTcpClient(graphiteParams.Hostname, graphiteParams.Port);
            }

            if (clientType == "graphiteudp")
            {
                return new GraphiteUdpClient(graphiteParams.Hostname, graphiteParams.Port);
            }

            if (clientType == "statsdudp")
            {
                return new StatsdClient(graphiteParams.Hostname, graphiteParams.Port);
            }

            throw new UnknownGraphiteClientTypeException(string.Format("{0} {1}", ErrorMessage, clientType));
        }
 public void Should_throw_UnknownDataClientException()
 {
     var taskParams = new TaskParams("path", "sql", "cs", "unknown", "name", "client");
     var ex = Assert.Throws<UnknownDataClientException>(() => this.dataClientFactory.Create(taskParams));
     Assert.That(ex.Message, Is.EqualTo(string.Format("{0}", "unknown")));
 }