From c3ccf88aede72c0fa3726a29ac73dcd6a1bfa000 Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Tue, 31 Dec 2019 11:25:15 +0530 Subject: [PATCH 01/12] Issue #0000 refactor: Increase embedded cassandra timeout in api test cases --- .../src/test/scala/org/ekstep/analytics/api/BaseSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/BaseSpec.scala b/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/BaseSpec.scala index 7006eab98..0caa37a0e 100644 --- a/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/BaseSpec.scala +++ b/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/BaseSpec.scala @@ -20,7 +20,7 @@ class BaseSpec extends FlatSpec with Matchers with BeforeAndAfterAll with Mockit override def beforeAll() { if (embeddedCassandraMode) { System.setProperty("cassandra.unsafesystem", "true") - EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000L) + EmbeddedCassandraServerHelper.startEmbeddedCassandra(30000L) val session = DBUtil.session val dataLoader = new CQLDataLoader(session); dataLoader.load(new FileCQLDataSet(AppConf.getConfig("cassandra.cql_path"), true, true)); From 13ea1096f7da8edbc8d1d40e0caf18411aae70fc Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Tue, 31 Dec 2019 12:41:55 +0530 Subject: [PATCH 02/12] Issue #0000 refactor:Fix getMonthRange method in api CommonUtil --- .../main/scala/org/ekstep/analytics/api/util/CommonUtil.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala b/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala index 8bded5fb3..10e0034cc 100644 --- a/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala +++ b/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala @@ -66,8 +66,8 @@ object CommonUtil { def getMonthRange(count: Int): Range = { val endDate = DateTime.now(DateTimeZone.UTC); - val startDate = endDate.minusDays(count * 30); - Range(monthPeriod.print(startDate).toInt, monthPeriod.print(endDate).toInt) + val startMonth = endDate.minusMonths(count); + Range(monthPeriod.print(startMonth).toInt, monthPeriod.print(endDate).toInt) } def errorResponse(apiId: String, err: String, responseCode: String): Response = { From dcec42b85e61a7cf036d4fda52ea9685a6d232ef Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Tue, 31 Dec 2019 17:46:38 +0530 Subject: [PATCH 03/12] Issue #0000 refactor: Add fc.closeContext for report jobs --- .../analytics/api/util/CommonUtil.scala | 4 ++-- .../job/report/AssessmentMetricsJob.scala | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala b/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala index 10e0034cc..8bded5fb3 100644 --- a/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala +++ b/platform-api/analytics-api-core/src/main/scala/org/ekstep/analytics/api/util/CommonUtil.scala @@ -66,8 +66,8 @@ object CommonUtil { def getMonthRange(count: Int): Range = { val endDate = DateTime.now(DateTimeZone.UTC); - val startMonth = endDate.minusMonths(count); - Range(monthPeriod.print(startMonth).toInt, monthPeriod.print(endDate).toInt) + val startDate = endDate.minusDays(count * 30); + Range(monthPeriod.print(startDate).toInt, monthPeriod.print(endDate).toInt) } def errorResponse(apiId: String, err: String, responseCode: String): Response = { diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index df3dcee80..0faeedb55 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -26,14 +26,19 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo def main(config: String)(implicit sc: Option[SparkContext] = None, fc: Option[FrameworkContext] = None) { - JobLogger.init("Assessment Metrics") - JobLogger.start("Assessment Job Started executing", Option(Map("config" -> config, "model" -> name))) - val jobConfig = JSONUtils.deserialize[JobConfig](config) - JobContext.parallelization = jobConfig.parallelization.getOrElse(10) // Default to 10 - - implicit val sparkContext: SparkContext = getReportingSparkContext(jobConfig); - implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); - execute(jobConfig) + try { + JobLogger.init("Assessment Metrics") + JobLogger.start("Assessment Job Started executing", Option(Map("config" -> config, "model" -> name))) + val jobConfig = JSONUtils.deserialize[JobConfig](config) + JobContext.parallelization = jobConfig.parallelization.getOrElse(10) // Default to 10 + + implicit val sparkContext: SparkContext = getReportingSparkContext(jobConfig); + implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); + execute(jobConfig) + } + finally { + if(fc.nonEmpty) fc.get.closeContext(); + } } private def execute(config: JobConfig)(implicit sc: SparkContext, fc: FrameworkContext) = { From 405af93083e90299c1af74cfb45bd4d62464e7c1 Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Tue, 31 Dec 2019 18:14:28 +0530 Subject: [PATCH 04/12] Issue #0000 refactor: Add print statements for debugging --- .../org/ekstep/analytics/job/report/AssessmentMetricsJob.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index 0faeedb55..1f370434f 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -37,6 +37,7 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo execute(jobConfig) } finally { + println("framework context inside finally: " + fc.isEmpty) if(fc.nonEmpty) fc.get.closeContext(); } } From c0c95d59145da47ca9cf28c344eb831db4b3253f Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Tue, 31 Dec 2019 18:25:54 +0530 Subject: [PATCH 05/12] Issue #0000 refactor: Add print statements for debugging --- .../job/report/AssessmentMetricsJob.scala | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index 1f370434f..40dfcc66e 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -26,19 +26,21 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo def main(config: String)(implicit sc: Option[SparkContext] = None, fc: Option[FrameworkContext] = None) { - try { - JobLogger.init("Assessment Metrics") - JobLogger.start("Assessment Job Started executing", Option(Map("config" -> config, "model" -> name))) - val jobConfig = JSONUtils.deserialize[JobConfig](config) - JobContext.parallelization = jobConfig.parallelization.getOrElse(10) // Default to 10 - implicit val sparkContext: SparkContext = getReportingSparkContext(jobConfig); - implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); + JobLogger.init("Assessment Metrics") + JobLogger.start("Assessment Job Started executing", Option(Map("config" -> config, "model" -> name))) + val jobConfig = JSONUtils.deserialize[JobConfig](config) + JobContext.parallelization = jobConfig.parallelization.getOrElse(10) // Default to 10 + + implicit val sparkContext: SparkContext = getReportingSparkContext(jobConfig); + implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); + try { execute(jobConfig) } finally { + println("framework context: " + frameworkContext) println("framework context inside finally: " + fc.isEmpty) - if(fc.nonEmpty) fc.get.closeContext(); + if(fc.nonEmpty) frameworkContext.closeContext(); } } From af3dcc640ebd7583e40162bf83b18e6b9e33fdc2 Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Tue, 31 Dec 2019 18:49:05 +0530 Subject: [PATCH 06/12] Issue #0000 refactor: Add fc.closeContext for report jobs --- .../org/ekstep/analytics/job/report/AssessmentMetricsJob.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index 40dfcc66e..b75210d4c 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -38,9 +38,8 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo execute(jobConfig) } finally { - println("framework context: " + frameworkContext) println("framework context inside finally: " + fc.isEmpty) - if(fc.nonEmpty) frameworkContext.closeContext(); + if(fc.isEmpty) frameworkContext.closeContext(); } } From 485b7ae9fbd59e7444203baa4982e99b14d21668 Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Thu, 2 Jan 2020 12:11:31 +0530 Subject: [PATCH 07/12] Issue #0000 refactor: Add print statements for debugging --- .../scala/org/ekstep/analytics/framework/FrameworkContext.scala | 1 + .../org/ekstep/analytics/job/report/AssessmentMetricsJob.scala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala b/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala index c4a05b13d..052c0a7f8 100644 --- a/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala +++ b/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala @@ -50,6 +50,7 @@ class FrameworkContext { } def shutdownStorageService() = { + println("inside shutdownStorageService " + storageContainers.nonEmpty) if (null != storageContainers) { storageContainers.foreach(f => f._2.closeContext()); } diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index b75210d4c..eb67ef837 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -38,7 +38,7 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo execute(jobConfig) } finally { - println("framework context inside finally: " + fc.isEmpty) + println("fc inside finally: " + fc.isEmpty + "framework context: " + frameworkContext) if(fc.isEmpty) frameworkContext.closeContext(); } } From 3f2df6550f888be3a4cce10a1a451e90f3bbd15e Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Thu, 2 Jan 2020 13:40:49 +0530 Subject: [PATCH 08/12] Issue #0000 refactor: Add print statements for debugging --- .../org/ekstep/analytics/framework/FrameworkContext.scala | 1 + .../ekstep/analytics/job/report/AssessmentMetricsJob.scala | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala b/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala index 052c0a7f8..670f29e61 100644 --- a/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala +++ b/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala @@ -52,6 +52,7 @@ class FrameworkContext { def shutdownStorageService() = { println("inside shutdownStorageService " + storageContainers.nonEmpty) if (null != storageContainers) { + println("inside null check") storageContainers.foreach(f => f._2.closeContext()); } } diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index eb67ef837..17176c082 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -39,7 +39,10 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo } finally { println("fc inside finally: " + fc.isEmpty + "framework context: " + frameworkContext) - if(fc.isEmpty) frameworkContext.closeContext(); + if(fc.isEmpty) { + frameworkContext.closeContext(); + sparkContext.stop(); + } } } From 788dbe16cf54f00a9e7a657b6a1242387ed34699 Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Thu, 2 Jan 2020 16:12:26 +0530 Subject: [PATCH 09/12] Issue #0000 refactor: Add print statements for debugging --- .../scala/org/ekstep/analytics/framework/FrameworkContext.scala | 2 -- .../org/ekstep/analytics/job/report/AssessmentMetricsJob.scala | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala b/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala index 670f29e61..c4a05b13d 100644 --- a/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala +++ b/platform-framework/analytics-core/src/main/scala/org/ekstep/analytics/framework/FrameworkContext.scala @@ -50,9 +50,7 @@ class FrameworkContext { } def shutdownStorageService() = { - println("inside shutdownStorageService " + storageContainers.nonEmpty) if (null != storageContainers) { - println("inside null check") storageContainers.foreach(f => f._2.closeContext()); } } diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index 17176c082..df7f4937e 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -36,9 +36,9 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); try { execute(jobConfig) + frameworkContext.closeContext(); } finally { - println("fc inside finally: " + fc.isEmpty + "framework context: " + frameworkContext) if(fc.isEmpty) { frameworkContext.closeContext(); sparkContext.stop(); From bd9668342b8fd64306579c12134e978f7e51f33e Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Thu, 2 Jan 2020 17:26:45 +0530 Subject: [PATCH 10/12] Issue #0000 refactor: Remove print statements --- .../org/ekstep/analytics/job/report/AssessmentMetricsJob.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index df7f4937e..75e179b5a 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -36,12 +36,10 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); try { execute(jobConfig) - frameworkContext.closeContext(); } finally { if(fc.isEmpty) { frameworkContext.closeContext(); - sparkContext.stop(); } } } @@ -291,6 +289,7 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo FileUtil.renameReport(tempDir, renamedDir, batchId) val storageService = getReportStorageService(); storageService.upload(container, renamedDir, objectKey, isDirectory = Option(true)) + storageService.closeContext() } def saveToElastic(index: String, reportDF: DataFrame): Unit = { From 117b2d5efe799596f874bf59c15be38db1a7c16f Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Thu, 2 Jan 2020 18:21:04 +0530 Subject: [PATCH 11/12] Issue #0000 refactor: Fix for report jobs not exiting --- .../analytics/job/report/AssessmentMetricsJob.scala | 9 +-------- .../ekstep/analytics/job/report/CourseMetricsJob.scala | 1 + .../analytics/job/report/StateAdminGeoReportJob.scala | 1 + .../analytics/job/report/StateAdminReportJob.scala | 1 + 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala index 75e179b5a..67b701216 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/AssessmentMetricsJob.scala @@ -34,14 +34,7 @@ object AssessmentMetricsJob extends optional.Application with IJob with BaseRepo implicit val sparkContext: SparkContext = getReportingSparkContext(jobConfig); implicit val frameworkContext: FrameworkContext = getReportingFrameworkContext(); - try { - execute(jobConfig) - } - finally { - if(fc.isEmpty) { - frameworkContext.closeContext(); - } - } + execute(jobConfig) } private def execute(config: JobConfig)(implicit sc: SparkContext, fc: FrameworkContext) = { diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/CourseMetricsJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/CourseMetricsJob.scala index 1d7dfaadc..18e9a3e65 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/CourseMetricsJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/CourseMetricsJob.scala @@ -337,6 +337,7 @@ object CourseMetricsJob extends optional.Application with IJob with ReportGenera val objectKey = AppConf.getConfig("course.metrics.cloud.objectKey") val storageService = getReportStorageService(); storageService.upload(container, sourcePath, objectKey, isDirectory = Option(true)) + storageService.closeContext() } private def recursiveListFiles(file: File, ext: String): Array[File] = { diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminGeoReportJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminGeoReportJob.scala index 4c0b80f86..105590f4d 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminGeoReportJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminGeoReportJob.scala @@ -106,6 +106,7 @@ object StateAdminGeoReportJob extends optional.Application with IJob with StateA val storageService = getReportStorageService(); storageService.upload(container, sourcePath, objectKey, isDirectory = Option(true)) + storageService.closeContext() } } diff --git a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminReportJob.scala b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminReportJob.scala index 548873970..3fde394c2 100644 --- a/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminReportJob.scala +++ b/platform-modules/batch-models/src/main/scala/org/ekstep/analytics/job/report/StateAdminReportJob.scala @@ -254,6 +254,7 @@ object StateAdminReportJob extends optional.Application with IJob with StateAdmi val storageService = getReportStorageService(); storageService.upload(container, sourcePath, objectKey, isDirectory = Option(true)) + storageService.closeContext() } def dataFrameToJsonFile(dataFrame: DataFrame)(implicit fc: FrameworkContext): Unit = { From 7c38e36cd9281955439dfc13a1f811650d11e5f7 Mon Sep 17 00:00:00 2001 From: SowmyaDixit Date: Thu, 2 Jan 2020 19:32:14 +0530 Subject: [PATCH 12/12] Issue #0000 refactor:Fix getMonthRange method in api CommonUtil --- .../org/ekstep/analytics/api/util/TestCommonUtil.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/util/TestCommonUtil.scala b/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/util/TestCommonUtil.scala index 6ee62235d..a8a27ba89 100644 --- a/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/util/TestCommonUtil.scala +++ b/platform-api/analytics-api-core/src/test/scala/org/ekstep/analytics/api/util/TestCommonUtil.scala @@ -1,5 +1,6 @@ package org.ekstep.analytics.api.util +import org.ekstep.analytics.api.util.CommonUtil.monthPeriod import org.ekstep.analytics.api.{BaseSpec, Range, ResponseCode} import org.joda.time.format.{DateTimeFormat, DateTimeFormatter} import org.joda.time.{DateTime, DateTimeZone, Duration} @@ -14,7 +15,7 @@ class TestCommonUtil extends BaseSpec { val thisYear: Int = (new DateTime).getYear val thisMonth: Int = (new DateTime).getMonthOfYear val thisWeekNo = (new DateTime).getWeekOfWeekyear - val monthYear = Integer.parseInt(s"$thisYear"+s"$thisMonth") + val monthYear = monthPeriod.print(new DateTime).toInt val now = DateTime.now(DateTimeZone.UTC) val dateInt = Integer.parseInt(dateFormat.print(now).replace("-", "")) @@ -32,7 +33,8 @@ class TestCommonUtil extends BaseSpec { resp3.params.status should be("successful"); resp3.result.get should be(Map("ttl" -> 24.asInstanceOf[AnyRef])); CommonUtil.getDayRange(7) should be(Range(Integer.parseInt(dateFormat.print(now.minusDays(7)).replace("-", "")), dateInt)) - CommonUtil.getMonthRange(2) should be(Range(monthYear-2, monthYear)) + val startMonth = monthPeriod.print((new DateTime).minusMonths(2)).toInt + CommonUtil.getMonthRange(2) should be(Range(startMonth, monthYear)) CommonUtil.getRemainingHours() should be(remainingTime) CommonUtil.getWeeksBetween(1451650400000L, 1454650400000L) should be(5);