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();
}
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");
}
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);
}
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;
}
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);
}
}
}
Aggregations