|
50 | 50 | import org.elasticsearch.xpack.dataframe.DataFrameSingleNodeTestCase; |
51 | 51 | import org.elasticsearch.xpack.dataframe.notifications.DataFrameAuditor; |
52 | 52 | import org.elasticsearch.xpack.dataframe.persistence.DataFrameTransformsConfigManager; |
53 | | -import org.junit.After; |
| 53 | +import org.junit.AfterClass; |
54 | 54 | import org.junit.Before; |
55 | 55 |
|
56 | 56 | import java.nio.file.Path; |
|
67 | 67 |
|
68 | 68 | public class DataFrameTransformCheckpointServiceNodeTests extends DataFrameSingleNodeTestCase { |
69 | 69 |
|
| 70 | + // re-use the mock client for the whole test suite as the underlying thread pool and the |
| 71 | + // corresponding context if recreated cause unreliable test execution |
| 72 | + // see https://github.com/elastic/elasticsearch/issues/45238 and https://github.com/elastic/elasticsearch/issues/42577 |
| 73 | + private static MockClientForCheckpointing mockClientForCheckpointing = null; |
| 74 | + |
70 | 75 | private DataFrameTransformsConfigManager transformsConfigManager; |
71 | | - private MockClientForCheckpointing mockClientForCheckpointing; |
72 | 76 | private DataFrameTransformsCheckpointService transformsCheckpointService; |
73 | 77 |
|
74 | 78 | private class MockClientForCheckpointing extends NoOpClient { |
@@ -121,18 +125,22 @@ void doExecute(ActionType<Response> action, Request request, ActionListener<Resp |
121 | 125 |
|
122 | 126 | @Before |
123 | 127 | public void createComponents() { |
| 128 | + // it's not possible to run it as @BeforeClass as clients aren't initialized |
| 129 | + if (mockClientForCheckpointing == null) { |
| 130 | + mockClientForCheckpointing = new MockClientForCheckpointing("DataFrameTransformCheckpointServiceNodeTests"); |
| 131 | + } |
| 132 | + |
124 | 133 | transformsConfigManager = new DataFrameTransformsConfigManager(client(), xContentRegistry()); |
125 | 134 |
|
126 | 135 | // use a mock for the checkpoint service |
127 | | - mockClientForCheckpointing = new MockClientForCheckpointing(getTestName()); |
128 | 136 | DataFrameAuditor mockAuditor = mock(DataFrameAuditor.class); |
129 | 137 | transformsCheckpointService = new DataFrameTransformsCheckpointService(mockClientForCheckpointing, |
130 | 138 | transformsConfigManager, |
131 | 139 | mockAuditor); |
132 | 140 | } |
133 | 141 |
|
134 | | - @After |
135 | | - public void tearDownClient() { |
| 142 | + @AfterClass |
| 143 | + public static void tearDownClient() { |
136 | 144 | mockClientForCheckpointing.close(); |
137 | 145 | } |
138 | 146 |
|
|
0 commit comments