Search in sources :

Example 1 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class CodeServiceTest method testInvlidateCodeTypes.

/**
 * Tests that a client notification is created when invalidating a list of code types
 * {@link CodeService#invalidateCodeTypes(List)}
 */
@Test
public void testInvlidateCodeTypes() {
    ICodeService codeService = BEANS.get(ICodeService.class);
    List<Class<? extends ICodeType<?, ?>>> list = new ArrayList<Class<? extends ICodeType<?, ?>>>();
    list.add(SomeCodeType.class);
    list.add(DummyCodeType.class);
    codeService.invalidateCodeTypes(list);
    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", 2, codeTypeClasses.size());
    for (Class<? extends ICodeType<?, ?>> codeTypeClass : codeTypeClasses) {
        assertTrue("CodeTypes not invalidated", codeTypeClass == SomeCodeType.class || codeTypeClass == DummyCodeType.class);
    }
}
Also used : ICodeType(org.eclipse.scout.rt.shared.services.common.code.ICodeType) CodeTypeCacheEntryFilter(org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter) ICodeService(org.eclipse.scout.rt.shared.services.common.code.ICodeService) ArrayList(java.util.ArrayList) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) Test(org.junit.Test)

Example 2 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class CodeServiceTest method testReloadCodeTypes.

@Test
public void testReloadCodeTypes() {
    ICodeService codeService = BEANS.get(ICodeService.class);
    List<Class<? extends ICodeType<?, ?>>> list = new ArrayList<Class<? extends ICodeType<?, ?>>>();
    list.add(SomeCodeType.class);
    list.add(DummyCodeType.class);
    codeService.reloadCodeTypes(list);
    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", 2, codeTypeClasses.size());
    for (Class<? extends ICodeType<?, ?>> codeTypeClass : codeTypeClasses) {
        assertTrue("CodeTypes not invalidated", codeTypeClass == SomeCodeType.class || codeTypeClass == DummyCodeType.class);
    }
}
Also used : ICodeType(org.eclipse.scout.rt.shared.services.common.code.ICodeType) CodeTypeCacheEntryFilter(org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter) ICodeService(org.eclipse.scout.rt.shared.services.common.code.ICodeService) ArrayList(java.util.ArrayList) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) Test(org.junit.Test)

Example 3 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class InvalidateCacheNofificationCoalescerTest method testCoalesceNotificationsSet.

@Test
public void testCoalesceNotificationsSet() {
    InvalidateCacheNotificationCoalescer coalescer = new InvalidateCacheNotificationCoalescer();
    ICacheEntryFilter<Object, Object> filter1 = new KeyCacheEntryFilter<Object, Object>(CollectionUtility.<Object>arrayList(CodeType1.class));
    ICacheEntryFilter<Object, Object> filter2 = new KeyCacheEntryFilter<Object, Object>(CollectionUtility.<Object>arrayList(CodeType2.class));
    List<InvalidateCacheNotification> testList = CollectionUtility.arrayList(new InvalidateCacheNotification(CACHE_ID_1, filter1), new InvalidateCacheNotification(CACHE_ID_1, filter2), new InvalidateCacheNotification(CACHE_ID_2, filter2), new InvalidateCacheNotification(CACHE_ID_3, new AllCacheEntryFilter<>()), new InvalidateCacheNotification(CACHE_ID_3, filter2));
    List<InvalidateCacheNotification> res = coalescer.coalesce(testList);
    assertEquals(3, res.size());
    for (InvalidateCacheNotification notification : res) {
        if (CACHE_ID_1.equals(notification.getCacheId())) {
            Set<?> keys = ((KeyCacheEntryFilter<?, ?>) notification.getFilter()).getKeys();
            assertEquals(2, keys.size());
            assertTrue(keys.contains(CodeType1.class));
            assertTrue(keys.contains(CodeType2.class));
        } else if (CACHE_ID_2.equals(notification.getCacheId())) {
            Set<?> keys = ((KeyCacheEntryFilter<?, ?>) notification.getFilter()).getKeys();
            assertEquals(1, keys.size());
            assertTrue(keys.contains(CodeType2.class));
        } else if (CACHE_ID_3.equals(notification.getCacheId())) {
            assertTrue(notification.getFilter() instanceof AllCacheEntryFilter);
        } else {
            fail("invalid cacheId" + notification.getCacheId());
        }
    }
}
Also used : AllCacheEntryFilter(org.eclipse.scout.rt.shared.cache.AllCacheEntryFilter) Set(java.util.Set) KeyCacheEntryFilter(org.eclipse.scout.rt.shared.cache.KeyCacheEntryFilter) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) Test(org.junit.Test)

Example 4 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class ClusterSynchronizationServiceTest method testTransactionalWithCoalesce.

@Test
public void testTransactionalWithCoalesce() throws Exception {
    ArgumentCaptor<ClusterNotificationMessage> msgCaptor = ArgumentCaptor.forClass(ClusterNotificationMessage.class);
    doNothing().when(m_nullMomImplementorSpy).publish(eq(IClusterMomDestinations.CLUSTER_NOTIFICATION_TOPIC), msgCaptor.capture(), any(PublishInput.class));
    m_svc.publishTransactional(new BookmarkChangedClientNotification());
    m_svc.publishTransactional(new BookmarkChangedClientNotification());
    m_svc.publishTransactional(new InvalidateCacheNotification("TEST", new AllCacheEntryFilter<>()));
    ITransaction.CURRENT.get().commitPhase1();
    ITransaction.CURRENT.get().commitPhase2();
    // verify
    verify(m_nullMomImplementorSpy, times(2)).publish(eq(IClusterMomDestinations.CLUSTER_NOTIFICATION_TOPIC), any(IClusterNotificationMessage.class), any(PublishInput.class));
    assertEquals(2, m_svc.getStatusInfo().getSentMessageCount());
    List<ClusterNotificationMessage> messages = msgCaptor.getAllValues();
    assertEquals(BookmarkChangedClientNotification.class, messages.get(0).getNotification().getClass());
    assertEquals(InvalidateCacheNotification.class, messages.get(1).getNotification().getClass());
}
Also used : BookmarkChangedClientNotification(org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkChangedClientNotification) AllCacheEntryFilter(org.eclipse.scout.rt.shared.cache.AllCacheEntryFilter) PublishInput(org.eclipse.scout.rt.mom.api.PublishInput) ClusterNotificationMessage(org.eclipse.scout.rt.server.services.common.clustersync.internal.ClusterNotificationMessage) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) Test(org.junit.Test)

Example 5 with InvalidateCacheNotification

use of org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification in project scout.rt by eclipse.

the class CodeServiceTest method testReloadCodeType.

/**
 * Tests that a client notification is created when reloading a code type {@link CodeService#reloadCodeType}
 */
@Test
public void testReloadCodeType() {
    ICodeService codeService = BEANS.get(ICodeService.class);
    codeService.reloadCodeType(SomeCodeType.class);
    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());
}
Also used : ICodeType(org.eclipse.scout.rt.shared.services.common.code.ICodeType) CodeTypeCacheEntryFilter(org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter) ICodeService(org.eclipse.scout.rt.shared.services.common.code.ICodeService) InvalidateCacheNotification(org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification) Test(org.junit.Test)

Aggregations

InvalidateCacheNotification (org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification)8 Test (org.junit.Test)6 CodeTypeCacheEntryFilter (org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter)4 ICodeService (org.eclipse.scout.rt.shared.services.common.code.ICodeService)4 ICodeType (org.eclipse.scout.rt.shared.services.common.code.ICodeType)4 ArrayList (java.util.ArrayList)3 AllCacheEntryFilter (org.eclipse.scout.rt.shared.cache.AllCacheEntryFilter)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Set (java.util.Set)1 PublishInput (org.eclipse.scout.rt.mom.api.PublishInput)1 ClientNotificationRegistry (org.eclipse.scout.rt.server.clientnotification.ClientNotificationRegistry)1 ClusterNotificationMessage (org.eclipse.scout.rt.server.services.common.clustersync.internal.ClusterNotificationMessage)1 ICacheEntryFilter (org.eclipse.scout.rt.shared.cache.ICacheEntryFilter)1 KeyCacheEntryFilter (org.eclipse.scout.rt.shared.cache.KeyCacheEntryFilter)1 BookmarkChangedClientNotification (org.eclipse.scout.rt.shared.services.common.bookmark.BookmarkChangedClientNotification)1