You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2014/05/20 14:21:35 UTC

[2/4] git commit: AMBARI-5821. Add unit tests for jobs models. (Max Shepel via akovalenko)

AMBARI-5821. Add unit tests for jobs models. (Max Shepel via akovalenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6d029a22
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6d029a22
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6d029a22

Branch: refs/heads/trunk
Commit: 6d029a22764bb30102b9a5beb2792040f0632515
Parents: de90972
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Tue May 20 15:08:24 2014 +0300
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Tue May 20 15:08:24 2014 +0300

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js         |   2 +
 ambari-web/test/models/jobs/job_test.js     |  98 ++++++++++++++++++++
 ambari-web/test/models/jobs/tez_dag_test.js | 111 +++++++++++++++++++++++
 3 files changed, 211 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6d029a22/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index d820fcd..f694cb9 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -172,6 +172,8 @@ require('test/views/wizard/step8_view_test');
 require('test/views/wizard/step9_view_test');
 require('test/views/wizard/step9/hostLogPopupBody_view_test');
 require('test/views/wizard/step10_view_test');
+require('test/models/jobs/job_test');
+require('test/models/jobs/tez_dag_test');
 require('test/models/service/flume_test');
 require('test/models/service/hbase_test');
 require('test/models/service/hdfs_test');

http://git-wip-us.apache.org/repos/asf/ambari/blob/6d029a22/ambari-web/test/models/jobs/job_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/jobs/job_test.js b/ambari-web/test/models/jobs/job_test.js
new file mode 100644
index 0000000..1ca21d8
--- /dev/null
+++ b/ambari-web/test/models/jobs/job_test.js
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+var modelSetup = require('test/init_model_test');
+require('models/jobs/job');
+
+var job,
+  jobData = {
+    id: 'job'
+  },
+  timeCases = [
+    {
+      toSet: 'startTime',
+      toExpect: 'startTimeDisplay'
+    },
+    {
+      toSet: 'endTime',
+      toExpect: 'endTimeDisplay'
+    }
+  ],
+  timeDataCorrect = {
+    startTime: 1000,
+    endTime: 2000
+  },
+  timeDataRunning = {
+    startTime: App.dateTime() - 1000,
+    endTime: undefined
+  },
+  timeDataIncorrect = {
+    startTime: App.dateTime() - 1000,
+    endTime: 1
+  };
+
+describe('App.AbstractJob', function () {
+
+  beforeEach(function () {
+    job = App.AbstractJob.createRecord(jobData);
+  });
+
+  afterEach(function () {
+    modelSetup.deleteRecord(job);
+  });
+
+  timeCases.forEach(function (item) {
+    var toSet = item.toSet,
+      toExpect = item.toExpect;
+    describe('#' + toExpect, function () {
+      it('should be empty', function () {
+        job.set(toSet, 0);
+        expect(job.get(toExpect)).to.be.empty;
+      });
+      it('should return formatted time', function () {
+        job.set(toSet, 1000000);
+        expect(job.get(toExpect)).to.equal('Thu, Jan 01, 1970 00:16');
+      });
+    });
+  });
+
+  describe('#duration', function () {
+    it('should calculate the difference between endTime and startTime', function () {
+      job.setProperties(timeDataCorrect);
+      expect(job.get('duration')).to.equal(1000);
+    });
+    it('should calculate the difference between current time and startTime if the job is running', function () {
+      job.setProperties(timeDataRunning);
+      expect(job.get('duration')).to.be.at.least(1000);
+    });
+    it('should calculate the difference between current time and startTime if endTime is incorrect', function () {
+      job.setProperties(timeDataIncorrect);
+      expect(job.get('duration')).to.be.at.least(1000);
+    });
+  });
+
+  describe('#durationDisplay', function () {
+    it('should return formatted string', function () {
+      job.setProperties(timeDataCorrect);
+      expect(job.get('durationDisplay')).to.equal('1.00 secs');
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/6d029a22/ambari-web/test/models/jobs/tez_dag_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/jobs/tez_dag_test.js b/ambari-web/test/models/jobs/tez_dag_test.js
new file mode 100644
index 0000000..17e6c7e
--- /dev/null
+++ b/ambari-web/test/models/jobs/tez_dag_test.js
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+var modelSetup = require('test/init_model_test');
+require('models/jobs/tez_dag');
+
+var vertex,
+  vertexData = {
+    id: 'vertex'
+  },
+  timeData = {
+    startTime: 1000,
+    endTime: 2000
+  },
+  tasksCases = [
+    {
+      count: 5,
+      number: 5,
+      title: 'should return tasks count'
+    },
+    {
+      count: null,
+      number: 0,
+      title: 'should return 0'
+    }
+  ],
+  dataSizeCases = [
+    {
+      file: 'fileReadBytes',
+      hdfs: 'hdfsReadBytes',
+      total: 'totalReadBytes',
+      totalDisplay: 'totalReadBytesDisplay'
+    },
+    {
+      file: 'fileWriteBytes',
+      hdfs: 'hdfsWriteBytes',
+      total: 'totalWriteBytes',
+      totalDisplay: 'totalWriteBytesDisplay'
+    }
+  ],
+  setDataSize = function (vertex, fileProp, fileVal, hdfsProp, hdfsVal) {
+    vertex.set(fileProp, fileVal);
+    vertex.set(hdfsProp, hdfsVal);
+  };
+
+describe('App.TezDagVertex', function () {
+
+  beforeEach(function () {
+    vertex = App.TezDagVertex.createRecord(vertexData);
+  });
+
+  afterEach(function () {
+    modelSetup.deleteRecord(vertex);
+  });
+
+  describe('#duration', function () {
+    it('should calculate the difference between endTime and startTime', function () {
+      vertex.setProperties(timeData);
+      expect(vertex.get('duration')).to.equal(1000);
+    });
+  });
+
+  tasksCases.forEach(function(item) {
+    describe('#tasksNumber', function () {
+      it(item.title, function () {
+        vertex.set('tasksCount', item.count);
+        expect(vertex.get('tasksNumber')).to.equal(item.number);
+      });
+    });
+  });
+
+  dataSizeCases.forEach(function (item) {
+    describe('#' + item.total, function () {
+      it('should sum ' + item.file + ' and ' + item.hdfs, function () {
+        setDataSize(vertex, item.file, 1024, item.hdfs, 2048);
+        expect(vertex.get(item.total)).to.equal(3072);
+      });
+    });
+    describe('#' + item.totalDisplay, function () {
+      it('should return formatted ' + item.total, function () {
+        setDataSize(vertex, item.file, 1024, item.hdfs, 2048);
+        expect(vertex.get(item.totalDisplay)).to.equal('3 KB');
+      });
+    });
+  });
+
+  describe('#durationDisplay', function () {
+    it('should return formatted string', function () {
+      vertex.setProperties(timeData);
+      expect(vertex.get('durationDisplay')).to.equal('1.00 secs');
+    });
+  });
+
+});