2 Replies Latest reply on Jun 21, 2017 9:29 AM by bmajsak

    Precedence on @Observes

    jonh.wendell

      Hi folks.

       

      I have an Arquillian extension that registers (a) an observer and (b) an enricher service.

       

      Here's the skeleton of the observer:

       

      public class Initializer {
          @Inject
          @ApplicationScoped
          private InstanceProducer<Configuration> configurationProducer;
      
          public void configure(@Observes ArquillianDescriptor arquillianDescriptor, org.arquillian.cube.kubernetes.api.Configuration cubeConfig) {
              Configuration config = Configuration.fromMap(arquillianDescriptor.extension("my-extension").getExtensionProperties());
      
              configurationProducer.set(config);
          }    
      }
      

       

      The enricher service relies on the Configuration object set above:

       

      public class MyEnricher implements TestEnricher {
        @Inject
        private Instance<Configuration> configurationInstance;
      
        ... (within a method:)
        Configuration config = configurationInstance.get();
      }
      

       

      The problem is that the statement configurationInstance.get(); above (line 6) is sometimes returning null. Sometimes it works fine. I believe this is happening because the time this line is executed the producer above hadn't been executed.

       

      So, is there a way to set a dependency here? I mean, this enricher should only be called after the producer above actually set the value of the Configuration object?

       

      Thanks.

        • 1. Re: Precedence on @Observes
          iocanel

          There is always one observer which upon a predefined event performs some tasks.

          In your case, that observer is started, earlier than it should, or at least before all the actual requirements are fulfilled.

           

          I would search to find which is that observer (the stack trace would easily reveal that) and I would try to express the dependency on that observer (e.g. by having it observer the configuration object). If this doesn't solve the issue I would create and fire a new event that will signal that all requirements are fullfilled.

          In cube kubernetes, we do something similar: "When the configuration and the logger are available we produce a session and then we fire the start event".

          • 2. Re: Precedence on @Observes
            bmajsak

            Custom events and observes sounds like a feasible thing to do.

             

            In order to see exact events/observers flow you can also enable debug mode and it will be logged at runtime. Simply set -Darquillian.debug=true