You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/02/26 05:54:20 UTC

[GitHub] coolbeevip commented on a change in pull request #415: [SCB-1171] Improve unit test coverage for ClusterLockServiceTest

coolbeevip commented on a change in pull request #415: [SCB-1171] Improve unit test coverage for ClusterLockServiceTest
URL: https://github.com/apache/servicecomb-pack/pull/415#discussion_r260135186
 
 

 ##########
 File path: alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/cluster/master/ClusterLockServiceTest.java
 ##########
 @@ -60,33 +63,105 @@
   ClusterLockService clusterLockService;
 
   @MockBean
-  private MasterLockRepository masterLockRepository;
+  private MasterLockEntityRepository masterLockEntityRepository;
 
-  @Test(timeout = 10000)
-  public void testClusterNodeType() throws InterruptedException {
-    //node type is master
-    clusterLockService.setMasterLock(null);
+  @Autowired
+  MasterLockRepository masterLockRepository;
+
+
+  @Test(timeout = 5000)
+  public void testMasterNode() throws InterruptedException {
+    MasterLock masterLock = clusterLockService.getMasterLock();
+    Assert.assertEquals(masterLock.getServiceName(),serviceName);
+    Assert.assertEquals(masterLock.getInstanceId(),instanceId);
+    Assert.assertEquals((masterLock.getExpireTime().getTime()-masterLock.getLockedTime().getTime()),expire);
+    when(masterLockEntityRepository.initLock(Mockito.anyString(),Mockito.any(Date.class),Mockito.any(Date.class),Mockito.anyString())).thenReturn(1);
+    when(masterLockEntityRepository.findMasterLockByServiceName(Mockito.anyString())).thenReturn(Optional.of(masterLock));
+    when(masterLockEntityRepository.updateLock(Mockito.anyString(),Mockito.any(Date.class),Mockito.any(Date.class),Mockito.anyString())).thenReturn(1);
+    Thread.sleep(2000);
 
 Review comment:
   OK, I will replace Mockito.any() with any()

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services