Skip to content
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

[Transform] reuse mock client to avoid problems with thread context closed errors #46398

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.elasticsearch.xpack.dataframe.DataFrameSingleNodeTestCase;
import org.elasticsearch.xpack.dataframe.notifications.DataFrameAuditor;
import org.elasticsearch.xpack.dataframe.persistence.DataFrameTransformsConfigManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;

import java.nio.file.Path;
Expand All @@ -67,8 +67,12 @@

public class DataFrameTransformCheckpointServiceNodeTests extends DataFrameSingleNodeTestCase {

// re-use the mock client for the whole test suite as the underlying thread pool and the
// corresponding context if recreated cause unreliable test execution
// see https://github.com/elastic/elasticsearch/issues/45238 and https://github.com/elastic/elasticsearch/issues/42577
private static MockClientForCheckpointing mockClientForCheckpointing = null;

private DataFrameTransformsConfigManager transformsConfigManager;
private MockClientForCheckpointing mockClientForCheckpointing;
private DataFrameTransformsCheckpointService transformsCheckpointService;

private class MockClientForCheckpointing extends NoOpClient {
Expand Down Expand Up @@ -121,18 +125,22 @@ void doExecute(ActionType<Response> action, Request request, ActionListener<Resp

@Before
public void createComponents() {
// it's not possible to run it as @BeforeClass as clients aren't initialized
if (mockClientForCheckpointing == null) {
mockClientForCheckpointing = new MockClientForCheckpointing("DataFrameTransformCheckpointServiceNodeTests");
}

transformsConfigManager = new DataFrameTransformsConfigManager(client(), xContentRegistry());

// use a mock for the checkpoint service
mockClientForCheckpointing = new MockClientForCheckpointing(getTestName());
DataFrameAuditor mockAuditor = mock(DataFrameAuditor.class);
transformsCheckpointService = new DataFrameTransformsCheckpointService(mockClientForCheckpointing,
transformsConfigManager,
mockAuditor);
}

@After
public void tearDownClient() {
@AfterClass
public static void tearDownClient() {
mockClientForCheckpointing.close();
}

Expand Down