From 431f704d6daebfef7dcfc1b3559ded54c1a19530 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 13 Jan 2014 16:07:27 +0100 Subject: [PATCH] Move tests to elasticsearch test framework Closes #8. --- pom.xml | 26 +++++-- .../cloud/gce/tests/GceAbstractTest.java | 73 +++---------------- 2 files changed, 29 insertions(+), 70 deletions(-) diff --git a/pom.xml b/pom.xml index d446ae1787a4e..6c5701b0d27be 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ - - 0.90.3 + 0.90.10 v1beta15-rev3-1.15.0-rc 1.15.0-rc + 4.6.0 + 1 + true + onerror + + INFO + + org.apache.lucene + lucene-test-framework + ${lucene.version} + test + + org.elasticsearch @@ -90,9 +103,10 @@ governing permissions and limitations under the License. --> test - junit - junit - 4.11 + org.elasticsearch + elasticsearch + ${elasticsearch.version} + test-jar test diff --git a/src/test/java/org/elasticsearch/cloud/gce/tests/GceAbstractTest.java b/src/test/java/org/elasticsearch/cloud/gce/tests/GceAbstractTest.java index 05804ffdd73d3..8e41eb14be3fa 100644 --- a/src/test/java/org/elasticsearch/cloud/gce/tests/GceAbstractTest.java +++ b/src/test/java/org/elasticsearch/cloud/gce/tests/GceAbstractTest.java @@ -20,28 +20,14 @@ package org.elasticsearch.cloud.gce.tests; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cloud.gce.GceComputeService; -import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.node.Node; -import org.elasticsearch.node.NodeBuilder; -import org.elasticsearch.node.internal.InternalNode; -import org.elasticsearch.transport.netty.NettyTransport; -import org.junit.After; +import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.junit.Assert; -import org.junit.Before; -import java.io.File; -import java.util.ArrayList; -import java.util.List; +@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.TEST, numNodes = 0) +public abstract class GceAbstractTest extends ElasticsearchIntegrationTest { -public abstract class GceAbstractTest { - - private static List nodes; private Class mock; public GceAbstractTest(Class mock) { @@ -49,63 +35,22 @@ public GceAbstractTest(Class mock) { this.mock = mock; } - @Before - public void setUp() { - nodes = new ArrayList(); - - File dataDir = new File("./target/es/data"); - if(dataDir.exists()) { - FileSystemUtils.deleteRecursively(dataDir, true); - } - } - - @After - public void tearDown() { - // Cleaning nodes after test - for (Node node : nodes) { - node.close(); - } - } - - protected Client getClient() { - // Create a TransportClient on node 1 and 2 - Settings settings = ImmutableSettings.settingsBuilder() - .put("cluster.name", "gce").build(); - - TransportClient client = new TransportClient(settings); - - for (Node node : nodes) { - NettyTransport nettyTransport = ((InternalNode) node).injector().getInstance(NettyTransport.class); - TransportAddress transportAddress = nettyTransport.boundAddress().publishAddress(); - client.addTransportAddress(transportAddress); - } - - return client; - } - protected void checkNumberOfNodes(int expected) { - NodesInfoResponse nodeInfos = getClient().admin().cluster().prepareNodesInfo().execute().actionGet(); + NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().execute().actionGet(); Assert.assertNotNull(nodeInfos.getNodes()); Assert.assertEquals(expected, nodeInfos.getNodes().length); } protected void nodeBuilder(String filteredTags) { - ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder() - //.put("gateway.type", "local") - .put("path.data", "./target/es/data") - .put("path.logs", "./target/es/logs") - .put("path.work", "./target/es/work") + ImmutableSettings.Builder nodeSettings = ImmutableSettings.settingsBuilder() .put("cloud.gce.api.impl", mock) - .put("cloud.gce.refresh_interval", "5s") - .put("node.name", (nodes.size()+1) + "#" + mock.getSimpleName()); + .put("cloud.gce.refresh_interval", "5s"); if (filteredTags != null) { - builder.put("discovery.gce.tags", filteredTags); + nodeSettings.put("discovery.gce.tags", filteredTags); } else { - builder.put("discovery.gce.tags", ""); + nodeSettings.put("discovery.gce.tags", ""); } - - Node node = NodeBuilder.nodeBuilder().settings(builder).node(); - nodes.add(node); + cluster().startNode(nodeSettings); } }