Search in sources :

Example 16 with Sql

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

the class ReleaseCreationTest method testPublishMasterNamespaceAndBranchHasNotItems.

/**
 *               Master     |      Branch
 *           ------------------------------                                      Master    |    Branch
 *     Items      k1=v1     |                                                 ----------------------------
 *                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 testPublishMasterNamespaceAndBranchHasNotItems() {
    long parentNamespaceId = 101;
    String parentClusterName = "default1";
    long childNamespaceId = 102;
    String childClusterName = "child-cluster1";
    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 parent namespace
    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 17 with Sql

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

the class ConfigFileControllerIntegrationTest method testQueryPublicConfigAsJsonWithGrayReleaseAndIncorrectCase.

@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-default-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-gray-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigAsJsonWithGrayReleaseAndIncorrectCase() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace), stop);
    TimeUnit.MILLISECONDS.sleep(500);
    stop.set(true);
    ResponseEntity<String> response = restTemplate.getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}&label={clientLabel}", String.class, getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), grayClientIp, grayClientLabel);
    ResponseEntity<String> anotherResponse = restTemplate.getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}&label={clientLabel}", String.class, getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace.toUpperCase(), nonGrayClientIp, nonGrayClientLabel);
    Map<String, String> configs = GSON.fromJson(response.getBody(), mapResponseType);
    Map<String, String> anotherConfigs = GSON.fromJson(anotherResponse.getBody(), mapResponseType);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals(HttpStatus.OK, anotherResponse.getStatusCode());
    assertEquals("override-v1", configs.get("k1"));
    assertEquals("gray-v2", configs.get("k2"));
    assertEquals("override-v1", anotherConfigs.get("k1"));
    assertEquals("default-v2", anotherConfigs.get("k2"));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 18 with Sql

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

the class ConfigFileControllerIntegrationTest method testQueryConfigAsPropertiesWithGrayRelease.

@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-gray-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryConfigAsPropertiesWithGrayRelease() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    periodicSendMessage(executorService, assembleKey(someAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, ConfigConsts.NAMESPACE_APPLICATION), stop);
    TimeUnit.MILLISECONDS.sleep(500);
    stop.set(true);
    ResponseEntity<String> response = restTemplate.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}&label={clientLabel}", String.class, getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, grayClientIp, grayClientLabel);
    ResponseEntity<String> anotherResponse = restTemplate.getForEntity("http://{baseurl}/configfiles/{appId}/{clusterName}/{namespace}?ip={clientIp}&label={clientLabel}", String.class, getHostUrl(), someAppId, someDefaultCluster, ConfigConsts.NAMESPACE_APPLICATION, nonGrayClientIp, nonGrayClientLabel);
    String result = response.getBody();
    String anotherResult = anotherResponse.getBody();
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue(result.contains("k1=v1-gray"));
    assertEquals(HttpStatus.OK, anotherResponse.getStatusCode());
    assertFalse(anotherResult.contains("k1=v1-gray"));
    assertTrue(anotherResult.contains("k1=v1"));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 19 with Sql

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

the class ConfigFileControllerIntegrationTest method testQueryPublicConfigAsJsonWithGrayRelease.

@Test
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-public-default-override.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-gray-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testQueryPublicConfigAsJsonWithGrayRelease() throws Exception {
    AtomicBoolean stop = new AtomicBoolean();
    periodicSendMessage(executorService, assembleKey(somePublicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace), stop);
    TimeUnit.MILLISECONDS.sleep(500);
    stop.set(true);
    ResponseEntity<String> response = restTemplate.getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}&label={clientLabel}", String.class, getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, grayClientIp, grayClientLabel);
    ResponseEntity<String> anotherResponse = restTemplate.getForEntity("http://{baseurl}/configfiles/json/{appId}/{clusterName}/{namespace}?ip={clientIp}&label={clientLabel}", String.class, getHostUrl(), someAppId, someDefaultCluster, somePublicNamespace, nonGrayClientIp, nonGrayClientLabel);
    Map<String, String> configs = GSON.fromJson(response.getBody(), mapResponseType);
    Map<String, String> anotherConfigs = GSON.fromJson(anotherResponse.getBody(), mapResponseType);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals(HttpStatus.OK, anotherResponse.getStatusCode());
    assertEquals("override-v1", configs.get("k1"));
    assertEquals("gray-v2", configs.get("k2"));
    assertEquals("override-v1", anotherConfigs.get("k1"));
    assertEquals("default-v2", anotherConfigs.get("k2"));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 20 with Sql

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

the class NotificationControllerV2IntegrationTest method testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase4WithNotificationIdOutDated.

@Test(timeout = 5000L)
@Sql(scripts = "/integration-test/test-release.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/test-release-message.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/integration-test/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testPollNotificationWithMultiplePublicNamespaceWithIncorrectCase4WithNotificationIdOutDated() throws Exception {
    String publicAppId = "somePublicAppId";
    long someOutDatedNotificationId = 1;
    long newNotificationId = 20;
    String somePublicNameWithIncorrectCase = somePublicNamespace.toUpperCase();
    // the same namespace with difference character case, and difference notification id
    ResponseEntity<List<ApolloConfigNotification>> result = restTemplate.exchange("http://{baseurl}/notifications/v2?appId={appId}&cluster={clusterName}&notifications={notifications}", HttpMethod.GET, null, typeReference, getHostUrl(), someAppId, someCluster, transformApolloConfigNotificationsToString(somePublicNamespace, someOutDatedNotificationId, somePublicNameWithIncorrectCase, newNotificationId));
    List<ApolloConfigNotification> notifications = result.getBody();
    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertEquals(1, notifications.size());
    assertEquals(somePublicNamespace, notifications.get(0).getNamespaceName());
    assertEquals(newNotificationId, notifications.get(0).getNotificationId());
    String key = assembleKey(publicAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, somePublicNamespace);
    ApolloNotificationMessages messages = result.getBody().get(0).getMessages();
    assertEquals(1, messages.getDetails().size());
    assertTrue(messages.has(key));
    assertEquals(newNotificationId, messages.get(key).longValue());
}
Also used : ApolloNotificationMessages(com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages) List(java.util.List) ApolloConfigNotification(com.ctrip.framework.apollo.core.dto.ApolloConfigNotification) Test(org.junit.Test) 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