don't use AfterTest / BeforeTest in any tests

This commit is contained in:
kimchy 2011-02-28 22:28:55 +02:00
parent 24199a3394
commit 3bac33e69e
11 changed files with 36 additions and 26 deletions

View File

@ -20,7 +20,7 @@
package org.elasticsearch.common.compress.lzf; package org.elasticsearch.common.compress.lzf;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.*; import java.io.*;
@ -38,7 +38,7 @@ public class LZFInputStreamTests {
private ByteArrayOutputStream nonCompressed; private ByteArrayOutputStream nonCompressed;
private ByteArrayOutputStream compressed; private ByteArrayOutputStream compressed;
@BeforeTest(alwaysRun = true) @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
SecureRandom.getInstance("SHA1PRNG").nextBytes(nonEncodableBytesToWrite); SecureRandom.getInstance("SHA1PRNG").nextBytes(nonEncodableBytesToWrite);
String phrase = "all work and no play make Jack a dull boy"; String phrase = "all work and no play make Jack a dull boy";

View File

@ -20,7 +20,7 @@
package org.elasticsearch.common.compress.lzf; package org.elasticsearch.common.compress.lzf;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -36,7 +36,7 @@ public class LZFOutputStreamTests {
private byte[] nonEncodableBytesToWrite = new byte[BUFFER_SIZE]; private byte[] nonEncodableBytesToWrite = new byte[BUFFER_SIZE];
private byte[] bytesToWrite = new byte[BUFFER_SIZE]; private byte[] bytesToWrite = new byte[BUFFER_SIZE];
@BeforeTest(alwaysRun = true) @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
SecureRandom.getInstance("SHA1PRNG").nextBytes(nonEncodableBytesToWrite); SecureRandom.getInstance("SHA1PRNG").nextBytes(nonEncodableBytesToWrite);
String phrase = "all work and no play make Jack a dull boy"; String phrase = "all work and no play make Jack a dull boy";

View File

@ -26,8 +26,8 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs; import org.apache.lucene.index.TermDocs;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.common.lucene.DocumentBuilder.*;
@ -44,7 +44,7 @@ public class VersionedIndexReaderTests {
private IndexWriter indexWriter; private IndexWriter indexWriter;
private VersionedMap versionedMap; private VersionedMap versionedMap;
@BeforeTest public void setUp() throws Exception { @BeforeClass public void setUp() throws Exception {
versionedMap = new ConcurrentVersionedMapLong(); versionedMap = new ConcurrentVersionedMapLong();
dir = new RAMDirectory(); dir = new RAMDirectory();
indexWriter = new IndexWriter(dir, Lucene.STANDARD_ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED); indexWriter = new IndexWriter(dir, Lucene.STANDARD_ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED);
@ -56,7 +56,7 @@ public class VersionedIndexReaderTests {
indexReader = IndexReader.open(dir, true); indexReader = IndexReader.open(dir, true);
} }
@AfterTest public void tearDown() throws Exception { @AfterClass public void tearDown() throws Exception {
indexWriter.close(); indexWriter.close();
indexReader.close(); indexReader.close();
dir.close(); dir.close();

View File

@ -24,8 +24,8 @@ import org.apache.lucene.store.RAMDirectory;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.elasticsearch.common.lucene.Directories.*; import static org.elasticsearch.common.lucene.Directories.*;
@ -47,13 +47,13 @@ public class SnapshotDeletionPolicyTests {
private SnapshotDeletionPolicy deletionPolicy; private SnapshotDeletionPolicy deletionPolicy;
private IndexWriter indexWriter; private IndexWriter indexWriter;
@BeforeTest public void setUp() throws Exception { @BeforeClass public void setUp() throws Exception {
dir = new RAMDirectory(); dir = new RAMDirectory();
deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastDeletionPolicy(shardId, EMPTY_SETTINGS)); deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastDeletionPolicy(shardId, EMPTY_SETTINGS));
indexWriter = new IndexWriter(dir, Lucene.STANDARD_ANALYZER, true, deletionPolicy, IndexWriter.MaxFieldLength.UNLIMITED); indexWriter = new IndexWriter(dir, Lucene.STANDARD_ANALYZER, true, deletionPolicy, IndexWriter.MaxFieldLength.UNLIMITED);
} }
@AfterTest public void tearDown() throws Exception { @AfterClass public void tearDown() throws Exception {
indexWriter.close(); indexWriter.close();
dir.close(); dir.close();
} }

View File

@ -38,7 +38,7 @@ import org.elasticsearch.index.settings.IndexSettingsModule;
import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.index.similarity.SimilarityModule;
import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.threadpool.ThreadPoolModule; import org.elasticsearch.threadpool.ThreadPoolModule;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*;
@ -53,7 +53,7 @@ public class PercolatorExecutorTests {
private PercolatorExecutor percolatorExecutor; private PercolatorExecutor percolatorExecutor;
@BeforeTest public void buildPercolatorService() { @BeforeClass public void buildPercolatorService() {
Settings settings = ImmutableSettings.settingsBuilder() Settings settings = ImmutableSettings.settingsBuilder()
.put("index.cache.filter.type", "none") .put("index.cache.filter.type", "none")
.build(); .build();

View File

@ -22,7 +22,7 @@ package org.elasticsearch.index.translog.fs;
import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.index.translog.AbstractSimpleTranslogTests; import org.elasticsearch.index.translog.AbstractSimpleTranslogTests;
import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.Translog;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterClass;
import java.io.File; import java.io.File;
@ -37,7 +37,7 @@ public class FsChannelSimpleTranslogTests extends AbstractSimpleTranslogTests {
return new FsTranslog(shardId, EMPTY_SETTINGS, new File("work/fs-translog"), false); return new FsTranslog(shardId, EMPTY_SETTINGS, new File("work/fs-translog"), false);
} }
@AfterTest public void cleanup() { @AfterClass public void cleanup() {
FileSystemUtils.deleteRecursively(new File("work/fs-translog"), true); FileSystemUtils.deleteRecursively(new File("work/fs-translog"), true);
} }
} }

View File

@ -22,7 +22,7 @@ package org.elasticsearch.index.translog.fs;
import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.index.translog.AbstractSimpleTranslogTests; import org.elasticsearch.index.translog.AbstractSimpleTranslogTests;
import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.Translog;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterClass;
import java.io.File; import java.io.File;
@ -37,7 +37,7 @@ public class FsStreamSimpleTranslogTests extends AbstractSimpleTranslogTests {
return new FsTranslog(shardId, EMPTY_SETTINGS, new File("work/fs-translog"), true); return new FsTranslog(shardId, EMPTY_SETTINGS, new File("work/fs-translog"), true);
} }
@AfterTest public void cleanup() { @AfterClass public void cleanup() {
FileSystemUtils.deleteRecursively(new File("work/fs-translog"), true); FileSystemUtils.deleteRecursively(new File("work/fs-translog"), true);
} }
} }

View File

@ -23,7 +23,7 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.integration.AbstractNodesTests; import org.elasticsearch.test.integration.AbstractNodesTests;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.MatcherAssert.*;
@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.*;
@Test @Test
public class DiscoveryTests extends AbstractNodesTests { public class DiscoveryTests extends AbstractNodesTests {
@AfterTest public void closeNodes() { @AfterClass public void closeNodes() {
closeAllNodes(); closeAllNodes();
} }

View File

@ -23,7 +23,8 @@ import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ExecutableScript;
import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.HashMap; import java.util.HashMap;
@ -39,10 +40,14 @@ public class JavaScriptScriptEngineTests {
private JavaScriptScriptEngineService se; private JavaScriptScriptEngineService se;
@BeforeTest public void setup() { @BeforeClass public void setup() {
se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS);
} }
@AfterClass public void close() {
se.close();
}
@Test public void testSimpleEquation() { @Test public void testSimpleEquation() {
Map<String, Object> vars = new HashMap<String, Object>(); Map<String, Object> vars = new HashMap<String, Object>();
Object o = se.execute(se.compile("1 + 2"), vars); Object o = se.execute(se.compile("1 + 2"), vars);

View File

@ -23,7 +23,8 @@ import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ExecutableScript;
import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.util.HashMap; import java.util.HashMap;
@ -39,10 +40,14 @@ public class PythonScriptEngineTests {
private PythonScriptEngineService se; private PythonScriptEngineService se;
@BeforeTest public void setup() { @BeforeClass public void setup() {
se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS);
} }
@AfterClass public void close() {
se.close();
}
@Test public void testSimpleEquation() { @Test public void testSimpleEquation() {
Map<String, Object> vars = new HashMap<String, Object>(); Map<String, Object> vars = new HashMap<String, Object>();
Object o = se.execute(se.compile("1 + 2"), vars); Object o = se.execute(se.compile("1 + 2"), vars);

View File

@ -22,7 +22,7 @@ package org.elasticsearch.index.mapper.xcontent;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.analysis.AnalysisService;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.elasticsearch.common.io.Streams.*; import static org.elasticsearch.common.io.Streams.*;
@ -38,7 +38,7 @@ public class SimpleAttachmentMapperTests {
private XContentDocumentMapperParser mapperParser; private XContentDocumentMapperParser mapperParser;
@BeforeTest public void setupMapperParser() { @BeforeClass public void setupMapperParser() {
mapperParser = new XContentDocumentMapperParser(new Index("test"), new AnalysisService(new Index("test"))); mapperParser = new XContentDocumentMapperParser(new Index("test"), new AnalysisService(new Index("test")));
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
} }