james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1688134 - in /james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch: ElasticSearchIndexerTest.java ElasticSearchIntegrationTest.java EmbeddedElasticSearch.java
Date Mon, 29 Jun 2015 08:36:32 GMT
Author: btellier
Date: Mon Jun 29 08:36:31 2015
New Revision: 1688134

URL: http://svn.apache.org/r1688134
Log:
MAILBOX-235 Adding full mail search support

Modified:
    james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
    james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
    james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/EmbeddedElasticSearch.java

Modified: james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java?rev=1688134&r1=1688133&r2=1688134&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
(original)
+++ james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
Mon Jun 29 08:36:31 2015
@@ -27,37 +27,36 @@ import org.elasticsearch.action.search.S
 import org.elasticsearch.client.Client;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.node.Node;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
 
 public class ElasticSearchIndexerTest {
 
-    @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
+    
+    @Rule
+    public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
     
     private Node node;
     private ElasticSearchIndexer testee;
 
     @Before
     public void setup() throws IOException {
-        node = EmbeddedElasticSearch.provideNode(temporaryFolder);
+        node = embeddedElasticSearch.getNode();
         testee = new ElasticSearchIndexer(node);
     }
     
-    @After
-    public void tearDown() {
-        EmbeddedElasticSearch.shutDown(node);
-    }
-    
     @Test
     public void indexMessageShouldWork() throws Exception {
         String messageId = "1";
         String content = "{\"message\": \"trying out Elasticsearch\"}";
         
         testee.indexMessage(messageId, content);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
             SearchResponse searchResponse = client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)
@@ -79,10 +78,10 @@ public class ElasticSearchIndexerTest {
         String content = "{\"message\": \"trying out Elasticsearch\",\"field\":\"Should be
unchanged\"}";
 
         testee.indexMessage(messageId, content);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
 
         testee.updateMessage(messageId, "{\"message\": \"mastering out Elasticsearch\"}");
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
 
         try (Client client = node.client()) {
             SearchResponse searchResponse = client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)
@@ -107,7 +106,7 @@ public class ElasticSearchIndexerTest {
         String content = "{\"message\": \"trying out Elasticsearch\"}";
 
         testee.indexMessage(messageId, content);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
 
         testee.updateMessage("1", null);
     }
@@ -118,10 +117,10 @@ public class ElasticSearchIndexerTest {
         String content = "{\"message\": \"trying out Elasticsearch\"}";
 
         testee.indexMessage(messageId, content);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         testee.deleteAllWithIdStarting("1:");
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
             SearchResponse searchResponse = client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)
@@ -138,22 +137,22 @@ public class ElasticSearchIndexerTest {
         String content = "{\"message\": \"trying out Elasticsearch\"}";
         
         testee.indexMessage(messageId, content);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         String messageId2 = "1:2";
         String content2 = "{\"message\": \"trying out Elasticsearch 2\"}";
         
         testee.indexMessage(messageId2, content2);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         String messageId3 = "2:3";
         String content3 = "{\"message\": \"trying out Elasticsearch 3\"}";
         
         testee.indexMessage(messageId3, content3);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         testee.deleteAllWithIdStarting("1:");
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
             SearchResponse searchResponse = client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)
@@ -170,10 +169,10 @@ public class ElasticSearchIndexerTest {
         String content = "{\"message\": \"trying out Elasticsearch\"}";
 
         testee.indexMessage(messageId, content);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
 
         testee.deleteMessage(messageId);
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
         
         try (Client client = node.client()) {
             SearchResponse searchResponse = client.prepareSearch(ElasticSearchIndexer.MAILBOX_INDEX)

Modified: james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java?rev=1688134&r1=1688133&r2=1688134&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
(original)
+++ james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
Mon Jun 29 08:36:31 2015
@@ -45,11 +45,11 @@ import org.apache.james.mailbox.store.St
 import org.apache.james.mailbox.store.StoreMessageManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.elasticsearch.node.Node;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,14 +60,17 @@ public class ElasticSearchIntegrationTes
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchIntegrationTest.class);
 
-    private static Node node;
-    private static StoreMailboxManager<InMemoryId> storeMailboxManager;
-    private static ElasticSearchListeningMessageSearchIndex elasticSearchListeningMessageSearchIndex;
-    private static Mailbox mailbox;
-    private static SimpleDateFormat format;
-    private static MailboxSession session;
+    private TemporaryFolder temporaryFolder = new TemporaryFolder();
+    private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
 
-    @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+    @Rule
+    public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
+    
+    private StoreMailboxManager<InMemoryId> storeMailboxManager;
+    private ElasticSearchListeningMessageSearchIndex<InMemoryId> elasticSearchListeningMessageSearchIndex;
+    private Mailbox<InMemoryId> mailbox;
+    private SimpleDateFormat format;
+    private MailboxSession session;
 
     @Before
     @SuppressWarnings("unchecked")
@@ -146,17 +149,17 @@ public class ElasticSearchIntegrationTes
             true,
             new Flags("Hello you"));
 
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+        embeddedElasticSearch.awaitForElasticSearch();
     }
 
     private void initializeMailboxManager() throws Exception {
-        node = NodeMappingFactory.applyMapping(
+        Node node = NodeMappingFactory.applyMapping(
             IndexCreationFactory.createIndex(
-                EmbeddedElasticSearch.provideNode(temporaryFolder)
+                embeddedElasticSearch.getNode()
             )
         );
         MailboxSessionMapperFactory<InMemoryId> mapperFactory = new InMemoryMailboxSessionMapperFactory();
-        elasticSearchListeningMessageSearchIndex = new ElasticSearchListeningMessageSearchIndex(mapperFactory,
+        elasticSearchListeningMessageSearchIndex = new ElasticSearchListeningMessageSearchIndex<InMemoryId>(mapperFactory,
             new ElasticSearchIndexer(node),
             new ElasticSearchSearcher<InMemoryId>(node, new QueryConverter(new CriterionConverter())),
             new MessageToElasticSearchJson());
@@ -170,11 +173,6 @@ public class ElasticSearchIntegrationTes
         storeMailboxManager.init();
     }
 
-    @After
-    public void cleanUp() {
-        EmbeddedElasticSearch.shutDown(node);
-    }
-
     @Test
     public void allShouldReturnAllUids() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();

Modified: james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/EmbeddedElasticSearch.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/EmbeddedElasticSearch.java?rev=1688134&r1=1688133&r2=1688134&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/EmbeddedElasticSearch.java
(original)
+++ james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/EmbeddedElasticSearch.java
Mon Jun 29 08:36:31 2015
@@ -19,44 +19,70 @@
 
 package org.apache.james.mailbox.elasticsearch;
 
-
-
 import static com.jayway.awaitility.Awaitility.await;
 import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
 
 import java.io.IOException;
+import java.nio.file.Path;
+import java.util.function.Supplier;
 
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
 import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.node.Node;
+import org.junit.rules.ExternalResource;
 import org.junit.rules.TemporaryFolder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Throwables;
 import com.jayway.awaitility.Duration;
 
-public class EmbeddedElasticSearch {
+public class EmbeddedElasticSearch extends ExternalResource {
 
     private static Logger LOGGER = LoggerFactory.getLogger(EmbeddedElasticSearch.class);
 
-    public static Node provideNode(TemporaryFolder temporaryFolder) throws IOException {
-        Node node = nodeBuilder().local(true)
+    private final Supplier<Path> folder;
+    private Node node;
+
+    private static Path createTempDir(TemporaryFolder temporaryFolder) {
+        try {
+            return temporaryFolder.newFolder().toPath();
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
+    }
+    
+    public EmbeddedElasticSearch(TemporaryFolder temporaryFolder) {
+        this(() -> EmbeddedElasticSearch.createTempDir(temporaryFolder));
+    }
+    
+    public EmbeddedElasticSearch(Path folder) {
+        this(() -> folder);
+    }
+    
+    private EmbeddedElasticSearch(Supplier<Path> folder) {
+        this.folder = folder;
+    }
+    
+    @Override
+    public void before() throws IOException {
+        node = nodeBuilder().local(true)
             .settings(ImmutableSettings.builder()
-                .put("path.data", temporaryFolder.newFolder().getAbsolutePath())
+                .put("path.data", folder.get().toAbsolutePath())
+                .put("script.disable_dynamic",true)
                 .build())
             .node();
         node.start();
-        awaitForElasticSearch(node);
-        return node;
+        awaitForElasticSearch();
     }
 
-    public static void shutDown(Node node) {
-        EmbeddedElasticSearch.awaitForElasticSearch(node);
+    @Override
+    public void after() {
+        awaitForElasticSearch();
         try (Client client = node.client()) {
-            node.client()
-                .admin()
+            client.admin()
                 .indices()
                 .delete(new DeleteIndexRequest(ElasticSearchIndexer.MAILBOX_INDEX))
                 .actionGet();
@@ -66,15 +92,19 @@ public class EmbeddedElasticSearch {
         node.close();
     }
 
+    public Node getNode() {
+        return node;
+    }
+
     /**
      * Sometimes, tests are too fast.
      * This method ensure that ElasticSearch service is up and indices are updated
      */
-    public static void awaitForElasticSearch(Node node) {
-        await().atMost(Duration.TEN_SECONDS).until(() -> flush(node));
+    public void awaitForElasticSearch() {
+        await().atMost(Duration.TEN_SECONDS).until(this::flush);
     }
 
-    private static boolean flush(Node node) {
+    private boolean flush() {
         try (Client client = node.client()) {
             new FlushRequestBuilder(client.admin().indices()).setForce(true).get();
             return true;



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message