-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from lepdou/namespace_delete
improve delete namespace
- Loading branch information
Showing
15 changed files
with
217 additions
and
36 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
94 changes: 94 additions & 0 deletions
94
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/NamespaceServiceTest.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,94 @@ | ||
package com.ctrip.framework.apollo.biz.service; | ||
|
||
import com.ctrip.framework.apollo.biz.AbstractIntegrationTest; | ||
import com.ctrip.framework.apollo.biz.entity.Cluster; | ||
import com.ctrip.framework.apollo.biz.entity.Commit; | ||
import com.ctrip.framework.apollo.biz.entity.InstanceConfig; | ||
import com.ctrip.framework.apollo.biz.entity.Item; | ||
import com.ctrip.framework.apollo.biz.entity.Namespace; | ||
import com.ctrip.framework.apollo.biz.entity.Release; | ||
import com.ctrip.framework.apollo.biz.entity.ReleaseHistory; | ||
import com.ctrip.framework.apollo.biz.repository.InstanceConfigRepository; | ||
import com.ctrip.framework.apollo.common.entity.AppNamespace; | ||
|
||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author lepdou 2016-11-28 | ||
*/ | ||
public class NamespaceServiceTest extends AbstractIntegrationTest { | ||
|
||
|
||
@Autowired | ||
private NamespaceService namespaceService; | ||
@Autowired | ||
private ItemService itemService; | ||
@Autowired | ||
private CommitService commitService; | ||
@Autowired | ||
private AppNamespaceService appNamespaceService; | ||
@Autowired | ||
private ClusterService clusterService; | ||
@Autowired | ||
private ReleaseService releaseService; | ||
@Autowired | ||
private ReleaseHistoryService releaseHistoryService; | ||
@Autowired | ||
private InstanceConfigRepository instanceConfigRepository; | ||
|
||
private String testApp = "testApp"; | ||
private String testCluster = "default"; | ||
private String testChildCluster = "child-cluster"; | ||
private String testPrivateNamespace = "application"; | ||
private String testUser = "apollo"; | ||
|
||
@Test | ||
@Sql(scripts = "/sql/namespace-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
public void testDeleteNamespace() { | ||
|
||
Namespace namespace = new Namespace(); | ||
namespace.setAppId(testApp); | ||
namespace.setClusterName(testCluster); | ||
namespace.setNamespaceName(testPrivateNamespace); | ||
namespace.setId(1); | ||
|
||
namespaceService.deleteNamespace(namespace, testUser); | ||
|
||
List<Item> items = itemService.findItems(testApp, testCluster, testPrivateNamespace); | ||
List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10)); | ||
AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace); | ||
List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster); | ||
InstanceConfig instanceConfig = instanceConfigRepository.findOne(1L); | ||
List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster, | ||
testPrivateNamespace, | ||
new PageRequest(0, 10)); | ||
List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster, | ||
testPrivateNamespace, | ||
new PageRequest(0, 10)); | ||
Page<ReleaseHistory> releaseHistories = | ||
releaseHistoryService | ||
.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, new PageRequest(0, 10)); | ||
|
||
assertEquals(0, items.size()); | ||
assertEquals(0, commits.size()); | ||
assertNotNull(appNamespace); | ||
assertEquals(0, childClusters.size()); | ||
assertEquals(0, parentNamespaceReleases.size()); | ||
assertEquals(0, childNamespaceReleases.size()); | ||
assertTrue(!releaseHistories.hasContent()); | ||
assertNull(instanceConfig); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
DELETE FROM App; | ||
DELETE FROM AppNamespace; | ||
DELETE FROM Cluster; | ||
DELETE FROM namespace; | ||
DELETE FROM grayreleaserule; | ||
DELETE FROM release; | ||
DELETE FROM item; | ||
DELETE FROM releasemessage; | ||
DELETE FROM releasehistory; | ||
DELETE FROM namespacelock; | ||
DELETE FROM `commit`; |
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,32 @@ | ||
INSERT INTO `app` ( `AppId`, `Name`, `OrgId`, `OrgName`, `OwnerName`, `OwnerEmail`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES('testApp', 'test', 'default', 'default', 'default', 'default', 0, 'default', 'default'); | ||
|
||
INSERT INTO `cluster` (`ID`, `Name`, `AppId`, `ParentClusterId`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`) VALUES (1, 'default', 'testApp', 0, 0, 'default', 'default'); | ||
INSERT INTO `cluster` (`Name`, `AppId`, `ParentClusterId`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES('child-cluster', 'testApp', 1, 0, 'default', 'default'); | ||
|
||
INSERT INTO `appnamespace` (`Name`, `AppId`, `Format`, `IsPublic`) VALUES ( 'application', 'testApp', 'properties', 0); | ||
|
||
INSERT INTO `namespace` (`ID`, `AppId`, `ClusterName`, `NamespaceName`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES(1,'testApp', 'default', 'application', 0, 'apollo', 'apollo'); | ||
INSERT INTO `namespace` (`AppId`, `ClusterName`, `NamespaceName`, `IsDeleted`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`)VALUES('testApp', 'child-cluster', 'application', 0, 'apollo', 'apollo'); | ||
|
||
INSERT INTO `commit` (`ChangeSets`, `AppId`, `ClusterName`, `NamespaceName`)VALUES('{}', 'testApp', 'default', 'application'); | ||
|
||
INSERT INTO `item` (`NamespaceId`, `Key`, `Value`, `Comment`, `LineNum`)VALUES(1, 'k1', 'v1', '', 1); | ||
|
||
INSERT INTO `namespacelock` (`NamespaceId`)VALUES(1); | ||
|
||
INSERT INTO `release` (`AppId`, `ClusterName`, `NamespaceName`, `Configurations`, `IsAbandoned`)VALUES('branch-test', 'default', 'application', '{}', 0); | ||
INSERT INTO `release` (`AppId`, `ClusterName`, `NamespaceName`, `Configurations`, `IsAbandoned`)VALUES('branch-test', 'child-cluster', 'application', '{}', 0); | ||
|
||
INSERT INTO `releasehistory` (`AppId`, `ClusterName`, `NamespaceName`, `BranchName`, `ReleaseId`, `PreviousReleaseId`, `Operation`, `OperationContext`)VALUES('branch-test', 'default', 'application', 'default', 0, 0, 7, '{}'); | ||
|
||
INSERT INTO `instanceconfig` (`ID`, `InstanceId`, `ConfigAppId`, `ConfigClusterName`, `ConfigNamespaceName`, `ReleaseKey`, `ReleaseDeliveryTime`, `DataChange_CreatedTime`, `DataChange_LastTime`) | ||
VALUES | ||
(1, 90, 'testApp', 'default', 'application', '20160829134524-dee271ddf9fced58', '2016-08-29 13:45:24', '2016-08-30 17:03:32', '2016-10-19 11:13:47'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
<root level="INFO"> | ||
<appender-ref ref="FILE" /> | ||
</root> | ||
</configuration> | ||
</configuration> |
Oops, something went wrong.