Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that failed place startups don't block server startup unless the server is configured to do so #622

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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