Permalink
Browse files

FIX: some issues with priority not being propagated to components

causing issues with components ordering
  • Loading branch information...
xhanin committed Oct 10, 2014
1 parent bea3aad commit da0a80dd793401d9331ea6be6e73eac4bfd07e42
@@ -29,7 +29,7 @@ public boolean canBuild(Name<?> name) {
if (!canBuild(name)) {
throw new IllegalArgumentException("unsuported name " + name);
}
- return (MachineEngine<T>) new StdMachineEngine<RestxConfig>((Name<RestxConfig>) name, BoundlessComponentBox.FACTORY) {
+ return (MachineEngine<T>) new StdMachineEngine<RestxConfig>((Name<RestxConfig>) name, priority(), BoundlessComponentBox.FACTORY) {
private final Factory.Query<ConfigSupplier> configSupplierQuery = Factory.Query.byClass(ConfigSupplier.class);
private final Factory.Query<String> stringsQuery = Factory.Query.byClass(String.class);
@@ -8,7 +8,7 @@ public AlternativesFactoryMachine(int priority,
final ImmutableMap<T, ? extends FactoryMachine> alternatives,
ComponentBox.BoxFactory boxFactory) {
super(priority, new StdMachineEngine<FactoryMachine>(
- Name.of(FactoryMachine.class, name.getName() + "Alternatives"), boxFactory) {
+ Name.of(FactoryMachine.class, name.getName() + "Alternatives"), priority, boxFactory) {
private Factory.Query<T> query = Factory.Query.byName(name);
@Override
@@ -13,7 +13,7 @@
private final NamedComponent<C> component;
public SingletonFactoryMachine(int priority, final NamedComponent<C> component) {
- super(priority, new NoDepsMachineEngine<C>(component.getName(), BoundlessComponentBox.FACTORY) {
+ super(priority, new NoDepsMachineEngine<C>(component.getName(), priority, BoundlessComponentBox.FACTORY) {
@Override
public C doNewComponent(SatisfiedBOM satisfiedBOM) {
return component.getComponent();
@@ -18,7 +18,7 @@ public boolean canBuild(Name<?> name) {
@Override
@SuppressWarnings("unchecked")
public <T> MachineEngine<T> getEngine(final Name<T> name) {
- return new NoDepsMachineEngine<T>(name, BoundlessComponentBox.FACTORY) {
+ return new NoDepsMachineEngine<T>(name, priority(), BoundlessComponentBox.FACTORY) {
@Override
protected T doNewComponent(SatisfiedBOM satisfiedBOM) {
// in case the system property has been nullified, we return an empty string as value, rather than null
@@ -19,7 +19,7 @@ public class {{machine}} extends SingleNameFactoryMachine<FactoryMachine> {
if (satisfiedBOM.getOne(query).isPresent()
&& satisfiedBOM.getOne(query).get().getComponent().equals("{{whenValue}}")) {
return new SingleNameFactoryMachine<{{alternativeToComponentType}}>({{priority}},
- new StdMachineEngine<{{alternativeToComponentType}}>(NAME, 0, BoundlessComponentBox.FACTORY) {
+ new StdMachineEngine<{{alternativeToComponentType}}>(NAME, {{priority}}, BoundlessComponentBox.FACTORY) {
{{queriesDeclarations}}
@Override
@@ -80,6 +80,31 @@ public void should_start_auto_startable() throws Exception {
assertThat(lifecycleComponent.started).isTrue();
}
+ @Test
+ public void should_start_auto_startable_in_order() throws Exception {
+ final LifecycleComponent lifecycleComponent1 = new LifecycleComponent();
+ final boolean[] l2Started = new boolean[1];
+ final boolean[] wasL1Started = new boolean[1];
+ Factory factory = Factory.builder()
+ .addMachine(new SingletonFactoryMachine<>(10, NamedComponent.of(
+ AutoStartable.class, "t0", new AutoStartable() {
+ @Override
+ public void start() {
+ wasL1Started[0] = lifecycleComponent1.started;
+ l2Started[0] = true;
+ }
+ }
+ )))
+ .addMachine(new SingletonFactoryMachine<>(0, NamedComponent.of(
+ AutoStartable.class, "t1", lifecycleComponent1)))
+ .build();
+ factory.start();
+
+ assertThat(lifecycleComponent1.started).isTrue();
+ assertThat(l2Started[0]).isTrue();
+ assertThat(wasL1Started[0]).isTrue();
+ }
+
@Test
public void should_prepare_auto_preparable() throws Exception {
LifecycleComponent lifecycleComponent = new LifecycleComponent();
@@ -23,7 +23,7 @@ public boolean canBuild(Name<?> name) {
@Override
public <T> MachineEngine<T> getEngine(final Name<T> name) {
- return new StdMachineEngine<T>(name, BoundlessComponentBox.FACTORY) {
+ return new StdMachineEngine<T>(name, priority(), BoundlessComponentBox.FACTORY) {
@Override
@SuppressWarnings("unchecked")
protected T doNewComponent(SatisfiedBOM satisfiedBOM) {

0 comments on commit da0a80d

Please sign in to comment.