|
20 | 20 | package org.elasticsearch.cloud.gce.tests;
|
21 | 21 |
|
22 | 22 | import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
23 |
| -import org.elasticsearch.client.Client; |
24 |
| -import org.elasticsearch.client.transport.TransportClient; |
25 | 23 | import org.elasticsearch.cloud.gce.GceComputeService;
|
26 |
| -import org.elasticsearch.common.io.FileSystemUtils; |
27 | 24 | import org.elasticsearch.common.settings.ImmutableSettings;
|
28 |
| -import org.elasticsearch.common.settings.Settings; |
29 |
| -import org.elasticsearch.common.transport.TransportAddress; |
30 |
| -import org.elasticsearch.node.Node; |
31 |
| -import org.elasticsearch.node.NodeBuilder; |
32 |
| -import org.elasticsearch.node.internal.InternalNode; |
33 |
| -import org.elasticsearch.transport.netty.NettyTransport; |
34 |
| -import org.junit.After; |
| 25 | +import org.elasticsearch.test.ElasticsearchIntegrationTest; |
35 | 26 | import org.junit.Assert;
|
36 |
| -import org.junit.Before; |
37 | 27 |
|
38 |
| -import java.io.File; |
39 |
| -import java.util.ArrayList; |
40 |
| -import java.util.List; |
| 28 | +@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numNodes = 0) |
| 29 | +public abstract class GceAbstractTest extends ElasticsearchIntegrationTest { |
41 | 30 |
|
42 |
| -public abstract class GceAbstractTest { |
43 |
| - |
44 |
| - private static List<Node> nodes; |
45 | 31 | private Class<? extends GceComputeService> mock;
|
46 | 32 |
|
47 | 33 | public GceAbstractTest(Class<? extends GceComputeService> mock) {
|
48 | 34 | // We want to inject the GCE API Mock
|
49 | 35 | this.mock = mock;
|
50 | 36 | }
|
51 | 37 |
|
52 |
| - @Before |
53 |
| - public void setUp() { |
54 |
| - nodes = new ArrayList<Node>(); |
55 |
| - |
56 |
| - File dataDir = new File("./target/es/data"); |
57 |
| - if(dataDir.exists()) { |
58 |
| - FileSystemUtils.deleteRecursively(dataDir, true); |
59 |
| - } |
60 |
| - } |
61 |
| - |
62 |
| - @After |
63 |
| - public void tearDown() { |
64 |
| - // Cleaning nodes after test |
65 |
| - for (Node node : nodes) { |
66 |
| - node.close(); |
67 |
| - } |
68 |
| - } |
69 |
| - |
70 |
| - protected Client getClient() { |
71 |
| - // Create a TransportClient on node 1 and 2 |
72 |
| - Settings settings = ImmutableSettings.settingsBuilder() |
73 |
| - .put("cluster.name", "gce").build(); |
74 |
| - |
75 |
| - TransportClient client = new TransportClient(settings); |
76 |
| - |
77 |
| - for (Node node : nodes) { |
78 |
| - NettyTransport nettyTransport = ((InternalNode) node).injector().getInstance(NettyTransport.class); |
79 |
| - TransportAddress transportAddress = nettyTransport.boundAddress().publishAddress(); |
80 |
| - client.addTransportAddress(transportAddress); |
81 |
| - } |
82 |
| - |
83 |
| - return client; |
84 |
| - } |
85 |
| - |
86 | 38 | protected void checkNumberOfNodes(int expected) {
|
87 |
| - NodesInfoResponse nodeInfos = getClient().admin().cluster().prepareNodesInfo().execute().actionGet(); |
| 39 | + NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().execute().actionGet(); |
88 | 40 |
|
89 | 41 | Assert.assertNotNull(nodeInfos.getNodes());
|
90 | 42 | Assert.assertEquals(expected, nodeInfos.getNodes().length);
|
91 | 43 | }
|
92 | 44 |
|
93 | 45 | protected void nodeBuilder(String filteredTags) {
|
94 |
| - ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder() |
95 |
| - //.put("gateway.type", "local") |
96 |
| - .put("path.data", "./target/es/data") |
97 |
| - .put("path.logs", "./target/es/logs") |
98 |
| - .put("path.work", "./target/es/work") |
| 46 | + ImmutableSettings.Builder nodeSettings = ImmutableSettings.settingsBuilder() |
99 | 47 | .put("cloud.gce.api.impl", mock)
|
100 |
| - .put("cloud.gce.refresh_interval", "5s") |
101 |
| - .put("node.name", (nodes.size()+1) + "#" + mock.getSimpleName()); |
| 48 | + .put("cloud.gce.refresh_interval", "5s"); |
102 | 49 | if (filteredTags != null) {
|
103 |
| - builder.put("discovery.gce.tags", filteredTags); |
| 50 | + nodeSettings.put("discovery.gce.tags", filteredTags); |
104 | 51 | } else {
|
105 |
| - builder.put("discovery.gce.tags", ""); |
| 52 | + nodeSettings.put("discovery.gce.tags", ""); |
106 | 53 | }
|
107 |
| - |
108 |
| - Node node = NodeBuilder.nodeBuilder().settings(builder).node(); |
109 |
| - nodes.add(node); |
| 54 | + cluster().startNode(nodeSettings); |
110 | 55 | }
|
111 | 56 | }
|
0 commit comments