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()));
}
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"));
}
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"));
}
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"));
}
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}¬ifications={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());
}
Aggregations