use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class NamespaceServiceTest method testDeleteNamespaceBranchHasInstance.
@Test(expected = BadRequestException.class)
public void testDeleteNamespaceBranchHasInstance() {
AppNamespace publicNamespace = createAppNamespace(testAppId, testNamespaceName, true);
String branchName = "branch";
NamespaceDTO branch = createNamespace(testAppId, branchName, testNamespaceName);
when(appNamespaceService.findByAppIdAndName(testAppId, testNamespaceName)).thenReturn(publicNamespace);
when(instanceService.getInstanceCountByNamepsace(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(0);
when(branchService.findBranchBaseInfo(testAppId, testEnv, testClusterName, testNamespaceName)).thenReturn(branch);
when(instanceService.getInstanceCountByNamepsace(testAppId, testEnv, branchName, testNamespaceName)).thenReturn(10);
namespaceService.deleteNamespace(testAppId, testEnv, testClusterName, testNamespaceName);
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceTest method testCreateDefaultAppNamespace.
@Test
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateDefaultAppNamespace() {
appNamespaceService.createDefaultAppNamespace(APP);
AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(APP, ConfigConsts.NAMESPACE_APPLICATION);
Assert.assertNotNull(appNamespace);
Assert.assertEquals(ConfigFileFormat.Properties.getValue(), appNamespace.getFormat());
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceTest method assmbleBaseAppNamespace.
private AppNamespace assmbleBaseAppNamespace() {
AppNamespace appNamespace = new AppNamespace();
appNamespace.setName("appNamespace");
appNamespace.setAppId("1000");
appNamespace.setFormat(ConfigFileFormat.XML.getValue());
return appNamespace;
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceWithCache method findByAppIdAndNamespaces.
public List<AppNamespace> findByAppIdAndNamespaces(String appId, Set<String> namespaceNames) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(appId), "appId must not be null");
if (namespaceNames == null || namespaceNames.isEmpty()) {
return Collections.emptyList();
}
List<AppNamespace> result = Lists.newArrayList();
for (String namespaceName : namespaceNames) {
AppNamespace appNamespace = appNamespaceCache.get(STRING_JOINER.join(appId, namespaceName));
if (appNamespace != null) {
result.add(appNamespace);
}
}
return result;
}
use of com.ctrip.framework.apollo.common.entity.AppNamespace in project apollo by ctripcorp.
the class AppNamespaceServiceWithCache method handleUpdatedAppNamespaces.
// for those updated app namespaces
private Set<Long> handleUpdatedAppNamespaces(Iterable<AppNamespace> appNamespaces) {
Set<Long> foundIds = Sets.newHashSet();
for (AppNamespace appNamespace : appNamespaces) {
foundIds.add(appNamespace.getId());
AppNamespace thatInCache = appNamespaceIdCache.get(appNamespace.getId());
if (thatInCache != null && appNamespace.getDataChangeLastModifiedTime().after(thatInCache.getDataChangeLastModifiedTime())) {
appNamespaceIdCache.put(appNamespace.getId(), appNamespace);
String oldKey = assembleAppNamespaceKey(thatInCache);
String newKey = assembleAppNamespaceKey(appNamespace);
appNamespaceCache.put(newKey, appNamespace);
// in case appId or namespaceName changes
if (!newKey.equals(oldKey)) {
appNamespaceCache.remove(oldKey);
}
if (appNamespace.isPublic()) {
publicAppNamespaceCache.put(appNamespace.getName(), appNamespace);
// in case namespaceName changes
if (!appNamespace.getName().equals(thatInCache.getName()) && thatInCache.isPublic()) {
publicAppNamespaceCache.remove(thatInCache.getName());
}
} else if (thatInCache.isPublic()) {
// just in case isPublic changes
publicAppNamespaceCache.remove(thatInCache.getName());
}
logger.info("Found AppNamespace changes, old: {}, new: {}", thatInCache, appNamespace);
}
}
return foundIds;
}
Aggregations