From: David ‘Bombe’ Roden Date: Tue, 4 Nov 2014 18:24:46 +0000 (+0100) Subject: Load known post replies in configuration loader, too. X-Git-Tag: 0.9-rc1^2~3^2~53 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b6de5505ae5d2f835a235de6e9f23cb83affe4b7;p=Sone.git Load known post replies in configuration loader, too. --- diff --git a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java index 39f2ca1..078b5f4 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java @@ -33,4 +33,19 @@ public class ConfigurationLoader { return knownPosts; } + public synchronized Set loadKnownPostReplies() { + Set knownPostReplies = new HashSet(); + int replyCounter = 0; + while (true) { + String knownReplyId = configuration + .getStringValue("KnownReplies/" + replyCounter++ + "/ID") + .getValue(null); + if (knownReplyId == null) { + break; + } + knownPostReplies.add(knownReplyId); + } + return knownPostReplies; + } + } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 7640f61..3c5ef55 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -782,16 +782,11 @@ public class MemoryDatabase extends AbstractService implements Database { /** Loads the known post replies. */ private void loadKnownPostReplies() { + Set knownPostReplies = configurationLoader.loadKnownPostReplies(); lock.writeLock().lock(); try { - int replyCounter = 0; - while (true) { - String knownReplyId = configuration.getStringValue("KnownReplies/" + replyCounter++ + "/ID").getValue(null); - if (knownReplyId == null) { - break; - } - knownPostReplies.add(knownReplyId); - } + this.knownPostReplies.clear(); + this.knownPostReplies.addAll(knownPostReplies); } finally { lock.writeLock().unlock(); } diff --git a/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java b/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java index 6449b43..82d465b 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java @@ -35,4 +35,17 @@ public class ConfigurationLoaderTest { assertThat(knownPosts, containsInAnyOrder("Post1", "Post2")); } + @Test + public void loaderCanLoadKnownPostReplies() { + when(configuration.getStringValue("KnownReplies/0/ID")) + .thenReturn(new TestValue("PostReply2")); + when(configuration.getStringValue("KnownReplies/1/ID")) + .thenReturn(new TestValue("PostReply1")); + when(configuration.getStringValue("KnownReplies/2/ID")) + .thenReturn(new TestValue(null)); + Set knownPosts = configurationLoader.loadKnownPostReplies(); + assertThat(knownPosts, + containsInAnyOrder("PostReply1", "PostReply2")); + } + }