You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2019/03/11 16:48:14 UTC

[james-project] 01/05: JAMES-2675 Index all messages from a range, not only the first one

This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch 3.3.x
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e8a4ed872f772cf366b8043fba9e56532de0ac67
Author: Raphael Ouazana <ra...@linagora.com>
AuthorDate: Mon Mar 4 15:41:21 2019 +0100

    JAMES-2675 Index all messages from a range, not only the first one
---
 .../store/search/ListeningMessageSearchIndex.java  |  6 ++--
 .../cucumber/CassandraIMAPInconsistenciesTest.java | 36 ++++++++++++++++++++++
 .../methods/integration/cucumber/ImapStepdefs.java |  7 +++++
 .../resources/cucumber/ImapConsistency.feature     | 36 ++++++++++++++++++++++
 .../cucumber/MemoryIMAPInconsistenciesTest.java    | 33 ++++++++++++++++++++
 .../cucumber/RabbitMQIMAPInconsistenciesTest.java  | 36 ++++++++++++++++++++++
 .../org/apache/james/utils/IMAPMessageReader.java  |  5 +++
 7 files changed, 156 insertions(+), 3 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index 53d9ac7..2c351e0 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.store.SessionProvider;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.util.streams.Iterators;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -96,9 +97,8 @@ public abstract class ListeningMessageSearchIndex implements MessageSearchIndex,
 
     private Stream<MailboxMessage> retrieveMailboxMessages(MailboxSession session, Mailbox mailbox, MessageRange range) {
         try {
-            return Stream.of(factory.getMessageMapper(session)
-                .findInMailbox(mailbox, range, FetchType.Full, UNLIMITED)
-                .next());
+            return Iterators.toStream(factory.getMessageMapper(session)
+                    .findInMailbox(mailbox, range, FetchType.Full, UNLIMITED));
         } catch (Exception e) {
             LOGGER.error("Could not retrieve message {} in mailbox {}", range.toString(), mailbox.getMailboxId().serialize(), e);
             return Stream.empty();
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPInconsistenciesTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPInconsistenciesTest.java
new file mode 100644
index 0000000..740ab2b
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraIMAPInconsistenciesTest.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.cassandra.cucumber;
+
+import org.apache.james.jmap.categories.EnableCucumber;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features = "classpath:cucumber/ImapConsistency.feature",
+    glue = {"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"},
+    tags = {"not @Ignore", "@BasicFeature"},
+    strict = true)
+@Category(EnableCucumber.class)
+public class CassandraIMAPInconsistenciesTest {
+}
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
index b09b4d8..03194d0 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/ImapStepdefs.java
@@ -122,6 +122,13 @@ public class ImapStepdefs {
         mainStepdefs.awaitMethod.run();
     }
 
+    @Then("^the user copies via IMAP all messages from mailbox \"([^\"]*)\" to mailbox \"([^\"]*)\"$")
+    public void copyAllMessagesViaIMAPInMailbox(String sourceMailbox, String destinationMailbox) throws Throwable {
+        IMAPMessageReader imapMessageReader = imapConnections.get(sourceMailbox);
+        imapMessageReader.copyAllMessagesInMailboxTo(destinationMailbox);
+        mainStepdefs.awaitMethod.run();
+    }
+
     @Then("^the user has a IMAP RECENT and a notification about (\\d+) new messages on connection for mailbox \"([^\"]*)\"$")
     public void checkNotificationForNewMessageOnActiveConnection(int numberOfMessages, String mailbox) throws Throwable {
         IMAPMessageReader imapMessageReader = imapConnections.get(mailbox);
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapConsistency.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapConsistency.feature
new file mode 100644
index 0000000..4354208
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/ImapConsistency.feature
@@ -0,0 +1,36 @@
+#***************************************************************
+# Licensed to the Apache Software Foundation (ASF) under one   *
+# or more contributor license agreements.  See the NOTICE file *
+# distributed with this work for additional information        *
+# regarding copyright ownership.  The ASF licenses this file   *
+# to you under the Apache License, Version 2.0 (the            *
+# "License"); you may not use this file except in compliance   *
+# with the License.  You may obtain a copy of the License at   *
+#                                                              *
+#   http://www.apache.org/licenses/LICENSE-2.0                 *
+#                                                              *
+# Unless required by applicable law or agreed to in writing,   *
+# software distributed under the License is distributed on an  *
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+# KIND, either express or implied.  See the License for the    *
+# specific language governing permissions and limitations      *
+# under the License.                                           *
+# **************************************************************/
+Feature: Impact of IMAP on JMAP consistency
+
+  Background:
+    Given a domain named "domain.tld"
+    And a connected user "username@domain.tld"
+    And "username@domain.tld" has a mailbox "source"
+    And "username@domain.tld" has a mailbox "trash"
+
+  @BasicFeature
+  Scenario: Two messages copied in one step via IMAP should be seen via JMAP
+    Given the user has a message "m1" in "source" mailbox with subject "My awesome subject 1", content "This is the content 1"
+    And the user has a message "m2" in "source" mailbox with subject "My awesome subject 2", content "This is the content 2"
+    And the user has an open IMAP connection with mailbox "source" selected
+    And the user copies via IMAP all messages from mailbox "source" to mailbox "trash"
+    When "username@domain.tld" asks for message list in mailbox "trash"
+    Then the message list has size 2
+    And the message list contains "m1"
+    And the message list contains "m2"
\ No newline at end of file
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPInconsistenciesTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPInconsistenciesTest.java
new file mode 100644
index 0000000..3ff06e2
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryIMAPInconsistenciesTest.java
@@ -0,0 +1,33 @@
+/****************************************************************
+
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.memory.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features = "classpath:cucumber/ImapConsistency.feature",
+    glue = {"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"},
+    strict = true)
+public class MemoryIMAPInconsistenciesTest {
+}
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQIMAPInconsistenciesTest.java b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQIMAPInconsistenciesTest.java
new file mode 100644
index 0000000..5aec9d3
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQIMAPInconsistenciesTest.java
@@ -0,0 +1,36 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.rabbitmq.cucumber;
+
+import org.apache.james.jmap.categories.EnableCucumber;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber;
+
+@RunWith(Cucumber.class)
+@CucumberOptions(features = "classpath:cucumber/ImapConsistency.feature",
+    glue = {"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.rabbitmq.cucumber"},
+    tags = {"not @Ignore", "@BasicFeature"},
+    strict = true)
+@Category(EnableCucumber.class)
+public class RabbitMQIMAPInconsistenciesTest {
+}
diff --git a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
index 7e80983..80d2786 100644
--- a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
+++ b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
@@ -142,6 +142,11 @@ public class IMAPMessageReader extends ExternalResource implements Closeable, Af
         return imapClient.getReplyString();
     }
 
+    public String copyAllMessagesInMailboxTo(String mailboxName) throws IOException {
+        imapClient.copy("1:*", mailboxName);
+        return imapClient.getReplyString();
+    }
+
     private String readFirstMessageInMailbox(String parameters) throws IOException {
         imapClient.fetch("1:1", parameters);
         return imapClient.getReplyString();


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