-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
saturn-console-api/src/test/java/com/vip/saturn/job/console/domain/ZkClusterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.vip.saturn.job.console.domain; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.beans.BeanUtils; | ||
|
||
public class ZkClusterTest { | ||
|
||
@Test | ||
public void testEqualsNoNeedReconnect() { | ||
ZkCluster zkCluster1 = new ZkCluster(); | ||
zkCluster1.setZkAlias("saturn"); | ||
zkCluster1.setZkAddr("127.0.0.1:2181"); | ||
zkCluster1.setZkClusterKey("saturn-zk"); | ||
zkCluster1.setDescription("cluster1"); | ||
|
||
ZkCluster zkCluster2 = new ZkCluster(); | ||
BeanUtils.copyProperties(zkCluster1, zkCluster2); | ||
zkCluster2.setDescription("cluster2"); | ||
|
||
Assert.assertFalse(zkCluster1.equals(zkCluster2)); | ||
Assert.assertTrue(zkCluster1.equalsNoNeedReconnect(zkCluster2)); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
.../src/test/java/com/vip/saturn/job/console/service/impl/RegistryCenterServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.vip.saturn.job.console.service.impl; | ||
|
||
import com.vip.saturn.job.console.domain.RegistryCenterConfiguration; | ||
import com.vip.saturn.job.console.domain.ZkCluster; | ||
import com.vip.saturn.job.console.exception.SaturnJobConsoleException; | ||
import com.vip.saturn.job.console.mybatis.service.NamespaceZkClusterMapping4SqlService; | ||
import com.vip.saturn.job.console.mybatis.service.ZkClusterInfoService; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
|
||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class RegistryCenterServiceImplTest { | ||
|
||
@Mock | ||
private LinkedHashMap<String, ZkCluster> zkClusterMap; | ||
|
||
@Mock | ||
private NamespaceZkClusterMapping4SqlService namespaceZkClusterMapping4SqlService; | ||
|
||
@Mock | ||
private ZkClusterInfoService zkClusterInfoService; | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
@InjectMocks | ||
private RegistryCenterServiceImpl registryCenterService; | ||
|
||
@Test | ||
public void testDeleteZkClusterFail() throws Exception { | ||
//delete fail | ||
when(zkClusterMap.get("empty")).thenReturn(null); | ||
try { | ||
registryCenterService.deleteZkCluster("empty"); | ||
fail("should not be here"); | ||
} catch (SaturnJobConsoleException e) { | ||
Assert.assertEquals("fail to delete.for ZkCluster does not exist", e.getMessage()); | ||
} | ||
|
||
//delete fail | ||
ZkCluster zkCluster = new ZkCluster(); | ||
ArrayList<RegistryCenterConfiguration> regCenterConfList = new ArrayList(); | ||
zkCluster.setRegCenterConfList(regCenterConfList); | ||
regCenterConfList.add(new RegistryCenterConfiguration()); | ||
when(zkClusterMap.get("hasDomains")).thenReturn(zkCluster); | ||
try { | ||
registryCenterService.deleteZkCluster("hasDomains"); | ||
fail("should not be here"); | ||
} catch (SaturnJobConsoleException e) { | ||
Assert.assertEquals("fail to delete.for ZkCluster still has domains", e.getMessage()); | ||
} | ||
|
||
//delete fail | ||
when(zkClusterMap.get("noDomainsInMemory")).thenReturn(new ZkCluster()); | ||
when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(Arrays.asList("")); | ||
try { | ||
registryCenterService.deleteZkCluster("noDomainsInMemory"); | ||
fail("should not be here"); | ||
} catch (SaturnJobConsoleException e) { | ||
Assert.assertEquals("fail to delete.for ZkCluster still has domains", e.getMessage()); | ||
} | ||
|
||
//delete success | ||
when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(null); | ||
registryCenterService.deleteZkCluster("noDomainsInMemory"); | ||
verify(zkClusterInfoService, times(1)).deleteZkCluster("noDomainsInMemory"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters