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");
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations