Search in sources :

Example 11 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleZoneContextTest method normalCaseTest.

@SuppressWarnings("unchecked")
@Test
public void normalCaseTest() {
    EzyServerContext parent = mock(EzyServerContext.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    EzySimpleZone zone = new EzySimpleZone();
    zone.setUserManager(mock(EzyZoneUserManager.class));
    zone.setSetting(zoneSetting);
    EzySimpleZoneContext context = new EzySimpleZoneContext();
    context.setZone(zone);
    context.setParent(parent);
    context.init();
    assert context.get(EzyBroadcastEvent.class) != null;
    Asserts.assertNull(context.get(Void.class));
    context.addCommand(ExCommand.class, ExCommand::new);
    assert context.cmd(ExCommand.class) != null;
    Asserts.assertNull(context.cmd(Void.class));
    context.broadcast(EzyEventType.SERVER_INITIALIZING, new EzySimpleServerInitializingEvent(), true);
    context.broadcastApps(EzyEventType.SERVER_READY, new EzySimpleServerReadyEvent(), true);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("dungtv");
    EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, "dungtv", true);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, user, true);
    context.broadcastApps(EzyEventType.USER_ACCESS_APP, accessAppEvent, EzyPredicates.ALWAYS_TRUE, true);
    // noinspection EqualsWithItself
    assert context.equals(context);
    EzyZoneContext zoneContext2 = mock(EzyZoneContext.class);
    EzySimpleZone zone2 = new EzySimpleZone();
    when(zoneContext2.getZone()).thenReturn(zone2);
    assert !zoneContext2.equals(context);
    System.out.println(context.hashCode() + ", " + context.hashCode());
    assert context.hashCode() == context.hashCode();
    EzyResponse response = mock(EzyResponse.class);
    EzySession recipient = spy(EzyAbstractSession.class);
    context.send(response, recipient, false);
    context.send(response, Lists.newArrayList(recipient), false);
    context.stream(new byte[0], recipient);
    context.stream(new byte[0], Lists.newArrayList(recipient));
    context.destroy();
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) EzyBroadcastEvent(com.tvd12.ezyfoxserver.command.EzyBroadcastEvent) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzySimpleServerReadyEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) EzyUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 12 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzySimpleZoneContextTest method equalsCaseTest.

@Test
public void equalsCaseTest() {
    EzySimpleZoneContext zoneContext1 = new EzySimpleZoneContext();
    EzySimpleZone zone1 = new EzySimpleZone();
    zoneContext1.setZone(zone1);
    EzySimpleZoneContext zoneContext2 = new EzySimpleZoneContext();
    EzySimpleZone zone2 = new EzySimpleZone();
    zoneContext1.setZone(zone2);
    assert !zoneContext1.equals(zoneContext2);
}
Also used : EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 13 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzyAppsStarterTest method newAppEntryLoaderClassLoaderIsNull.

@Test
public void newAppEntryLoaderClassLoaderIsNull() {
    // given
    Map<String, ClassLoader> loaders = new ConcurrentHashMap<>();
    EzySimpleZoneContext zoneContext = EzyZoneContextsTest.newDefaultZoneContext();
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("abc");
    app.setSetting(appSetting);
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(app);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
    appsSetting.setItem(appSetting);
    zoneSetting.setApplications(appsSetting);
    zoneContext.addAppContext(appSetting, appContext);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    zoneContext.setZone(zone);
    EzyAppsStarter starter = new EzyAppsStarter.Builder().zoneContext(zoneContext).appClassLoaders(loaders).enableAppClassLoader(true).build();
    // when
    starter.start();
    // then
    Asserts.assertNull(app.getEntry());
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleAppsSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 14 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzyAppsStarterTest method newAppEntryLoaderArgsNotNullTest.

@Test
public void newAppEntryLoaderArgsNotNullTest() {
    // given
    Map<String, ClassLoader> loaders = new ConcurrentHashMap<>();
    EzySimpleZoneContext zoneContext = EzyZoneContextsTest.newDefaultZoneContext();
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("abc");
    appSetting.setEntryLoader(InternalAppEntryLoader.class);
    appSetting.setEntryLoaderArgs(new String[] { "Hello" });
    app.setSetting(appSetting);
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(app);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
    appsSetting.setItem(appSetting);
    zoneSetting.setApplications(appsSetting);
    zoneContext.addAppContext(appSetting, appContext);
    EzySimpleZone zone = new EzySimpleZone();
    zone.setSetting(zoneSetting);
    zoneContext.setZone(zone);
    EzyAppsStarter starter = new EzyAppsStarter.Builder().zoneContext(zoneContext).appClassLoaders(loaders).enableAppClassLoader(false).classLoader(Thread.currentThread().getContextClassLoader()).build();
    // when
    starter.start();
    // then
    Asserts.assertNotNull(app.getEntry());
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) EzySimpleZone(com.tvd12.ezyfoxserver.EzySimpleZone) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleAppsSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 15 with EzySimpleZoneContext

use of com.tvd12.ezyfoxserver.context.EzySimpleZoneContext in project ezyfox-server by youngmonkeys.

the class EzyAppsStarterTest method test2.

@Test
public void test2() {
    Map<String, ClassLoader> loaders = new ConcurrentHashMap<>();
    EzySimpleZoneContext zoneContext = EzyZoneContextsTest.newDefaultZoneContext();
    EzySimpleApplication app = new EzySimpleApplication();
    EzySimpleAppSetting appSetting = new EzySimpleAppSetting();
    appSetting.setName("abc");
    app.setSetting(appSetting);
    EzySimpleAppContext appContext = new EzySimpleAppContext();
    appContext.setApp(app);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    EzySimpleAppsSetting appsSetting = new EzySimpleAppsSetting();
    appsSetting.setItem(appSetting);
    zoneSetting.setApplications(appsSetting);
    zoneContext.addAppContext(appSetting, appContext);
    EzyAppsStarter starter = new EzyAppsStarter.Builder().zoneContext(zoneContext).appClassLoaders(loaders).build();
    starter.start();
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzySimpleApplication(com.tvd12.ezyfoxserver.EzySimpleApplication) EzySimpleZoneContext(com.tvd12.ezyfoxserver.context.EzySimpleZoneContext) EzySimpleAppsSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting) EzyAppsStarter(com.tvd12.ezyfoxserver.EzyAppsStarter) EzySimpleAppContext(com.tvd12.ezyfoxserver.context.EzySimpleAppContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Aggregations

EzySimpleZoneContext (com.tvd12.ezyfoxserver.context.EzySimpleZoneContext)18 Test (org.testng.annotations.Test)17 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)16 EzyEventControllers (com.tvd12.ezyfoxserver.wrapper.EzyEventControllers)11 EzyErrorScheduledExecutorService (com.tvd12.ezyfox.concurrent.EzyErrorScheduledExecutorService)10 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)10 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)10 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)10 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)9 EzySimpleAppContext (com.tvd12.ezyfoxserver.context.EzySimpleAppContext)9 BaseTest (com.tvd12.test.base.BaseTest)9 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)7 EzySimplePlugin (com.tvd12.ezyfoxserver.EzySimplePlugin)6 EzySimplePluginContext (com.tvd12.ezyfoxserver.context.EzySimplePluginContext)6 EzySimpleAppEntry (com.tvd12.ezyfoxserver.support.entry.EzySimpleAppEntry)5 EzySimplePluginEntry (com.tvd12.ezyfoxserver.support.entry.EzySimplePluginEntry)5 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)5 EzyAppsStarter (com.tvd12.ezyfoxserver.EzyAppsStarter)4 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)4 EzySimpleAppsSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppsSetting)4