use of org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall in project scout.rt by eclipse.
the class BatchNormalizerTest method testNullCalls.
/**
* <ul>
* <li>Calls: some null</li>
* <li>Keys: not null</li>
* <li>Cacheable: all</li>
* </ul>
*/
@SuppressWarnings("unchecked")
@Test
public void testNullCalls() throws Exception {
BatchLookupCall batchCall = new BatchLookupCall();
for (int i = 0; i < 1000; i++) {
FruitLookupCall call = new FruitLookupCall();
long key = (i / 100) + 1;
call.setKey(key);
if (key == 5L || key == 6L || key == 9L) {
call = null;
}
batchCall.addLookupCall((LookupCall) call);
}
testInternal(batchCall, 7, 7, 300, 700);
}
use of org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall in project scout.rt by eclipse.
the class BatchNormalizerTest method testInternal.
private void testInternal(BatchLookupCall batchCall, int expectedNormalizedSize, int expectedServerInvocations, int expectedNullArrayCount, int expectedTotalResultRowCount) throws Exception {
//
BatchLookupNormalizer normalizer = new BatchLookupNormalizer();
List<ILookupCall<?>> callArray = batchCall.getCallBatch();
List<ILookupCall<?>> normCallArray = normalizer.normalizeCalls(callArray);
List<List<ILookupRow<?>>> normResultArray = new BatchLookupService().getBatchDataByKey(new BatchLookupCall(normCallArray));
List<List<ILookupRow<?>>> resultArray = normalizer.denormalizeResults(normResultArray);
//
assertEquals(resultArray.size(), callArray.size());
assertEquals(normResultArray.size(), normCallArray.size());
assertEquals(expectedNormalizedSize, normResultArray.size());
Mockito.verify(m_lookupService, Mockito.times(expectedServerInvocations)).getDataByKey(Mockito.<ILookupCall<Object>>any());
int rowCount = 0;
int nullArrayCount = 0;
for (int i = 0; i < resultArray.size(); i++) {
if (resultArray.get(i) == null) {
nullArrayCount++;
} else if (resultArray.get(i).size() == 1) {
rowCount++;
assertEquals(callArray.get(i).getKey(), resultArray.get(i).get(0).getKey());
assertEquals(dumpCall(callArray.get(i)), resultArray.get(i).get(0).getText());
} else if (resultArray.get(i).size() > 1) {
fail("result length is expected to be 0 or 1");
}
}
assertEquals(expectedNullArrayCount, nullArrayCount);
assertEquals(expectedTotalResultRowCount, rowCount);
}
use of org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall in project scout.rt by eclipse.
the class BatchNormalizerTest method testNice.
/**
* <ul>
* <li>Calls: not null</li>
* <li>Keys: not null</li>
* <li>Cacheable: all</li>
* </ul>
*/
@SuppressWarnings("unchecked")
@Test
public void testNice() throws Exception {
BatchLookupCall batchCall = new BatchLookupCall();
for (int i = 0; i < 1000; i++) {
FruitLookupCall call = new FruitLookupCall();
call.setKey(new Long((i / 100) + 1));
batchCall.addLookupCall((LookupCall) call);
}
testInternal(batchCall, 10, 10, 0, 1000);
}
use of org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall in project scout.rt by eclipse.
the class BatchLookupServiceClientProxy method getBatchDataByKey.
@Override
public List<List<ILookupRow<?>>> getBatchDataByKey(BatchLookupCall batch) {
List<ILookupCall<?>> allCalls = batch.getCallBatch();
List<ILookupCall<?>> cleanCalls = new ArrayList<ILookupCall<?>>(allCalls.size());
// set calls with key==null to null
for (ILookupCall<?> call : allCalls) {
if (call != null && call.getKey() == null) {
cleanCalls.add(null);
} else {
cleanCalls.add(call);
}
}
BatchSplit split = new BatchSplit(cleanCalls);
if (split.getLocalCallCount() > 0) {
BatchLookupResultCache cache = new BatchLookupResultCache();
List<ILookupCall<?>> calls = split.getLocalCalls();
List<List<ILookupRow<?>>> result = new ArrayList<List<ILookupRow<?>>>();
for (ILookupCall<?> call : calls) {
result.add(cache.getDataByKey(call));
}
split.setLocalResults(result);
}
if (split.getRemoteCallCount() > 0) {
BatchLookupNormalizer normalizer = new BatchLookupNormalizer();
List<ILookupCall<?>> normCallArray = normalizer.normalizeCalls(split.getRemoteCalls());
List<List<ILookupRow<?>>> normResultArray = getTargetService().getBatchDataByKey(new BatchLookupCall(normCallArray));
List<List<ILookupRow<?>>> resultArray = normalizer.denormalizeResults(normResultArray);
split.setRemoteResults(resultArray);
}
List<List<ILookupRow<?>>> results = split.getCombinedResults();
// set null results to empty list
for (int i = 0; i < results.size(); i++) {
if (results.get(i) == null) {
List<ILookupRow<?>> emptyList = CollectionUtility.emptyArrayList();
results.set(i, emptyList);
}
}
return results;
}
use of org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall in project scout.rt by eclipse.
the class BatchLookupTest method testInternal.
private void testInternal(Class<? extends IFlowerLookupCall> callClazz, int expectedLocalInvocations, int expectedServerInvocations) throws Exception {
m_localInvocations = 0;
BatchLookupCall batchCall = new BatchLookupCall();
for (int i = 0; i < 1000; i++) {
IFlowerLookupCall call = callClazz.newInstance();
call.setKey((i / 100) + 1L);
call.setLatinId((i / 10) + 1L);
batchCall.addLookupCall((LookupCall) call);
}
//
List<ILookupCall<?>> callArray = batchCall.getCallBatch();
List<List<ILookupRow<?>>> resultArray = new BatchLookupService().getBatchDataByKey(batchCall);
assertEquals(resultArray.size(), callArray.size());
assertEquals(expectedLocalInvocations, m_localInvocations);
Mockito.verify(m_lookupService, Mockito.times(expectedServerInvocations)).getDataByKey(Mockito.<ILookupCall<Object>>any());
for (int i = 0; i < resultArray.size(); i++) {
assertEquals(1, resultArray.get(i).size());
assertEquals(callArray.get(i).getKey(), resultArray.get(i).get(0).getKey());
assertEquals(dumpCall(callArray.get(i)), resultArray.get(i).get(0).getText());
}
}
Aggregations