use of com.tvd12.ezyfox.bean.EzyBeanContext in project calabash by youngmonkeys.
the class LocalMapAnimalPersistExample method test.
@SuppressWarnings("rawtypes")
public void test() throws Exception {
SimpleSettings settings = new SimpleSettings();
SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
mapPersistSetting.setWriteDelay(0);
SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
mapSetting.setMapName(CollectionNames.ANIMAL);
mapSetting.setPersistSetting(mapPersistSetting);
settings.addMapSetting(mapSetting);
EzyBeanContext beanContext = newBeanContext();
SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
List mapPersistences = beanContext.getSingletons(MapPersistence.class);
for (Object mapPersist : mapPersistences) {
String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
}
Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
Animal animal = new Animal(2, "animal 2", "cat");
EntityMap<Long, Animal> entityMap = calabash.getEntityMap(CollectionNames.ANIMAL);
entityMap.put(animal.getId(), animal);
AnimalByNickQuery query = new AnimalByNickQuery(animal.getNick());
Animal animalByQuery = entityMap.getByQuery(1L, query);
System.out.println("animal by query: " + animalByQuery);
Map<String, Object> statistics = new HashMap<>();
// noinspection InfiniteLoopStatement
while (true) {
// noinspection BusyWait
Thread.sleep(1000);
((StatisticsAware) calabash).addStatistics(statistics);
System.out.println("statistics: " + statistics);
}
}
use of com.tvd12.ezyfox.bean.EzyBeanContext in project calabash by youngmonkeys.
the class LocalMapPersistExample method test.
@SuppressWarnings("rawtypes")
public void test() throws Exception {
SimpleSettings settings = new SimpleSettings();
SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
mapPersistSetting.setWriteDelay(0);
SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
mapSetting.setMapName(CollectionNames.PERSON);
mapSetting.setPersistSetting(mapPersistSetting);
settings.addMapSetting(mapSetting);
EzyBeanContext beanContext = newBeanContext();
SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
List mapPersistenceList = beanContext.getSingletons(MapPersistence.class);
for (Object mapPersist : mapPersistenceList) {
String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
}
Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
Person person = new Person(11, "person 6", 18);
EntityMap<Long, Person> entityMap = calabash.getEntityMap(CollectionNames.PERSON);
entityMap.put(person.getId(), person);
IAtomicLong atomicLong = calabash.getAtomicLong("hello");
long newValue = atomicLong.addAndGet(100L);
System.out.println("atomic long new value: " + newValue);
Map<String, Object> statistics = new HashMap<>();
// noinspection InfiniteLoopStatement
while (true) {
// noinspection BusyWait
Thread.sleep(1000);
((StatisticsAware) calabash).addStatistics(statistics);
System.out.println("statistics: " + statistics);
}
}
use of com.tvd12.ezyfox.bean.EzyBeanContext in project calabash by youngmonkeys.
the class LocalMapPersistExample method test.
@SuppressWarnings("rawtypes")
public void test() {
EzyEntityCodec entityCodec = newEntityCodec();
SimpleSettings settings = new SimpleSettings();
SimpleMapPersistSetting mapPersistSetting = new SimpleMapPersistSetting();
SimpleMapSetting mapSetting = new SimpleMapSetting();
mapSetting.setMapName(CollectionNames.PERSON);
mapSetting.setPersistSetting(mapPersistSetting);
settings.addMapSetting(mapSetting);
EzyBeanContext beanContext = newBeanContext();
SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
List mapPersistenceList = beanContext.getSingletons(MapPersistence.class);
for (Object mapPersist : mapPersistenceList) {
String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
}
BytesMapPersistFactory bytesMapPersistFactory = EntityBytesMapPersistFactory.builder().entityCodec(entityCodec).entityMapPersistFactory(mapPersistFactoryBuilder.build()).build();
Calabash calabash = CalabashServerContext.builder().settings(settings).bytesMapPersistFactory(bytesMapPersistFactory).build();
ByteArray keyBytes = new ByteArray(entityCodec.serialize(1L));
byte[] values = entityCodec.serialize(new Person(9L, "bar", 29));
BytesMap bytesMap = calabash.getBytesMap(CollectionNames.PERSON);
bytesMap.put(keyBytes, values);
}
use of com.tvd12.ezyfox.bean.EzyBeanContext in project calabash by youngmonkeys.
the class ServerCoreBaseTest method newBeanContext.
protected EzyBeanContext newBeanContext() {
MongoClient mongoClient = newMongoClient();
EzyBeanContextBuilder builder = EzyBeanContext.builder().addSingleton("mongoClient", mongoClient).scan("com.tvd12.calabash.local.test.mappersist");
addAutoImplMongoRepo(builder, mongoClient);
return builder.build();
}
use of com.tvd12.ezyfox.bean.EzyBeanContext in project ezyfox-server by youngmonkeys.
the class EzySimpleAppEntryTest method scanPackages.
@Test
public void scanPackages() {
// given
EzyAppContext appContext = mock(EzyAppContext.class);
ScheduledExecutorService executorService = mock(ScheduledExecutorService.class);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
EzyServerContext serverContext = mock(EzyServerContext.class);
EzyApplication application = mock(EzyApplication.class);
EzyAppUserManager appUserManager = mock(EzyAppUserManager.class);
EzyAppSetup appSetup = mock(EzyAppSetup.class);
EzyAppSetting appSetting = mock(EzyAppSetting.class);
when(application.getSetting()).thenReturn(appSetting);
InternalAppEntry sut = new InternalAppEntry();
// when
when(appContext.get(ScheduledExecutorService.class)).thenReturn(executorService);
when(appContext.getParent()).thenReturn(zoneContext);
when(zoneContext.getParent()).thenReturn(serverContext);
when(appContext.getApp()).thenReturn(application);
when(application.getUserManager()).thenReturn(appUserManager);
when(appContext.get(EzyAppSetup.class)).thenReturn(appSetup);
sut.config(appContext);
// then
EzyBeanContext beanContext = sut.beanContext;
MongoConfig mongoConfig = (MongoConfig) beanContext.getBean(MongoConfig.class);
Set<String> expectedPackages = Sets.newHashSet(EzySupportConstants.DEFAULT_PACKAGE_TO_SCAN, "com.tvd12.ezyfoxserver.support.v120.test.entry");
Asserts.assertEquals(expectedPackages, mongoConfig.packagesToScan);
Singleton singleton = (Singleton) beanContext.getBean(Singleton.class);
Asserts.assertNotNull(singleton);
}
Aggregations