use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.
the class CodeServiceTest method testInvlidateCodeType.
/**
* Tests that a client notification is created when invalidating a code type
* {@link CodeService#invalidateCodeType(Class)}
*/
@Test
public void testInvlidateCodeType() {
ICodeService codeService = BEANS.get(ICodeService.class);
codeService.getCodeType(SomeCodeType.class);
// verify that execLoadCodes has been invoked and reset flag, so that next execLoadCodes can be detected
assertTrue(SomeCodeType.EXEC_LOAD_CODES_INVOKED.getAndSet(false));
codeService.invalidateCodeType(SomeCodeType.class);
assertFalse(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
// check notification
ArgumentCaptor<InvalidateCacheNotification> notification = ArgumentCaptor.forClass(InvalidateCacheNotification.class);
verify(m_clientNotificationReg).putTransactionalForAllNodes(notification.capture(), anyBoolean());
Set<Class<? extends ICodeType<?, ?>>> codeTypeClasses = ((CodeTypeCacheEntryFilter) notification.getValue().getFilter()).getCodeTypeClasses();
assertEquals("CodeType list in the notification size", 1, codeTypeClasses.size());
assertEquals("CodeType list(0) class", SomeCodeType.class, codeTypeClasses.iterator().next());
// get codetype manually
codeService.getCodeType(SomeCodeType.class);
assertTrue(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
}
use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.
the class ClientNotificationServerCacheWrapper method invalidate.
@Override
public void invalidate(ICacheEntryFilter<K, V> filter, boolean propagate) {
super.invalidate(filter, propagate);
// always send invalidate operations from a server to clients and do not check on the propagate property
InvalidateCacheNotification notification = new InvalidateCacheNotification(getCacheId(), filter);
BEANS.get(ClientNotificationRegistry.class).putTransactionalForAllNodes(notification, false);
}
use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.
the class InvalidateCacheNotificationCoalescer method coalesce.
@Override
public List<InvalidateCacheNotification> coalesce(List<InvalidateCacheNotification> notifications) {
List<InvalidateCacheNotification> result = new ArrayList<>();
if (notifications.isEmpty()) {
return result;
}
Map<String, List<ICacheEntryFilter<?, ?>>> filterMap = new HashMap<>();
for (InvalidateCacheNotification notification : notifications) {
List<ICacheEntryFilter<?, ?>> list = filterMap.get(notification.getCacheId());
if (list == null) {
list = new ArrayList<>();
list.add(notification.getFilter());
} else {
coalesceFilters(list, notification.getFilter());
}
filterMap.put(notification.getCacheId(), list);
}
for (Entry<String, List<ICacheEntryFilter<?, ?>>> entry : filterMap.entrySet()) {
for (ICacheEntryFilter<?, ?> filter : entry.getValue()) {
result.add(new InvalidateCacheNotification(entry.getKey(), filter));
}
}
return result;
}
Aggregations