Search in sources :

Example 6 with Release

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

the class ConfigServiceWithCacheTest method testFindLatestActiveReleaseWithIrrelevantMessages.

@Test
public void testFindLatestActiveReleaseWithIrrelevantMessages() throws Exception {
    long someNewNotificationId = someNotificationId + 1;
    String someIrrelevantKey = "someIrrelevantKey";
    when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(someReleaseMessage);
    when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(someRelease);
    when(someReleaseMessage.getId()).thenReturn(someNotificationId);
    Release release = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    Release stillOldRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    someNotificationMessages.put(someIrrelevantKey, someNewNotificationId);
    Release shouldStillBeOldRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    assertEquals(someRelease, release);
    assertEquals(someRelease, stillOldRelease);
    assertEquals(someRelease, shouldStillBeOldRelease);
    verify(releaseMessageService, times(1)).findLatestReleaseMessageForMessages(Lists.newArrayList(someKey));
    verify(releaseService, times(1)).findLatestActiveRelease(someAppId, someClusterName, someNamespaceName);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 7 with Release

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

the class ConfigServiceWithCacheTest method testFindLatestActiveReleaseWithReleaseNotFound.

@Test
public void testFindLatestActiveReleaseWithReleaseNotFound() throws Exception {
    when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(null);
    when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(null);
    Release release = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    Release anotherRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    int retryTimes = 100;
    for (int i = 0; i < retryTimes; i++) {
        configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    }
    assertNull(release);
    assertNull(anotherRelease);
    verify(releaseMessageService, times(1)).findLatestReleaseMessageForMessages(Lists.newArrayList(someKey));
    verify(releaseService, times(1)).findLatestActiveRelease(someAppId, someClusterName, someNamespaceName);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 8 with Release

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

the class AbstractBaseIntegrationTest method buildRelease.

public Release buildRelease(String name, String comment, Namespace namespace, Map<String, String> configurations, String owner) {
    Release release = new Release();
    release.setReleaseKey(ReleaseKeyGenerator.generateReleaseKey(namespace));
    release.setDataChangeCreatedTime(new Date());
    release.setDataChangeCreatedBy(owner);
    release.setDataChangeLastModifiedBy(owner);
    release.setName(name);
    release.setComment(comment);
    release.setAppId(namespace.getAppId());
    release.setClusterName(namespace.getClusterName());
    release.setNamespaceName(namespace.getNamespaceName());
    release.setConfigurations(GSON.toJson(configurations));
    release = releaseRepository.save(release);
    return release;
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Date(java.util.Date)

Example 9 with Release

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

the class DefaultConfigServiceTest method testLoadConfigWithGrayRelease.

@Test
public void testLoadConfigWithGrayRelease() throws Exception {
    Release grayRelease = mock(Release.class);
    long grayReleaseId = 999;
    when(grayReleaseRulesHolder.findReleaseIdFromGrayReleaseRule(someClientAppId, someClientIp, someClientLabel, someConfigAppId, someClusterName, defaultNamespaceName)).thenReturn(grayReleaseId);
    when(releaseService.findActiveOne(grayReleaseId)).thenReturn(grayRelease);
    Release release = configService.loadConfig(someClientAppId, someClientIp, someClientLabel, someConfigAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    verify(releaseService, times(1)).findActiveOne(grayReleaseId);
    verify(releaseService, never()).findLatestActiveRelease(someConfigAppId, someClusterName, defaultNamespaceName);
    assertEquals(grayRelease, release);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 10 with Release

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

the class DefaultConfigServiceTest method testLoadConfigWithReleaseNotFound.

@Test
public void testLoadConfigWithReleaseNotFound() throws Exception {
    when(releaseService.findLatestActiveRelease(someConfigAppId, someClusterName, defaultNamespaceName)).thenReturn(null);
    Release release = configService.loadConfig(someClientAppId, someClientIp, someClientLabel, someConfigAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    assertNull(release);
}
Also used : 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