You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2017/06/26 01:09:58 UTC
incubator-griffin git commit: 20170623service u tcoverage80percent
Repository: incubator-griffin
Updated Branches:
refs/heads/master f1ad4b7b6 -> 04a108375
20170623service u tcoverage80percent
Author: Chen <xi...@lm-shc-16501061.corp.ebay.com>
Closes #83 from justACT/20170623serviceUTcoverage80percent.
Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/04a10837
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/04a10837
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/04a10837
Branch: refs/heads/master
Commit: 04a1083755c35dfe9ec66f0ae9f9218b7a157f33
Parents: f1ad4b7
Author: Chen <xi...@lm-shc-16501061.corp.ebay.com>
Authored: Mon Jun 26 09:09:40 2017 +0800
Committer: William Guo <gu...@icloud.com>
Committed: Mon Jun 26 09:09:40 2017 +0800
----------------------------------------------------------------------
.../griffin/core/schedule/ScheduleResult.java | 14 +++----
.../griffin/core/schedule/SparkSubmitJob.java | 7 ++--
.../metastore/HiveMetastoreServiceImplTest.java | 42 +++++++++++++++++++-
.../core/schedule/SchedulerServiceImplTest.java | 27 ++++++++++++-
.../core/schedule/SparkSubmitJobTest.java | 31 ++++++++++-----
5 files changed, 97 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/04a10837/service/src/main/java/org/apache/griffin/core/schedule/ScheduleResult.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/ScheduleResult.java b/service/src/main/java/org/apache/griffin/core/schedule/ScheduleResult.java
index d8622d6..0c84f4f 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/ScheduleResult.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/ScheduleResult.java
@@ -74,11 +74,11 @@ public class ScheduleResult {
public ScheduleResult() {
}
- public ScheduleResult(long id, String state, String appId, JsonObject appInfo, ArrayList<JsonObject> log) {
- this.id = id;
- this.state = state;
- this.appId = appId;
- this.appInfo = appInfo;
- this.log = log;
- }
+// public ScheduleResult(long id, String state, String appId, JsonObject appInfo, ArrayList<JsonObject> log) {
+// this.id = id;
+// this.state = state;
+// this.appId = appId;
+// this.appInfo = appInfo;
+// this.log = log;
+// }
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/04a10837/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
----------------------------------------------------------------------
diff --git a/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java b/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
index f66c599..eded651 100644
--- a/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
+++ b/service/src/main/java/org/apache/griffin/core/schedule/SparkSubmitJob.java
@@ -76,6 +76,9 @@ public class SparkSubmitJob implements Job {
String eachJoblastTimestamp;
String periodTime;
+ RestTemplate restTemplate = new RestTemplate();
+
+
String uri;
SparkJobDO sparkJobDO = new SparkJobDO();
@@ -123,7 +126,7 @@ public class SparkSubmitJob implements Job {
jd.getJobDataMap().put("lastTime", currentTimstamp + "");
}
//final String uri = "http://10.9.246.187:8998/batches";
- RestTemplate restTemplate = new RestTemplate();
+// RestTemplate restTemplate = new RestTemplate();
setSparkJobDO();
String result = restTemplate.postForObject(uri, sparkJobDO, String.class);
logger.info(result);
@@ -236,9 +239,7 @@ public class SparkSubmitJob implements Job {
;
try {
String propFileName = "sparkJob.properties";
-
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
-
if (inputStream != null) {
prop.load(inputStream);
} else {
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/04a10837/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
index 9934e5d..914203d 100644
--- a/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
+++ b/service/src/test/java/org/apache/griffin/core/metastore/HiveMetastoreServiceImplTest.java
@@ -16,10 +16,13 @@ limitations under the License.
package org.apache.griffin.core.metastore;
import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.Table;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -34,11 +37,12 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.doNothing;
@RunWith(SpringRunner.class)
-//@TestPropertySource(properties = {"hive.metastore.uris=thrift://10.9.246.187:9083"})
public class HiveMetastoreServiceImplTest {
+ private static final Logger log = LoggerFactory.getLogger(HiveMetastoreServiceImplTest.class);
@TestConfiguration
public static class HiveMetastoreServiceConfiguration{
@@ -67,6 +71,13 @@ public class HiveMetastoreServiceImplTest {
}catch (Throwable t){
fail("Cannot get all tables from all dbs");
}
+ try {
+ given(client.getAllDatabases()).willThrow(MetaException.class);
+ doNothing().when(client).reconnect();
+ service.getAllDatabases();
+ } catch (MetaException e) {
+ log.info("testGetAllDatabases: test catch "+e);
+ }
}
@@ -75,9 +86,17 @@ public class HiveMetastoreServiceImplTest {
try {
Iterable<String> tmp = service.getAllTableNames("default");
assertTrue(true);
+
}catch (Throwable t){
fail("Cannot get all tables in db default");
}
+ try {
+ given(client.getAllTables("default")).willThrow(MetaException.class);
+ doNothing().when(client).reconnect();
+ service.getAllTableNames("default");
+ } catch (MetaException e) {
+ log.info("testGetAllTableNames: test catch "+e);
+ }
}
@Test
@@ -90,6 +109,13 @@ public class HiveMetastoreServiceImplTest {
}catch (Throwable t){
fail("Cannot get all tables in default db");
}
+ try {
+ given(client.getAllTables("default")).willThrow(MetaException.class);
+ doNothing().when(client).reconnect();
+ service.getAllTable("default");
+ } catch (Exception e) {
+ log.info("testGetAllTableByDBName: test catch "+e);
+ }
}
@Test
@@ -104,6 +130,13 @@ public class HiveMetastoreServiceImplTest {
}catch (Throwable t){
fail("Cannot get all table in map format");
}
+ try {
+ given(client.getAllTables("default")).willThrow(MetaException.class);
+ doNothing().when(client).reconnect();
+ service.getAllTable();
+ } catch (Exception e) {
+ log.info("testGetAllTable: test catch "+e);
+ }
}
@Test
@@ -114,5 +147,12 @@ public class HiveMetastoreServiceImplTest {
}catch (Throwable t){
fail("Cannot get xxx table in default db");
}
+ try {
+ given(client.getTable("default","xxx")).willThrow(MetaException.class);
+ doNothing().when(client).reconnect();
+ service.getTable("default","xxx");
+ } catch (Exception e) {
+ log.info("testGetDesignatedTable: test catch "+e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/04a10837/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
index 372db9e..9f00c8f 100644
--- a/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
+++ b/service/src/test/java/org/apache/griffin/core/schedule/SchedulerServiceImplTest.java
@@ -23,6 +23,8 @@ import org.mockito.Mockito;
import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;
import org.quartz.impl.triggers.CronTriggerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -43,6 +45,7 @@ import static org.mockito.BDDMockito.given;
@RunWith(SpringRunner.class)
public class SchedulerServiceImplTest {
+ private static final Logger log = LoggerFactory.getLogger(SchedulerServiceImplTest.class);
@TestConfiguration
public static class SchedulerServiceConfiguration{
@@ -128,9 +131,9 @@ public class SchedulerServiceImplTest {
@Test
public void testDeleteJob(){
+ String groupName="BA";
+ String jobName="job1";
try {
- String groupName="BA";
- String jobName="job1";
Scheduler scheduler=Mockito.mock(Scheduler.class);
given(factory.getObject()).willReturn(scheduler);
Boolean tmp = service.deleteJob(groupName,jobName);
@@ -138,6 +141,12 @@ public class SchedulerServiceImplTest {
}catch (Throwable t){
fail("Cannot delete job");
}
+ try {
+ given(factory.getObject()).willThrow(SchedulerException.class);
+ Boolean tmp = service.deleteJob(groupName,jobName);
+ } catch (Exception e) {
+ log.info("testGetAllTable: test catch "+e);
+ }
}
@Test
@@ -167,9 +176,23 @@ public class SchedulerServiceImplTest {
Pageable pageRequest=new PageRequest(0,1, Sort.Direction.DESC,"timestamp");
List<ScheduleState> scheduleStateList=new ArrayList<ScheduleState>();
+ ScheduleState scheduleState1=new ScheduleState();
+ scheduleState1.setGroupName("BA");
+ scheduleState1.setJobName("job1");
+ scheduleState1.setScheduleid(1);
+ scheduleState1.setState("starting");
+ scheduleState1.setAppId("ttt");
+ scheduleState1.setTimestamp(System.currentTimeMillis());
+ scheduleStateList.add(scheduleState1);
given(scheduleStateRepo.findByGroupNameAndJobName(jobKey.getGroup(),jobKey.getName(),pageRequest)).willReturn(scheduleStateList);
JobHealth tmp = service.getHealthInfo();
assertTrue(true);
+
+ scheduleStateList.remove(0);
+ scheduleState1.setState("down");
+ scheduleStateList.add(scheduleState1);
+ given(scheduleStateRepo.findByGroupNameAndJobName(jobKey.getGroup(),jobKey.getName(),pageRequest)).willReturn(scheduleStateList);
+ JobHealth tmp1 = service.getHealthInfo();
}catch (Throwable t){
fail("Cannot get Health info "+t);
}
http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/04a10837/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
----------------------------------------------------------------------
diff --git a/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java b/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
index f852893..8da1f1b 100644
--- a/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
+++ b/service/src/test/java/org/apache/griffin/core/schedule/SparkSubmitJobTest.java
@@ -24,13 +24,11 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
@@ -42,19 +40,22 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(SparkSubmitJob.class)
+//@RunWith(PowerMockRunner.class)
+//@PrepareForTest(SparkSubmitJob.class)
+@RunWith(SpringRunner.class)
public class SparkSubmitJobTest{
private SparkSubmitJob ssj;
- @Autowired
+// @Autowired
+ @MockBean
MeasureRepo measureRepo;
@Before
public void setUp() throws IOException {
ssj=new SparkSubmitJob();
ssj.measureRepo=mock(MeasureRepo.class);
+ ssj.restTemplate= mock(RestTemplate.class);
}
@Test
@@ -76,18 +77,26 @@ public class SparkSubmitJobTest{
when(ssj.measureRepo.findByName("bevssoj")).thenReturn(measure);
RestTemplate restTemplate =Mockito.mock(RestTemplate.class);
- PowerMockito.whenNew(RestTemplate.class).withAnyArguments().thenReturn(restTemplate);
- String uri="";
+// PowerMockito.whenNew(RestTemplate.class).withAnyArguments().thenReturn(restTemplate);
+ String uri=ssj.uri;
SparkJobDO sparkJobDO= Mockito.mock(SparkJobDO.class);
- PowerMockito.when(restTemplate.postForObject(uri, sparkJobDO, String.class)).thenReturn(null);
+// PowerMockito.when(restTemplate.postForObject(uri, sparkJobDO, String.class)).thenReturn(null);
+ when(restTemplate.postForObject(uri, sparkJobDO, String.class)).thenReturn(null);
ssj.execute(context);
long currentSystemTimestamp=System.currentTimeMillis();
long currentTimstamp = ssj.setCurrentTimestamp(currentSystemTimestamp);
-//
+
verify(ssj.measureRepo).findByName("bevssoj");
verify(jdmap,atLeast(2)).put("lastTime",currentTimstamp+"");
+ when(ssj.measureRepo.findByName("bevssoj")).thenReturn(null);
+ ssj.execute(context);
+
+ when(ssj.measureRepo.findByName("bevssoj")).thenReturn(measure);
+ String result="{\"id\":8718,\"state\":\"starting\",\"appId\":null,\"appInfo\":{\"driverLogUrl\":null,\"sparkUiUrl\":null},\"log\":[]}";
+ when(restTemplate.postForObject(uri, sparkJobDO, String.class)).thenReturn(result);
+ ssj.execute(context);
}
private Measure createATestMeasure(String name,String org)throws IOException,Exception{