Skip to content

Commit

Permalink
Move tests to elasticsearch test framework
Browse files Browse the repository at this point in the history
Move tests to elasticsearch test framework.
In addition to this, we want to refactor some package names to prepare next snapshot/restore feature (see #2).

Closes #3.
  • Loading branch information
dadoonet committed Jan 6, 2014
1 parent 41de615 commit 316a141
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 192 deletions.
131 changes: 125 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,55 @@ governing permissions and limitations under the License. -->
</parent>

<properties>
<elasticsearch.version>0.90.6</elasticsearch.version>
<elasticsearch.version>1.0.0.RC1-SNAPSHOT</elasticsearch.version>
<lucene.version>4.6.0</lucene.version>
<tests.output>onerror</tests.output>
<tests.jvms>1</tests.jvms>
<tests.shuffle>true</tests.shuffle>
<tests.output>onerror</tests.output>
<tests.client.ratio></tests.client.ratio>
<tests.jvm.argline></tests.jvm.argline>
<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>

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<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>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3.RC2</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand All @@ -91,10 +117,103 @@ governing permissions and limitations under the License. -->
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>junit4-maven-plugin</artifactId>
<version>2.0.14</version>
<executions>
<execution>
<id>tests</id>
<phase>test</phase>
<goals>
<goal>junit4</goal>
</goals>
<configuration>
<heartbeat>20</heartbeat>
<jvmOutputAction>pipe,warn</jvmOutputAction>
<leaveTemporary>true</leaveTemporary>
<listeners>
<report-ant-xml mavenExtensions="true"
dir="${project.build.directory}/surefire-reports"/>
<report-text
showThrowable="true"
showStackTraces="true"
showOutput="${tests.output}"
showStatusOk="false"
showStatusError="true"
showStatusFailure="true"
showStatusIgnored="true"
showSuiteSummary="true"
timestamps="false"/>
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
</listeners>
<assertions>
<enable/>
</assertions>
<parallelism>${tests.jvms}</parallelism>
<balancers>
<execution-times>
<fileset dir="${basedir}" includes=".local-execution-hints.log"/>
</execution-times>
</balancers>
<includes>
<include>**/*Tests.class</include>
<include>**/*Test.class</include>
</includes>
<excludes>
<exclude>**/Abstract*.class</exclude>
<exclude>**/*StressTest.class</exclude>
</excludes>
<argLine>
${tests.jvm.argline}
</argLine>
<jvmArgs>
<param>-Xmx512m</param>
<param>-Xss256k</param>
<param>-XX:MaxDirectMemorySize=512m</param>
<param>-Des.logger.prefix=</param>
</jvmArgs>
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
<sysouts>${tests.verbose}</sysouts>
<seed>${tests.seed}</seed>
<haltOnFailure>${tests.failfast}</haltOnFailure>
<systemProperties>
<!-- RandomizedTesting library system properties -->
<tests.jvm.argline>${tests.jvm.argline}</tests.jvm.argline>
<tests.iters>${tests.iters}</tests.iters>
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
<tests.failfast>${tests.failfast}</tests.failfast>
<tests.class>${tests.class}</tests.class>
<tests.method>${tests.method}</tests.method>
<tests.nightly>${tests.nightly}</tests.nightly>
<tests.badapples>${tests.badapples}</tests.badapples>
<tests.weekly>${tests.weekly}</tests.weekly>
<tests.slow>${tests.slow}</tests.slow>
<tests.azure>${tests.azure}</tests.azure>
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
<tests.slow>${tests.slow}</tests.slow>
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
<tests.integration>${tests.integration}</tests.integration>
<tests.cluster_seed>${tests.cluster_seed}</tests.cluster_seed>
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
<es.node.mode>${es.node.mode}</es.node.mode>
<es.config>${es.config}</es.config>
<es.logger.level>${es.logger.level}</es.logger.level>
<java.awt.headless>true</java.awt.headless>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/elasticsearch/cloud/azure/AzureModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,49 @@

import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.azure.AzureDiscovery;

/**
* Azure Module
*
* <ul>
* <li>If needed this module will bind azure discovery service by default
* to AzureComputeServiceImpl.</li>
* </ul>
*
* @see org.elasticsearch.cloud.azure.AzureComputeServiceImpl
*/
public class AzureModule extends AbstractModule {
protected final ESLogger logger;
private Settings settings;

@Inject
public AzureModule(Settings settings) {
this.settings = settings;
this.logger = Loggers.getLogger(getClass(), settings);
}

@Override
protected void configure() {
logger.debug("starting azure services");

// If we have set discovery to azure, let's start the azure compute service
if (isDiscoveryReady(settings)) {
logger.debug("starting azure discovery service");
bind(AzureComputeService.class)
.to(settings.getAsClass("cloud.azure.api.impl", AzureComputeServiceImpl.class))
.asEagerSingleton();
}
}

/**
* Check if discovery is meant to start
* @return true if we can start discovery features
*/
public static boolean isDiscoveryReady(Settings settings) {
return (AzureDiscovery.AZURE.equalsIgnoreCase(settings.get("discovery.type")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
import org.elasticsearch.common.settings.SettingsFilter;

/**
*
* Filtering cloud.azure.* settings
*/
public class AzureSettingsFilter implements SettingsFilter.Filter {

@Override
public void filter(ImmutableSettings.Builder settings) {
settings.remove("cloud.private_key");
// Cloud settings
settings.remove("cloud.certificate");
settings.remove("cloud.azure.password");
settings.remove("cloud.azure.subscription_id");
settings.remove("cloud.azure.service_name");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
*/
public class AzureDiscovery extends ZenDiscovery {

public static final String AZURE = "azure";

@Inject
public AzureDiscovery(Settings settings, ClusterName clusterName, ThreadPool threadPool, TransportService transportService,
ClusterService clusterService, NodeSettingsService nodeSettingsService, ZenPingService pingService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

package org.elasticsearch.discovery.azure;

import org.elasticsearch.cloud.azure.AzureModule;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.zen.ZenDiscoveryModule;

Expand All @@ -27,8 +32,21 @@
*/
public class AzureDiscoveryModule extends ZenDiscoveryModule {

protected final ESLogger logger;
private Settings settings;

@Inject
public AzureDiscoveryModule(Settings settings) {
super();
this.logger = Loggers.getLogger(getClass(), settings);
this.settings = settings;
}
@Override
protected void bindDiscovery() {
if (AzureModule.isDiscoveryReady(settings)) {
bind(Discovery.class).to(AzureDiscovery.class).asEagerSingleton();
} else {
logger.debug("disabling azure discovery features");
}
}
}
40 changes: 30 additions & 10 deletions src/test/java/org/elasticsearch/azure/itest/AzureSimpleITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,40 @@
*/
package org.elasticsearch.azure.itest;

import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.cloud.azure.AbstractAzureTest;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.node.NodeBuilder;
import org.junit.Ignore;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.hamcrest.Matchers;
import org.junit.Test;

public class AzureSimpleITest {
/**
* This test needs Azure to run and -Dtests.azure=true to be set
* and -Des.config=/path/to/elasticsearch.yml
* @see org.elasticsearch.cloud.azure.AbstractAzureTest
*/
@AbstractAzureTest.AzureTest
@ElasticsearchIntegrationTest.ClusterScope(
scope = ElasticsearchIntegrationTest.Scope.TEST,
numNodes = 1,
transportClientRatio = 0.0)
public class AzureSimpleITest extends AbstractAzureTest {

@Test @Ignore
@Test
public void one_node_should_run() {
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");
NodeBuilder.nodeBuilder().settings(builder).node();
// Do nothing... Just start :-)
// but let's check that we have at least 1 node (local node)
ClusterStateResponse clusterState = client().admin().cluster().prepareState().execute().actionGet();

assertThat(clusterState.getState().getNodes().getSize(), Matchers.greaterThanOrEqualTo(1));
}

@Override
public Settings indexSettings() {
// During restore we frequently restore index to exactly the same state it was before, that might cause the same
// checksum file to be written twice during restore operation
return ImmutableSettings.builder().put(super.indexSettings())
.build();
}
}
Loading

0 comments on commit 316a141

Please sign in to comment.