Search in sources :

Example 76 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class NamespaceServiceIntegrationTest method testDeleteNamespace.

@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.findItemsWithoutOrdered(testApp, testCluster, testPrivateNamespace);
    List<Commit> commits = commitService.find(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
    AppNamespace appNamespace = appNamespaceService.findOne(testApp, testPrivateNamespace);
    List<Cluster> childClusters = clusterService.findChildClusters(testApp, testCluster);
    InstanceConfig instanceConfig = instanceConfigRepository.findById(1L).orElse(null);
    List<Release> parentNamespaceReleases = releaseService.findActiveReleases(testApp, testCluster, testPrivateNamespace, PageRequest.of(0, 10));
    List<Release> childNamespaceReleases = releaseService.findActiveReleases(testApp, testChildCluster, testPrivateNamespace, PageRequest.of(0, 10));
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, testCluster, testPrivateNamespace, PageRequest.of(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);
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Item(com.ctrip.framework.apollo.biz.entity.Item) Commit(com.ctrip.framework.apollo.biz.entity.Commit) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 77 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class ReleaseCreationTest method testPublishMasterNamespaceAndBranchHasItems.

/**
 *               Master     |      Branch
 *           ------------------------------                                      Master    |    Branch
 *     Items      k1=v1     |      k1=v1-2                                      -------------------------
 *                k2=v2     |                                                     k1=v1    |    k1=v1
 *                k3=v3                            publish master                 k2=v2    |    k2=v2
 *           ------------------------------        ===========>>      Result      k3=v3    |    k3=v3
 *    Release               |
 *                          |
 *                          |
 */
@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPublishMasterNamespaceAndBranchHasItems() {
    long parentNamespaceId = 103;
    String parentClusterName = "default2";
    long childNamespaceId = 104;
    String childClusterName = "child-cluster2";
    Namespace parentNamespace = instanceNamespace(parentNamespaceId, parentClusterName);
    releaseService.publish(parentNamespace, "", "", operator, false);
    Release latestParentNamespaceRelease = releaseService.findLatestActiveRelease(parentNamespace);
    // assert parent namespace
    Assert.assertNotNull(latestParentNamespaceRelease);
    Map<String, String> parentNamespaceConfiguration = parseConfiguration(latestParentNamespaceRelease.getConfigurations());
    Assert.assertEquals(3, parentNamespaceConfiguration.size());
    Assert.assertEquals("v1", parentNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2", parentNamespaceConfiguration.get("k2"));
    Assert.assertEquals("v3", parentNamespaceConfiguration.get("k3"));
    // assert child namespace
    Namespace childNamespace = instanceNamespace(childNamespaceId, childClusterName);
    Release latestChildNamespaceRelease = releaseService.findLatestActiveRelease(childNamespace);
    Assert.assertNotNull(latestChildNamespaceRelease);
    Map<String, String> childNamespaceConfiguration = parseConfiguration(latestChildNamespaceRelease.getConfigurations());
    Assert.assertEquals(3, childNamespaceConfiguration.size());
    Assert.assertEquals("v1", childNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2", childNamespaceConfiguration.get("k2"));
    Assert.assertEquals("v3", childNamespaceConfiguration.get("k3"));
    GrayReleaseRule rule = namespaceBranchService.findBranchGrayRules(testApp, parentClusterName, testNamespace, childClusterName);
    Assert.assertNotNull(rule);
    Assert.assertEquals(1, rule.getBranchStatus());
    Assert.assertEquals(Long.valueOf(latestChildNamespaceRelease.getId()), rule.getReleaseId());
    // assert release history
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, parentClusterName, testNamespace, pageable);
    ReleaseHistory masterReleaseHistory = releaseHistories.getContent().get(1);
    ReleaseHistory branchReleaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(2, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.NORMAL_RELEASE, masterReleaseHistory.getOperation());
    Assert.assertEquals(latestParentNamespaceRelease.getId(), masterReleaseHistory.getReleaseId());
    Assert.assertEquals(0, masterReleaseHistory.getPreviousReleaseId());
    Assert.assertEquals(ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, branchReleaseHistory.getOperation());
    Assert.assertEquals(latestChildNamespaceRelease.getId(), branchReleaseHistory.getReleaseId());
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(String.format("\"baseReleaseId\":%d", latestParentNamespaceRelease.getId())));
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(rule.getRules()));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 78 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class ReleaseCreationTest method testPublishBranch.

/**
 *               Master     |      Branch
 *           ------------------------------                                      Master    |    Branch
 *     Items      k1=v1     |      k1=v1-2                                    ----------------------------
 *               k2=v2-2    |      k4=v4                                          k1=v1    |    k1=v1-2
 *                                 k6=v6           publish branch                 k2=v2    |    k2=v2
 *           ------------------------------        ===========>>      Result      k3=v3    |    k3=v3
 *    Release     k1=v1     |      k1=v1-1                                                 |    k4=v4
 *                k2=v2     |      k2=v2                                                   |    k6=v6
 *                k3=v3     |      k3=v3
 *                          |      k4=v4
 *                          |      k5=v5
 */
@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPublishBranch() {
    long parentNamespaceId = 109;
    String parentClusterName = "default5";
    long childNamespaceId = 1010;
    String childClusterName = "child-cluster5";
    // assert child namespace
    Namespace childNamespace = instanceNamespace(childNamespaceId, childClusterName);
    releaseService.publish(childNamespace, "", "", operator, false);
    Release latestChildNamespaceRelease = releaseService.findLatestActiveRelease(childNamespace);
    Assert.assertNotNull(latestChildNamespaceRelease);
    Map<String, String> childNamespaceConfiguration = parseConfiguration(latestChildNamespaceRelease.getConfigurations());
    Assert.assertEquals(5, childNamespaceConfiguration.size());
    Assert.assertEquals("v1-2", childNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2", childNamespaceConfiguration.get("k2"));
    Assert.assertEquals("v3", childNamespaceConfiguration.get("k3"));
    Assert.assertEquals("v4", childNamespaceConfiguration.get("k4"));
    Assert.assertEquals("v6", childNamespaceConfiguration.get("k6"));
    Namespace parentNamespace = instanceNamespace(parentNamespaceId, parentClusterName);
    Release latestParentNamespaceRelease = releaseService.findLatestActiveRelease(parentNamespace);
    // assert parent namespace
    Assert.assertNotNull(latestParentNamespaceRelease);
    Map<String, String> parentNamespaceConfiguration = parseConfiguration(latestParentNamespaceRelease.getConfigurations());
    Assert.assertEquals(3, parentNamespaceConfiguration.size());
    Assert.assertEquals("v1", parentNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2", parentNamespaceConfiguration.get("k2"));
    Assert.assertEquals("v3", parentNamespaceConfiguration.get("k3"));
    GrayReleaseRule rule = namespaceBranchService.findBranchGrayRules(testApp, parentClusterName, testNamespace, childClusterName);
    Assert.assertNotNull(rule);
    Assert.assertEquals(1, rule.getBranchStatus());
    Assert.assertEquals(Long.valueOf(latestChildNamespaceRelease.getId()), rule.getReleaseId());
    // assert release history
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, parentClusterName, testNamespace, pageable);
    ReleaseHistory branchReleaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(1, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.GRAY_RELEASE, branchReleaseHistory.getOperation());
    Assert.assertEquals(latestChildNamespaceRelease.getId(), branchReleaseHistory.getReleaseId());
    Assert.assertEquals(5, branchReleaseHistory.getPreviousReleaseId());
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains("\"baseReleaseId\":4"));
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(rule.getRules()));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 79 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class ReleaseCreationTest method testRollback.

/**
 *                          Master     |      Branch
 *                       ------------------------------                                      Master   |    Branch
 *     Rollback Release      k1=v1     |      k1=v1-2                                    ----------------------------
 *                           k2=v2     |      k2=v2                                        k1=v1-1    |    k1=v1-2
 *                                     |      k3=v3                                        k2=v2-1    |    k2=v2-1
 *                                                            rollback                     k3=v3      |    k3=v3
 *                       ------------------------------     ===========>>   New Release
 *    New  Release           k1=v1-1   |
 *                           k2=v2-1   |
 *                           k3=v3     |
 */
@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testRollback() {
    String parentClusterName = "default6";
    String childClusterName = "child-cluster6";
    String operator = "apollo";
    Release parentNamespaceLatestRelease = releaseService.findLatestActiveRelease(testApp, parentClusterName, testNamespace);
    releaseService.rollback(parentNamespaceLatestRelease.getId(), operator);
    Release parentNamespaceNewLatestRelease = releaseService.findLatestActiveRelease(testApp, parentClusterName, testNamespace);
    Map<String, String> parentNamespaceConfiguration = parseConfiguration(parentNamespaceNewLatestRelease.getConfigurations());
    Assert.assertEquals(3, parentNamespaceConfiguration.size());
    Assert.assertEquals("v1-1", parentNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2-1", parentNamespaceConfiguration.get("k2"));
    Assert.assertEquals("v3", parentNamespaceConfiguration.get("k3"));
    Release childNamespaceNewLatestRelease = releaseService.findLatestActiveRelease(testApp, childClusterName, testNamespace);
    Map<String, String> childNamespaceConfiguration = parseConfiguration(childNamespaceNewLatestRelease.getConfigurations());
    Assert.assertEquals(3, childNamespaceConfiguration.size());
    Assert.assertEquals("v1-2", childNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2-1", childNamespaceConfiguration.get("k2"));
    Assert.assertEquals("v3", childNamespaceConfiguration.get("k3"));
    // assert release history
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, parentClusterName, testNamespace, pageable);
    ReleaseHistory masterReleaseHistory = releaseHistories.getContent().get(1);
    ReleaseHistory branchReleaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(2, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.ROLLBACK, masterReleaseHistory.getOperation());
    Assert.assertEquals(6, masterReleaseHistory.getReleaseId());
    Assert.assertEquals(7, masterReleaseHistory.getPreviousReleaseId());
    Assert.assertEquals(ReleaseOperation.MATER_ROLLBACK_MERGE_TO_GRAY, branchReleaseHistory.getOperation());
    Assert.assertEquals(childNamespaceNewLatestRelease.getId(), branchReleaseHistory.getReleaseId());
    Assert.assertEquals(8, branchReleaseHistory.getPreviousReleaseId());
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(String.format("\"baseReleaseId\":%d", parentNamespaceNewLatestRelease.getId())));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Example 80 with Sql

use of org.springframework.test.context.jdbc.Sql in project apollo by ctripcorp.

the class ReleaseCreationTest method testModifyMasterNamespaceItemsAndBranchAlsoModify.

/**
 *               Master     |      Branch
 *           ------------------------------                                      Master    |    Branch
 *     Items      k1=v1     |      k1=v1-2                                    ----------------------------
 *               k2=v2-2    |                      publish master                 k1=v1    |    k1=v1-1
 *           ------------------------------        ===========>>      Result      k2=v2-2  |    k2=v2-2
 *    Release     k1=v1     |      k1=v1-1                                                 |
 *                k2=v2     |      k2=v3
 *                k3=v3     |      k3=v3
 */
@Test
@Sql(scripts = "/sql/release-creation-test.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testModifyMasterNamespaceItemsAndBranchAlsoModify() {
    long parentNamespaceId = 105;
    String parentClusterName = "default3";
    long childNamespaceId = 106;
    String childClusterName = "child-cluster3";
    Namespace parentNamespace = instanceNamespace(parentNamespaceId, parentClusterName);
    releaseService.publish(parentNamespace, "", "", operator, false);
    Release latestParentNamespaceRelease = releaseService.findLatestActiveRelease(parentNamespace);
    // assert parent namespace
    Assert.assertNotNull(latestParentNamespaceRelease);
    Map<String, String> parentNamespaceConfiguration = parseConfiguration(latestParentNamespaceRelease.getConfigurations());
    Assert.assertEquals(2, parentNamespaceConfiguration.size());
    Assert.assertEquals("v1", parentNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2-2", parentNamespaceConfiguration.get("k2"));
    // assert child namespace
    Namespace childNamespace = instanceNamespace(childNamespaceId, childClusterName);
    Release latestChildNamespaceRelease = releaseService.findLatestActiveRelease(childNamespace);
    Assert.assertNotNull(latestChildNamespaceRelease);
    Map<String, String> childNamespaceConfiguration = parseConfiguration(latestChildNamespaceRelease.getConfigurations());
    Assert.assertEquals(2, childNamespaceConfiguration.size());
    Assert.assertEquals("v1-1", childNamespaceConfiguration.get("k1"));
    Assert.assertEquals("v2-2", childNamespaceConfiguration.get("k2"));
    GrayReleaseRule rule = namespaceBranchService.findBranchGrayRules(testApp, parentClusterName, testNamespace, childClusterName);
    Assert.assertNotNull(rule);
    Assert.assertEquals(1, rule.getBranchStatus());
    Assert.assertEquals(Long.valueOf(latestChildNamespaceRelease.getId()), rule.getReleaseId());
    // assert release history
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, parentClusterName, testNamespace, pageable);
    ReleaseHistory masterReleaseHistory = releaseHistories.getContent().get(1);
    ReleaseHistory branchReleaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(2, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.NORMAL_RELEASE, masterReleaseHistory.getOperation());
    Assert.assertEquals(latestParentNamespaceRelease.getId(), masterReleaseHistory.getReleaseId());
    Assert.assertEquals(1, masterReleaseHistory.getPreviousReleaseId());
    Assert.assertEquals(ReleaseOperation.MASTER_NORMAL_RELEASE_MERGE_TO_GRAY, branchReleaseHistory.getOperation());
    Assert.assertEquals(latestChildNamespaceRelease.getId(), branchReleaseHistory.getReleaseId());
    Assert.assertEquals(2, branchReleaseHistory.getPreviousReleaseId());
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(String.format("\"baseReleaseId\":%d", latestParentNamespaceRelease.getId())));
    Assert.assertTrue(branchReleaseHistory.getOperationContext().contains(rule.getRules()));
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) GrayReleaseRule(com.ctrip.framework.apollo.biz.entity.GrayReleaseRule) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Sql(org.springframework.test.context.jdbc.Sql)

Aggregations

Sql (org.springframework.test.context.jdbc.Sql)122 Test (org.junit.Test)111 ApolloConfigNotification (com.ctrip.framework.apollo.core.dto.ApolloConfigNotification)26 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)26 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)23 AppDTO (com.ctrip.framework.apollo.common.dto.AppDTO)17 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)17 ApolloNotificationMessages (com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages)17 List (java.util.List)17 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)16 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)13 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)11 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)10 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Release (com.ctrip.framework.apollo.biz.entity.Release)8 AbstractControllerTest (com.ctrip.framework.apollo.adminservice.controller.AbstractControllerTest)6 Favorite (com.ctrip.framework.apollo.portal.entity.po.Favorite)6 CustomerData (io.codekvast.common.customer.CustomerData)6 HttpHeaders (org.springframework.http.HttpHeaders)6