Skip to content

Commit 2ff12ce

Browse files
author
duke
committed
Added webrev for skara/1343
1 parent 6ceb278 commit 2ff12ce

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

skara/1343/00/commits.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"commit":{"message":"SKARA-1513"},"files":[{"filename":"mailinglist\/src\/main\/java\/org\/openjdk\/skara\/mailinglist\/mailman\/MailmanListReader.java"},{"filename":"mailinglist\/src\/test\/java\/org\/openjdk\/skara\/mailinglist\/MailmanTests.java"},{"filename":"test\/src\/main\/java\/org\/openjdk\/skara\/test\/TestMailmanServer.java"}],"sha":"c0073c9c7a5d4573273ea0448c2fbd980f04a497"}]

skara/1343/00/comparison.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"files":[{"patch":"@@ -99,0 +99,1 @@\n+ pageCache.put(uri, response);\n@@ -118,4 +119,1 @@\n- var useCached = new HashMap<String, Boolean>();\n- for (var name : names) {\n- useCached.put(name, false);\n- }\n+ var monthCount = 0;\n@@ -129,1 +127,2 @@\n- if (useCached.get(name)) {\n+ \/\/ For archives older than the previous month, always use cached results\n+ if (monthCount > 1 && pageCache.containsKey(mboxUri)) {\n@@ -131,1 +130,1 @@\n- if (cachedResponse != null) {\n+ if (cachedResponse != null && cachedResponse.statusCode() != 404) {\n@@ -139,1 +138,0 @@\n- useCached.put(name, true);\n@@ -147,0 +145,1 @@\n+ monthCount++;\n","filename":"mailinglist\/src\/main\/java\/org\/openjdk\/skara\/mailinglist\/mailman\/MailmanListReader.java","additions":6,"deletions":7,"binary":false,"changes":13,"status":"modified"},{"patch":"@@ -25,0 +25,1 @@\n+import java.time.ZonedDateTime;\n@@ -171,0 +172,83 @@\n+\n+ @Test\n+ void poll3months() throws Exception {\n+ try (var testServer = new TestMailmanServer()) {\n+ var listAddress = testServer.createList(\"test\");\n+ var mailmanServer = MailingListServerFactory.createMailmanServer(testServer.getArchive(),\n+ testServer.getSMTP(), Duration.ZERO);\n+ var mailmanList = mailmanServer.getListReader(listAddress);\n+ var sender = EmailAddress.from(\"Test\", \"[email protected]\");\n+ var now = ZonedDateTime.now();\n+ var mail2monthsAgo = Email.create(sender, \"Subject 2 months ago\", \"Body 1\")\n+ .recipient(EmailAddress.parse(listAddress))\n+ .date(now.minusMonths(2))\n+ .build();\n+ var mail1monthAgo = Email.create(sender, \"Subject 1 month ago\", \"Body 2\")\n+ .recipient(EmailAddress.parse(listAddress))\n+ .date(now.minusMonths(1))\n+ .build();\n+ var mailNow = Email.create(sender, \"Subject now\", \"Body 3\")\n+ .recipient(EmailAddress.parse(listAddress))\n+ .build();\n+\n+ var duration2Months = Duration.between(now.minusMonths(2), now);\n+ {\n+ var conversations = mailmanList.conversations(duration2Months);\n+ assertEquals(0, conversations.size());\n+ assertEquals(3, testServer.callCount(), \"Server wasn't called for every month\");\n+ }\n+ {\n+ \/\/ A 2 months old mail should not be picked up now as old results should be cached\n+ mailmanServer.post(mail2monthsAgo);\n+ testServer.processIncoming();\n+ testServer.resetCallCount();\n+ var conversations = mailmanList.conversations(duration2Months);\n+ assertEquals(0, conversations.size());\n+ \/\/\n+ assertEquals(2, testServer.callCount(), \"Server should only be called for the current and previous month\");\n+ }\n+ {\n+ \/\/ A mail from last month should be found\n+ mailmanServer.post(mail1monthAgo);\n+ testServer.processIncoming();\n+ testServer.resetCallCount();\n+ var conversations = mailmanList.conversations(duration2Months);\n+ assertEquals(1, conversations.size());\n+ assertEquals(2, testServer.callCount());\n+ }\n+ {\n+ \/\/ A current mail should be found\n+ mailmanServer.post(mailNow);\n+ testServer.processIncoming();\n+ testServer.resetCallCount();\n+ var conversations = mailmanList.conversations(duration2Months);\n+ assertEquals(2, conversations.size());\n+ assertEquals(2, testServer.callCount());\n+ }\n+ {\n+ \/\/ Another mail from last month should be found\n+ var mail1monthAgo2 = Email.create(sender, \"Subject 1 month ago 2\", \"Body 2\")\n+ .recipient(EmailAddress.parse(listAddress))\n+ .date(now.minusMonths(1))\n+ .build();\n+ mailmanServer.post(mail1monthAgo2);\n+ testServer.processIncoming();\n+ testServer.resetCallCount();\n+ var conversations = mailmanList.conversations(duration2Months);\n+ assertEquals(3, conversations.size());\n+ assertEquals(2, testServer.callCount());\n+ }\n+ {\n+ \/\/ Another current mail should be found\n+ var mailNow2 = Email.create(sender, \"Subject now 2\", \"Body 3\")\n+ .recipient(EmailAddress.parse(listAddress))\n+ .build();\n+ mailmanServer.post(mailNow2);\n+ testServer.processIncoming();\n+ testServer.resetCallCount();\n+ var conversations = mailmanList.conversations(duration2Months);\n+ assertEquals(4, conversations.size());\n+ assertEquals(2, testServer.callCount());\n+ }\n+ }\n+ }\n","filename":"mailinglist\/src\/test\/java\/org\/openjdk\/skara\/mailinglist\/MailmanTests.java","additions":84,"deletions":0,"binary":false,"changes":84,"status":"modified"},{"patch":"@@ -26,0 +26,1 @@\n+import java.time.format.DateTimeFormatter;\n@@ -33,1 +34,0 @@\n-import java.nio.file.*;\n@@ -42,1 +42,3 @@\n- private final Map<String, Path> lists = new HashMap<>();\n+ private final Map<String, HashMap<String, StringBuilder>> lists = new HashMap<>();\n+\n+ private int callCount = 0;\n@@ -46,1 +48,1 @@\n- static private final Pattern listPathPattern = Pattern.compile(\"^\/test\/(.*?)\/.*\");\n+ static private final Pattern listPathPattern = Pattern.compile(\"^\/test\/(.*?)\/(.*)\\\\.txt\");\n@@ -51,0 +53,1 @@\n+ callCount++;\n@@ -55,2 +58,9 @@\n- var list = lists.get(listMatcher.group(1));\n- var response = Files.readString(list);\n+ var listPath = listMatcher.group(1);\n+ var datePath = listMatcher.group(2);\n+ var listMap = lists.get(listPath);\n+ if (!listMap.containsKey(datePath)) {\n+ exchange.sendResponseHeaders(404, 0);\n+ exchange.close();\n+ return;\n+ }\n+ var response = listMap.get(datePath).toString();\n@@ -105,2 +115,1 @@\n- var listPath = Files.createTempFile(\"list-\" + name, \".txt\");\n- lists.put(name, listPath);\n+ lists.put(name, new HashMap<>());\n@@ -121,1 +130,1 @@\n- var listPath = email.recipients().stream()\n+ var listMap = email.recipients().stream()\n@@ -125,1 +134,5 @@\n- Files.writeString(listPath, mboxEntry, StandardOpenOption.CREATE, StandardOpenOption.APPEND);\n+ var datePath = DateTimeFormatter.ofPattern(\"yyyy-MMMM\", Locale.US).format(email.date());\n+ if (!listMap.containsKey(datePath)) {\n+ listMap.put(datePath, new StringBuilder());\n+ }\n+ listMap.get(datePath).append(mboxEntry);\n@@ -141,0 +154,8 @@\n+\n+ public void resetCallCount() {\n+ callCount = 0;\n+ }\n+\n+ public int callCount() {\n+ return callCount;\n+ }\n","filename":"test\/src\/main\/java\/org\/openjdk\/skara\/test\/TestMailmanServer.java","additions":30,"deletions":9,"binary":false,"changes":39,"status":"modified"}]}

skara/1343/00/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"head":{"repo":{"full_name":"erikj79\/skara","html_url":"https:\/\/github.com\/erikj79\/skara"},"sha":"c0073c9c7a5d4573273ea0448c2fbd980f04a497"},"created_at":"2022-07-29T17:35:55.282959704Z","base":{"repo":{"full_name":"openjdk\/skara","html_url":"https:\/\/git.openjdk.org\/skara"},"sha":"af100a5f86c23d3b75e5f674d3b294d3d6edfa12"}}

0 commit comments

Comments
 (0)