From 3bac33e69eb8ef3e5aad1ce59c48b669d80cbfd5 Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 28 Feb 2011 22:28:55 +0200 Subject: [PATCH] don't use AfterTest / BeforeTest in any tests --- .../common/compress/lzf/LZFInputStreamTests.java | 4 ++-- .../common/compress/lzf/LZFOutputStreamTests.java | 4 ++-- .../lucene/versioned/VersionedIndexReaderTests.java | 8 ++++---- .../deletionpolicy/SnapshotDeletionPolicyTests.java | 8 ++++---- .../index/percolator/PercolatorExecutorTests.java | 4 ++-- .../index/translog/fs/FsChannelSimpleTranslogTests.java | 4 ++-- .../index/translog/fs/FsStreamSimpleTranslogTests.java | 4 ++-- .../test/integration/discovery/DiscoveryTests.java | 4 ++-- .../script/javascript/JavaScriptScriptEngineTests.java | 9 +++++++-- .../script/python/PythonScriptEngineTests.java | 9 +++++++-- .../mapper/xcontent/SimpleAttachmentMapperTests.java | 4 ++-- 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFInputStreamTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFInputStreamTests.java index 8f5a3697680..b3c95e2a6c7 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFInputStreamTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFInputStreamTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.common.compress.lzf; import org.testng.Assert; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.*; @@ -38,7 +38,7 @@ public class LZFInputStreamTests { private ByteArrayOutputStream nonCompressed; private ByteArrayOutputStream compressed; - @BeforeTest(alwaysRun = true) + @BeforeClass public void setUp() throws Exception { SecureRandom.getInstance("SHA1PRNG").nextBytes(nonEncodableBytesToWrite); String phrase = "all work and no play make Jack a dull boy"; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFOutputStreamTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFOutputStreamTests.java index 8451db30776..5fd501813ab 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFOutputStreamTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/compress/lzf/LZFOutputStreamTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.common.compress.lzf; import org.testng.Assert; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import java.io.ByteArrayOutputStream; @@ -36,7 +36,7 @@ public class LZFOutputStreamTests { private byte[] nonEncodableBytesToWrite = new byte[BUFFER_SIZE]; private byte[] bytesToWrite = new byte[BUFFER_SIZE]; - @BeforeTest(alwaysRun = true) + @BeforeClass public void setUp() throws Exception { SecureRandom.getInstance("SHA1PRNG").nextBytes(nonEncodableBytesToWrite); String phrase = "all work and no play make Jack a dull boy"; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java index c1ffc053ec6..2807fa5d2c5 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/common/lucene/versioned/VersionedIndexReaderTests.java @@ -26,8 +26,8 @@ import org.apache.lucene.index.Term; import org.apache.lucene.index.TermDocs; import org.apache.lucene.store.RAMDirectory; import org.elasticsearch.common.lucene.Lucene; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.elasticsearch.common.lucene.DocumentBuilder.*; @@ -44,7 +44,7 @@ public class VersionedIndexReaderTests { private IndexWriter indexWriter; private VersionedMap versionedMap; - @BeforeTest public void setUp() throws Exception { + @BeforeClass public void setUp() throws Exception { versionedMap = new ConcurrentVersionedMapLong(); dir = new RAMDirectory(); indexWriter = new IndexWriter(dir, Lucene.STANDARD_ANALYZER, true, IndexWriter.MaxFieldLength.UNLIMITED); @@ -56,7 +56,7 @@ public class VersionedIndexReaderTests { indexReader = IndexReader.open(dir, true); } - @AfterTest public void tearDown() throws Exception { + @AfterClass public void tearDown() throws Exception { indexWriter.close(); indexReader.close(); dir.close(); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java index 6c5bbef5219..0df27d2c3db 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java @@ -24,8 +24,8 @@ import org.apache.lucene.store.RAMDirectory; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.elasticsearch.common.lucene.Directories.*; @@ -47,13 +47,13 @@ public class SnapshotDeletionPolicyTests { private SnapshotDeletionPolicy deletionPolicy; private IndexWriter indexWriter; - @BeforeTest public void setUp() throws Exception { + @BeforeClass public void setUp() throws Exception { dir = new RAMDirectory(); deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastDeletionPolicy(shardId, EMPTY_SETTINGS)); 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(); dir.close(); } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/percolator/PercolatorExecutorTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/percolator/PercolatorExecutorTests.java index b939f24dda8..523c70f986e 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/percolator/PercolatorExecutorTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/percolator/PercolatorExecutorTests.java @@ -38,7 +38,7 @@ import org.elasticsearch.index.settings.IndexSettingsModule; import org.elasticsearch.index.similarity.SimilarityModule; import org.elasticsearch.script.ScriptModule; import org.elasticsearch.threadpool.ThreadPoolModule; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.elasticsearch.index.query.xcontent.QueryBuilders.*; @@ -53,7 +53,7 @@ public class PercolatorExecutorTests { private PercolatorExecutor percolatorExecutor; - @BeforeTest public void buildPercolatorService() { + @BeforeClass public void buildPercolatorService() { Settings settings = ImmutableSettings.settingsBuilder() .put("index.cache.filter.type", "none") .build(); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsChannelSimpleTranslogTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsChannelSimpleTranslogTests.java index 0c01c759600..457a7628239 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsChannelSimpleTranslogTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsChannelSimpleTranslogTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.index.translog.fs; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.index.translog.AbstractSimpleTranslogTests; import org.elasticsearch.index.translog.Translog; -import org.testng.annotations.AfterTest; +import org.testng.annotations.AfterClass; 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); } - @AfterTest public void cleanup() { + @AfterClass public void cleanup() { FileSystemUtils.deleteRecursively(new File("work/fs-translog"), true); } } \ No newline at end of file diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsStreamSimpleTranslogTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsStreamSimpleTranslogTests.java index 7917477a85b..a4f01196de3 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsStreamSimpleTranslogTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/translog/fs/FsStreamSimpleTranslogTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.index.translog.fs; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.index.translog.AbstractSimpleTranslogTests; import org.elasticsearch.index.translog.Translog; -import org.testng.annotations.AfterTest; +import org.testng.annotations.AfterClass; 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); } - @AfterTest public void cleanup() { + @AfterClass public void cleanup() { FileSystemUtils.deleteRecursively(new File("work/fs-translog"), true); } } \ No newline at end of file diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/discovery/DiscoveryTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/discovery/DiscoveryTests.java index 019c44d9bc2..fb1ac1165d4 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/discovery/DiscoveryTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/discovery/DiscoveryTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.integration.AbstractNodesTests; -import org.testng.annotations.AfterTest; +import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import static org.hamcrest.MatcherAssert.*; @@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.*; @Test public class DiscoveryTests extends AbstractNodesTests { - @AfterTest public void closeNodes() { + @AfterClass public void closeNodes() { closeAllNodes(); } diff --git a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java b/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java index 2fa43c9ebb3..02a13044d7d 100644 --- a/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java +++ b/plugins/lang/javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineTests.java @@ -23,7 +23,8 @@ import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.ImmutableSettings; 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 java.util.HashMap; @@ -39,10 +40,14 @@ public class JavaScriptScriptEngineTests { private JavaScriptScriptEngineService se; - @BeforeTest public void setup() { + @BeforeClass public void setup() { se = new JavaScriptScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); } + @AfterClass public void close() { + se.close(); + } + @Test public void testSimpleEquation() { Map vars = new HashMap(); Object o = se.execute(se.compile("1 + 2"), vars); diff --git a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java b/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java index 95c4d784d6a..cd6de57beba 100644 --- a/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java +++ b/plugins/lang/python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java @@ -23,7 +23,8 @@ import org.elasticsearch.common.collect.Lists; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.ImmutableSettings; 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 java.util.HashMap; @@ -39,10 +40,14 @@ public class PythonScriptEngineTests { private PythonScriptEngineService se; - @BeforeTest public void setup() { + @BeforeClass public void setup() { se = new PythonScriptEngineService(ImmutableSettings.Builder.EMPTY_SETTINGS); } + @AfterClass public void close() { + se.close(); + } + @Test public void testSimpleEquation() { Map vars = new HashMap(); Object o = se.execute(se.compile("1 + 2"), vars); diff --git a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java index 1d2f985d971..7cad6b7095a 100644 --- a/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java +++ b/plugins/mapper/attachments/src/test/java/org/elasticsearch/index/mapper/xcontent/SimpleAttachmentMapperTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.index.mapper.xcontent; import org.apache.lucene.document.Document; import org.elasticsearch.index.Index; import org.elasticsearch.index.analysis.AnalysisService; -import org.testng.annotations.BeforeTest; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.elasticsearch.common.io.Streams.*; @@ -38,7 +38,7 @@ public class SimpleAttachmentMapperTests { private XContentDocumentMapperParser mapperParser; - @BeforeTest public void setupMapperParser() { + @BeforeClass public void setupMapperParser() { mapperParser = new XContentDocumentMapperParser(new Index("test"), new AnalysisService(new Index("test"))); mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); }