Search in sources :

Example 1 with ObjectFactory

use of org.qi4j.api.object.ObjectFactory in project qi4j-sdk by Qi4j.

the class CompositeCreationPerformanceTest method newInstanceForRegisteredCompositePerformance.

@Test
public void newInstanceForRegisteredCompositePerformance() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(AnyComposite.class);
            module.objects(AnyObject.class);
            module.values(AnyValue.class);
        }
    };
    int loops = 2;
    long t0 = 0;
    {
        for (int i = 0; i < loops; i++) {
            t0 = t0 + testJavaObjectCreationPerformance();
        }
        t0 = t0 / loops;
    }
    long t1 = 0;
    {
        TransientBuilderFactory module = assembler.module();
        for (int i = 0; i < loops; i++) {
            t1 = t1 + testCompositeCreationPerformance(module);
        }
        t1 = t1 / loops;
    }
    long t2 = 0;
    {
        ObjectFactory objectFactory = assembler.module();
        for (int i = 0; i < loops; i++) {
            t2 = t2 + testObjectCreationPerformance(objectFactory);
        }
        t2 = t2 / loops;
    }
    long t3 = 0;
    {
        ValueBuilderFactory valueBuilderFactory = assembler.module();
        for (int i = 0; i < loops; i++) {
            t3 = t3 + testValueCreationPerformance(valueBuilderFactory);
        }
        t3 = t3 / loops;
    }
    long t4 = 0;
    {
        TransientBuilderFactory module = assembler.module();
        for (int i = 0; i < loops; i++) {
            t4 = t4 + testCompositeCreationWithBuilderPerformance(module);
        }
        t4 = t4 / loops;
    }
    long t6 = 0;
    {
        ValueBuilderFactory valueBuilderFactory = assembler.module();
        for (int i = 0; i < loops; i++) {
            t6 = t6 + testValueCreationWithBuilderPerformance(valueBuilderFactory);
        }
        t6 = t6 / loops;
    }
    System.out.println("Transient: " + (t1 / t0) + "x");
    System.out.println("TransientBuilder: " + (t4 / t0) + "x");
    System.out.println("Value: " + (t3 / t0) + "x");
    System.out.println("ValueBuilder: " + (t6 / t0) + "x");
    System.out.println("Object: " + (t2 / t0) + "x");
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ObjectFactory(org.qi4j.api.object.ObjectFactory) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ValueBuilderFactory(org.qi4j.api.value.ValueBuilderFactory) TransientBuilderFactory(org.qi4j.api.composite.TransientBuilderFactory) Test(org.junit.Test)

Example 2 with ObjectFactory

use of org.qi4j.api.object.ObjectFactory in project qi4j-sdk by Qi4j.

the class ObjectCreationPerformanceTest method newInstanceForRegisteredObjectPerformance.

@Test
public void newInstanceForRegisteredObjectPerformance() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(AnyObject.class);
        }
    };
    ObjectFactory objectFactory = assembler.module();
    for (int i = 0; i < 10; i++) {
        testPerformance(objectFactory);
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ObjectFactory(org.qi4j.api.object.ObjectFactory) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Example 3 with ObjectFactory

use of org.qi4j.api.object.ObjectFactory in project qi4j-sdk by Qi4j.

the class ServiceInjectionTest method testInjection.

private void testInjection(SingletonAssembler assembly) {
    ObjectFactory factory = assembly.module();
    ServiceUser user = factory.newObject(ServiceUser.class);
    assertEquals("X", user.testSingle());
    assertEquals("Foo", user.testIdentity());
    assertEquals("XX", user.testIterable());
    assertEquals("FooX", user.testServiceReference());
    assertEquals("FooXBarX", user.testIterableServiceReferences());
    assertEquals("Bar", user.testQualifier());
    assertEquals("A", user.testStringIterable());
    assertEquals(new Long(1L), user.testLongIterable());
}
Also used : ObjectFactory(org.qi4j.api.object.ObjectFactory)

Example 4 with ObjectFactory

use of org.qi4j.api.object.ObjectFactory in project qi4j-sdk by Qi4j.

the class ServiceIdSelectorTest method givenManyServicesWhenInjectServiceThenGetSelectedOne.

@Test
public void givenManyServicesWhenInjectServiceThenGetSelectedOne() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.objects(ServiceConsumer.class);
            module.services(TestServiceComposite1.class, TestServiceComposite2.class);
        }
    };
    ObjectFactory obf = assembler.module();
    ServiceConsumer consumer = obf.newObject(ServiceConsumer.class, TestServiceComposite2.class.getSimpleName());
    TestService service = consumer.getService();
    assertThat("service is selected one", service.test(), equalTo("mixin2"));
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ObjectFactory(org.qi4j.api.object.ObjectFactory) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Test(org.junit.Test)

Aggregations

ObjectFactory (org.qi4j.api.object.ObjectFactory)4 Test (org.junit.Test)3 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)3 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)3 TransientBuilderFactory (org.qi4j.api.composite.TransientBuilderFactory)1 ValueBuilderFactory (org.qi4j.api.value.ValueBuilderFactory)1