Search in sources :

Example 31 with Namespace

use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.

the class NamespacePublishInfoTest method createNamespace.

private Namespace createNamespace(String clusterName, String namespaceName) {
    Namespace namespace = new Namespace();
    namespace.setAppId(testApp);
    namespace.setClusterName(clusterName);
    namespace.setNamespaceName(namespaceName);
    namespace.setId(new Random().nextLong());
    return namespace;
}
Also used : Random(java.util.Random) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace)

Example 32 with Namespace

use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.

the class NamespacePublishInfoTest method testNamespaceEverPublishedAndModifiedAfter.

@Test
public void testNamespaceEverPublishedAndModifiedAfter() {
    Cluster cluster = createCluster(ConfigConsts.CLUSTER_NAME_DEFAULT);
    Namespace namespace = createNamespace(ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION);
    Item item = createItem(namespace.getId(), "a", "b");
    Release release = createRelease("{\"a\":\"c\"}");
    when(clusterService.findParentClusters(testApp)).thenReturn(Collections.singletonList(cluster));
    when(namespaceRepository.findByAppIdAndClusterNameOrderByIdAsc(testApp, ConfigConsts.CLUSTER_NAME_DEFAULT)).thenReturn(Collections.singletonList(namespace));
    when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
    when(itemService.findItemsModifiedAfterDate(anyLong(), any())).thenReturn(Collections.singletonList(item));
    Map<String, Boolean> result = namespaceService.namespacePublishInfo(testApp);
    Assert.assertEquals(1, result.size());
    Assert.assertTrue(result.get(ConfigConsts.CLUSTER_NAME_DEFAULT));
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Cluster(com.ctrip.framework.apollo.biz.entity.Cluster) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 33 with Namespace

use of com.ctrip.framework.apollo.biz.entity.Namespace in project apollo by ctripcorp.

the class NamespaceServiceTest method testFindPublicAppNamespace.

@Test
public void testFindPublicAppNamespace() {
    AppNamespace publicAppNamespace = MockBeanFactory.mockAppNamespace(null, testPublicAppNamespace, true);
    when(appNamespaceService.findPublicNamespaceByName(testPublicAppNamespace)).thenReturn(publicAppNamespace);
    Namespace firstParentNamespace = MockBeanFactory.mockNamespace("app", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
    Namespace secondParentNamespace = MockBeanFactory.mockNamespace("app1", ConfigConsts.CLUSTER_NAME_DEFAULT, testPublicAppNamespace);
    Pageable page = PageRequest.of(0, 10);
    when(namespaceRepository.findByNamespaceName(testPublicAppNamespace, page)).thenReturn(Arrays.asList(firstParentNamespace, secondParentNamespace));
    doReturn(false).when(namespaceService).isChildNamespace(firstParentNamespace);
    doReturn(false).when(namespaceService).isChildNamespace(secondParentNamespace);
    List<Namespace> namespaces = namespaceService.findPublicAppNamespaceAllNamespaces(testPublicAppNamespace, page);
    assertEquals(2, namespaces.size());
}
Also used : Pageable(org.springframework.data.domain.Pageable) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) AppNamespace(com.ctrip.framework.apollo.common.entity.AppNamespace) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 34 with Namespace

use of com.ctrip.framework.apollo.biz.entity.Namespace 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 35 with Namespace

use of com.ctrip.framework.apollo.biz.entity.Namespace 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)

Aggregations

Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)60 Test (org.junit.Test)24 Release (com.ctrip.framework.apollo.biz.entity.Release)22 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)14 Item (com.ctrip.framework.apollo.biz.entity.Item)13 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)10 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)10 Sql (org.springframework.test.context.jdbc.Sql)10 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)8 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)8 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)8 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)4 Commit (com.ctrip.framework.apollo.biz.entity.Commit)3 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)2 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2