Search in sources :

Example 56 with Release

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

the class DefaultConfigServiceTest method testLoadConfigWithDefaultClusterWithDataCenterRelease.

@Test
public void testLoadConfigWithDefaultClusterWithDataCenterRelease() throws Exception {
    when(releaseService.findLatestActiveRelease(someConfigAppId, someDataCenter, defaultNamespaceName)).thenReturn(someRelease);
    Release release = configService.loadConfig(someClientAppId, someClientIp, someClientLabel, someConfigAppId, defaultClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    verify(releaseService, times(1)).findLatestActiveRelease(someConfigAppId, someDataCenter, defaultNamespaceName);
    assertEquals(someRelease, release);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 57 with Release

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

the class ItemController method findDeletedItems.

@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/deleted")
public List<ItemDTO> findDeletedItems(@PathVariable("appId") String appId, @PathVariable("clusterName") String clusterName, @PathVariable("namespaceName") String namespaceName) {
    // get latest release time
    Release latestActiveRelease = releaseService.findLatestActiveRelease(appId, clusterName, namespaceName);
    List<Commit> commits;
    if (Objects.nonNull(latestActiveRelease)) {
        commits = commitService.find(appId, clusterName, namespaceName, latestActiveRelease.getDataChangeCreatedTime(), null);
    } else {
        commits = commitService.find(appId, clusterName, namespaceName, null);
    }
    if (Objects.nonNull(commits)) {
        List<Item> deletedItems = commits.stream().map(item -> ConfigChangeContentBuilder.convertJsonString(item.getChangeSets()).getDeleteItems()).flatMap(Collection::stream).collect(Collectors.toList());
        return BeanUtils.batchTransform(ItemDTO.class, deletedItems);
    }
    return Collections.emptyList();
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Commit(com.ctrip.framework.apollo.biz.entity.Commit) Release(com.ctrip.framework.apollo.biz.entity.Release) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 58 with Release

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

the class InstanceConfigControllerTest method testGetByReleasesNotIn.

@Test
public void testGetByReleasesNotIn() throws Exception {
    String someConfigAppId = "someConfigAppId";
    String someConfigClusterName = "someConfigClusterName";
    String someConfigNamespaceName = "someConfigNamespaceName";
    long someReleaseId = 1;
    long anotherReleaseId = 2;
    String releaseIds = Joiner.on(",").join(someReleaseId, anotherReleaseId);
    Date someReleaseDeliveryTime = new Date();
    Date anotherReleaseDeliveryTime = new Date();
    Release someRelease = mock(Release.class);
    Release anotherRelease = mock(Release.class);
    String someReleaseKey = "someReleaseKey";
    String anotherReleaseKey = "anotherReleaseKey";
    when(someRelease.getReleaseKey()).thenReturn(someReleaseKey);
    when(anotherRelease.getReleaseKey()).thenReturn(anotherReleaseKey);
    when(releaseService.findByReleaseIds(Sets.newHashSet(someReleaseId, anotherReleaseId))).thenReturn(Lists.newArrayList(someRelease, anotherRelease));
    long someInstanceId = 1;
    long anotherInstanceId = 2;
    String someInstanceConfigReleaseKey = "someInstanceConfigReleaseKey";
    String anotherInstanceConfigReleaseKey = "anotherInstanceConfigReleaseKey";
    InstanceConfig someInstanceConfig = mock(InstanceConfig.class);
    InstanceConfig anotherInstanceConfig = mock(InstanceConfig.class);
    when(someInstanceConfig.getInstanceId()).thenReturn(someInstanceId);
    when(anotherInstanceConfig.getInstanceId()).thenReturn(anotherInstanceId);
    when(someInstanceConfig.getReleaseKey()).thenReturn(someInstanceConfigReleaseKey);
    when(anotherInstanceConfig.getReleaseKey()).thenReturn(anotherInstanceConfigReleaseKey);
    when(someInstanceConfig.getReleaseDeliveryTime()).thenReturn(someReleaseDeliveryTime);
    when(anotherInstanceConfig.getReleaseDeliveryTime()).thenReturn(anotherReleaseDeliveryTime);
    when(instanceService.findInstanceConfigsByNamespaceWithReleaseKeysNotIn(someConfigAppId, someConfigClusterName, someConfigNamespaceName, Sets.newHashSet(someReleaseKey, anotherReleaseKey))).thenReturn(Lists.newArrayList(someInstanceConfig, anotherInstanceConfig));
    String someInstanceAppId = "someInstanceAppId";
    String someInstanceClusterName = "someInstanceClusterName";
    String someInstanceNamespaceName = "someInstanceNamespaceName";
    String someIp = "someIp";
    String anotherIp = "anotherIp";
    Instance someInstance = assembleInstance(someInstanceId, someInstanceAppId, someInstanceClusterName, someInstanceNamespaceName, someIp);
    Instance anotherInstance = assembleInstance(anotherInstanceId, someInstanceAppId, someInstanceClusterName, someInstanceNamespaceName, anotherIp);
    when(instanceService.findInstancesByIds(Sets.newHashSet(someInstanceId, anotherInstanceId))).thenReturn(Lists.newArrayList(someInstance, anotherInstance));
    Release someInstanceConfigRelease = new Release();
    someInstanceConfigRelease.setReleaseKey(someInstanceConfigReleaseKey);
    Release anotherInstanceConfigRelease = new Release();
    anotherInstanceConfigRelease.setReleaseKey(anotherInstanceConfigReleaseKey);
    when(releaseService.findByReleaseKeys(Sets.newHashSet(someInstanceConfigReleaseKey, anotherInstanceConfigReleaseKey))).thenReturn(Lists.newArrayList(someInstanceConfigRelease, anotherInstanceConfigRelease));
    List<InstanceDTO> result = instanceConfigController.getByReleasesNotIn(someConfigAppId, someConfigClusterName, someConfigNamespaceName, releaseIds);
    assertEquals(2, result.size());
    InstanceDTO someInstanceDto = null;
    InstanceDTO anotherInstanceDto = null;
    for (InstanceDTO instanceDTO : result) {
        if (instanceDTO.getId() == someInstanceId) {
            someInstanceDto = instanceDTO;
        } else if (instanceDTO.getId() == anotherInstanceId) {
            anotherInstanceDto = instanceDTO;
        }
    }
    verifyInstance(someInstance, someInstanceDto);
    verifyInstance(anotherInstance, anotherInstanceDto);
    assertEquals(someInstanceConfigReleaseKey, someInstanceDto.getConfigs().get(0).getRelease().getReleaseKey());
    assertEquals(anotherInstanceConfigReleaseKey, anotherInstanceDto.getConfigs().get(0).getRelease().getReleaseKey());
    assertEquals(someReleaseDeliveryTime, someInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
    assertEquals(anotherReleaseDeliveryTime, anotherInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
}
Also used : InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Instance(com.ctrip.framework.apollo.biz.entity.Instance) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) Date(java.util.Date) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 59 with Release

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

the class NamespaceUnlockAspectTest method testChildNamespaceNotModified.

@Test
public void testChildNamespaceNotModified() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
    List<Item> childItems = Collections.singletonList(createItem("k1", "v3"));
    Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertFalse(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 60 with Release

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

the class NamespaceUnlockAspectTest method testParentNamespaceNotReleased.

@Test
public void testParentNamespaceNotReleased() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
    List<Item> childItems = Arrays.asList(createItem("k1", "v2"), createItem("k2", "v2"));
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(null);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Aggregations

Release (com.ctrip.framework.apollo.biz.entity.Release)71 Test (org.junit.Test)36 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)22 Item (com.ctrip.framework.apollo.biz.entity.Item)12 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)9 Transactional (org.springframework.transaction.annotation.Transactional)9 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)7 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)7 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)7 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)7 Sql (org.springframework.test.context.jdbc.Sql)7 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)5 Instance (com.ctrip.framework.apollo.biz.entity.Instance)4 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)4 Date (java.util.Date)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)3 ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)3 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PageRequest (org.springframework.data.domain.PageRequest)3