New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleNamingContextBuilder: Second builder does not change JNDI context after first has been deactivated [SPR-17505] #22037
Comments
Eelco de Lang commented As a workaround I use:
|
Juergen Hoeller commented In your test code, why do you call And through your workaround, you effectively make |
Eelco de Lang commented Maybe I oversimplified my problem a bit. This maybe this looks a bit more realistic: @BeforeClass
public static void testSuite()
throws NamingException, MalformedURLException, IllegalStateException
{
InitialContext initialContext = new InitialContext();
initialContext.bind("testname", "MyFirst");
}
@Test
public void testsInSpecificOrder()
throws NamingException, MalformedURLException, IllegalStateException
{
test1Somewhere();
test2SomewhereElseEntirely();
test3ExtraTestWithSpecificContext();
}
@Test
public void test1Somewhere()
throws NamingException, MalformedURLException, IllegalStateException
{
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
builder.bind("testname", "WillNotBeCleared");
InitialContext initialContext = new InitialContext();
assertEquals("WillNotBeCleared", initialContext.lookup("testname"));
builder.deactivate();
}
@Test
public void test2SomewhereElseEntirely()
throws NamingException, MalformedURLException, IllegalStateException
{
InitialContext initialContext = new InitialContext();
assertEquals("MyFirst", initialContext.lookup("testname"));
}
@Test
public void test3ExtraTestWithSpecificContext()
throws NamingException, MalformedURLException, IllegalStateException
{
SimpleNamingContextBuilder builder2 = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
builder2.bind("testname", "ThisIsNotSet");
InitialContext initialContext2 = new InitialContext();
assertEquals("WillNotBeCleared", initialContext2.lookup("testname"));
builder2.deactivate();
} |
Eelco de Lang commented The deactivate in my workaround is not a no-op. The original context is used after calling it. The real problem is that you can easily have two different builder. One on the stack and a different one in the NamingManager. This leads to strange testcan results, that will be depend on the order which they are run. I see three solutions:
|
Eelco de Lang opened SPR-17505 and commented
When creating the SimpleNamingContextBuilder for a second time, it doesn't work well. Different testcases can cause eachother to fail. The second will be missing it's JDNI settings.
This is caused by the fact that the first SimpleNamingContextBuilder is still connected to the NamingManager.
Affects: 4.3.14, 5.1.2
The text was updated successfully, but these errors were encountered: