Skip to content

Commit

Permalink
use randomized testing in TransportSQLActionClassLifecycleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Nov 11, 2014
1 parent 4355920 commit ca7e19a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import io.crate.test.integration.ClassLifecycleIntegrationTest;
import io.crate.testing.SQLTransportExecutor;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;

Expand All @@ -48,6 +48,13 @@ public void before() throws Exception {
executor = SQLTransportExecutor.create(ClassLifecycleIntegrationTest.GLOBAL_CLUSTER);
}

@After
public void after() throws Exception {
if (executor != null) {
executor = null;
}
}

@Test
public void testSysNodesMem() throws Exception {
SQLResponse response = executor.exec("select mem['free'], mem['used'], mem['free_percent'], mem['used_percent'] from sys.nodes limit 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*;

public class SysShardsTest extends ClassLifecycleIntegrationTest {

Expand Down Expand Up @@ -68,6 +68,13 @@ public void initTestData() throws Exception {
}
}

@AfterClass
public synchronized static void after() throws Exception {
if (transportExecutor != null) {
transportExecutor = null;
}
}

@Test
public void testSelectGroupByWhereTable() throws Exception {
SQLResponse response = transportExecutor.exec("" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.crate.testing.SQLTransportExecutor;
import io.crate.testing.TestingHelpers;
import org.hamcrest.Matchers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -47,10 +48,8 @@
import java.util.List;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;

public class TransportSQLActionClassLifecycleTest extends ClassLifecycleIntegrationTest {

Expand Down Expand Up @@ -82,6 +81,14 @@ public void initTestData() throws Exception {
}
}

@AfterClass
public synchronized static void after() throws Exception {
if (executor != null) {
executor = null;
}
}


@Test
public void testRefreshSystemTable() throws Exception {
SQLResponse response = executor.exec("refresh table sys.shards");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package io.crate.test.integration;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import org.apache.lucene.util.AbstractRandomizedTest;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.test.ElasticsearchTestCase;
Expand All @@ -38,31 +40,44 @@
*
* For all other Integration test purposes use {@link io.crate.test.integration.CrateIntegrationTest}
*/
public class ClassLifecycleIntegrationTest {
@ThreadLeakScope(value = ThreadLeakScope.Scope.NONE)
public class ClassLifecycleIntegrationTest extends AbstractRandomizedTest {

public static final long CLUSTER_SEED = System.nanoTime();

static {
ESLoggerFactory.getRootLogger().setLevel("WARN");
Loggers.getLogger("org.elasticsearch.http").setLevel("INFO");
}


public static final CrateTestCluster GLOBAL_CLUSTER = new CrateTestCluster(
CLUSTER_SEED,
CrateTestCluster.clusterName("shared", ElasticsearchTestCase.CHILD_VM_ID, CLUSTER_SEED)
);

private static final Random random = new Random(CLUSTER_SEED);
public static CrateTestCluster GLOBAL_CLUSTER;
private static Random random;

@BeforeClass
public synchronized static void beforeClass() {
long CLUSTER_SEED = System.nanoTime();
if (random == null) {
random = new Random(CLUSTER_SEED);
}
if (GLOBAL_CLUSTER == null) {
GLOBAL_CLUSTER = new CrateTestCluster(
CLUSTER_SEED,
CrateTestCluster.clusterName("shared", ElasticsearchTestCase.CHILD_VM_ID, CLUSTER_SEED)
);
}
GLOBAL_CLUSTER.beforeTest(random);
}

@AfterClass
public synchronized static void afterClass() throws Exception {
GLOBAL_CLUSTER.client().admin().indices().prepareDelete("_all").execute().get();
GLOBAL_CLUSTER.afterTest();
if (GLOBAL_CLUSTER != null) {
GLOBAL_CLUSTER.client().admin().indices().prepareDelete("_all").execute().get();
GLOBAL_CLUSTER.afterTest();
GLOBAL_CLUSTER = null;
}

if (random != null) {
random = null;
}
}
}

0 comments on commit ca7e19a

Please sign in to comment.