Skip to content

Commit

Permalink
Fix failures related to not cleaning HazelcastBootstrap (hazelcast#18923
Browse files Browse the repository at this point in the history
)


We preferred to use reflection to cleanup the static field after the
test ran rather than introducing a method that will only be used in
test.
  • Loading branch information
ufukyilmaz committed Jun 17, 2021
1 parent 2102742 commit dfa600c
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.jet.JetService;
import com.hazelcast.jet.Jet;
import com.hazelcast.jet.JetInstance;
import com.hazelcast.jet.JetService;
import com.hazelcast.jet.pipeline.Pipeline;
import com.hazelcast.jet.pipeline.test.AssertionSinks;
import com.hazelcast.jet.pipeline.test.TestSources;
Expand All @@ -32,6 +32,7 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

Expand All @@ -40,8 +41,21 @@
public class HazelcastBootstrapTest {

@AfterClass
public static void teardown() {
public static void teardown() throws NoSuchFieldException, IllegalAccessException {
Hazelcast.bootstrappedInstance().shutdown();
cleanUpHazelcastBootstrapSupplier();
}

private static void cleanUpHazelcastBootstrapSupplier() throws NoSuchFieldException, IllegalAccessException {
// Set the static instance supplier field of HazelcastBootstrap
// to null. Because of the lifetime of this field spans many
// test classes run on the same JVM, HazelcastBootstrapTest
// and HazelcastCommandLineTest were interfering with each
// other before this cleanup step added.
// See: https://github.com/hazelcast/hazelcast/issues/18725
Field field = HazelcastBootstrap.class.getDeclaredField("supplier");
field.setAccessible(true);
field.set(null, null);
}

@Test
Expand Down

0 comments on commit dfa600c

Please sign in to comment.