use of com.ctrip.framework.apollo.biz.entity.InstanceConfig in project apollo by ctripcorp.
the class InstanceConfigRepositoryTest method shouldPaginated.
@Rollback
@Test
public void shouldPaginated() {
for (int i = 0; i < 25; i++) {
Instance instance = new Instance();
instance.setAppId("appId");
instanceRepository.save(instance);
final InstanceConfig instanceConfig = new InstanceConfig();
instanceConfig.setConfigAppId("appId");
instanceConfig.setInstanceId(instance.getId());
instanceConfig.setConfigClusterName("cluster");
instanceConfig.setConfigNamespaceName("namespace");
instanceConfigRepository.save(instanceConfig);
}
Page<Object> ids = instanceConfigRepository.findInstanceIdsByNamespaceAndInstanceAppId("appId", "appId", "cluster", "namespace", new Date(0), PageRequest.of(0, 10));
assertThat(ids.getContent(), hasSize(10));
ids = instanceConfigRepository.findInstanceIdsByNamespaceAndInstanceAppId("appId", "appId", "cluster", "namespace", new Date(0), PageRequest.of(1, 10));
assertThat(ids.getContent(), hasSize(10));
ids = instanceConfigRepository.findInstanceIdsByNamespaceAndInstanceAppId("appId", "appId", "cluster", "namespace", new Date(0), PageRequest.of(2, 10));
assertThat(ids.getContent(), hasSize(5));
}
use of com.ctrip.framework.apollo.biz.entity.InstanceConfig in project apollo by ctripcorp.
the class InstanceServiceTest method testFindActiveInstanceConfigs.
@Test
@Rollback
public void testFindActiveInstanceConfigs() throws Exception {
long someInstanceId = 1;
long anotherInstanceId = 2;
String someConfigAppId = "someConfigAppId";
String someConfigClusterName = "someConfigClusterName";
String someConfigNamespaceName = "someConfigNamespaceName";
Date someValidDate = new Date();
Pageable pageable = PageRequest.of(0, 10);
String someReleaseKey = "someReleaseKey";
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -2);
Date someInvalidDate = calendar.getTime();
prepareInstanceConfigForInstance(someInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
prepareInstanceConfigForInstance(anotherInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someInvalidDate);
Page<InstanceConfig> validInstanceConfigs = instanceService.findActiveInstanceConfigsByReleaseKey(someReleaseKey, pageable);
assertEquals(1, validInstanceConfigs.getContent().size());
assertEquals(someInstanceId, validInstanceConfigs.getContent().get(0).getInstanceId());
}
use of com.ctrip.framework.apollo.biz.entity.InstanceConfig in project apollo by ctripcorp.
the class InstanceServiceTest method testCreateAndFindInstanceConfig.
@Test
@Rollback
public void testCreateAndFindInstanceConfig() throws Exception {
long someInstanceId = 1;
String someConfigAppId = "someConfigAppId";
String someConfigClusterName = "someConfigClusterName";
String someConfigNamespaceName = "someConfigNamespaceName";
String someReleaseKey = "someReleaseKey";
String anotherReleaseKey = "anotherReleaseKey";
InstanceConfig instanceConfig = instanceService.findInstanceConfig(someInstanceId, someConfigAppId, someConfigNamespaceName);
assertNull(instanceConfig);
instanceService.createInstanceConfig(assembleInstanceConfig(someInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey));
instanceConfig = instanceService.findInstanceConfig(someInstanceId, someConfigAppId, someConfigNamespaceName);
assertNotEquals(0, instanceConfig.getId());
assertEquals(someReleaseKey, instanceConfig.getReleaseKey());
instanceConfig.setReleaseKey(anotherReleaseKey);
instanceService.updateInstanceConfig(instanceConfig);
InstanceConfig updated = instanceService.findInstanceConfig(someInstanceId, someConfigAppId, someConfigNamespaceName);
assertEquals(instanceConfig.getId(), updated.getId());
assertEquals(anotherReleaseKey, updated.getReleaseKey());
}
use of com.ctrip.framework.apollo.biz.entity.InstanceConfig in project apollo by ctripcorp.
the class InstanceServiceTest method testFindInstanceConfigsByNamespaceWithReleaseKeysNotIn.
@Test
@Rollback
public void testFindInstanceConfigsByNamespaceWithReleaseKeysNotIn() throws Exception {
long someInstanceId = 1;
long anotherInstanceId = 2;
long yetAnotherInstanceId = 3;
String someConfigAppId = "someConfigAppId";
String someConfigClusterName = "someConfigClusterName";
String someConfigNamespaceName = "someConfigNamespaceName";
Date someValidDate = new Date();
String someReleaseKey = "someReleaseKey";
String anotherReleaseKey = "anotherReleaseKey";
String yetAnotherReleaseKey = "yetAnotherReleaseKey";
InstanceConfig someInstanceConfig = prepareInstanceConfigForInstance(someInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
InstanceConfig anotherInstanceConfig = prepareInstanceConfigForInstance(anotherInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, someReleaseKey, someValidDate);
prepareInstanceConfigForInstance(yetAnotherInstanceId, someConfigAppId, someConfigClusterName, someConfigNamespaceName, anotherReleaseKey, someValidDate);
List<InstanceConfig> instanceConfigs = instanceService.findInstanceConfigsByNamespaceWithReleaseKeysNotIn(someConfigAppId, someConfigClusterName, someConfigNamespaceName, Sets.newHashSet(anotherReleaseKey, yetAnotherReleaseKey));
assertEquals(Lists.newArrayList(someInstanceConfig, anotherInstanceConfig), instanceConfigs);
}
use of com.ctrip.framework.apollo.biz.entity.InstanceConfig in project apollo by ctripcorp.
the class InstanceService method updateInstanceConfig.
@Transactional
public InstanceConfig updateInstanceConfig(InstanceConfig instanceConfig) {
InstanceConfig existedInstanceConfig = instanceConfigRepository.findById(instanceConfig.getId()).orElse(null);
Preconditions.checkArgument(existedInstanceConfig != null, String.format("Instance config %d doesn't exist", instanceConfig.getId()));
existedInstanceConfig.setConfigClusterName(instanceConfig.getConfigClusterName());
existedInstanceConfig.setReleaseKey(instanceConfig.getReleaseKey());
existedInstanceConfig.setReleaseDeliveryTime(instanceConfig.getReleaseDeliveryTime());
existedInstanceConfig.setDataChangeLastModifiedTime(instanceConfig.getDataChangeLastModifiedTime());
return instanceConfigRepository.save(existedInstanceConfig);
}
Aggregations