Search in sources :

Example 6 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyServiceWithCache method initialize.

private void initialize() {
    scheduledExecutorService = new ScheduledThreadPoolExecutor(1, ApolloThreadFactory.create("AccessKeyServiceWithCache", true));
    lastTimeScanned = new Date(0L);
    ListMultimap<String, AccessKey> multimap = ListMultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().build();
    accessKeyCache = Multimaps.synchronizedListMultimap(multimap);
    accessKeyIdCache = Maps.newConcurrentMap();
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) Date(java.util.Date)

Example 7 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyRepositoryTest method testFindFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTime.

@Test
@Sql(scripts = "/sql/accesskey-test.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/clean.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testFindFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTime() {
    Instant instant = LocalDateTime.of(2019, 12, 19, 13, 44, 20).atZone(ZoneId.systemDefault()).toInstant();
    Date date = Date.from(instant);
    List<AccessKey> accessKeyList = accessKeyRepository.findFirst500ByDataChangeLastModifiedTimeGreaterThanOrderByDataChangeLastModifiedTimeAsc(date);
    assertThat(accessKeyList).hasSize(2);
    assertThat(accessKeyList.get(0).getAppId()).isEqualTo("100004458");
    assertThat(accessKeyList.get(0).getSecret()).isEqualTo("4003c4d7783443dc9870932bebf3b7fe");
    assertThat(accessKeyList.get(1).getAppId()).isEqualTo("100004458");
    assertThat(accessKeyList.get(1).getSecret()).isEqualTo("c715cbc80fc44171b43732c3119c9456");
}
Also used : Instant(java.time.Instant) AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) Date(java.util.Date) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 8 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyRepositoryTest method testSave.

@Test
public void testSave() {
    String appId = "someAppId";
    String secret = "someSecret";
    AccessKey entity = new AccessKey();
    entity.setAppId(appId);
    entity.setSecret(secret);
    AccessKey accessKey = accessKeyRepository.save(entity);
    assertThat(accessKey).isNotNull();
    assertThat(accessKey.getAppId()).isEqualTo(appId);
    assertThat(accessKey.getSecret()).isEqualTo(secret);
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey) AbstractIntegrationTest(com.ctrip.framework.apollo.biz.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyServiceTest method assembleAccessKey.

private AccessKey assembleAccessKey(String appId, String secret) {
    AccessKey accessKey = new AccessKey();
    accessKey.setAppId(appId);
    accessKey.setSecret(secret);
    return accessKey;
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey)

Example 10 with AccessKey

use of com.ctrip.framework.apollo.biz.entity.AccessKey in project apollo by ctripcorp.

the class AccessKeyServiceWithCache method mergeAccessKeys.

private void mergeAccessKeys(List<AccessKey> accessKeys) {
    for (AccessKey accessKey : accessKeys) {
        AccessKey thatInCache = accessKeyIdCache.get(accessKey.getId());
        accessKeyIdCache.put(accessKey.getId(), accessKey);
        accessKeyCache.put(accessKey.getAppId(), accessKey);
        if (thatInCache != null && accessKey.getDataChangeLastModifiedTime().after(thatInCache.getDataChangeLastModifiedTime())) {
            accessKeyCache.remove(accessKey.getAppId(), thatInCache);
            logger.info("Found Accesskey changes, old: {}, new: {}", thatInCache, accessKey);
        }
    }
}
Also used : AccessKey(com.ctrip.framework.apollo.biz.entity.AccessKey)

Aggregations

AccessKey (com.ctrip.framework.apollo.biz.entity.AccessKey)17 Test (org.junit.Test)5 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)4 Date (java.util.Date)4 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 Instant (java.time.Instant)1 List (java.util.List)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 Sql (org.springframework.test.context.jdbc.Sql)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1