Skip to content

Commit

Permalink
Move tests to elasticsearch test framework
Browse files Browse the repository at this point in the history
Closes #8.
  • Loading branch information
dadoonet committed Jan 13, 2014
1 parent cc78694 commit 431f704
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 70 deletions.
26 changes: 20 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Licensed to ElasticSearch under one or more contributor
<!-- Licensed to Elasticsearch under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. ElasticSearch licenses this file to you
information regarding copyright ownership. Elasticsearch licenses this file to you
under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
Expand Down Expand Up @@ -47,12 +47,25 @@ governing permissions and limitations under the License. -->
</issueManagement>

<properties>
<elasticsearch.version>0.90.3</elasticsearch.version>
<elasticsearch.version>0.90.10</elasticsearch.version>
<google.gce.version>v1beta15-rev3-1.15.0-rc</google.gce.version>
<google.api.version>1.15.0-rc</google.api.version>
<lucene.version>4.6.0</lucene.version>
<tests.jvms>1</tests.jvms>
<tests.shuffle>true</tests.shuffle>
<tests.output>onerror</tests.output>
<tests.client.ratio></tests.client.ratio>
<es.logger.level>INFO</es.logger.level>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>${lucene.version}</version>
<scope>test</scope>
</dependency>

<!-- Elasticsearch -->
<dependency>
<groupId>org.elasticsearch</groupId>
Expand Down Expand Up @@ -90,9 +103,10 @@ governing permissions and limitations under the License. -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,92 +20,37 @@
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<Node> nodes;
private Class<? extends GceComputeService> mock;

public GceAbstractTest(Class<? extends GceComputeService> mock) {
// We want to inject the GCE API Mock
this.mock = mock;
}

@Before
public void setUp() {
nodes = new ArrayList<Node>();

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);
}
}

0 comments on commit 431f704

Please sign in to comment.