Skip to content

Commit da0a80d

Browse files
committed
FIX: some issues with priority not being propagated to components
causing issues with components ordering
1 parent bea3aad commit da0a80d

File tree

7 files changed

+31
-6
lines changed

7 files changed

+31
-6
lines changed

restx-core/src/main/java/restx/config/ConsolidatedConfigFactoryMachine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public <T> MachineEngine<T> getEngine(Name<T> name) {
2929
if (!canBuild(name)) {
3030
throw new IllegalArgumentException("unsuported name " + name);
3131
}
32-
return (MachineEngine<T>) new StdMachineEngine<RestxConfig>((Name<RestxConfig>) name, BoundlessComponentBox.FACTORY) {
32+
return (MachineEngine<T>) new StdMachineEngine<RestxConfig>((Name<RestxConfig>) name, priority(), BoundlessComponentBox.FACTORY) {
3333

3434
private final Factory.Query<ConfigSupplier> configSupplierQuery = Factory.Query.byClass(ConfigSupplier.class);
3535
private final Factory.Query<String> stringsQuery = Factory.Query.byClass(String.class);

restx-factory/src/main/java/restx/factory/AlternativesFactoryMachine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public AlternativesFactoryMachine(int priority,
88
final ImmutableMap<T, ? extends FactoryMachine> alternatives,
99
ComponentBox.BoxFactory boxFactory) {
1010
super(priority, new StdMachineEngine<FactoryMachine>(
11-
Name.of(FactoryMachine.class, name.getName() + "Alternatives"), boxFactory) {
11+
Name.of(FactoryMachine.class, name.getName() + "Alternatives"), priority, boxFactory) {
1212
private Factory.Query<T> query = Factory.Query.byName(name);
1313

1414
@Override

restx-factory/src/main/java/restx/factory/SingletonFactoryMachine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SingletonFactoryMachine<C> extends SingleNameFactoryMachine<C> {
1313
private final NamedComponent<C> component;
1414

1515
public SingletonFactoryMachine(int priority, final NamedComponent<C> component) {
16-
super(priority, new NoDepsMachineEngine<C>(component.getName(), BoundlessComponentBox.FACTORY) {
16+
super(priority, new NoDepsMachineEngine<C>(component.getName(), priority, BoundlessComponentBox.FACTORY) {
1717
@Override
1818
public C doNewComponent(SatisfiedBOM satisfiedBOM) {
1919
return component.getComponent();

restx-factory/src/main/java/restx/factory/SystemPropertyFactoryMachine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public boolean canBuild(Name<?> name) {
1818
@Override
1919
@SuppressWarnings("unchecked")
2020
public <T> MachineEngine<T> getEngine(final Name<T> name) {
21-
return new NoDepsMachineEngine<T>(name, BoundlessComponentBox.FACTORY) {
21+
return new NoDepsMachineEngine<T>(name, priority(), BoundlessComponentBox.FACTORY) {
2222
@Override
2323
protected T doNewComponent(SatisfiedBOM satisfiedBOM) {
2424
// in case the system property has been nullified, we return an empty string as value, rather than null

restx-factory/src/main/resources/restx/factory/processor/AlternativeMachine.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class {{machine}} extends SingleNameFactoryMachine<FactoryMachine> {
1919
if (satisfiedBOM.getOne(query).isPresent()
2020
&& satisfiedBOM.getOne(query).get().getComponent().equals("{{whenValue}}")) {
2121
return new SingleNameFactoryMachine<{{alternativeToComponentType}}>({{priority}},
22-
new StdMachineEngine<{{alternativeToComponentType}}>(NAME, 0, BoundlessComponentBox.FACTORY) {
22+
new StdMachineEngine<{{alternativeToComponentType}}>(NAME, {{priority}}, BoundlessComponentBox.FACTORY) {
2323
{{queriesDeclarations}}
2424

2525
@Override

restx-factory/src/test/java/restx/factory/FactoryTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ public void should_start_auto_startable() throws Exception {
8080
assertThat(lifecycleComponent.started).isTrue();
8181
}
8282

83+
@Test
84+
public void should_start_auto_startable_in_order() throws Exception {
85+
final LifecycleComponent lifecycleComponent1 = new LifecycleComponent();
86+
final boolean[] l2Started = new boolean[1];
87+
final boolean[] wasL1Started = new boolean[1];
88+
Factory factory = Factory.builder()
89+
.addMachine(new SingletonFactoryMachine<>(10, NamedComponent.of(
90+
AutoStartable.class, "t0", new AutoStartable() {
91+
@Override
92+
public void start() {
93+
wasL1Started[0] = lifecycleComponent1.started;
94+
l2Started[0] = true;
95+
}
96+
}
97+
)))
98+
.addMachine(new SingletonFactoryMachine<>(0, NamedComponent.of(
99+
AutoStartable.class, "t1", lifecycleComponent1)))
100+
.build();
101+
factory.start();
102+
103+
assertThat(lifecycleComponent1.started).isTrue();
104+
assertThat(l2Started[0]).isTrue();
105+
assertThat(wasL1Started[0]).isTrue();
106+
}
107+
83108
@Test
84109
public void should_prepare_auto_preparable() throws Exception {
85110
LifecycleComponent lifecycleComponent = new LifecycleComponent();

restx-jongo/src/main/java/restx/jongo/JongoCollectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public boolean canBuild(Name<?> name) {
2323

2424
@Override
2525
public <T> MachineEngine<T> getEngine(final Name<T> name) {
26-
return new StdMachineEngine<T>(name, BoundlessComponentBox.FACTORY) {
26+
return new StdMachineEngine<T>(name, priority(), BoundlessComponentBox.FACTORY) {
2727
@Override
2828
@SuppressWarnings("unchecked")
2929
protected T doNewComponent(SatisfiedBOM satisfiedBOM) {

0 commit comments

Comments
 (0)