Load known post replies in configuration loader, too.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 4 Nov 2014 18:24:46 +0000 (19:24 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 4 Nov 2014 18:24:46 +0000 (19:24 +0100)
src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
src/test/java/net/pterodactylus/sone/database/memory/ConfigurationLoaderTest.java

index 39f2ca1..078b5f4 100644 (file)
@@ -33,4 +33,19 @@ public class ConfigurationLoader {
                return knownPosts;
        }
 
+       public synchronized Set<String> loadKnownPostReplies() {
+               Set<String> knownPostReplies = new HashSet<String>();
+               int replyCounter = 0;
+               while (true) {
+                       String knownReplyId = configuration
+                                       .getStringValue("KnownReplies/" + replyCounter++ + "/ID")
+                                       .getValue(null);
+                       if (knownReplyId == null) {
+                               break;
+                       }
+                       knownPostReplies.add(knownReplyId);
+               }
+               return knownPostReplies;
+       }
+
 }
index 7640f61..3c5ef55 100644 (file)
@@ -782,16 +782,11 @@ public class MemoryDatabase extends AbstractService implements Database {
 
        /** Loads the known post replies. */
        private void loadKnownPostReplies() {
+               Set<String> 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();
                }
index 6449b43..82d465b 100644 (file)
@@ -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<String>("PostReply2"));
+               when(configuration.getStringValue("KnownReplies/1/ID"))
+                               .thenReturn(new TestValue<String>("PostReply1"));
+               when(configuration.getStringValue("KnownReplies/2/ID"))
+                               .thenReturn(new TestValue<String>(null));
+               Set<String> knownPosts = configurationLoader.loadKnownPostReplies();
+               assertThat(knownPosts,
+                               containsInAnyOrder("PostReply1", "PostReply2"));
+       }
+
 }