Search in sources :

Example 1 with ICodeService

use of org.eclipse.scout.rt.shared.services.common.code.ICodeService 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 ICodeService

use of org.eclipse.scout.rt.shared.services.common.code.ICodeService 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 ICodeService

use of org.eclipse.scout.rt.shared.services.common.code.ICodeService 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)

Example 4 with ICodeService

use of org.eclipse.scout.rt.shared.services.common.code.ICodeService 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());
}
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)

Example 5 with ICodeService

use of org.eclipse.scout.rt.shared.services.common.code.ICodeService in project scout.rt by eclipse.

the class CodeServiceTest method testInvlidateCodeTypeInDifferentTransactions.

@Test
public void testInvlidateCodeTypeInDifferentTransactions() {
    final ICodeService codeService = BEANS.get(ICodeService.class);
    // make sure code type is loaded
    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));
    // invalidate code type in another transaction
    ServerRunContexts.copyCurrent().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            // invalidate code type
            codeService.invalidateCodeType(SomeCodeType.class);
            // verify that code type has not been loaded yet
            assertFalse(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
        }
    });
    // verify that code type has not been loaded yet
    assertFalse(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
    // load code type in another transaction
    ServerRunContexts.copyCurrent().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            // invalidate code type
            assertNotNull(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));
        }
    });
    assertNotNull(codeService.getCodeType(SomeCodeType.class));
    assertFalse(SomeCodeType.EXEC_LOAD_CODES_INVOKED.get());
}
Also used : ICodeService(org.eclipse.scout.rt.shared.services.common.code.ICodeService) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Aggregations

ICodeService (org.eclipse.scout.rt.shared.services.common.code.ICodeService)5 Test (org.junit.Test)5 InvalidateCacheNotification (org.eclipse.scout.rt.shared.cache.InvalidateCacheNotification)4 CodeTypeCacheEntryFilter (org.eclipse.scout.rt.shared.services.common.code.CodeTypeCacheEntryFilter)4 ICodeType (org.eclipse.scout.rt.shared.services.common.code.ICodeType)4 ArrayList (java.util.ArrayList)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)1