Search in sources :

Example 1 with EzyEventControllersImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl in project ezyfox-server by youngmonkeys.

the class EzyEventControllersImplTest method multiThreadTest.

@SuppressWarnings("unchecked")
@Test
public void multiThreadTest() {
    EzyEventControllersImpl sut = new EzyEventControllersImpl();
    ExecutorService executorService = Executors.newFixedThreadPool(12);
    AtomicBoolean active = new AtomicBoolean(true);
    executorService.execute(() -> {
        while (active.get()) {
            for (EzyEventType eventType : EzyEventType.values()) {
                sut.addController(eventType, mock(EzyEventController.class));
            }
            EzyThreads.sleep(1);
        }
    });
    executorService.execute(() -> {
        while (active.get()) {
            for (EzyEventType eventType : EzyEventType.values()) {
                for (EzyEventController controller : sut.getControllers(eventType)) {
                    controller.handle(null, null);
                }
            }
            EzyThreads.sleep(1);
        }
    });
    EzyThreads.sleep(1000);
    executorService.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EzyEventType(com.tvd12.ezyfoxserver.constant.EzyEventType) EzyEventControllersImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl) ExecutorService(java.util.concurrent.ExecutorService) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 2 with EzyEventControllersImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl in project ezyfox-server by youngmonkeys.

the class EzyEventControllersImplTest method getListControllerTest.

@Test
public void getListControllerTest() {
    // given
    EzyEventControllersImpl sut = new EzyEventControllersImpl();
    EzyEventController c1 = mock(EzyEventController.class);
    EzyEventController c2 = mock(EzyEventController.class);
    sut.addController(EzyEventType.SERVER_INITIALIZING, c1);
    sut.addController(EzyEventType.SERVER_INITIALIZING, c2);
    // when
    List<EzyEventController> controllers = sut.getControllers(EzyEventType.SERVER_INITIALIZING);
    // then
    Asserts.assertEquals(controllers, Arrays.asList(c1, c2), false);
    Asserts.assertEmpty(sut.getControllers(EzyEventType.USER_ACCESS_APP));
}
Also used : EzyEventControllersImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl) EzyEventController(com.tvd12.ezyfoxserver.controller.EzyEventController) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with EzyEventControllersImpl

use of com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl in project ezyfox-server by youngmonkeys.

the class EzyAppFireEventImplTest method test.

@Test
public void test() {
    EzySimpleAppSetting app = mock(EzySimpleAppSetting.class);
    EzyAppContext context = mock(EzyAppContext.class);
    EzySimpleApplication application = new EzySimpleApplication();
    application.setEventControllers(new EzyEventControllersImpl());
    application.setSetting(app);
    when(context.getApp()).thenReturn(application);
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzyEventControllersImpl(com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Aggregations

EzyEventControllersImpl (com.tvd12.ezyfoxserver.wrapper.impl.EzyEventControllersImpl)3 Test (org.testng.annotations.Test)3 EzyEventController (com.tvd12.ezyfoxserver.controller.EzyEventController)2 BaseTest (com.tvd12.test.base.BaseTest)2 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)1 EzyEventType (com.tvd12.ezyfoxserver.constant.EzyEventType)1 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)1 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)1 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1