Search in sources :

Example 1 with InstanceConfig

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));
}
Also used : InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Instance(com.ctrip.framework.apollo.biz.entity.Instance) Date(java.util.Date) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 2 with InstanceConfig

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());
}
Also used : Pageable(org.springframework.data.domain.Pageable) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with InstanceConfig

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());
}
Also used : InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with InstanceConfig

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);
}
Also used : InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Rollback(org.springframework.test.annotation.Rollback)

Example 5 with InstanceConfig

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);
}
Also used : InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)14 Test (org.junit.Test)7 Date (java.util.Date)6 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)5 Instance (com.ctrip.framework.apollo.biz.entity.Instance)5 Release (com.ctrip.framework.apollo.biz.entity.Release)5 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)4 Rollback (org.springframework.test.annotation.Rollback)4 Pageable (org.springframework.data.domain.Pageable)3 InstanceService (com.ctrip.framework.apollo.biz.service.InstanceService)2 ReleaseService (com.ctrip.framework.apollo.biz.service.ReleaseService)2 InstanceConfigDTO (com.ctrip.framework.apollo.common.dto.InstanceConfigDTO)2 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)2 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)2 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)2 BeanUtils (com.ctrip.framework.apollo.common.utils.BeanUtils)2 Splitter (com.google.common.base.Splitter)2 Strings (com.google.common.base.Strings)2 HashMultimap (com.google.common.collect.HashMultimap)2 Maps (com.google.common.collect.Maps)2