From c13889b012a50f618171599543806bde045e7860 Mon Sep 17 00:00:00 2001 From: drivenflywheel Date: Thu, 9 Nov 2023 21:47:06 +0000 Subject: [PATCH 1/2] Ensure that failed places prevent server startup only when configured to do so. --- src/main/java/emissary/admin/Startup.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/emissary/admin/Startup.java b/src/main/java/emissary/admin/Startup.java index 246406ae19..410bd389c2 100755 --- a/src/main/java/emissary/admin/Startup.java +++ b/src/main/java/emissary/admin/Startup.java @@ -515,9 +515,11 @@ public boolean verifyNoInvisiblePlacesStarted() { try { IDirectoryPlace dirPlace = DirectoryPlace.lookup(); List dirEntries = dirPlace.getEntries(); - for (DirectoryEntry currentDir : dirEntries) { - // add place names of active directories - activeDirPlaces.add(currentDir.getLocalPlace().getPlaceName()); + for (DirectoryEntry entry : dirEntries) { + // add place names of active places. getLocalPlace() returns null for any place that failed to start + if (entry.getLocalPlace() != null) { + activeDirPlaces.add(entry.getLocalPlace().getPlaceName()); + } } // remove DirectoryPlace from activeDirPlaces. DirectoryPlace is started up automatically in order to From 2a685a4ca519e539e431a5ce03d3914ad4c18c8a Mon Sep 17 00:00:00 2001 From: drivenflywheel Date: Mon, 13 Nov 2023 15:59:21 +0000 Subject: [PATCH 2/2] Add unit test for null localPlace handling --- src/test/java/emissary/admin/StartupTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/java/emissary/admin/StartupTest.java b/src/test/java/emissary/admin/StartupTest.java index b8ae96efa4..c82a756a11 100644 --- a/src/test/java/emissary/admin/StartupTest.java +++ b/src/test/java/emissary/admin/StartupTest.java @@ -1,8 +1,10 @@ package emissary.admin; import emissary.core.Namespace; +import emissary.directory.DirectoryEntry; import emissary.directory.DirectoryPlace; import emissary.directory.EmissaryNode; +import emissary.directory.IDirectoryPlace; import emissary.pickup.file.FilePickUpClient; import emissary.pickup.file.FilePickUpPlace; import emissary.place.CoordinationPlace; @@ -12,6 +14,8 @@ import emissary.util.io.ResourceReader; import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import java.io.IOException; import java.io.InputStream; @@ -22,7 +26,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; class StartupTest extends UnitTest { @Test @@ -80,6 +86,29 @@ void testInvisPlaceStart() throws IOException { dirTeardown(); } + @Test + void verifyNoInvisiblePlacesStartedHandlesNullLocalPlace() throws IOException { + // setup node, startup, and DirectoryPlace + EmissaryNode node = new EmissaryNode(); + Startup startup = new Startup(node.getNodeConfigurator(), node); + + try (MockedStatic dirPlace = Mockito.mockStatic(DirectoryPlace.class)) { + + DirectoryEntry entry = mock(DirectoryEntry.class); + when(entry.getLocalPlace()).thenReturn(null); + + List dirEntries = new ArrayList<>(); + dirEntries.add(0, entry); + + IDirectoryPlace directoryPlace = mock(IDirectoryPlace.class); + when(directoryPlace.getEntries()).thenReturn(dirEntries); + + dirPlace.when(DirectoryPlace::lookup).thenReturn(directoryPlace); + + assertTrue(startup.verifyNoInvisiblePlacesStarted()); + } + } + private DirectoryPlace master = null; private DirectoryPlace client = null;