Search in sources :

Example 51 with Release

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

the class ReleaseCreationTest method testPublishNormalNamespace.

@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 testPublishNormalNamespace() {
    long namespaceId = 100;
    String clusterName = "only-master";
    Namespace namespace = instanceNamespace(namespaceId, clusterName);
    releaseService.publish(namespace, "", "", operator, false);
    Release latestRelease = releaseService.findLatestActiveRelease(namespace);
    Assert.assertNotNull(latestRelease);
    Map<String, String> configuration = parseConfiguration(latestRelease.getConfigurations());
    Assert.assertEquals(3, configuration.size());
    Assert.assertEquals("v1", configuration.get("k1"));
    Assert.assertEquals("v2", configuration.get("k2"));
    Assert.assertEquals("v3", configuration.get("k3"));
    Page<ReleaseHistory> releaseHistories = releaseHistoryService.findReleaseHistoriesByNamespace(testApp, clusterName, testNamespace, pageable);
    ReleaseHistory releaseHistory = releaseHistories.getContent().get(0);
    Assert.assertEquals(1, releaseHistories.getTotalElements());
    Assert.assertEquals(ReleaseOperation.NORMAL_RELEASE, releaseHistory.getOperation());
    Assert.assertEquals(latestRelease.getId(), releaseHistory.getReleaseId());
    Assert.assertEquals(0, releaseHistory.getPreviousReleaseId());
}
Also used : ReleaseHistory(com.ctrip.framework.apollo.biz.entity.ReleaseHistory) 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 52 with Release

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

the class ConfigControllerTest method testTransformConfigurationToMapFailed.

@Test(expected = JsonSyntaxException.class)
public void testTransformConfigurationToMapFailed() throws Exception {
    String someInvalidConfiguration = "xxx";
    Release someRelease = new Release();
    someRelease.setConfigurations(someInvalidConfiguration);
    configController.mergeReleaseConfigurations(Lists.newArrayList(someRelease));
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 53 with Release

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

the class ConfigServiceWithCacheTest method testFindActiveOneWithMultipleIdMultipleTimes.

@Test
public void testFindActiveOneWithMultipleIdMultipleTimes() throws Exception {
    long someId = 1;
    long anotherId = 2;
    Release anotherRelease = mock(Release.class);
    when(releaseService.findActiveOne(someId)).thenReturn(someRelease);
    when(releaseService.findActiveOne(anotherId)).thenReturn(anotherRelease);
    assertEquals(someRelease, configServiceWithCache.findActiveOne(someId, someNotificationMessages));
    assertEquals(someRelease, configServiceWithCache.findActiveOne(someId, someNotificationMessages));
    assertEquals(anotherRelease, configServiceWithCache.findActiveOne(anotherId, someNotificationMessages));
    assertEquals(anotherRelease, configServiceWithCache.findActiveOne(anotherId, someNotificationMessages));
    verify(releaseService, times(1)).findActiveOne(someId);
    verify(releaseService, times(1)).findActiveOne(anotherId);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 54 with Release

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

the class ConfigServiceWithCacheTest method testFindLatestActiveRelease.

@Test
public void testFindLatestActiveRelease() throws Exception {
    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 anotherRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    int retryTimes = 100;
    for (int i = 0; i < retryTimes; i++) {
        configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName, someNotificationMessages);
    }
    assertEquals(someRelease, release);
    assertEquals(someRelease, 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 55 with Release

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

the class DefaultConfigServiceTest method testLoadConfig.

@Test
public void testLoadConfig() throws Exception {
    when(releaseService.findLatestActiveRelease(someConfigAppId, someClusterName, defaultNamespaceName)).thenReturn(someRelease);
    Release release = configService.loadConfig(someClientAppId, someClientIp, someClientLabel, someConfigAppId, someClusterName, defaultNamespaceName, someDataCenter, someNotificationMessages);
    verify(releaseService, times(1)).findLatestActiveRelease(someConfigAppId, someClusterName, defaultNamespaceName);
    assertEquals(someRelease, 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