Skip to content

Commit

Permalink
ensure that failed place startups don't prevent server startup (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
drivenflywheel authored Nov 14, 2023
1 parent 5794d03 commit 49899a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/emissary/admin/Startup.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,11 @@ public boolean verifyNoInvisiblePlacesStarted() {
try {
IDirectoryPlace dirPlace = DirectoryPlace.lookup();
List<DirectoryEntry> 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
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/emissary/admin/StartupTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<DirectoryPlace> dirPlace = Mockito.mockStatic(DirectoryPlace.class)) {

DirectoryEntry entry = mock(DirectoryEntry.class);
when(entry.getLocalPlace()).thenReturn(null);

List<DirectoryEntry> 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;

Expand Down

0 comments on commit 49899a8

Please sign in to comment.