Search in sources :

Example 31 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler 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 32 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler 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 33 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class ServiceInvocationPerformanceTest method testInjectService.

public void testInjectService() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(ServiceInvocationPerformanceTest.MyServiceComposite.class);
            module.objects(ServiceInvocationPerformanceTest.class);
        }
    };
    assembly.module().injectTo(this);
    // Warmup
    for (int i = 0; i < 60000; i++) {
        service.test();
    }
    int rounds = 5;
    for (int i = 0; i < rounds; i++) {
        performanceCheck(service);
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler)

Example 34 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class Main method main.

public static void main(String[] args) throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(BoundPersonComposite.class);
            module.transients(AddressTransient.class);
            module.values(CityValue.class, CountryValue.class);
            new SwingBindingAssembler().assemble(module);
        }
    };
    module = assembler.module();
    Address address1 = createAddress("Vista Damai", "Jalan Tun Razak");
    Address address2 = createAddress("Mutiara", "Jalan Ceylon");
    TransientBuilder<BoundPersonComposite> builder = module.newTransientBuilder(BoundPersonComposite.class);
    PersonComposite prototype = builder.prototype();
    prototype.address().set(address1);
    prototype.firstName().set("Niclas");
    final BoundPersonComposite p1 = builder.newInstance();
    prototype.address().set(address2);
    prototype.firstName().set("Edward");
    final BoundPersonComposite p2 = builder.newInstance();
    final StateModel<BoundPersonComposite> model = module.newObject(StateModel.class, BoundPersonComposite.class);
    Form form = new Form<BoundPersonComposite>(model);
    JFrame frame = new JFrame("testing");
    frame.add(form, BorderLayout.CENTER);
    JPanel checkBoxPanel = new JPanel();
    checkBoxPanel.setFocusable(true);
    checkBoxPanel.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            System.out.println("Gained!");
        }

        public void focusLost(FocusEvent e) {
            System.out.println("LOst!");
        }
    });
    JCheckBox sw = new JCheckBox("Toggle");
    sw.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (((JCheckBox) e.getSource()).isSelected()) {
                model.use(p1);
                System.out.println(p1.firstName().get());
            } else {
                model.use(p2);
                System.out.println(p2.firstName().get());
            }
        }
    });
    checkBoxPanel.add(sw);
    frame.add(checkBoxPanel, BorderLayout.EAST);
    frame.pack();
    System.out.println(model);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
Also used : JPanel(javax.swing.JPanel) SwingBindingAssembler(org.qi4j.lib.swing.binding.SwingBindingAssembler) ActionEvent(java.awt.event.ActionEvent) FocusEvent(java.awt.event.FocusEvent) JCheckBox(javax.swing.JCheckBox) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) FocusListener(java.awt.event.FocusListener)

Example 35 with SingletonAssembler

use of org.qi4j.bootstrap.SingletonAssembler in project qi4j-sdk by Qi4j.

the class SequencingConcernTest method successfulBooking.

/**
     * Tests that when shipping service succeeds to make the booking generator gets called and generated value is
     * returned.
     */
@Test
@Ignore("Expectations need to be figured out.")
public void successfulBooking() throws ActivationException, AssemblyException {
    SingletonAssembler assembler = new SingletonAssembler() {

        @Override
        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.transients(ShippingServiceTestComposite.class);
        }
    };
    ShippingService shippingService = createMock(ShippingService.class);
    Cargo cargo = createMock(Cargo.class);
    Voyage voyage = createMock(Voyage.class);
    HasSequence generator = createMock(HasSequence.class);
    Property<Integer> sequence = createMock(Property.class);
    expect(shippingService.makeBooking(cargo, voyage)).andReturn(100);
    expect(generator.sequence()).andReturn(sequence).anyTimes();
    expect(sequence.get()).andReturn(1000);
    replay(shippingService, cargo, voyage, generator, sequence);
    ShippingServiceTestComposite underTest = assembler.module().newTransient(ShippingServiceTestComposite.class);
    underTest.useMock(shippingService).forClass(ShippingService.class);
    underTest.useMock(generator).forClass(HasSequence.class);
    assertThat("Booking result", underTest.makeBooking(cargo, voyage), is(equalTo(1000)));
    verify(shippingService, cargo, voyage, generator, sequence);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)87 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)87 Test (org.junit.Test)65 Module (org.qi4j.api.structure.Module)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)14 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)13 Before (org.junit.Before)11 Application (org.qi4j.api.structure.Application)10 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)5 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 ServiceReference (org.qi4j.api.service.ServiceReference)4 ArrayList (java.util.ArrayList)3 TransientBuilderFactory (org.qi4j.api.composite.TransientBuilderFactory)3 ObjectFactory (org.qi4j.api.object.ObjectFactory)3 ValueBuilder (org.qi4j.api.value.ValueBuilder)3 UnitOfWorkDomainEventsValue (org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue)3 File (java.io.File)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 ServiceDeclaration (org.qi4j.bootstrap.ServiceDeclaration)2