Git Product home page Git Product logo

Comments (11)

timothyjward avatar timothyjward commented on June 12, 2024 1

I agree with the use case, but disagree with the enabled property.

If someone specifies

@InjectConfiguration(withFactoryConfig = 
    @WithFactoryConfiguration(factoryPid = "Blub", location = "?", name = "test"))

Then the properties are NOT_SET. This should mean that the configuration is not updated, and I think that if it is being updated that that is a bug.

Do you feel up to making a PR for this?

from osgi-test.

maho7791 avatar maho7791 commented on June 12, 2024

I'll take a look into it

from osgi-test.

stbischof avatar stbischof commented on June 12, 2024

@maho7791

here is a check

&& !ConfigUtil.isDictionaryWithNotSetMarker(newConfigurationProperties)) {

from osgi-test.

maho7791 avatar maho7791 commented on June 12, 2024

I'll check this out

from osgi-test.

maho7791 avatar maho7791 commented on June 12, 2024

I made a short test and it worked with @WithConfiguration but not with @WithFactoryConfiguration.

This test fails with cs == null:

static final String MY_PID = "my.fpid";

@Test
@WithFactoryConfiguration(factoryPid = MY_PID)
public void testMethodConfigurationFactoryEmtpy() throws Exception {

	Configuration cs = ConfigUtil.getConfigsByServicePid(ca, MY_PID);
	assertThat(cs).isNotNull();

}

The config is in the configuration manager, but it cannot be found using the provided filter in `ConfigUtil.getConfigsByPid'. This belong to the name that was generated by config admin.

This test succeeds:

static final String MY_OTHER_PID = "my.other.pid";

@Test
@WithFactoryConfiguration(factoryPid = MY_OTHER_PID, name = "myname")
public void testMethodConfigurationFactoryNameEmtpy() throws Exception {

	Configuration cs = ConfigUtil.getConfigsByServicePid(ca, MY_OTHER_PID + "~myname");
	assertThat(cs).isNotNull();

}

I also debugged both test cases and realized that The update method was called in both tests:

blockingConfigHandler.update(configurationToBeUpdated, Dictionaries.dictionaryOf(), 1000);

This test also fails with getting a null value for the configuration parameter c:

@WithFactoryConfiguration(factoryPid = ConfigAnnotationParamVariants2.MY_PID, name = "test")
public class ConfigAnnotationParamVariants2 {

	static final String MY_PID = "my.pid";

	@Test
	public void test_Parameter_Configuration(@InjectConfiguration(MY_PID) Configuration c) throws Exception {

		Assertions.assertThat(c)
			.isNotNull();

	}
}

Here as well the update method on the config admin is called in the codeline linked above.

I realized that the injecing boolean paramter is always false in all described cases.

I not getting through, what is done here exactly. Further I dont thing that it is possible to distinguish between when someone wants update called on the config admin or what I wanted, that update was not called.

If we see the not-set flag as indicator, to not update the config admin, wehy do we have a line to update nevertheless. This confuses me a bit ;-)

from osgi-test.

maho7791 avatar maho7791 commented on June 12, 2024

To be clear, I looked for a way to get an empty configuration injected with no Configuration#update calls upfront.

from osgi-test.

maho7791 avatar maho7791 commented on June 12, 2024

I can confirm that this works, without any update calls:

public void testInjectNoUpdate(@InjectConfiguration(withConfig = @WithConfiguration(pid = "pid"))

If we want a different behavior, how to deal with this case, we should document it somewhere.

In general I am ok with releasing this feature in this state and making the behavior consistent in the next release. Especially, if it is too difficult to implement. I can also help, but without introduction I takes too long to understand all different cases.

from osgi-test.

timothyjward avatar timothyjward commented on June 12, 2024

This test fails with cs == null:

static final String MY_PID = "my.fpid";

@Test
@WithFactoryConfiguration(factoryPid = MY_PID)
public void testMethodConfigurationFactoryEmtpy() throws Exception {

	Configuration cs = ConfigUtil.getConfigsByServicePid(ca, MY_PID);
	assertThat(cs).isNotNull();

}

This is user error - there is no configuration with pid MY_PID. There is a factory configuration with factoryPid MY_PID and an unknown pid of the form MYPID + "~" + "someString". There is a similar problem with the other failing test.

I also debugged both test cases and realized that The update method was called in both tests:

This is required - if you declare your configuration at Class or Test level using a @WithConfiguration or @WithFactoryConfiguration then it must be updated. If not then no configuration will ever be available (i.e. calling listConfigurations will not include the configuration you want). The only way to get a configuration which does not have update called is by using @InjectConfiguration

from osgi-test.

timothyjward avatar timothyjward commented on June 12, 2024

To be clear, I looked for a way to get an empty configuration injected with no Configuration#update calls upfront.

You appear to have found the way to do this:

public void testInjectNoUpdate(@InjectConfiguration(withConfig = @WithConfiguration(pid = "pid"))

It is the only way.

from osgi-test.

maho7791 avatar maho7791 commented on June 12, 2024

This is required - if you declare your configuration at Class or Test level using a @WithConfiguration or @WithFactoryConfiguration then it must be updated. If not then no configuration will ever be available (i.e. calling listConfigurations will not include the configuration you want). The only way to get a configuration which does not have update called is by using @InjectConfiguration

Ok, I see your point.

This is then related to the fact, that all configurations are fetched from config admin list and there is (currently) no other source for empty configuration entries.

I am fine with this current solution. But we should document it :-)

from osgi-test.

timothyjward avatar timothyjward commented on June 12, 2024

I am fine with this current solution. But we should document it :-)

We need a proper documentation site, but for now what we have is this

/**
* Indicate the properties that will be used to update the defined
* configuration.
* <p>
* When this annotation is used with
* {@link InjectConfiguration#withConfig()} then leaving the properties
* unset will result in the injection of a configuration that <em>has
* not</em> had {@link Configuration#update(java.util.Dictionary)} called.
* <p>
* When used as a direct annotation leaving the properties unset has the
* same effect as an empty array, and the configuration will be updated with
* empty properties.
*
* @return The Properties.
*/
Property[] properties() default {
@Property(key = Property.NOT_SET)
};

from osgi-test.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.