use of org.summerb.microservices.properties.impl.dao.AliasEntry in project summerb by skarpushin.
the class StringIdAliasServiceEagerImplFactory method createDaoMock.
private static StringIdAliasDao createDaoMock() {
StringIdAliasDao ret = Mockito.mock(StringIdAliasDao.class);
when(ret.createAliasFor(NAME)).thenReturn(NAME_ALIAS);
when(ret.findAliasFor(NAME)).thenReturn(NAME_ALIAS);
when(ret.loadAllAliases(any(PagerParams.class))).thenAnswer(new Answer<PaginatedList<Entry<String, Long>>>() {
@Override
public PaginatedList<Entry<String, Long>> answer(InvocationOnMock invocation) throws Throwable {
PagerParams pagerParams = (PagerParams) invocation.getArguments()[0];
// Synthetic pause, simulate
Thread.sleep(250);
PaginatedList<Entry<String, Long>> result = new PaginatedList<Entry<String, Long>>();
result.setPagerParams(pagerParams);
result.setTotalResults(150);
ArrayList<Entry<String, Long>> items = new ArrayList<Entry<String, Long>>();
result.setItems(items);
long offset = pagerParams.getOffset();
long max = -1;
if (offset == 0) {
max = 100;
} else if (offset == 100) {
max = 50;
} else {
fail();
}
for (long i = offset; i < max; i++) {
items.add(new AliasEntry("str" + i, i));
}
return result;
}
});
return ret;
}
use of org.summerb.microservices.properties.impl.dao.AliasEntry in project summerb by skarpushin.
the class StringIdAliasServiceEagerImpl method loadAllAliases.
protected final BiMap<String, Long> loadAllAliases() {
try {
BiMap<String, Long> ret = HashBiMap.create();
long maxOffset = -2;
for (long offset = 0; maxOffset == -2 || offset < maxOffset; offset = offset + EAGER_LOAD_BATCH_SIZE) {
PagerParams pagerParams = new PagerParams(offset, EAGER_LOAD_BATCH_SIZE);
PaginatedList<AliasEntry> loadedAliases = stringIdAliasDao.loadAllAliases(pagerParams);
maxOffset = loadedAliases.getTotalResults() - 1;
for (Entry<String, Long> entry : loadedAliases.getItems()) {
ret.put(entry.getKey(), entry.getValue());
}
}
return ret;
} catch (Throwable t) {
String msg = "Failed to eagerly load alias map";
log.error(msg, t);
throw new PropertyServiceUnexpectedException(msg, t);
}
}
Aggregations